1 # 2 # Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. 8 # 9 # This code is distributed in the hope that it will be useful, but WITHOUT 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 # version 2 for more details (a copy is included in the LICENSE file that 13 # accompanied this code). 14 # 15 # You should have received a copy of the GNU General Public License version 16 # 2 along with this work; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 # 19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 # or visit www.oracle.com if you need additional information or have any 21 # questions. 22 # 23 24 # @test 25 # @bug 6274276 26 # @summary JLI JAR manifest processing should ignore leading and trailing white space. 27 # @author Daniel D. Daugherty 28 # 29 # @run build ManifestTestApp ExampleForBootClassPath 30 # @run shell/timeout=900 ManifestTest.sh 31 # 32 33 make_a_JAR() { 34 # version_line and premain_line are required 35 version_line="Manifest-Version: 1.0" 36 premain_line="Premain-Class: ${AGENT}" 37 boot_cp_line="" 38 expect_boot_cp_line="ExampleForBootClassPath was not loaded." 39 can_redef_line="" 40 expect_redef_line="isRedefineClassesSupported()=false" 41 can_retrans_line="" 42 expect_retrans_line="isRetransformClassesSupported()=false" 43 can_set_nmp_line="" 44 expect_set_nmp_line="isNativeMethodPrefixSupported()=false" 45 # some tests create directories with spaces in their name, 46 # explicitly delete these. 47 to_be_deleted="" 48 49 while [ $# != 0 ] ; do 50 case "$1" in 51 defaults) 52 # just use the defaults for the test 53 ;; 54 55 boot_cp_line1) 56 boot_cp_line="Boot-Class-Path: no_white_space" 57 expect_boot_cp_line="ExampleForBootClassPath was loaded." 58 mkdir -p no_white_space 59 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class no_white_space 60 ;; 61 62 boot_cp_line2) 63 boot_cp_line="Boot-Class-Path: has_leading_blank" 64 expect_boot_cp_line="ExampleForBootClassPath was loaded." 65 to_be_deleted=" has_leading_blank" 66 mkdir -p has_leading_blank " has_leading_blank" 67 # the good class is in the directory without the blank 68 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \ 69 has_leading_blank 70 # the bad class is in the directory with the blank 71 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ 72 " has_leading_blank/ExampleForBootClassPath.class" 73 ;; 74 75 boot_cp_line3) 76 boot_cp_line="Boot-Class-Path: has_trailing_blank " 77 expect_boot_cp_line="ExampleForBootClassPath was loaded." 78 to_be_deleted="has_trailing_blank " 79 mkdir -p has_trailing_blank "has_trailing_blank " 80 # the good class is in the directory without the blank 81 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \ 82 has_trailing_blank 83 # the bad class is in the directory with the blank 84 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ 85 "has_trailing_blank /ExampleForBootClassPath.class" 86 ;; 87 88 boot_cp_line4) 89 boot_cp_line="Boot-Class-Path: has_leading_and_trailing_blank " 90 expect_boot_cp_line="ExampleForBootClassPath was loaded." 91 to_be_deleted=" has_leading_and_trailing_blank " 92 mkdir -p has_leading_and_trailing_blank \ 93 " has_leading_and_trailing_blank " 94 # the good class is in the directory without the blanks 95 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \ 96 has_leading_and_trailing_blank 97 # the bad class is in the directory with the blanks 98 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ 99 " has_leading_and_trailing_blank /ExampleForBootClassPath.class" 100 ;; 101 102 boot_cp_line5) 103 boot_cp_line="Boot-Class-Path: has_embedded blank" 104 expect_boot_cp_line="ExampleForBootClassPath was loaded." 105 to_be_deleted="has_embedded blank" 106 mkdir -p has_embedded "has_embedded blank" 107 # the good class is in the first blank separated word 108 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class has_embedded 109 # the bad class is in the directory with the blank 110 cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \ 111 "has_embedded blank/ExampleForBootClassPath.class" 112 ;; 113 114 can_redef_line1) 115 can_redef_line="Can-Redefine-Classes: true" 116 expect_redef_line="isRedefineClassesSupported()=true" 117 ;; 118 119 can_redef_line2) 120 can_redef_line="Can-Redefine-Classes: true" 121 expect_redef_line="isRedefineClassesSupported()=true" 122 ;; 123 124 can_redef_line3) 125 can_redef_line="Can-Redefine-Classes: true " 126 expect_redef_line="isRedefineClassesSupported()=true" 127 ;; 128 129 can_redef_line4) 130 can_redef_line="Can-Redefine-Classes: true " 131 expect_redef_line="isRedefineClassesSupported()=true" 132 ;; 133 134 can_redef_line5) 135 can_redef_line="Can-Redefine-Classes: false" 136 ;; 137 138 can_redef_line6) 139 can_redef_line="Can-Redefine-Classes: false" 140 ;; 141 142 can_redef_line7) 143 can_redef_line="Can-Redefine-Classes: false " 144 ;; 145 146 can_redef_line8) 147 can_redef_line="Can-Redefine-Classes: false " 148 ;; 149 150 can_redef_line9) 151 # this line makes the jar command unhappy and that's 152 # not what we're testing so skip this case 153 can_redef_line="Can-Redefine-Classes:" 154 ;; 155 156 can_redef_line10) 157 can_redef_line="Can-Redefine-Classes: " 158 ;; 159 160 can_redef_line11) 161 can_redef_line="Can-Redefine-Classes: " 162 ;; 163 164 can_retrans_line1) 165 can_retrans_line="Can-Retransform-Classes: true" 166 expect_retrans_line="isRetransformClassesSupported()=true" 167 ;; 168 169 can_retrans_line2) 170 can_retrans_line="Can-Retransform-Classes: true" 171 expect_retrans_line="isRetransformClassesSupported()=true" 172 ;; 173 174 can_retrans_line3) 175 can_retrans_line="Can-Retransform-Classes: true " 176 expect_retrans_line="isRetransformClassesSupported()=true" 177 ;; 178 179 can_retrans_line4) 180 can_retrans_line="Can-Retransform-Classes: true " 181 expect_retrans_line="isRetransformClassesSupported()=true" 182 ;; 183 184 can_retrans_line5) 185 can_retrans_line="Can-Retransform-Classes: false" 186 ;; 187 188 can_retrans_line6) 189 can_retrans_line="Can-Retransform-Classes: false" 190 ;; 191 192 can_retrans_line7) 193 can_retrans_line="Can-Retransform-Classes: false " 194 ;; 195 196 can_retrans_line8) 197 can_retrans_line="Can-Retransform-Classes: false " 198 ;; 199 200 can_retrans_line9) 201 # this line makes the jar command unhappy and that's 202 # not what we're testing so skip this case 203 can_retrans_line="Can-Retransform-Classes:" 204 ;; 205 206 can_retrans_line10) 207 can_retrans_line="Can-Retransform-Classes: " 208 ;; 209 210 can_retrans_line11) 211 can_retrans_line="Can-Retransform-Classes: " 212 ;; 213 214 can_set_nmp_line1) 215 can_set_nmp_line="Can-Set-Native-Method-Prefix: true" 216 expect_set_nmp_line="isNativeMethodPrefixSupported()=true" 217 ;; 218 219 can_set_nmp_line2) 220 can_set_nmp_line="Can-Set-Native-Method-Prefix: true" 221 expect_set_nmp_line="isNativeMethodPrefixSupported()=true" 222 ;; 223 224 can_set_nmp_line3) 225 can_set_nmp_line="Can-Set-Native-Method-Prefix: true " 226 expect_set_nmp_line="isNativeMethodPrefixSupported()=true" 227 ;; 228 229 can_set_nmp_line4) 230 can_set_nmp_line="Can-Set-Native-Method-Prefix: true " 231 expect_set_nmp_line="isNativeMethodPrefixSupported()=true" 232 ;; 233 234 can_set_nmp_line5) 235 can_set_nmp_line="Can-Set-Native-Method-Prefix: false" 236 ;; 237 238 can_set_nmp_line6) 239 can_set_nmp_line="Can-Set-Native-Method-Prefix: false" 240 ;; 241 242 can_set_nmp_line7) 243 can_set_nmp_line="Can-Set-Native-Method-Prefix: false " 244 ;; 245 246 can_set_nmp_line8) 247 can_set_nmp_line="Can-Set-Native-Method-Prefix: false " 248 ;; 249 250 can_set_nmp_line9) 251 # this line makes the jar command unhappy and that's 252 # not what we're testing so skip this case 253 can_set_nmp_line="Can-Set-Native-Method-Prefix:" 254 ;; 255 256 can_set_nmp_line10) 257 can_set_nmp_line="Can-Set-Native-Method-Prefix: " 258 ;; 259 260 can_set_nmp_line11) 261 can_set_nmp_line="Can-Set-Native-Method-Prefix: " 262 ;; 263 264 premain_line1) 265 premain_line="Premain-Class: ${AGENT}" 266 ;; 267 268 premain_line2) 269 premain_line="Premain-Class: ${AGENT} " 270 ;; 271 272 premain_line3) 273 premain_line="Premain-Class: ${AGENT} " 274 ;; 275 276 version_line1) 277 version_line="Manifest-Version: 1.0" 278 ;; 279 280 version_line2) 281 version_line="Manifest-Version: 1.0 " 282 ;; 283 284 version_line3) 285 version_line="Manifest-Version: 1.0 " 286 ;; 287 288 *) 289 echo "ERROR: invalid test token" 290 exit 1 291 esac 292 shift 293 done 294 295 echo "${version_line}" > ${AGENT}.mf 296 echo "${premain_line}" >> ${AGENT}.mf 297 298 if [ -n "$boot_cp_line" ]; then 299 echo "${boot_cp_line}" >> ${AGENT}.mf 300 fi 301 302 if [ -n "$can_redef_line" ]; then 303 echo "${can_redef_line}" >> ${AGENT}.mf 304 fi 305 306 if [ -n "$can_retrans_line" ]; then 307 echo "${can_retrans_line}" >> ${AGENT}.mf 308 fi 309 310 if [ -n "$can_set_nmp_line" ]; then 311 echo "${can_set_nmp_line}" >> ${AGENT}.mf 312 fi 313 314 rm -f ${AGENT}.jar 315 ${JAR} ${TESTTOOLVMOPTS} cvfm ${AGENT}.jar ${AGENT}.mf ${AGENT}.class 316 317 echo "$expect_boot_cp_line" > expect_boot_cp_line 318 echo "$expect_redef_line" > expect_redef_line 319 echo "$expect_retrans_line" > expect_retrans_line 320 echo "$expect_set_nmp_line" > expect_set_nmp_line 321 } 322 323 if [ "${TESTJAVA}" = "" ] 324 then 325 echo "TESTJAVA not set. Test cannot execute. Failed." 326 exit 1 327 fi 328 329 if [ "${COMPILEJAVA}" = "" ] 330 then 331 COMPILEJAVA="${TESTJAVA}" 332 fi 333 echo "COMPILEJAVA=${COMPILEJAVA}" 334 335 if [ "${TESTSRC}" = "" ] 336 then 337 echo "TESTSRC not set. Test cannot execute. Failed." 338 exit 1 339 fi 340 341 if [ "${TESTCLASSES}" = "" ] 342 then 343 echo "TESTCLASSES not set. Test cannot execute. Failed." 344 exit 1 345 fi 346 347 JAR="${COMPILEJAVA}/bin/jar" 348 JAVAC="${COMPILEJAVA}"/bin/javac 349 JAVA="${TESTJAVA}"/bin/java 350 351 # Now that ManifestTestApp.class is built, we move 352 # ExampleForBootClassPath.class so that it cannot be found 353 # by default 354 OUT_OF_THE_WAY=out_of_the_way 355 mkdir $OUT_OF_THE_WAY 356 mv "${TESTCLASSES}/ExampleForBootClassPath.class" $OUT_OF_THE_WAY 357 358 # create a bad version of ExampleForBootClassPath.class 359 # so we can tell when the wrong version is run 360 sed 's/return 15/return 42/' "${TESTSRC}"/ExampleForBootClassPath.java \ 361 > ExampleForBootClassPath.java 362 "$JAVAC" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ExampleForBootClassPath.java 363 mv ExampleForBootClassPath.class \ 364 $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad 365 mv ExampleForBootClassPath.java \ 366 $OUT_OF_THE_WAY/ExampleForBootClassPath.java.bad 367 368 AGENT=ManifestTestAgent 369 # We compile the agent in the working directory instead of with 370 # a build task because we construct a different agent JAR file 371 # for each test case. 372 ${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/${AGENT}.java 373 374 FAIL_MARKER=fail_marker 375 rm -f $FAIL_MARKER 376 377 while read token; do 378 echo 379 echo "===== begin test case: $token =====" 380 make_a_JAR "$token" 381 382 "${JAVA}" ${TESTVMOPTS} -javaagent:${AGENT}.jar \ 383 -classpath "${TESTCLASSES}" ManifestTestApp > output.log 2>&1 384 result=$? 385 386 cat output.log 387 388 if [ "$result" = 0 ]; then 389 echo "PASS: ManifestTestApp exited with status of 0." 390 else 391 echo "FAIL: ManifestTestApp exited with status of $result" 392 touch $FAIL_MARKER 393 fi 394 395 MESG="Hello from ${AGENT}!" 396 grep -s "$MESG" output.log > /dev/null 397 result=$? 398 if [ "$result" = 0 ]; then 399 echo "PASS: found '$MESG' in the test output" 400 else 401 echo "FAIL: did NOT find '$MESG' in the test output" 402 touch $FAIL_MARKER 403 fi 404 405 MESG=`cat expect_boot_cp_line | tr -d '\n\r'` 406 grep -s "$MESG" output.log > /dev/null 407 result=$? 408 if [ "$result" = 0 ]; then 409 echo "PASS: found '$MESG' in the test output" 410 else 411 echo "FAIL: did NOT find '$MESG' in the test output" 412 touch $FAIL_MARKER 413 fi 414 415 MESG=`cat expect_redef_line | tr -d '\n\r'` 416 grep -s "$MESG" output.log > /dev/null 417 result=$? 418 if [ "$result" = 0 ]; then 419 echo "PASS: found '$MESG' in the test output" 420 else 421 echo "FAIL: did NOT find '$MESG' in the test output" 422 touch $FAIL_MARKER 423 fi 424 425 MESG=`cat expect_retrans_line | tr -d '\n\r'` 426 grep -s "$MESG" output.log > /dev/null 427 result=$? 428 if [ "$result" = 0 ]; then 429 echo "PASS: found '$MESG' in the test output" 430 else 431 echo "FAIL: did NOT find '$MESG' in the test output" 432 touch $FAIL_MARKER 433 fi 434 435 MESG=`cat expect_set_nmp_line | tr -d '\n\r'` 436 grep -s "$MESG" output.log > /dev/null 437 result=$? 438 if [ "$result" = 0 ]; then 439 echo "PASS: found '$MESG' in the test output" 440 else 441 echo "FAIL: did NOT find '$MESG' in the test output" 442 touch $FAIL_MARKER 443 fi 444 445 #clean up any problematic directories 446 if [ -n "$to_be_deleted" ]; then 447 echo "Test removing [$to_be_deleted]" 448 rm -rf "$to_be_deleted" 449 fi 450 451 echo "===== end test case: $token =====" 452 echo 453 done << EOF 454 defaults 455 version_line1 456 version_line2 457 version_line3 458 premain_line1 459 premain_line2 460 premain_line3 461 boot_cp_line1 462 boot_cp_line2 463 boot_cp_line3 464 boot_cp_line4 465 boot_cp_line5 466 can_redef_line1 467 can_redef_line2 468 can_redef_line3 469 can_redef_line4 470 can_redef_line5 471 can_redef_line6 472 can_redef_line7 473 can_redef_line8 474 can_redef_line10 475 can_redef_line11 476 can_retrans_line1 477 can_retrans_line2 478 can_retrans_line3 479 can_retrans_line4 480 can_retrans_line5 481 can_retrans_line6 482 can_retrans_line7 483 can_retrans_line8 484 can_retrans_line10 485 can_retrans_line11 486 can_set_nmp_line1 487 can_set_nmp_line2 488 can_set_nmp_line3 489 can_set_nmp_line4 490 can_set_nmp_line5 491 can_set_nmp_line6 492 can_set_nmp_line7 493 can_set_nmp_line8 494 can_set_nmp_line10 495 can_set_nmp_line11 496 EOF 497 498 if [ -f $FAIL_MARKER ]; then 499 exit 1 500 else 501 exit 0 502 fi