1 #!/bin/sh -x 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 # @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 npid=`_get_pid` 88 if [ "${npid}" = "" ] 89 then 90 echo "ERROR: Test app not started. Please check machine resources before filing a bug." 91 if [ "${_jtreg}" = "yes" ] 92 then 93 exit 255 94 fi 95 fi 96 } 97 98 _get_pid(){ 99 ${TESTJAVA}/bin/jps | sed -n "/Jdp/s/ .*//p" 100 } 101 102 _app_stop(){ 103 rm ${_lockFileName} 104 105 # wait until VM is actually shuts down 106 while true 107 do 108 npid=`_get_pid` 109 if [ "${npid}" = "" ] 110 then 111 break 112 fi 113 sleep 1 114 done 115 } 116 117 _testme(){ 118 ${TESTJAVA}/bin/java \ 119 -cp ${_testclasses} \ 120 $* \ 121 -Dcom.sun.management.jdp.port=${_port} \ 122 -Dcom.sun.management.jdp.address=${_ip} \ 123 JdpClient 124 125 } 126 127 128 _jcmd(){ 129 ${TESTJAVA}/bin/jcmd JdpDoSomething $* > /dev/null 2>/dev/null 130 } 131 132 133 _echo(){ 134 echo "$*" 135 echo "$*" >> ${_logname} 136 } 137 138 # ============= TESTS ====================================== 139 140 test_01(){ 141 142 _echo "**** Test one ****" 143 144 _app_start JdpUnitTest \ 145 -Dcom.sun.management.jdp.port=${_port} \ 146 -Dcom.sun.management.jdp.address=${_ip} \ 147 -Dcom.sun.management.jdp.pause=5 148 149 res=`_testme` 150 151 case "${res}" in 152 OK*) 153 _echo "Passed" 154 ;; 155 *) 156 _echo "Failed!" 157 ;; 158 esac 159 160 _app_stop 161 } 162 163 test_02(){ 164 165 _echo "**** Test two ****" 166 167 _app_start JdpDoSomething \ 168 -Dcom.sun.management.jdp.port=${_port} \ 169 -Dcom.sun.management.jdp.address=${_ip} \ 170 -Dcom.sun.management.jdp.pause=5 \ 171 -Dcom.sun.management.jmxremote.port=${_jmxport} \ 172 -Dcom.sun.management.jmxremote.authenticate=false \ 173 -Dcom.sun.management.jmxremote.ssl=false 174 175 res=`_testme` 176 177 case "${res}" in 178 OK*) 179 _echo "Passed" 180 ;; 181 *) 182 _echo "Failed!" 183 ;; 184 esac 185 186 _app_stop 187 } 188 189 test_03(){ 190 191 _echo "**** Test three ****" 192 193 _app_start JdpDoSomething 194 195 _jcmd ManagementAgent.start\ 196 jdp.port=${_port} \ 197 jdp.address=${_ip} \ 198 jdp.pause=5 \ 199 jmxremote.port=${_jmxport} \ 200 jmxremote.authenticate=false \ 201 jmxremote.ssl=false 202 203 res=`_testme` 204 205 case "${res}" in 206 OK*) 207 _echo "Passed" 208 ;; 209 *) 210 _echo "Failed!" 211 ;; 212 esac 213 214 _app_stop 215 } 216 217 test_04(){ 218 219 _echo "**** Test four ****" 220 221 _app_start JdpDoSomething \ 222 -Dcom.sun.management.jmxremote.autodiscovery=true \ 223 -Dcom.sun.management.jmxremote.port=${_jmxport} \ 224 -Dcom.sun.management.jmxremote.authenticate=false \ 225 -Dcom.sun.management.jmxremote.ssl=false 226 227 res=`_testme` 228 229 case "${res}" in 230 OK*) 231 _echo "Passed" 232 ;; 233 *) 234 _echo "Failed!" 235 ;; 236 esac 237 238 _app_stop 239 } 240 241 test_05(){ 242 243 _echo "**** Test five ****" 244 245 _app_start JdpDoSomething 246 247 _jcmd ManagementAgent.start\ 248 jmxremote.autodiscovery=true \ 249 jmxremote.port=${_jmxport} \ 250 jmxremote.authenticate=false \ 251 jmxremote.ssl=false 252 253 254 res=`_testme` 255 256 case "${res}" in 257 OK*) 258 _echo "Passed" 259 ;; 260 *) 261 _echo "Failed!" 262 ;; 263 esac 264 265 _app_stop 266 } 267 268 269 # ============= MAIN ======================================= 270 271 if [ "x${TESTJAVA}" = "x" ] 272 then 273 echo "TESTJAVA env have to be set" 274 exit 275 fi 276 277 # COMPILEJAVA variable is set when we test jre 278 if [ "x${COMPILEJAVA}" = "x" ] 279 then 280 COMPILEJAVA="${TESTJAVA}" 281 fi 282 283 284 #------------------------------------------------------------------------------ 285 # reading parameters 286 287 for parm in "$@" 288 do 289 case $parm in 290 --verbose) _verbose=yes ;; 291 --jtreg) _jtreg=yes ;; 292 --no-compile) _compile=no ;; 293 --testsuite=*) _testsuite=`_echo $parm | sed "s,^--.*=\(.*\),\1,"` ;; 294 *) 295 echo "Undefined parameter $parm. Try --help for help" 296 exit 297 ;; 298 esac 299 done 300 301 if [ "${_compile}" = "yes" ] 302 then 303 _do_compile 304 fi 305 306 if [ "${_jtreg}" = "yes" ] 307 then 308 _testclasses=${TESTCLASSES} 309 _testsrc=${TESTSRC} 310 _logname="output.txt" 311 fi 312 313 # Make sure _tesclasses is absolute path 314 tt=`echo ${_testclasses} | sed -e 's,/,,'` 315 if [ "${tt}" = "${_testclasses}" ] 316 then 317 _testclasses="${_pwd}/${_testclasses}" 318 fi 319 320 _policyname="${_testclasses}/policy" 321 322 rm -f ${_logname} 323 rm -f ${_policyname} 324 325 if [ -f ${_testsrc}/policy.tpl ] 326 then 327 328 cat ${_testsrc}/policy.tpl | \ 329 sed -e "s,@_TESTCLASSES@,${_testclasses},g" -e "s,@TESTJAVA@,${TESTJAVA},g" \ 330 > ${_policyname} 331 332 fi 333 334 # Local mode tests 335 for i in `echo ${_testsuite} | sed -e "s/,/ /g"` 336 do 337 test_${i} 338 done