Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/launcher/MultipleJRE.sh
38833 views
#!/bin/sh1# @test MultipleJRE.sh2# @bug 4811102 4953711 4955505 4956301 4991229 4998210 5018605 6387069 67339593# @build PrintVersion4# @build UglyPrintVersion5# @build ZipMeUp6# @run shell MultipleJRE.sh7# @summary Verify Multiple JRE version support8# @author Joseph E. Kowalski910#11# Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.12# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.13#14# This code is free software; you can redistribute it and/or modify it15# under the terms of the GNU General Public License version 2 only, as16# published by the Free Software Foundation.17#18# This code is distributed in the hope that it will be useful, but WITHOUT19# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or20# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License21# version 2 for more details (a copy is included in the LICENSE file that22# accompanied this code).23#24# You should have received a copy of the GNU General Public License version25# 2 along with this work; if not, write to the Free Software Foundation,26# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.27#28# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA29# or visit www.oracle.com if you need additional information or have any30# questions.31#3233# Verify directory context variables are set34if [ "${TESTJAVA}" = "" ]35then36echo "TESTJAVA not set. Test cannot execute. Failed."37exit 138fi3940if [ "${COMPILEJAVA}" = "" ]; then41COMPILEJAVA="${TESTJAVA}"42fi4344if [ "${TESTSRC}" = "" ]45then46echo "TESTSRC not set. Test cannot execute. Failed."47exit 148fi4950if [ "${TESTCLASSES}" = "" ]51then52echo "TESTCLASSES not set. Test cannot execute. Failed."53exit 154fi5556JAVAEXE="$TESTJAVA/bin/java ${TESTVMOPTS}"57JAVA="$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES"58JAR="$COMPILEJAVA/bin/jar ${TESTTOOLVMOPTS}"59OS=`uname -s`;6061#62# Tests whether we are on windows (true) or not.63#64IsWindows() {65case "$OS" in66Windows* | CYGWIN* )67printf "true"68;;69* )70printf "false"71;;72esac73}7475#76# Shell routine to test for the proper rejection of syntactically incorrect77# version specifications.78#79TestSyntax() {80mess="`$JAVA -version:\"$1\" -version 2>&1`"81if [ $? -eq 0 ]; then82echo "Invalid version syntax $1 accepted"83exit 184fi85prefix="`echo "$mess" | cut -d ' ' -f 1-3`"86if [ "$prefix" != "Error: Syntax error" ]; then87echo "Unexpected error message for invalid syntax $1"88exit 189fi90}9192#93# Just as the name says. We sprinkle these in the appropriate location94# in the test file system and they just say who they are pretending to be.95#96CreateMockVM() {97mkdir -p jdk/j2re$1/bin98echo "#!/bin/sh" > jdk/j2re$1/bin/java99echo "echo \"$1\"" >> jdk/j2re$1/bin/java100chmod +x jdk/j2re$1/bin/java101}102103#104# Constructs the jar file needed by these tests.105#106CreateJar() {107mkdir -p META-INF108echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF109echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF110if [ "$1" != "" ]; then111echo "JRE-Version: $1" >> META-INF/MANIFEST.MF112fi113cp $TESTCLASSES/PrintVersion.class .114$JAR $2cmf META-INF/MANIFEST.MF PrintVersion PrintVersion.class115}116117#118# Constructs a jar file using zip.119#120CreateZippyJar() {121mkdir -p META-INF122echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF123echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF124if [ "$1" != "" ]; then125echo "JRE-Version: $1" >> META-INF/MANIFEST.MF126fi127cp $TESTCLASSES/PrintVersion.class .128/usr/bin/zip $2 PrintVersion META-INF/MANIFEST.MF PrintVersion.class129}130131#132# Constructs a jar file with a Main-Class attribute of greater than133# 80 characters to validate the continuation line processing.134#135# Make this just long enough to require two continuation lines. Longer136# paths take too much away from the restricted Windows maximum path length.137# Note: see the variable UGLYCLASS and its check for path length.138#139# Make sure that 5018605 remains fixed by including additional sections140# in the Manifest which contain the same names as those allowed in the141# main section.142#143PACKAGE=reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongpackagename144UGLYCLASS=$TESTCLASSES/$PACKAGE/UglyPrintVersion.class145CreateUglyJar() {146mkdir -p META-INF147echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF148echo "Main-Class: $PACKAGE.UglyPrintVersion" >> META-INF/MANIFEST.MF149if [ "$1" != "" ]; then150echo "JRE-Version: $1" >> META-INF/MANIFEST.MF151fi152echo "" >> META-INF/MANIFEST.MF153echo "Name: NotToBeFound.class" >> META-INF/MANIFEST.MF154echo "Main-Class: NotToBeFound" >> META-INF/MANIFEST.MF155mkdir -p $PACKAGE156cp $UGLYCLASS $PACKAGE157$JAR $2cmf META-INF/MANIFEST.MF PrintVersion \158$PACKAGE/UglyPrintVersion.class159}160161#162# Constructs a jar file with a fair number of "zip directory" entries and163# the MANIFEST.MF entry at or near the end of that directory to validate164# the ability to transverse that directory.165#166CreateFullJar() {167mkdir -p META-INF168echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF169echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF170if [ "$1" != "" ]; then171echo "JRE-Version: $1" >> META-INF/MANIFEST.MF172fi173cp $TESTCLASSES/PrintVersion.class .174for i in 0 1 2 3 4 5 6 7 8 9 ; do175for j in 0 1 2 3 4 5 6 7 8 9 ; do176touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j177done178done179$JAR $2cMf PrintVersion PrintVersion.class AfairlyLong*180$JAR $2umf META-INF/MANIFEST.MF PrintVersion181rm -f AfairlyLong*182}183184#185# Creates a jar file with the attributes which caused the failure186# described in 4991229.187#188# Generate a bunch of CENTAB entries, each of which is 64 bytes long189# which practically guarentees we will hit the appropriate power of190# two buffer (initially 1K). Note that due to the perversity of191# zip/jar files, the first entry gets extra stuff so it needs a192# shorter name to compensate.193#194CreateAlignedJar() {195mkdir -p META-INF196echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF197echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF198if [ "$1" != "" ]; then199echo "JRE-Version: $1" >> META-INF/MANIFEST.MF200fi201cp $TESTCLASSES/PrintVersion.class .202touch 57BytesSpecial203for i in 0 1 2 3 4 5 6 7 8 9 ; do204for j in 0 1 2 3 4 5 6 7 8 9 ; do205touch 64BytesPerEntry-$i$j206done207done208$JAR $2cMf PrintVersion 57* 64* PrintVersion.class209$JAR $2umf META-INF/MANIFEST.MF PrintVersion210rm -f 57* 64*211}212213#214# Adds comments to a jar/zip file. This serves two purposes:215#216# 1) Make sure zip file comments (both per file and per archive) are217# properly processed and ignored.218#219# 2) A long file comment creates a mondo "Central Directory" entry in220# the zip file. Such a "mondo" entry could also be due to a very221# long file name (path) or a long "Ext" entry, but adding the long222# comment is the easiest way.223#224CommentZipFile() {225file=226tail="is designed to take up space - lots and lots of space."227mv PrintVersion PrintVersion.zip228/usr/bin/zipnote PrintVersion.zip > zipout229while read ampersand line; do230if [ "$ampersand" = "@" ]; then231if [ "$line" = "(comment above this line)" ]; then232echo "File Comment Line." >> zipin233if [ "$file" = "$1" ]; then234for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do235for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do236echo "Mondo comment line $i$j $tail" >> zipin237done238done239fi240else241file=$line242fi243fi244echo "$ampersand $line" >> zipin245if [ "$ampersand" = "@" ]; then246if [ "$line" = "(zip file comment below this line)" ]; then247echo "Zip File Comment Line number 1" >> zipin248echo "Zip File Comment Line number 2" >> zipin249fi250fi251done < zipout252/usr/bin/zipnote -w PrintVersion.zip < zipin253mv PrintVersion.zip PrintVersion254rm zipout zipin255}256257#258# Attempt to launch a vm using a version specifier and make sure the259# resultant launch (probably a "mock vm") is appropriate.260#261LaunchVM() {262if [ "$1" != "" ]; then263mess="`$JAVA -version:\"$1\" -jar PrintVersion 2>&1`"264else265mess="`$JAVA -jar PrintVersion 2>&1`"266fi267if [ $? -ne 0 ]; then268prefix=`echo "$mess" | cut -d ' ' -f 1-3`269if [ "$prefix" != "Unable to locate" ]; then270echo "$mess"271exit 1272fi273echo "Unexpected error in attempting to locate $1"274exit 1275fi276echo $mess | grep "$2" > /dev/null 2>&1277if [ $? != 0 ]; then278echo "Launched $mess, expected $2"279exit 1280fi281}282283# Tests very long Main-Class attribute in the jar284TestLongMainClass() {285JVER=$1286if [ "$JVER" = "mklink" ]; then287JVER=XX288JDKXX=jdk/j2re$JVER289rm -rf jdk290mkdir jdk291ln -s $TESTJAVA $JDKXX292JAVA_VERSION_PATH="`pwd`/jdk"293export JAVA_VERSION_PATH294fi295$JAVAEXE -cp $TESTCLASSES ZipMeUp UglyBetty.jar 4097296message="`$JAVAEXE -version:$JVER -jar UglyBetty.jar 2>&1`"297echo $message | grep "Error: main-class: attribute exceeds system limits" > /dev/null 2>&1298if [ $? -ne 0 ]; then299printf "Long manifest test did not get expected error"300exit 1301fi302unset JAVA_VERSION_PATH303rm -rf jdk304}305306#307# Main test sequence starts here308#309RELEASE=`$JAVA -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | \310sed -e "s/\"//g" | sed -e "s/\r//g"`311BASE_RELEASE=`echo $RELEASE | sed -e "s/-.*//g"`312313#314# Make sure that the generic jar/manifest reading code works. Test both315# compressed and "stored" jar files.316#317# The "Ugly" jar (long manifest line) tests are only run if the combination318# of the file name length restrictions and the length of the cwd allow it.319#320CreateJar "" ""321LaunchVM "" "${RELEASE}"322CreateJar "" "0"323LaunchVM "" "${RELEASE}"324if [ `IsWindows` = "true" ]; then325MAXIMUM_PATH=255;326else327MAXIMUM_PATH=1024;328fi329330PATH_LENGTH=`printf "%s" "$UGLYCLASS" | wc -c`331if [ ${PATH_LENGTH} -lt ${MAXIMUM_PATH} ]; then332CreateUglyJar "" ""333LaunchVM "" "${RELEASE}"334CreateUglyJar "" "0"335LaunchVM "" "${RELEASE}"336else337printf "Warning: Skipped UglyJar test, path length exceeded, %d" $MAXIMUM_PATH338printf " allowed, the current path is %d\n" $PATH_LENGTH339fi340CreateAlignedJar "" ""341LaunchVM "" "${RELEASE}"342CreateFullJar "" ""343LaunchVM "" "${RELEASE}"344345#346# 4998210 shows that some very strange behaviors are semi-supported.347# In this case, it's the ability to prepend any kind of stuff to the348# jar file and require that the jar file still work. Note that this349# "interface" isn't publically supported and we may choose to break350# it in the future, but this test guarantees that we won't break it351# without informed consent. We take advantage the fact that the352# "FullJar" we just tested is probably the best jar to begin with353# for this test.354#355echo "This is just meaningless bytes to prepend to the jar" > meaningless356mv PrintVersion meaningfull357cat meaningless meaningfull > PrintVersion358LaunchVM "" "${RELEASE}"359rm meaningless meaningfull360361#362# Officially, one must use "the jar command to create a jar file. However,363# all the comments about jar commands **imply** that jar files and zip files364# are equivalent. (Note: this isn't true due to the "0xcafe" insertion.)365# On systems which have a command line zip, test the ability to use zip366# to construct a jar and then use it (6387069).367#368if [ -x /usr/bin/zip ]; then369CreateZippyJar "" "-q"370LaunchVM "" "${RELEASE}"371fi372373#374# jar files shouldn't have comments, but it is possible that somebody added375# one by using zip -c, zip -z, zipnote or a similar utility. On systems376# that have "zipnote", verify this functionality.377#378# This serves a dual purpose of creating a very large "central directory379# entry" which validates to code to read such entries.380#381if [ -x /usr/bin/zipnote ]; then382CreateFullJar "" ""383CommentZipFile "AfairlyLongNameEatsUpDirectorySpaceBetter20"384LaunchVM "" "${RELEASE}"385fi386387#388# Throw some syntactically challenged (illegal) version specifiers at389# the interface. Failure (of the launcher) is success for the test.390#391TestSyntax "1.2..3" # Two adjacent separators392TestSyntax "_1.2.3" # Begins with a separator393TestSyntax "1.2.3-" # Ends with a separator394TestSyntax "1.2+.3" # Embedded modifier395TestSyntax "1.2.4+&1.2*&1++" # Long and invalid396397# On windows we see if there is another jre installed, usually398# there is, then we test using that, otherwise links are created399# to get through to SelectVersion.400if [ `IsWindows` = "false" ]; then401TestLongMainClass "mklink"402else403$JAVAEXE -version:1.0+404if [ $? -eq 0 ]; then405TestLongMainClass "1.0+"406else407printf "Warning: TestLongMainClass skipped as there is no"408printf "viable MJRE installed.\n"409fi410fi411412#413# Because scribbling in the registry can be rather destructive, only a414# subset of the tests are run on Windows.415#416if [ `IsWindows` = "true" ]; then417exit 0;418fi419420#421# Additional version specifiers containing spaces. (Sigh, unable to422# figure out the glomming on Windows)423#424TestSyntax "1.2.3_99 1.3.2+ 1.2.4+&1.2*&1++" # Long and invalid425426#427# Create a mock installation of a number of shell scripts named as though428# they were installed JREs. Then test to see if the launcher can cause429# the right shell scripts to be invoked.430#431# Note, that as a side effect, this test verifies that JAVA_VERSION_PATH432# works.433#434rm -rf jdk435JAVA_VERSION_PATH="`pwd`/jdk"436export JAVA_VERSION_PATH437438CreateMockVM 1.10439CreateMockVM 1.11.3440CreateMockVM 1.11.3_03441CreateMockVM 1.11.4442CreateMockVM 1.12.3_03443CreateMockVM 1.12.3_03-lastweek444CreateMockVM 1.13.3_03445CreateMockVM 1.13.3_03-lastweek446CreateMockVM 1.13.3_03_lastweek447CreateMockVM 1.20.0448449#450# Test extracting the version information from the jar file:451#452# Requested Expected453CreateJar "1.10+" ""454LaunchVM "" "1.20.0"455CreateJar "1.11.3_03+&1.11*" ""456LaunchVM "" "1.11.4"457CreateJar "1.12.3_03+&1.12.3*" ""458LaunchVM "" "1.12.3_03"459CreateJar "1.13.3_03+&1.13.3*" ""460LaunchVM "" "1.13.3_03_lastweek" # Strange but true461462#463# Test obtaining the version information from the command line (and that464# it overrides the manifest).465#466CreateJar "${BASERELEASE}*" ""467LaunchVM "1.10+" "1.20.0"468LaunchVM "1.11.3_03+&1.11*" "1.11.4"469LaunchVM "1.12.3_03+&1.12.3*" "1.12.3_03"470LaunchVM "1.13.3_03+&1.13.3*" "1.13.3_03_lastweek" # Strange but true471472[ -d jdk ] && rm -rf jdk473[ -d META_INF ] && rm -rf META_INF474475exit 0476477478