Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/instrument/ManifestTest.sh
38813 views
#1# Copyright (c) 2008, 2013, 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# @run build ManifestTestApp ExampleForBootClassPath29# @run shell/timeout=900 ManifestTest.sh30#3132make_a_JAR() {33# version_line and premain_line are required34version_line="Manifest-Version: 1.0"35premain_line="Premain-Class: ${AGENT}"36boot_cp_line=""37expect_boot_cp_line="ExampleForBootClassPath was not loaded."38can_redef_line=""39expect_redef_line="isRedefineClassesSupported()=false"40can_retrans_line=""41expect_retrans_line="isRetransformClassesSupported()=false"42can_set_nmp_line=""43expect_set_nmp_line="isNativeMethodPrefixSupported()=false"44# some tests create directories with spaces in their name,45# explicitly delete these.46to_be_deleted=""4748while [ $# != 0 ] ; do49case "$1" in50defaults)51# just use the defaults for the test52;;5354boot_cp_line1)55boot_cp_line="Boot-Class-Path: no_white_space"56expect_boot_cp_line="ExampleForBootClassPath was loaded."57mkdir -p no_white_space58cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class no_white_space59;;6061boot_cp_line2)62boot_cp_line="Boot-Class-Path: has_leading_blank"63expect_boot_cp_line="ExampleForBootClassPath was loaded."64to_be_deleted=" has_leading_blank"65mkdir -p has_leading_blank " has_leading_blank"66# the good class is in the directory without the blank67cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \68has_leading_blank69# the bad class is in the directory with the blank70cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \71" has_leading_blank/ExampleForBootClassPath.class"72;;7374boot_cp_line3)75boot_cp_line="Boot-Class-Path: has_trailing_blank "76expect_boot_cp_line="ExampleForBootClassPath was loaded."77to_be_deleted="has_trailing_blank "78mkdir -p has_trailing_blank "has_trailing_blank "79# the good class is in the directory without the blank80cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \81has_trailing_blank82# the bad class is in the directory with the blank83cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \84"has_trailing_blank /ExampleForBootClassPath.class"85;;8687boot_cp_line4)88boot_cp_line="Boot-Class-Path: has_leading_and_trailing_blank "89expect_boot_cp_line="ExampleForBootClassPath was loaded."90to_be_deleted=" has_leading_and_trailing_blank "91mkdir -p has_leading_and_trailing_blank \92" has_leading_and_trailing_blank "93# the good class is in the directory without the blanks94cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \95has_leading_and_trailing_blank96# the bad class is in the directory with the blanks97cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \98" has_leading_and_trailing_blank /ExampleForBootClassPath.class"99;;100101boot_cp_line5)102boot_cp_line="Boot-Class-Path: has_embedded blank"103expect_boot_cp_line="ExampleForBootClassPath was loaded."104to_be_deleted="has_embedded blank"105mkdir -p has_embedded "has_embedded blank"106# the good class is in the first blank separated word107cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class has_embedded108# the bad class is in the directory with the blank109cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \110"has_embedded blank/ExampleForBootClassPath.class"111;;112113can_redef_line1)114can_redef_line="Can-Redefine-Classes: true"115expect_redef_line="isRedefineClassesSupported()=true"116;;117118can_redef_line2)119can_redef_line="Can-Redefine-Classes: true"120expect_redef_line="isRedefineClassesSupported()=true"121;;122123can_redef_line3)124can_redef_line="Can-Redefine-Classes: true "125expect_redef_line="isRedefineClassesSupported()=true"126;;127128can_redef_line4)129can_redef_line="Can-Redefine-Classes: true "130expect_redef_line="isRedefineClassesSupported()=true"131;;132133can_redef_line5)134can_redef_line="Can-Redefine-Classes: false"135;;136137can_redef_line6)138can_redef_line="Can-Redefine-Classes: false"139;;140141can_redef_line7)142can_redef_line="Can-Redefine-Classes: false "143;;144145can_redef_line8)146can_redef_line="Can-Redefine-Classes: false "147;;148149can_redef_line9)150# this line makes the jar command unhappy and that's151# not what we're testing so skip this case152can_redef_line="Can-Redefine-Classes:"153;;154155can_redef_line10)156can_redef_line="Can-Redefine-Classes: "157;;158159can_redef_line11)160can_redef_line="Can-Redefine-Classes: "161;;162163can_retrans_line1)164can_retrans_line="Can-Retransform-Classes: true"165expect_retrans_line="isRetransformClassesSupported()=true"166;;167168can_retrans_line2)169can_retrans_line="Can-Retransform-Classes: true"170expect_retrans_line="isRetransformClassesSupported()=true"171;;172173can_retrans_line3)174can_retrans_line="Can-Retransform-Classes: true "175expect_retrans_line="isRetransformClassesSupported()=true"176;;177178can_retrans_line4)179can_retrans_line="Can-Retransform-Classes: true "180expect_retrans_line="isRetransformClassesSupported()=true"181;;182183can_retrans_line5)184can_retrans_line="Can-Retransform-Classes: false"185;;186187can_retrans_line6)188can_retrans_line="Can-Retransform-Classes: false"189;;190191can_retrans_line7)192can_retrans_line="Can-Retransform-Classes: false "193;;194195can_retrans_line8)196can_retrans_line="Can-Retransform-Classes: false "197;;198199can_retrans_line9)200# this line makes the jar command unhappy and that's201# not what we're testing so skip this case202can_retrans_line="Can-Retransform-Classes:"203;;204205can_retrans_line10)206can_retrans_line="Can-Retransform-Classes: "207;;208209can_retrans_line11)210can_retrans_line="Can-Retransform-Classes: "211;;212213can_set_nmp_line1)214can_set_nmp_line="Can-Set-Native-Method-Prefix: true"215expect_set_nmp_line="isNativeMethodPrefixSupported()=true"216;;217218can_set_nmp_line2)219can_set_nmp_line="Can-Set-Native-Method-Prefix: true"220expect_set_nmp_line="isNativeMethodPrefixSupported()=true"221;;222223can_set_nmp_line3)224can_set_nmp_line="Can-Set-Native-Method-Prefix: true "225expect_set_nmp_line="isNativeMethodPrefixSupported()=true"226;;227228can_set_nmp_line4)229can_set_nmp_line="Can-Set-Native-Method-Prefix: true "230expect_set_nmp_line="isNativeMethodPrefixSupported()=true"231;;232233can_set_nmp_line5)234can_set_nmp_line="Can-Set-Native-Method-Prefix: false"235;;236237can_set_nmp_line6)238can_set_nmp_line="Can-Set-Native-Method-Prefix: false"239;;240241can_set_nmp_line7)242can_set_nmp_line="Can-Set-Native-Method-Prefix: false "243;;244245can_set_nmp_line8)246can_set_nmp_line="Can-Set-Native-Method-Prefix: false "247;;248249can_set_nmp_line9)250# this line makes the jar command unhappy and that's251# not what we're testing so skip this case252can_set_nmp_line="Can-Set-Native-Method-Prefix:"253;;254255can_set_nmp_line10)256can_set_nmp_line="Can-Set-Native-Method-Prefix: "257;;258259can_set_nmp_line11)260can_set_nmp_line="Can-Set-Native-Method-Prefix: "261;;262263premain_line1)264premain_line="Premain-Class: ${AGENT}"265;;266267premain_line2)268premain_line="Premain-Class: ${AGENT} "269;;270271premain_line3)272premain_line="Premain-Class: ${AGENT} "273;;274275version_line1)276version_line="Manifest-Version: 1.0"277;;278279version_line2)280version_line="Manifest-Version: 1.0 "281;;282283version_line3)284version_line="Manifest-Version: 1.0 "285;;286287*)288echo "ERROR: invalid test token"289exit 1290esac291shift292done293294echo "${version_line}" > ${AGENT}.mf295echo "${premain_line}" >> ${AGENT}.mf296297if [ -n "$boot_cp_line" ]; then298echo "${boot_cp_line}" >> ${AGENT}.mf299fi300301if [ -n "$can_redef_line" ]; then302echo "${can_redef_line}" >> ${AGENT}.mf303fi304305if [ -n "$can_retrans_line" ]; then306echo "${can_retrans_line}" >> ${AGENT}.mf307fi308309if [ -n "$can_set_nmp_line" ]; then310echo "${can_set_nmp_line}" >> ${AGENT}.mf311fi312313rm -f ${AGENT}.jar314${JAR} ${TESTTOOLVMOPTS} cvfm ${AGENT}.jar ${AGENT}.mf ${AGENT}.class315316echo "$expect_boot_cp_line" > expect_boot_cp_line317echo "$expect_redef_line" > expect_redef_line318echo "$expect_retrans_line" > expect_retrans_line319echo "$expect_set_nmp_line" > expect_set_nmp_line320}321322if [ "${TESTJAVA}" = "" ]323then324echo "TESTJAVA not set. Test cannot execute. Failed."325exit 1326fi327328if [ "${COMPILEJAVA}" = "" ]329then330COMPILEJAVA="${TESTJAVA}"331fi332echo "COMPILEJAVA=${COMPILEJAVA}"333334if [ "${TESTSRC}" = "" ]335then336echo "TESTSRC not set. Test cannot execute. Failed."337exit 1338fi339340if [ "${TESTCLASSES}" = "" ]341then342echo "TESTCLASSES not set. Test cannot execute. Failed."343exit 1344fi345346JAR="${COMPILEJAVA}/bin/jar"347JAVAC="${COMPILEJAVA}"/bin/javac348JAVA="${TESTJAVA}"/bin/java349350# Now that ManifestTestApp.class is built, we move351# ExampleForBootClassPath.class so that it cannot be found352# by default353OUT_OF_THE_WAY=out_of_the_way354mkdir $OUT_OF_THE_WAY355mv "${TESTCLASSES}/ExampleForBootClassPath.class" $OUT_OF_THE_WAY356357# create a bad version of ExampleForBootClassPath.class358# so we can tell when the wrong version is run359sed 's/return 15/return 42/' "${TESTSRC}"/ExampleForBootClassPath.java \360> ExampleForBootClassPath.java361"$JAVAC" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ExampleForBootClassPath.java362mv ExampleForBootClassPath.class \363$OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad364mv ExampleForBootClassPath.java \365$OUT_OF_THE_WAY/ExampleForBootClassPath.java.bad366367AGENT=ManifestTestAgent368# We compile the agent in the working directory instead of with369# a build task because we construct a different agent JAR file370# for each test case.371${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/${AGENT}.java372373FAIL_MARKER=fail_marker374rm -f $FAIL_MARKER375376while read token; do377echo378echo "===== begin test case: $token ====="379make_a_JAR "$token"380381"${JAVA}" ${TESTVMOPTS} -javaagent:${AGENT}.jar \382-classpath "${TESTCLASSES}" ManifestTestApp > output.log 2>&1383result=$?384385cat output.log386387if [ "$result" = 0 ]; then388echo "PASS: ManifestTestApp exited with status of 0."389else390echo "FAIL: ManifestTestApp exited with status of $result"391touch $FAIL_MARKER392fi393394MESG="Hello from ${AGENT}!"395grep -s "$MESG" output.log > /dev/null396result=$?397if [ "$result" = 0 ]; then398echo "PASS: found '$MESG' in the test output"399else400echo "FAIL: did NOT find '$MESG' in the test output"401touch $FAIL_MARKER402fi403404MESG=`cat expect_boot_cp_line | tr -d '\n\r'`405grep -s "$MESG" output.log > /dev/null406result=$?407if [ "$result" = 0 ]; then408echo "PASS: found '$MESG' in the test output"409else410echo "FAIL: did NOT find '$MESG' in the test output"411touch $FAIL_MARKER412fi413414MESG=`cat expect_redef_line | tr -d '\n\r'`415grep -s "$MESG" output.log > /dev/null416result=$?417if [ "$result" = 0 ]; then418echo "PASS: found '$MESG' in the test output"419else420echo "FAIL: did NOT find '$MESG' in the test output"421touch $FAIL_MARKER422fi423424MESG=`cat expect_retrans_line | tr -d '\n\r'`425grep -s "$MESG" output.log > /dev/null426result=$?427if [ "$result" = 0 ]; then428echo "PASS: found '$MESG' in the test output"429else430echo "FAIL: did NOT find '$MESG' in the test output"431touch $FAIL_MARKER432fi433434MESG=`cat expect_set_nmp_line | tr -d '\n\r'`435grep -s "$MESG" output.log > /dev/null436result=$?437if [ "$result" = 0 ]; then438echo "PASS: found '$MESG' in the test output"439else440echo "FAIL: did NOT find '$MESG' in the test output"441touch $FAIL_MARKER442fi443444#clean up any problematic directories445if [ -n "$to_be_deleted" ]; then446echo "Test removing [$to_be_deleted]"447rm -rf "$to_be_deleted"448fi449450echo "===== end test case: $token ====="451echo452done << EOF453defaults454version_line1455version_line2456version_line3457premain_line1458premain_line2459premain_line3460boot_cp_line1461boot_cp_line2462boot_cp_line3463boot_cp_line4464boot_cp_line5465can_redef_line1466can_redef_line2467can_redef_line3468can_redef_line4469can_redef_line5470can_redef_line6471can_redef_line7472can_redef_line8473can_redef_line10474can_redef_line11475can_retrans_line1476can_retrans_line2477can_retrans_line3478can_retrans_line4479can_retrans_line5480can_retrans_line6481can_retrans_line7482can_retrans_line8483can_retrans_line10484can_retrans_line11485can_set_nmp_line1486can_set_nmp_line2487can_set_nmp_line3488can_set_nmp_line4489can_set_nmp_line5490can_set_nmp_line6491can_set_nmp_line7492can_set_nmp_line8493can_set_nmp_line10494can_set_nmp_line11495EOF496497if [ -f $FAIL_MARKER ]; then498exit 1499else500exit 0501fi502503504