jdk/test/java/lang/instrument/ManifestTest.sh
changeset 273 3d51c181a2e5
child 5506 202f599c92aa
equal deleted inserted replaced
272:c4e0a3afe6f2 273:3d51c181a2e5
       
     1 #
       
     2 # Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20 # CA 95054 USA or visit www.sun.com if you need additional information or
       
    21 # have any 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
       
    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 
       
    46     while [ $# != 0 ] ; do
       
    47         case "$1" in
       
    48         defaults)
       
    49             # just use the defaults for the test
       
    50             ;;
       
    51 
       
    52         boot_cp_line1)
       
    53             boot_cp_line="Boot-Class-Path: no_white_space"
       
    54             expect_boot_cp_line="ExampleForBootClassPath was loaded."
       
    55             mkdir -p no_white_space
       
    56             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class no_white_space
       
    57             ;;
       
    58 
       
    59         boot_cp_line2)
       
    60             boot_cp_line="Boot-Class-Path:  has_leading_blank"
       
    61             expect_boot_cp_line="ExampleForBootClassPath was loaded."
       
    62             mkdir -p has_leading_blank " has_leading_blank"
       
    63             # the good class is in the directory without the blank
       
    64             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
       
    65                 has_leading_blank
       
    66             # the bad class is in the directory with the blank
       
    67             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
       
    68                 " has_leading_blank"/ExampleForBootClassPath.class
       
    69             ;;
       
    70 
       
    71         boot_cp_line3)
       
    72             boot_cp_line="Boot-Class-Path: has_trailing_blank "
       
    73             expect_boot_cp_line="ExampleForBootClassPath was loaded."
       
    74             mkdir -p has_trailing_blank "has_trailing_blank "
       
    75             # the good class is in the directory without the blank
       
    76             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
       
    77                 has_trailing_blank
       
    78             # the bad class is in the directory with the blank
       
    79             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
       
    80                 "has_trailing_blank "/ExampleForBootClassPath.class
       
    81             ;;
       
    82 
       
    83         boot_cp_line4)
       
    84             boot_cp_line="Boot-Class-Path:  has_leading_and_trailing_blank "
       
    85             expect_boot_cp_line="ExampleForBootClassPath was loaded."
       
    86             mkdir -p has_leading_and_trailing_blank \
       
    87                 " has_leading_and_trailing_blank "
       
    88             # the good class is in the directory without the blanks
       
    89             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
       
    90                 has_leading_and_trailing_blank
       
    91             # the bad class is in the directory with the blanks
       
    92             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
       
    93                 " has_leading_and_trailing_blank "/ExampleForBootClassPath.class
       
    94             ;;
       
    95 
       
    96         boot_cp_line5)
       
    97             boot_cp_line="Boot-Class-Path: has_embedded blank"
       
    98             expect_boot_cp_line="ExampleForBootClassPath was loaded."
       
    99             mkdir -p has_embedded "has_embedded blank"
       
   100             # the good class is in the first blank separated word
       
   101             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class has_embedded
       
   102             # the bad class is in the directory with the blank
       
   103             cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
       
   104                 "has_embedded blank"/ExampleForBootClassPath.class
       
   105             ;;
       
   106 
       
   107         can_redef_line1)
       
   108             can_redef_line="Can-Redefine-Classes: true"
       
   109             expect_redef_line="isRedefineClassesSupported()=true"
       
   110             ;;
       
   111 
       
   112         can_redef_line2)
       
   113             can_redef_line="Can-Redefine-Classes:  true"
       
   114             expect_redef_line="isRedefineClassesSupported()=true"
       
   115             ;;
       
   116 
       
   117         can_redef_line3)
       
   118             can_redef_line="Can-Redefine-Classes: true "
       
   119             expect_redef_line="isRedefineClassesSupported()=true"
       
   120             ;;
       
   121 
       
   122         can_redef_line4)
       
   123             can_redef_line="Can-Redefine-Classes:  true "
       
   124             expect_redef_line="isRedefineClassesSupported()=true"
       
   125             ;;
       
   126 
       
   127         can_redef_line5)
       
   128             can_redef_line="Can-Redefine-Classes: false"
       
   129             ;;
       
   130 
       
   131         can_redef_line6)
       
   132             can_redef_line="Can-Redefine-Classes:  false"
       
   133             ;;
       
   134 
       
   135         can_redef_line7)
       
   136             can_redef_line="Can-Redefine-Classes: false "
       
   137             ;;
       
   138 
       
   139         can_redef_line8)
       
   140             can_redef_line="Can-Redefine-Classes:  false "
       
   141             ;;
       
   142 
       
   143         can_redef_line9)
       
   144             # this line makes the jar command unhappy and that's
       
   145             # not what we're testing so skip this case
       
   146             can_redef_line="Can-Redefine-Classes:"
       
   147             ;;
       
   148 
       
   149         can_redef_line10)
       
   150             can_redef_line="Can-Redefine-Classes: "
       
   151             ;;
       
   152 
       
   153         can_redef_line11)
       
   154             can_redef_line="Can-Redefine-Classes:  "
       
   155             ;;
       
   156 
       
   157         can_retrans_line1)
       
   158             can_retrans_line="Can-Retransform-Classes: true"
       
   159             expect_retrans_line="isRetransformClassesSupported()=true"
       
   160             ;;
       
   161 
       
   162         can_retrans_line2)
       
   163             can_retrans_line="Can-Retransform-Classes:  true"
       
   164             expect_retrans_line="isRetransformClassesSupported()=true"
       
   165             ;;
       
   166 
       
   167         can_retrans_line3)
       
   168             can_retrans_line="Can-Retransform-Classes: true "
       
   169             expect_retrans_line="isRetransformClassesSupported()=true"
       
   170             ;;
       
   171 
       
   172         can_retrans_line4)
       
   173             can_retrans_line="Can-Retransform-Classes:  true "
       
   174             expect_retrans_line="isRetransformClassesSupported()=true"
       
   175             ;;
       
   176 
       
   177         can_retrans_line5)
       
   178             can_retrans_line="Can-Retransform-Classes: false"
       
   179             ;;
       
   180 
       
   181         can_retrans_line6)
       
   182             can_retrans_line="Can-Retransform-Classes:  false"
       
   183             ;;
       
   184 
       
   185         can_retrans_line7)
       
   186             can_retrans_line="Can-Retransform-Classes: false "
       
   187             ;;
       
   188 
       
   189         can_retrans_line8)
       
   190             can_retrans_line="Can-Retransform-Classes:  false "
       
   191             ;;
       
   192 
       
   193         can_retrans_line9)
       
   194             # this line makes the jar command unhappy and that's
       
   195             # not what we're testing so skip this case
       
   196             can_retrans_line="Can-Retransform-Classes:"
       
   197             ;;
       
   198 
       
   199         can_retrans_line10)
       
   200             can_retrans_line="Can-Retransform-Classes: "
       
   201             ;;
       
   202 
       
   203         can_retrans_line11)
       
   204             can_retrans_line="Can-Retransform-Classes:  "
       
   205             ;;
       
   206 
       
   207         can_set_nmp_line1)
       
   208             can_set_nmp_line="Can-Set-Native-Method-Prefix: true"
       
   209             expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
       
   210             ;;
       
   211 
       
   212         can_set_nmp_line2)
       
   213             can_set_nmp_line="Can-Set-Native-Method-Prefix:  true"
       
   214             expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
       
   215             ;;
       
   216 
       
   217         can_set_nmp_line3)
       
   218             can_set_nmp_line="Can-Set-Native-Method-Prefix: true "
       
   219             expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
       
   220             ;;
       
   221 
       
   222         can_set_nmp_line4)
       
   223             can_set_nmp_line="Can-Set-Native-Method-Prefix:  true "
       
   224             expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
       
   225             ;;
       
   226 
       
   227         can_set_nmp_line5)
       
   228             can_set_nmp_line="Can-Set-Native-Method-Prefix: false"
       
   229             ;;
       
   230 
       
   231         can_set_nmp_line6)
       
   232             can_set_nmp_line="Can-Set-Native-Method-Prefix:  false"
       
   233             ;;
       
   234 
       
   235         can_set_nmp_line7)
       
   236             can_set_nmp_line="Can-Set-Native-Method-Prefix: false "
       
   237             ;;
       
   238 
       
   239         can_set_nmp_line8)
       
   240             can_set_nmp_line="Can-Set-Native-Method-Prefix:  false "
       
   241             ;;
       
   242 
       
   243         can_set_nmp_line9)
       
   244             # this line makes the jar command unhappy and that's
       
   245             # not what we're testing so skip this case
       
   246             can_set_nmp_line="Can-Set-Native-Method-Prefix:"
       
   247             ;;
       
   248 
       
   249         can_set_nmp_line10)
       
   250             can_set_nmp_line="Can-Set-Native-Method-Prefix: "
       
   251             ;;
       
   252 
       
   253         can_set_nmp_line11)
       
   254             can_set_nmp_line="Can-Set-Native-Method-Prefix:  "
       
   255             ;;
       
   256 
       
   257         premain_line1)
       
   258             premain_line="Premain-Class:  ${AGENT}"
       
   259             ;;
       
   260 
       
   261         premain_line2)
       
   262             premain_line="Premain-Class: ${AGENT} "
       
   263             ;;
       
   264 
       
   265         premain_line3)
       
   266             premain_line="Premain-Class:  ${AGENT} "
       
   267             ;;
       
   268 
       
   269         version_line1)
       
   270             version_line="Manifest-Version:  1.0"
       
   271             ;;
       
   272 
       
   273         version_line2)
       
   274             version_line="Manifest-Version: 1.0 "
       
   275             ;;
       
   276 
       
   277         version_line3)
       
   278             version_line="Manifest-Version:  1.0 "
       
   279             ;;
       
   280 
       
   281         *)
       
   282             echo "ERROR: invalid test token"
       
   283             exit 1
       
   284         esac
       
   285         shift
       
   286     done
       
   287 
       
   288     echo "${version_line}" >  ${AGENT}.mf
       
   289     echo "${premain_line}" >> ${AGENT}.mf
       
   290 
       
   291     if [ -n "$boot_cp_line" ]; then
       
   292         echo "${boot_cp_line}" >> ${AGENT}.mf
       
   293     fi
       
   294 
       
   295     if [ -n "$can_redef_line" ]; then
       
   296         echo "${can_redef_line}" >> ${AGENT}.mf
       
   297     fi
       
   298 
       
   299     if [ -n "$can_retrans_line" ]; then
       
   300         echo "${can_retrans_line}" >> ${AGENT}.mf
       
   301     fi
       
   302 
       
   303     if [ -n "$can_set_nmp_line" ]; then
       
   304         echo "${can_set_nmp_line}" >> ${AGENT}.mf
       
   305     fi
       
   306 
       
   307     rm -f ${AGENT}.jar
       
   308     ${JAR} cvfm ${AGENT}.jar ${AGENT}.mf ${AGENT}.class
       
   309 
       
   310     echo "$expect_boot_cp_line" > expect_boot_cp_line
       
   311     echo "$expect_redef_line"   > expect_redef_line
       
   312     echo "$expect_retrans_line" > expect_retrans_line
       
   313     echo "$expect_set_nmp_line" > expect_set_nmp_line
       
   314 }
       
   315 
       
   316 if [ "${TESTJAVA}" = "" ]
       
   317 then
       
   318   echo "TESTJAVA not set.  Test cannot execute.  Failed."
       
   319   exit 1
       
   320 fi
       
   321 
       
   322 if [ "${TESTSRC}" = "" ]
       
   323 then
       
   324   echo "TESTSRC not set.  Test cannot execute.  Failed."
       
   325   exit 1
       
   326 fi
       
   327 
       
   328 if [ "${TESTCLASSES}" = "" ]
       
   329 then
       
   330   echo "TESTCLASSES not set.  Test cannot execute.  Failed."
       
   331   exit 1
       
   332 fi
       
   333 
       
   334 JAR="${TESTJAVA}/bin/jar"
       
   335 JAVAC="${TESTJAVA}"/bin/javac
       
   336 JAVA="${TESTJAVA}"/bin/java
       
   337 
       
   338 # Now that ManifestTestApp.class is built, we move
       
   339 # ExampleForBootClassPath.class so that it cannot be found
       
   340 # by default
       
   341 OUT_OF_THE_WAY=out_of_the_way
       
   342 mkdir $OUT_OF_THE_WAY
       
   343 mv "${TESTCLASSES}/ExampleForBootClassPath.class" $OUT_OF_THE_WAY
       
   344 
       
   345 # create a bad version of ExampleForBootClassPath.class
       
   346 # so we can tell when the wrong version is run
       
   347 sed 's/return 15/return 42/' "${TESTSRC}"/ExampleForBootClassPath.java \
       
   348     > ExampleForBootClassPath.java
       
   349 "$JAVAC" ExampleForBootClassPath.java
       
   350 mv ExampleForBootClassPath.class \
       
   351     $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad
       
   352 mv ExampleForBootClassPath.java \
       
   353     $OUT_OF_THE_WAY/ExampleForBootClassPath.java.bad
       
   354 
       
   355 AGENT=ManifestTestAgent
       
   356 # We compile the agent in the working directory instead of with
       
   357 # a build task because we construct a different agent JAR file
       
   358 # for each test case.
       
   359 ${JAVAC} -d . ${TESTSRC}/${AGENT}.java
       
   360 
       
   361 FAIL_MARKER=fail_marker
       
   362 rm -f $FAIL_MARKER
       
   363 
       
   364 while read token; do
       
   365     echo
       
   366     echo "===== begin test case: $token ====="
       
   367     make_a_JAR "$token"
       
   368 
       
   369     "${JAVA}" ${TESTVMOPTS} -javaagent:${AGENT}.jar \
       
   370         -classpath "${TESTCLASSES}" ManifestTestApp > output.log 2>&1
       
   371     result=$?
       
   372 
       
   373     cat output.log
       
   374 
       
   375     if [ "$result" = 0 ]; then
       
   376         echo "PASS: ManifestTestApp exited with status of 0."
       
   377     else
       
   378         echo "FAIL: ManifestTestApp exited with status of $result"
       
   379         touch $FAIL_MARKER
       
   380     fi
       
   381 
       
   382     MESG="Hello from ${AGENT}!"
       
   383     grep -s "$MESG" output.log > /dev/null
       
   384     result=$?
       
   385     if [ "$result" = 0 ]; then
       
   386         echo "PASS: found '$MESG' in the test output"
       
   387     else
       
   388         echo "FAIL: did NOT find '$MESG' in the test output"
       
   389         touch $FAIL_MARKER
       
   390     fi
       
   391 
       
   392     MESG=`cat expect_boot_cp_line`
       
   393     grep -s "$MESG" output.log > /dev/null
       
   394     result=$?
       
   395     if [ "$result" = 0 ]; then
       
   396         echo "PASS: found '$MESG' in the test output"
       
   397     else
       
   398         echo "FAIL: did NOT find '$MESG' in the test output"
       
   399         touch $FAIL_MARKER
       
   400     fi
       
   401 
       
   402     MESG=`cat expect_redef_line`
       
   403     grep -s "$MESG" output.log > /dev/null
       
   404     result=$?
       
   405     if [ "$result" = 0 ]; then
       
   406         echo "PASS: found '$MESG' in the test output"
       
   407     else
       
   408         echo "FAIL: did NOT find '$MESG' in the test output"
       
   409         touch $FAIL_MARKER
       
   410     fi
       
   411 
       
   412     MESG=`cat expect_retrans_line`
       
   413     grep -s "$MESG" output.log > /dev/null
       
   414     result=$?
       
   415     if [ "$result" = 0 ]; then
       
   416         echo "PASS: found '$MESG' in the test output"
       
   417     else
       
   418         echo "FAIL: did NOT find '$MESG' in the test output"
       
   419         touch $FAIL_MARKER
       
   420     fi
       
   421 
       
   422     MESG=`cat expect_set_nmp_line`
       
   423     grep -s "$MESG" output.log > /dev/null
       
   424     result=$?
       
   425     if [ "$result" = 0 ]; then
       
   426         echo "PASS: found '$MESG' in the test output"
       
   427     else
       
   428         echo "FAIL: did NOT find '$MESG' in the test output"
       
   429         touch $FAIL_MARKER
       
   430     fi
       
   431 
       
   432     echo "===== end test case: $token ====="
       
   433     echo
       
   434 done << EOF
       
   435 defaults
       
   436 version_line1
       
   437 version_line2
       
   438 version_line3
       
   439 premain_line1
       
   440 premain_line2
       
   441 premain_line3
       
   442 boot_cp_line1
       
   443 boot_cp_line2
       
   444 boot_cp_line3
       
   445 boot_cp_line4
       
   446 boot_cp_line5
       
   447 can_redef_line1
       
   448 can_redef_line2
       
   449 can_redef_line3
       
   450 can_redef_line4
       
   451 can_redef_line5
       
   452 can_redef_line6
       
   453 can_redef_line7
       
   454 can_redef_line8
       
   455 can_redef_line10
       
   456 can_redef_line11
       
   457 can_retrans_line1
       
   458 can_retrans_line2
       
   459 can_retrans_line3
       
   460 can_retrans_line4
       
   461 can_retrans_line5
       
   462 can_retrans_line6
       
   463 can_retrans_line7
       
   464 can_retrans_line8
       
   465 can_retrans_line10
       
   466 can_retrans_line11
       
   467 can_set_nmp_line1
       
   468 can_set_nmp_line2
       
   469 can_set_nmp_line3
       
   470 can_set_nmp_line4
       
   471 can_set_nmp_line5
       
   472 can_set_nmp_line6
       
   473 can_set_nmp_line7
       
   474 can_set_nmp_line8
       
   475 can_set_nmp_line10
       
   476 can_set_nmp_line11
       
   477 EOF
       
   478 
       
   479 if [ -f $FAIL_MARKER ]; then
       
   480     exit 1
       
   481 else
       
   482     exit 0
       
   483 fi