jdk/test/sun/management/jdp/JdpTest.sh
changeset 15531 071efc9f31ad
child 15642 5d93957f4749
equal deleted inserted replaced
15530:d918415aea3f 15531:071efc9f31ad
       
     1 #!/bin/sh
       
     2 
       
     3 # Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
       
     4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     5 # 
       
     6 # This code is free software; you can redistribute it and/or modify it
       
     7 # under the terms of the GNU General Public License version 2 only, as
       
     8 # published by the Free Software Foundation.
       
     9 # 
       
    10 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13 # version 2 for more details (a copy is included in the LICENSE file that
       
    14 # accompanied this code).
       
    15 # 
       
    16 # You should have received a copy of the GNU General Public License version
       
    17 # 2 along with this work; if not, write to the Free Software Foundation,
       
    18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19 #
       
    20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21 # or visit www.oracle.com if you need additional information or have any
       
    22 # questions.
       
    23 
       
    24 # @test
       
    25 # @bug 7169888 
       
    26 # @build JdpUnitTest JdpClient JdpDoSomething 
       
    27 # @run shell JdpTest.sh --jtreg --no-compile
       
    28 # @summary No word Failed expected in the test output
       
    29 
       
    30 _verbose=no
       
    31 _jtreg=no
       
    32 _compile=yes
       
    33 
       
    34 # temporary disable jcmd related tests
       
    35 # _testsuite="01,02,03,04,05"
       
    36 _testsuite="01,02,04"
       
    37 
       
    38 _pwd=`pwd`
       
    39 
       
    40 _testclasses=".classes"
       
    41 _testsrc="${_pwd}"
       
    42 _lockFileName="JdpDoSomething.lck"
       
    43 
       
    44 _logname=".classes/output.txt"
       
    45 _last_pid=""
       
    46 
       
    47 
       
    48 _compile(){
       
    49 
       
    50     if [ ! -e ${_testclasses} ]
       
    51     then
       
    52 	  mkdir -p ${_testclasses}
       
    53     fi   
       
    54 
       
    55     rm -f ${_testclasses}/*.class
       
    56 
       
    57     # Compile testcase
       
    58     ${TESTJAVA}/bin/javac -d ${_testclasses} JdpUnitTest.java \
       
    59                                              JdpDoSomething.java  \
       
    60                                              JdpClient.java
       
    61 
       
    62    
       
    63     if [ ! -e ${_testclasses}/JdpDoSomething.class -o ! -e ${_testclasses}/JdpClient.class -o ! -e ${_testclasses}/JdpUnitTest.class ]
       
    64     then
       
    65       echo "ERROR: Can't compile"
       
    66       exit -1
       
    67     fi
       
    68 }
       
    69 
       
    70 
       
    71 _app_start(){
       
    72 
       
    73   testappname=$1
       
    74   shift
       
    75 
       
    76   ${TESTJAVA}/bin/java -server $* -cp ${_testclasses} ${testappname}  >> ${_logname} 2>&1 &
       
    77  _last_pid=$!
       
    78 
       
    79   npid=`_get_pid`
       
    80   if [ "${npid}" = "" ]
       
    81   then
       
    82      echo "ERROR: Test app not started"
       
    83      if [ "${_jtreg}" = "yes" ]
       
    84      then
       
    85        exit -1
       
    86      fi
       
    87   fi
       
    88 }
       
    89 
       
    90 _get_pid(){
       
    91     ${TESTJAVA}/bin/jps | sed -n "/Jdp/s/ .*//p"
       
    92 }
       
    93 
       
    94 _app_stop(){
       
    95    rm ${_lockFileName}
       
    96 
       
    97 # wait until VM is actually shuts down
       
    98   while true 
       
    99   do
       
   100     npid=`_get_pid`
       
   101     if [ "${npid}" = "" ] 
       
   102     then
       
   103       break
       
   104     fi
       
   105     sleep 1
       
   106   done 
       
   107 }
       
   108    
       
   109 _testme(){
       
   110   ${TESTJAVA}/bin/java \
       
   111   -cp ${_testclasses} \
       
   112   $* \
       
   113     -Dcom.sun.management.jdp.port=7095 \
       
   114     -Dcom.sun.management.jdp.address=239.255.255.225 \
       
   115   JdpClient 
       
   116 
       
   117 }   
       
   118 
       
   119 
       
   120 _jcmd(){
       
   121     ${TESTJAVA}/bin/jcmd JdpDoSomething $* > /dev/null 2>/dev/null
       
   122 } 
       
   123 
       
   124 
       
   125 _echo(){
       
   126     echo "$*"
       
   127     echo "$*" >> ${_logname}
       
   128 }
       
   129    
       
   130 # ============= TESTS ======================================
       
   131    
       
   132 test_01(){
       
   133 		
       
   134     _echo "**** Test one ****"		
       
   135 
       
   136     _app_start JdpUnitTest \
       
   137     -Dcom.sun.management.jdp.port=7095 \
       
   138     -Dcom.sun.management.jdp.address=239.255.255.225 \
       
   139     -Dcom.sun.management.jdp.pause=5
       
   140 
       
   141     res=`_testme`
       
   142 
       
   143     case "${res}" in 
       
   144      OK*)  
       
   145 	_echo "Passed"
       
   146      ;;
       
   147      *)
       
   148 	_echo "Failed!"
       
   149      ;;
       
   150     esac
       
   151 
       
   152     _app_stop
       
   153 }  
       
   154 
       
   155 test_02(){
       
   156 		
       
   157     _echo "**** Test two ****"		
       
   158 
       
   159     _app_start JdpDoSomething \
       
   160      -Dcom.sun.management.jdp.port=7095 \
       
   161      -Dcom.sun.management.jdp.address=239.255.255.225 \
       
   162      -Dcom.sun.management.jdp.pause=5 \
       
   163      -Dcom.sun.management.jmxremote.port=4545 \
       
   164      -Dcom.sun.management.jmxremote.authenticate=false \
       
   165      -Dcom.sun.management.jmxremote.ssl=false
       
   166 
       
   167     res=`_testme`
       
   168 
       
   169     case "${res}" in 
       
   170      OK*)  
       
   171 	_echo "Passed"
       
   172      ;;
       
   173      *)
       
   174 	_echo "Failed!"
       
   175      ;;
       
   176     esac
       
   177 
       
   178     _app_stop
       
   179 }  
       
   180 
       
   181 test_03(){
       
   182 		
       
   183     _echo "**** Test three ****"
       
   184 
       
   185     _app_start JdpDoSomething
       
   186     
       
   187     _jcmd  ManagementAgent.start\
       
   188                 jdp.port=7095 \
       
   189                 jdp.address=239.255.255.225 \
       
   190                 jdp.pause=5 \
       
   191                 jmxremote.port=4545 \
       
   192                 jmxremote.authenticate=false \
       
   193                 jmxremote.ssl=false
       
   194 
       
   195     res=`_testme`
       
   196 
       
   197     case "${res}" in 
       
   198      OK*)  
       
   199 	_echo "Passed"
       
   200      ;;
       
   201      *)
       
   202 	_echo "Failed!"
       
   203      ;;
       
   204     esac
       
   205 
       
   206     _app_stop
       
   207 }  
       
   208 
       
   209 test_04(){
       
   210 
       
   211     _echo "**** Test four ****"
       
   212 
       
   213     _app_start JdpDoSomething \
       
   214      -Dcom.sun.management.jmxremote.autodiscovery=true \
       
   215      -Dcom.sun.management.jmxremote.port=4545 \
       
   216      -Dcom.sun.management.jmxremote.authenticate=false \
       
   217      -Dcom.sun.management.jmxremote.ssl=false
       
   218 
       
   219     res=`_testme`
       
   220 
       
   221     case "${res}" in
       
   222      OK*)
       
   223 	_echo "Passed"
       
   224      ;;
       
   225      *)
       
   226 	_echo "Failed!"
       
   227      ;;
       
   228     esac
       
   229 
       
   230     _app_stop
       
   231 }
       
   232 
       
   233 test_05(){
       
   234 
       
   235     _echo "**** Test five ****"
       
   236 
       
   237     _app_start JdpDoSomething
       
   238 
       
   239     _jcmd  ManagementAgent.start\
       
   240                 jmxremote.autodiscovery=true \
       
   241                 jmxremote.port=4545 \
       
   242                 jmxremote.authenticate=false \
       
   243                 jmxremote.ssl=false
       
   244 
       
   245 
       
   246     res=`_testme`
       
   247 
       
   248     case "${res}" in
       
   249      OK*)
       
   250 	_echo "Passed"
       
   251      ;;
       
   252      *)
       
   253 	_echo "Failed!"
       
   254      ;;
       
   255     esac
       
   256 
       
   257     _app_stop
       
   258 }
       
   259 
       
   260 
       
   261 # ============= MAIN =======================================
       
   262 
       
   263 if [ "x${TESTJAVA}" = "x" ]
       
   264 then
       
   265   echo "TESTJAVA env have to be set"
       
   266   exit
       
   267 fi
       
   268 
       
   269 #------------------------------------------------------------------------------
       
   270 # reading parameters 
       
   271 
       
   272 for parm in "$@"  
       
   273 do
       
   274    case $parm in
       
   275   --verbose)      _verbose=yes  ;;
       
   276   --jtreg)        _jtreg=yes    ;;
       
   277   --no-compile)   _compile=no   ;;
       
   278   --testsuite=*)  _testsuite=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
       
   279   *) 
       
   280      echo "Undefined parameter $parm. Try --help for help" 
       
   281      exit 
       
   282    ;;
       
   283  esac 
       
   284 done
       
   285 
       
   286 if [ ${_compile} = "yes" ]
       
   287 then
       
   288  _compile
       
   289 fi
       
   290 
       
   291 if [ ${_jtreg} = "yes" ]
       
   292 then
       
   293  _testclasses=${TESTCLASSES}
       
   294  _testsrc=${TESTSRC}
       
   295  _logname="output.txt"
       
   296 fi
       
   297 
       
   298 # Make sure _tesclasses is absolute path
       
   299 tt=`echo ${_testclasses} | sed -e 's,/,,'`
       
   300 if [ ${tt} = ${_testclasses} ]
       
   301 then
       
   302   _testclasses="${_pwd}/${_testclasses}"
       
   303 fi
       
   304 
       
   305 _policyname="${_testclasses}/policy"
       
   306 
       
   307 rm -f ${_logname}
       
   308 rm -f ${_policyname}
       
   309 
       
   310 if [ -e ${_testsrc}/policy.tpl ]
       
   311 then
       
   312 
       
   313 cat ${_testsrc}/policy.tpl | \
       
   314      sed -e "s,@_TESTCLASSES@,${_testclasses},g" -e "s,@TESTJAVA@,${TESTJAVA},g" \
       
   315  > ${_policyname}
       
   316  
       
   317 fi
       
   318  
       
   319 # Local mode tests
       
   320 for i in `echo ${_testsuite} | sed -e "s/,/ /g"`
       
   321 do
       
   322   test_${i} 
       
   323 done