Path: blob/master/test/jdk/java/lang/instrument/ManifestTest.sh
41152 views
#1# Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.2# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3#4# This code is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License version 2 only, as6# published by the Free Software Foundation.7#8# This code is distributed in the hope that it will be useful, but WITHOUT9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11# version 2 for more details (a copy is included in the LICENSE file that12# accompanied this code).13#14# You should have received a copy of the GNU General Public License version15# 2 along with this work; if not, write to the Free Software Foundation,16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17#18# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19# or visit www.oracle.com if you need additional information or have any20# questions.21#2223# @test24# @bug 627427625# @summary JLI JAR manifest processing should ignore leading and trailing white space.26# @author Daniel D. Daugherty27#28# @key intermittent29# @run build ManifestTestApp ExampleForBootClassPath30# @run shell/timeout=900 ManifestTest.sh31#3233make_a_JAR() {34# version_line and premain_line are required35version_line="Manifest-Version: 1.0"36premain_line="Premain-Class: ${AGENT}"37boot_cp_line=""38expect_boot_cp_line="ExampleForBootClassPath was not loaded."39can_redef_line=""40expect_redef_line="isRedefineClassesSupported()=false"41can_retrans_line=""42expect_retrans_line="isRetransformClassesSupported()=false"43can_set_nmp_line=""44expect_set_nmp_line="isNativeMethodPrefixSupported()=false"45# some tests create directories with spaces in their name,46# explicitly delete these.47to_be_deleted=""4849while [ $# != 0 ] ; do50case "$1" in51defaults)52# just use the defaults for the test53;;5455boot_cp_line1)56boot_cp_line="Boot-Class-Path: no_white_space"57expect_boot_cp_line="ExampleForBootClassPath was loaded."58mkdir -p no_white_space59cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class no_white_space60;;6162boot_cp_line2)63boot_cp_line="Boot-Class-Path: has_leading_blank"64expect_boot_cp_line="ExampleForBootClassPath was loaded."65to_be_deleted=" has_leading_blank"66mkdir -p has_leading_blank " has_leading_blank"67# the good class is in the directory without the blank68cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \69has_leading_blank70# the bad class is in the directory with the blank71cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \72" has_leading_blank/ExampleForBootClassPath.class"73;;7475boot_cp_line3)76boot_cp_line="Boot-Class-Path: has_trailing_blank "77expect_boot_cp_line="ExampleForBootClassPath was loaded."78to_be_deleted="has_trailing_blank "79mkdir -p has_trailing_blank "has_trailing_blank "80# the good class is in the directory without the blank81cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \82has_trailing_blank83# the bad class is in the directory with the blank84cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \85"has_trailing_blank /ExampleForBootClassPath.class"86;;8788boot_cp_line4)89boot_cp_line="Boot-Class-Path: has_leading_and_trailing_blank "90expect_boot_cp_line="ExampleForBootClassPath was loaded."91to_be_deleted=" has_leading_and_trailing_blank "92mkdir -p has_leading_and_trailing_blank \93" has_leading_and_trailing_blank "94# the good class is in the directory without the blanks95cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \96has_leading_and_trailing_blank97# the bad class is in the directory with the blanks98cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \99" has_leading_and_trailing_blank /ExampleForBootClassPath.class"100;;101102boot_cp_line5)103boot_cp_line="Boot-Class-Path: has_embedded blank"104expect_boot_cp_line="ExampleForBootClassPath was loaded."105to_be_deleted="has_embedded blank"106mkdir -p has_embedded "has_embedded blank"107# the good class is in the first blank separated word108cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class has_embedded109# the bad class is in the directory with the blank110cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \111"has_embedded blank/ExampleForBootClassPath.class"112;;113114can_redef_line1)115can_redef_line="Can-Redefine-Classes: true"116expect_redef_line="isRedefineClassesSupported()=true"117;;118119can_redef_line2)120can_redef_line="Can-Redefine-Classes: true"121expect_redef_line="isRedefineClassesSupported()=true"122;;123124can_redef_line3)125can_redef_line="Can-Redefine-Classes: true "126expect_redef_line="isRedefineClassesSupported()=true"127;;128129can_redef_line4)130can_redef_line="Can-Redefine-Classes: true "131expect_redef_line="isRedefineClassesSupported()=true"132;;133134can_redef_line5)135can_redef_line="Can-Redefine-Classes: false"136;;137138can_redef_line6)139can_redef_line="Can-Redefine-Classes: false"140;;141142can_redef_line7)143can_redef_line="Can-Redefine-Classes: false "144;;145146can_redef_line8)147can_redef_line="Can-Redefine-Classes: false "148;;149150can_redef_line9)151# this line makes the jar command unhappy and that's152# not what we're testing so skip this case153can_redef_line="Can-Redefine-Classes:"154;;155156can_redef_line10)157can_redef_line="Can-Redefine-Classes: "158;;159160can_redef_line11)161can_redef_line="Can-Redefine-Classes: "162;;163164can_retrans_line1)165can_retrans_line="Can-Retransform-Classes: true"166expect_retrans_line="isRetransformClassesSupported()=true"167;;168169can_retrans_line2)170can_retrans_line="Can-Retransform-Classes: true"171expect_retrans_line="isRetransformClassesSupported()=true"172;;173174can_retrans_line3)175can_retrans_line="Can-Retransform-Classes: true "176expect_retrans_line="isRetransformClassesSupported()=true"177;;178179can_retrans_line4)180can_retrans_line="Can-Retransform-Classes: true "181expect_retrans_line="isRetransformClassesSupported()=true"182;;183184can_retrans_line5)185can_retrans_line="Can-Retransform-Classes: false"186;;187188can_retrans_line6)189can_retrans_line="Can-Retransform-Classes: false"190;;191192can_retrans_line7)193can_retrans_line="Can-Retransform-Classes: false "194;;195196can_retrans_line8)197can_retrans_line="Can-Retransform-Classes: false "198;;199200can_retrans_line9)201# this line makes the jar command unhappy and that's202# not what we're testing so skip this case203can_retrans_line="Can-Retransform-Classes:"204;;205206can_retrans_line10)207can_retrans_line="Can-Retransform-Classes: "208;;209210can_retrans_line11)211can_retrans_line="Can-Retransform-Classes: "212;;213214can_set_nmp_line1)215can_set_nmp_line="Can-Set-Native-Method-Prefix: true"216expect_set_nmp_line="isNativeMethodPrefixSupported()=true"217;;218219can_set_nmp_line2)220can_set_nmp_line="Can-Set-Native-Method-Prefix: true"221expect_set_nmp_line="isNativeMethodPrefixSupported()=true"222;;223224can_set_nmp_line3)225can_set_nmp_line="Can-Set-Native-Method-Prefix: true "226expect_set_nmp_line="isNativeMethodPrefixSupported()=true"227;;228229can_set_nmp_line4)230can_set_nmp_line="Can-Set-Native-Method-Prefix: true "231expect_set_nmp_line="isNativeMethodPrefixSupported()=true"232;;233234can_set_nmp_line5)235can_set_nmp_line="Can-Set-Native-Method-Prefix: false"236;;237238can_set_nmp_line6)239can_set_nmp_line="Can-Set-Native-Method-Prefix: false"240;;241242can_set_nmp_line7)243can_set_nmp_line="Can-Set-Native-Method-Prefix: false "244;;245246can_set_nmp_line8)247can_set_nmp_line="Can-Set-Native-Method-Prefix: false "248;;249250can_set_nmp_line9)251# this line makes the jar command unhappy and that's252# not what we're testing so skip this case253can_set_nmp_line="Can-Set-Native-Method-Prefix:"254;;255256can_set_nmp_line10)257can_set_nmp_line="Can-Set-Native-Method-Prefix: "258;;259260can_set_nmp_line11)261can_set_nmp_line="Can-Set-Native-Method-Prefix: "262;;263264premain_line1)265premain_line="Premain-Class: ${AGENT}"266;;267268premain_line2)269premain_line="Premain-Class: ${AGENT} "270;;271272premain_line3)273premain_line="Premain-Class: ${AGENT} "274;;275276version_line1)277version_line="Manifest-Version: 1.0"278;;279280version_line2)281version_line="Manifest-Version: 1.0 "282;;283284version_line3)285version_line="Manifest-Version: 1.0 "286;;287288*)289echo "ERROR: invalid test token"290exit 1291esac292shift293done294295echo "${version_line}" > ${AGENT}.mf296echo "${premain_line}" >> ${AGENT}.mf297298if [ -n "$boot_cp_line" ]; then299echo "${boot_cp_line}" >> ${AGENT}.mf300fi301302if [ -n "$can_redef_line" ]; then303echo "${can_redef_line}" >> ${AGENT}.mf304fi305306if [ -n "$can_retrans_line" ]; then307echo "${can_retrans_line}" >> ${AGENT}.mf308fi309310if [ -n "$can_set_nmp_line" ]; then311echo "${can_set_nmp_line}" >> ${AGENT}.mf312fi313314rm -f ${AGENT}.jar315${JAR} ${TESTTOOLVMOPTS} cvfm ${AGENT}.jar ${AGENT}.mf ${AGENT}.class316317echo "$expect_boot_cp_line" > expect_boot_cp_line318echo "$expect_redef_line" > expect_redef_line319echo "$expect_retrans_line" > expect_retrans_line320echo "$expect_set_nmp_line" > expect_set_nmp_line321}322323if [ "${TESTJAVA}" = "" ]324then325echo "TESTJAVA not set. Test cannot execute. Failed."326exit 1327fi328329if [ "${COMPILEJAVA}" = "" ]330then331COMPILEJAVA="${TESTJAVA}"332fi333echo "COMPILEJAVA=${COMPILEJAVA}"334335if [ "${TESTSRC}" = "" ]336then337echo "TESTSRC not set. Test cannot execute. Failed."338exit 1339fi340341if [ "${TESTCLASSES}" = "" ]342then343echo "TESTCLASSES not set. Test cannot execute. Failed."344exit 1345fi346347JAR="${COMPILEJAVA}/bin/jar"348JAVAC="${COMPILEJAVA}"/bin/javac349JAVA="${TESTJAVA}"/bin/java350351# Now that ManifestTestApp.class is built, we move352# ExampleForBootClassPath.class so that it cannot be found353# by default354OUT_OF_THE_WAY=out_of_the_way355mkdir $OUT_OF_THE_WAY356mv "${TESTCLASSES}/ExampleForBootClassPath.class" $OUT_OF_THE_WAY357358# create a bad version of ExampleForBootClassPath.class359# so we can tell when the wrong version is run360sed 's/return 15/return 42/' "${TESTSRC}"/ExampleForBootClassPath.java \361> ExampleForBootClassPath.java362"$JAVAC" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ExampleForBootClassPath.java363mv ExampleForBootClassPath.class \364$OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad365mv ExampleForBootClassPath.java \366$OUT_OF_THE_WAY/ExampleForBootClassPath.java.bad367368AGENT=ManifestTestAgent369# We compile the agent in the working directory instead of with370# a build task because we construct a different agent JAR file371# for each test case.372${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/${AGENT}.java373374FAIL_MARKER=fail_marker375rm -f $FAIL_MARKER376377while read token; do378echo379echo "===== begin test case: $token ====="380make_a_JAR "$token"381382"${JAVA}" ${TESTVMOPTS} -javaagent:${AGENT}.jar \383-classpath "${TESTCLASSES}" ManifestTestApp > output.log 2>&1384result=$?385386cat output.log387388if [ "$result" = 0 ]; then389echo "PASS: ManifestTestApp exited with status of 0."390else391echo "FAIL: ManifestTestApp exited with status of $result"392touch $FAIL_MARKER393fi394395MESG="Hello from ${AGENT}!"396grep -s "$MESG" output.log > /dev/null397result=$?398if [ "$result" = 0 ]; then399echo "PASS: found '$MESG' in the test output"400else401echo "FAIL: did NOT find '$MESG' in the test output"402touch $FAIL_MARKER403fi404405MESG=`cat expect_boot_cp_line | tr -d '\n\r'`406grep -s "$MESG" output.log > /dev/null407result=$?408if [ "$result" = 0 ]; then409echo "PASS: found '$MESG' in the test output"410else411echo "FAIL: did NOT find '$MESG' in the test output"412touch $FAIL_MARKER413fi414415MESG=`cat expect_redef_line | tr -d '\n\r'`416grep -s "$MESG" output.log > /dev/null417result=$?418if [ "$result" = 0 ]; then419echo "PASS: found '$MESG' in the test output"420else421echo "FAIL: did NOT find '$MESG' in the test output"422touch $FAIL_MARKER423fi424425MESG=`cat expect_retrans_line | tr -d '\n\r'`426grep -s "$MESG" output.log > /dev/null427result=$?428if [ "$result" = 0 ]; then429echo "PASS: found '$MESG' in the test output"430else431echo "FAIL: did NOT find '$MESG' in the test output"432touch $FAIL_MARKER433fi434435MESG=`cat expect_set_nmp_line | tr -d '\n\r'`436grep -s "$MESG" output.log > /dev/null437result=$?438if [ "$result" = 0 ]; then439echo "PASS: found '$MESG' in the test output"440else441echo "FAIL: did NOT find '$MESG' in the test output"442touch $FAIL_MARKER443fi444445#clean up any problematic directories446if [ -n "$to_be_deleted" ]; then447echo "Test removing [$to_be_deleted]"448rm -rf "$to_be_deleted"449fi450451echo "===== end test case: $token ====="452echo453done << EOF454defaults455version_line1456version_line2457version_line3458premain_line1459premain_line2460premain_line3461boot_cp_line1462boot_cp_line2463boot_cp_line3464boot_cp_line4465boot_cp_line5466can_redef_line1467can_redef_line2468can_redef_line3469can_redef_line4470can_redef_line5471can_redef_line6472can_redef_line7473can_redef_line8474can_redef_line10475can_redef_line11476can_retrans_line1477can_retrans_line2478can_retrans_line3479can_retrans_line4480can_retrans_line5481can_retrans_line6482can_retrans_line7483can_retrans_line8484can_retrans_line10485can_retrans_line11486can_set_nmp_line1487can_set_nmp_line2488can_set_nmp_line3489can_set_nmp_line4490can_set_nmp_line5491can_set_nmp_line6492can_set_nmp_line7493can_set_nmp_line8494can_set_nmp_line10495can_set_nmp_line11496EOF497498if [ -f $FAIL_MARKER ]; then499exit 1500else501exit 0502fi503504505