jdk/test/sun/management/jdp/JdpTest.sh
changeset 26988 1b2c0139fb79
parent 26987 766607612d81
parent 26986 20a1f0856093
child 26995 18b8d8859b1a
equal deleted inserted replaced
26987:766607612d81 26988:1b2c0139fb79
     1 #!/bin/sh -x
       
     2 
       
     3 # Copyright (c) 2011, 2013, 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 # @compile -XDignore.symbol.file JdpUnitTest.java JdpClient.java JdpDoSomething.java
       
    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"
       
    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 _ip="224.0.23.178"
       
    48 _port="7095"
       
    49 _jmxport="4545"
       
    50 
       
    51 _do_compile(){
       
    52     # If the test run without JTReg, we have to compile it by our self
       
    53     # Under JTReg see @compile statement above
       
    54     # sun.* packages is not included to symbol file lib/ct.sym so we have
       
    55     # to ignore it
       
    56 
       
    57     if [ ! -d ${_testclasses} ]
       
    58     then
       
    59        mkdir -p ${_testclasses}
       
    60     fi
       
    61 
       
    62     rm -f ${_testclasses}/*.class
       
    63 
       
    64     # Compile testcase
       
    65     ${COMPILEJAVA}/bin/javac -XDignore.symbol.file -d ${_testclasses} \
       
    66                                              JdpUnitTest.java \
       
    67                                              JdpDoSomething.java \
       
    68                                              JdpClient.java
       
    69 
       
    70 
       
    71     if [ ! -f ${_testclasses}/JdpDoSomething.class -o ! -f ${_testclasses}/JdpClient.class -o ! -f ${_testclasses}/JdpUnitTest.class ]
       
    72     then
       
    73       echo "ERROR: Can't compile"
       
    74       exit 255
       
    75     fi
       
    76 }
       
    77 
       
    78 
       
    79 _app_start(){
       
    80 
       
    81   testappname=$1
       
    82   shift
       
    83 
       
    84   ${TESTJAVA}/bin/java -server $* -cp ${_testclasses} ${testappname}  >> ${_logname} 2>&1 &
       
    85  _last_pid=$!
       
    86 
       
    87 # wait until VM is actually starts.
       
    88 # please note, if vm doesn't start for some reason
       
    89 # jtreg kills the test by timeout. Don't file a bug.
       
    90   cnt=1
       
    91   while true
       
    92   do
       
    93     npid=`_get_pid`
       
    94     if [ "${npid}" != "" ]
       
    95     then
       
    96       break
       
    97     fi
       
    98     if [ "${cnt}" = "10" ]
       
    99     then
       
   100       echo "ERROR: Test app not started. Please check machine resources before filing a bug."
       
   101       if [ "${_jtreg}" = "yes" ]
       
   102       then
       
   103           exit 255
       
   104       fi
       
   105       break
       
   106     fi
       
   107     cnt=`expr $cnt + 1`
       
   108     sleep 1
       
   109   done
       
   110 }
       
   111 
       
   112 _get_pid(){
       
   113     ${TESTJAVA}/bin/jps | sed -n "/Jdp/s/ .*//p"
       
   114 }
       
   115 
       
   116 _app_stop(){
       
   117    rm ${_lockFileName}
       
   118 
       
   119 # wait until VM is actually shuts down
       
   120   while true
       
   121   do
       
   122     npid=`_get_pid`
       
   123     if [ "${npid}" = "" ]
       
   124     then
       
   125       break
       
   126     fi
       
   127     sleep 1
       
   128   done
       
   129 }
       
   130 
       
   131 _testme(){
       
   132   ${TESTJAVA}/bin/java \
       
   133   -cp ${_testclasses} \
       
   134   $* \
       
   135     -Dcom.sun.management.jdp.port=${_port} \
       
   136     -Dcom.sun.management.jdp.address=${_ip} \
       
   137   JdpClient
       
   138 }
       
   139 
       
   140 
       
   141 _jcmd(){
       
   142     ${TESTJAVA}/bin/jcmd JdpDoSomething $* > /dev/null 2>/dev/null
       
   143 }
       
   144 
       
   145 
       
   146 _echo(){
       
   147     echo "$*"
       
   148     echo "$*" >> ${_logname}
       
   149 }
       
   150 
       
   151 # ============= TESTS ======================================
       
   152 
       
   153 test_01(){
       
   154 
       
   155     _echo "**** Test one ****"
       
   156 
       
   157     _app_start JdpUnitTest \
       
   158         -Dcom.sun.management.jdp.port=${_port} \
       
   159         -Dcom.sun.management.jdp.address=${_ip} \
       
   160         -Dcom.sun.management.jdp.name=testme \
       
   161         -Djava.rmi.server.hostname=localhost \
       
   162         -Dcom.sun.management.jdp.pause=5
       
   163 
       
   164     res=`_testme`
       
   165 
       
   166     case "${res}" in
       
   167      OK*)
       
   168         _echo "Passed"
       
   169      ;;
       
   170      *)
       
   171         _echo "Failed!"
       
   172      ;;
       
   173     esac
       
   174 
       
   175     _app_stop
       
   176 }
       
   177 
       
   178 test_02(){
       
   179 
       
   180     _echo "**** Test two ****"
       
   181 
       
   182     _app_start JdpDoSomething \
       
   183         -Dcom.sun.management.jdp.port=${_port} \
       
   184         -Dcom.sun.management.jdp.address=${_ip} \
       
   185         -Dcom.sun.management.jdp.pause=5 \
       
   186         -Dcom.sun.management.jdp.name=testme \
       
   187         -Djava.rmi.server.hostname=localhost \
       
   188         -Dcom.sun.management.jmxremote.port=${_jmxport} \
       
   189         -Dcom.sun.management.jmxremote.authenticate=false \
       
   190         -Dcom.sun.management.jmxremote.ssl=false
       
   191 
       
   192     res=`_testme`
       
   193 
       
   194     case "${res}" in
       
   195      OK*)
       
   196         _echo "Passed"
       
   197      ;;
       
   198      *)
       
   199         _echo "Failed!"
       
   200      ;;
       
   201     esac
       
   202 
       
   203     _app_stop
       
   204 }
       
   205 
       
   206 test_03(){
       
   207 
       
   208     _echo "**** Test three ****"
       
   209 
       
   210     _app_start JdpDoSomething
       
   211 
       
   212     _jcmd  ManagementAgent.start\
       
   213                 jdp.port=${_port} \
       
   214                 jdp.address=${_ip} \
       
   215                 jdp.pause=5 \
       
   216                 jdp.name=jcmdtest \
       
   217                 jmxremote.port=${_jmxport} \
       
   218                 jmxremote.authenticate=false \
       
   219                 jmxremote.ssl=false
       
   220 
       
   221     res=`_testme`
       
   222 
       
   223     case "${res}" in
       
   224      OK*)
       
   225         _echo "Passed"
       
   226      ;;
       
   227      *)
       
   228         _echo "Failed!"
       
   229      ;;
       
   230     esac
       
   231 
       
   232     _app_stop
       
   233 }
       
   234 
       
   235 test_04(){
       
   236 
       
   237     _echo "**** Test four ****"
       
   238 
       
   239     _app_start JdpDoSomething \
       
   240         -Dcom.sun.management.jmxremote.autodiscovery=true \
       
   241         -Dcom.sun.management.jdp.name=testme \
       
   242         -Djava.rmi.server.hostname=localhost \
       
   243         -Dcom.sun.management.jmxremote.port=${_jmxport} \
       
   244         -Dcom.sun.management.jmxremote.authenticate=false \
       
   245         -Dcom.sun.management.jmxremote.ssl=false
       
   246 
       
   247     res=`_testme`
       
   248 
       
   249     case "${res}" in
       
   250      OK*)
       
   251         _echo "Passed"
       
   252      ;;
       
   253      *)
       
   254         _echo "Failed!"
       
   255      ;;
       
   256     esac
       
   257 
       
   258     _app_stop
       
   259 }
       
   260 
       
   261 test_05(){
       
   262 
       
   263     _echo "**** Test five ****"
       
   264 
       
   265     _app_start JdpDoSomething
       
   266 
       
   267     _jcmd  ManagementAgent.start\
       
   268                 jmxremote.autodiscovery=true \
       
   269                 jmxremote.port=${_jmxport} \
       
   270                 jmxremote.authenticate=false \
       
   271                 jmxremote.ssl=false
       
   272 
       
   273 
       
   274     res=`_testme`
       
   275 
       
   276     case "${res}" in
       
   277      OK*)
       
   278         _echo "Passed"
       
   279      ;;
       
   280      *)
       
   281         _echo "Failed!"
       
   282      ;;
       
   283     esac
       
   284 
       
   285     _app_stop
       
   286 }
       
   287 
       
   288 
       
   289 # ============= MAIN =======================================
       
   290 
       
   291 if [ "x${TESTJAVA}" = "x" ]
       
   292 then
       
   293   echo "TESTJAVA env have to be set"
       
   294   exit
       
   295 fi
       
   296 
       
   297 # COMPILEJAVA variable is set when we test jre
       
   298 if [ "x${COMPILEJAVA}" = "x" ]
       
   299 then
       
   300    COMPILEJAVA="${TESTJAVA}"
       
   301 fi
       
   302 
       
   303 
       
   304 #------------------------------------------------------------------------------
       
   305 # reading parameters
       
   306 
       
   307 for parm in "$@"
       
   308 do
       
   309   case $parm in
       
   310       --verbose)      _verbose=yes  ;;
       
   311       --jtreg)        _jtreg=yes    ;;
       
   312       --no-compile)   _compile=no   ;;
       
   313       --testsuite=*)  _testsuite=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
       
   314       *)
       
   315         echo "Undefined parameter $parm. Try --help for help"
       
   316         exit
       
   317       ;;
       
   318   esac
       
   319 done
       
   320 
       
   321 if [ "${_compile}" = "yes" ]
       
   322 then
       
   323   _do_compile
       
   324 fi
       
   325 
       
   326 if [ "${_jtreg}" = "yes" ]
       
   327 then
       
   328   _testclasses=${TESTCLASSES}
       
   329   _testsrc=${TESTSRC}
       
   330   _logname="output.txt"
       
   331 fi
       
   332 
       
   333 # Make sure _tesclasses is absolute path
       
   334 tt=`echo ${_testclasses} | sed -e 's,/,,'`
       
   335 if [ "${tt}" = "${_testclasses}" ]
       
   336 then
       
   337   _testclasses="${_pwd}/${_testclasses}"
       
   338 fi
       
   339 
       
   340 _policyname="${_testclasses}/policy"
       
   341 
       
   342 rm -f ${_logname}
       
   343 rm -f ${_policyname}
       
   344 
       
   345 if [ -f ${_testsrc}/policy.tpl ]
       
   346 then
       
   347 
       
   348 cat ${_testsrc}/policy.tpl | \
       
   349      sed -e "s,@_TESTCLASSES@,${_testclasses},g" -e "s,@TESTJAVA@,${TESTJAVA},g" \
       
   350  > ${_policyname}
       
   351 
       
   352 fi
       
   353 
       
   354 # Local mode tests
       
   355 for i in `echo ${_testsuite} | sed -e "s/,/ /g"`
       
   356 do
       
   357   test_${i}
       
   358 done