0N/A# @test MultipleJRE.sh
1113N/A# @bug 4811102 4953711 4955505 4956301 4991229 4998210 5018605 6387069 6733959
0N/A# @build PrintVersion
0N/A# @build UglyPrintVersion
1113N/A# @build ZipMeUp
0N/A# @run shell MultipleJRE.sh
0N/A# @summary Verify Multiple JRE version support
0N/A# @author Joseph E. Kowalski
0N/A
0N/A#
2362N/A# Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A#
0N/A# This code is free software; you can redistribute it and/or modify it
0N/A# under the terms of the GNU General Public License version 2 only, as
0N/A# published by the Free Software Foundation.
0N/A#
0N/A# This code is distributed in the hope that it will be useful, but WITHOUT
0N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A# version 2 for more details (a copy is included in the LICENSE file that
0N/A# accompanied this code).
0N/A#
0N/A# You should have received a copy of the GNU General Public License version
0N/A# 2 along with this work; if not, write to the Free Software Foundation,
0N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
0N/A#
0N/A
0N/A# Verify directory context variables are set
0N/Aif [ "${TESTJAVA}" = "" ]
0N/Athen
0N/A echo "TESTJAVA not set. Test cannot execute. Failed."
0N/A exit 1
0N/Afi
0N/A
0N/Aif [ "${TESTSRC}" = "" ]
0N/Athen
0N/A echo "TESTSRC not set. Test cannot execute. Failed."
0N/A exit 1
0N/Afi
0N/A
0N/Aif [ "${TESTCLASSES}" = "" ]
0N/Athen
0N/A echo "TESTCLASSES not set. Test cannot execute. Failed."
0N/A exit 1
0N/Afi
0N/A
1113N/AJAVAEXE="$TESTJAVA/bin/java"
0N/AJAVA="$TESTJAVA/bin/java -classpath $TESTCLASSES"
0N/AJAR="$TESTJAVA/bin/jar"
0N/AOS=`uname -s`;
0N/A
0N/A#
1113N/A# Tests whether we are on windows (true) or not.
1113N/A#
1113N/AIsWindows() {
1113N/A case "$OS" in
1113N/A Windows* | CYGWIN* )
1113N/A printf "true"
1113N/A ;;
1113N/A * )
1113N/A printf "false"
1113N/A ;;
1113N/A esac
1113N/A}
1113N/A
1113N/A#
0N/A# Shell routine to test for the proper rejection of syntactically incorrect
0N/A# version specifications.
0N/A#
0N/ATestSyntax() {
0N/A mess="`$JAVA -version:\"$1\" -version 2>&1`"
0N/A if [ $? -eq 0 ]; then
0N/A echo "Invalid version syntax $1 accepted"
0N/A exit 1
0N/A fi
0N/A prefix="`echo "$mess" | cut -d ' ' -f 1-3`"
0N/A if [ "$prefix" != "Error: Syntax error" ]; then
0N/A echo "Unexpected error message for invalid syntax $1"
0N/A exit 1
0N/A fi
0N/A}
0N/A
0N/A#
0N/A# Just as the name says. We sprinkle these in the appropriate location
0N/A# in the test file system and they just say who they are pretending to be.
0N/A#
0N/ACreateMockVM() {
0N/A mkdir -p jdk/j2re$1/bin
0N/A echo "#!/bin/sh" > jdk/j2re$1/bin/java
0N/A echo "echo \"$1\"" >> jdk/j2re$1/bin/java
0N/A chmod +x jdk/j2re$1/bin/java
0N/A}
0N/A
0N/A#
0N/A# Constructs the jar file needed by these tests.
0N/A#
0N/ACreateJar() {
0N/A mkdir -p META-INF
0N/A echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
0N/A echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
0N/A if [ "$1" != "" ]; then
0N/A echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
0N/A fi
0N/A cp $TESTCLASSES/PrintVersion.class .
0N/A $JAR $2cmf META-INF/MANIFEST.MF PrintVersion PrintVersion.class
0N/A}
0N/A
0N/A#
0N/A# Constructs a jar file using zip.
0N/A#
0N/ACreateZippyJar() {
0N/A mkdir -p META-INF
0N/A echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
0N/A echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
0N/A if [ "$1" != "" ]; then
0N/A echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
0N/A fi
0N/A cp $TESTCLASSES/PrintVersion.class .
0N/A /usr/bin/zip $2 PrintVersion META-INF/MANIFEST.MF PrintVersion.class
0N/A}
0N/A
0N/A#
0N/A# Constructs a jar file with a Main-Class attribute of greater than
0N/A# 80 characters to validate the continuation line processing.
0N/A#
0N/A# Make this just long enough to require two continuation lines. Longer
0N/A# paths take too much away from the restricted Windows maximum path length.
0N/A# Note: see the variable UGLYCLASS and its check for path length.
0N/A#
0N/A# Make sure that 5018605 remains fixed by including additional sections
0N/A# in the Manifest which contain the same names as those allowed in the
0N/A# main section.
0N/A#
0N/APACKAGE=reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongpackagename
0N/AUGLYCLASS=$TESTCLASSES/$PACKAGE/UglyPrintVersion.class
0N/ACreateUglyJar() {
0N/A mkdir -p META-INF
0N/A echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
0N/A echo "Main-Class: $PACKAGE.UglyPrintVersion" >> META-INF/MANIFEST.MF
0N/A if [ "$1" != "" ]; then
0N/A echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
0N/A fi
0N/A echo "" >> META-INF/MANIFEST.MF
0N/A echo "Name: NotToBeFound.class" >> META-INF/MANIFEST.MF
0N/A echo "Main-Class: NotToBeFound" >> META-INF/MANIFEST.MF
0N/A mkdir -p $PACKAGE
0N/A cp $UGLYCLASS $PACKAGE
0N/A $JAR $2cmf META-INF/MANIFEST.MF PrintVersion \
0N/A $PACKAGE/UglyPrintVersion.class
0N/A}
0N/A
0N/A#
0N/A# Constructs a jar file with a fair number of "zip directory" entries and
0N/A# the MANIFEST.MF entry at or near the end of that directory to validate
0N/A# the ability to transverse that directory.
0N/A#
0N/ACreateFullJar() {
0N/A mkdir -p META-INF
0N/A echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
0N/A echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
0N/A if [ "$1" != "" ]; then
0N/A echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
0N/A fi
0N/A cp $TESTCLASSES/PrintVersion.class .
0N/A for i in 0 1 2 3 4 5 6 7 8 9 ; do
0N/A for j in 0 1 2 3 4 5 6 7 8 9 ; do
0N/A touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j
0N/A done
0N/A done
0N/A $JAR $2cMf PrintVersion PrintVersion.class AfairlyLong*
0N/A $JAR $2umf META-INF/MANIFEST.MF PrintVersion
0N/A rm -f AfairlyLong*
0N/A}
0N/A
0N/A#
0N/A# Creates a jar file with the attributes which caused the failure
0N/A# described in 4991229.
0N/A#
0N/A# Generate a bunch of CENTAB entries, each of which is 64 bytes long
0N/A# which practically guarentees we will hit the appropriate power of
0N/A# two buffer (initially 1K). Note that due to the perversity of
0N/A# zip/jar files, the first entry gets extra stuff so it needs a
0N/A# shorter name to compensate.
0N/A#
0N/ACreateAlignedJar() {
0N/A mkdir -p META-INF
0N/A echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
0N/A echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
0N/A if [ "$1" != "" ]; then
0N/A echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
0N/A fi
0N/A cp $TESTCLASSES/PrintVersion.class .
0N/A touch 57BytesSpecial
0N/A for i in 0 1 2 3 4 5 6 7 8 9 ; do
0N/A for j in 0 1 2 3 4 5 6 7 8 9 ; do
0N/A touch 64BytesPerEntry-$i$j
0N/A done
0N/A done
0N/A $JAR $2cMf PrintVersion 57* 64* PrintVersion.class
0N/A $JAR $2umf META-INF/MANIFEST.MF PrintVersion
0N/A rm -f 57* 64*
0N/A}
0N/A
0N/A#
0N/A# Adds comments to a jar/zip file. This serves two purposes:
0N/A#
0N/A# 1) Make sure zip file comments (both per file and per archive) are
0N/A# properly processed and ignored.
0N/A#
0N/A# 2) A long file comment creates a mondo "Central Directory" entry in
0N/A# the zip file. Such a "mondo" entry could also be due to a very
0N/A# long file name (path) or a long "Ext" entry, but adding the long
0N/A# comment is the easiest way.
0N/A#
0N/ACommentZipFile() {
0N/A file=
0N/A tail="is designed to take up space - lots and lots of space."
0N/A mv PrintVersion PrintVersion.zip
0N/A /usr/bin/zipnote PrintVersion.zip > zipout
0N/A while read ampersand line; do
0N/A if [ "$ampersand" = "@" ]; then
0N/A if [ "$line" = "(comment above this line)" ]; then
0N/A echo "File Comment Line." >> zipin
0N/A if [ "$file" = "$1" ]; then
0N/A for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
0N/A for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
0N/A echo "Mondo comment line $i$j $tail" >> zipin
0N/A done
0N/A done
0N/A fi
0N/A else
0N/A file=$line
0N/A fi
0N/A fi
0N/A echo "$ampersand $line" >> zipin
0N/A if [ "$ampersand" = "@" ]; then
0N/A if [ "$line" = "(zip file comment below this line)" ]; then
0N/A echo "Zip File Comment Line number 1" >> zipin
0N/A echo "Zip File Comment Line number 2" >> zipin
0N/A fi
0N/A fi
0N/A done < zipout
0N/A /usr/bin/zipnote -w PrintVersion.zip < zipin
0N/A mv PrintVersion.zip PrintVersion
0N/A rm zipout zipin
0N/A}
0N/A
0N/A#
0N/A# Attempt to launch a vm using a version specifier and make sure the
0N/A# resultant launch (probably a "mock vm") is appropriate.
0N/A#
0N/ALaunchVM() {
0N/A if [ "$1" != "" ]; then
0N/A mess="`$JAVA -version:\"$1\" -jar PrintVersion 2>&1`"
0N/A else
0N/A mess="`$JAVA -jar PrintVersion 2>&1`"
0N/A fi
0N/A if [ $? -ne 0 ]; then
0N/A prefix=`echo "$mess" | cut -d ' ' -f 1-3`
0N/A if [ "$prefix" != "Unable to locate" ]; then
0N/A echo "$mess"
0N/A exit 1
0N/A fi
0N/A echo "Unexpected error in attempting to locate $1"
0N/A exit 1
0N/A fi
0N/A echo $mess | grep "$2" > /dev/null 2>&1
0N/A if [ $? != 0 ]; then
0N/A echo "Launched $mess, expected $2"
0N/A exit 1
0N/A fi
0N/A}
0N/A
1113N/A# Tests very long Main-Class attribute in the jar
1113N/ATestLongMainClass() {
1113N/A JVER=$1
1113N/A if [ "$JVER" = "mklink" ]; then
1113N/A JVER=XX
1113N/A JDKXX=jdk/j2re$JVER
1113N/A rm -rf jdk
1113N/A mkdir jdk
1113N/A ln -s $TESTJAVA $JDKXX
1113N/A JAVA_VERSION_PATH="`pwd`/jdk"
1113N/A export JAVA_VERSION_PATH
1113N/A fi
1113N/A $JAVAEXE -cp $TESTCLASSES ZipMeUp UglyBetty.jar 4097
1113N/A message="`$JAVAEXE -version:$JVER -jar UglyBetty.jar 2>&1`"
1113N/A echo $message | grep "Error: main-class: attribute exceeds system limits" > /dev/null 2>&1
1113N/A if [ $? -ne 0 ]; then
1113N/A printf "Long manifest test did not get expected error"
1113N/A exit 1
1113N/A fi
1113N/A unset JAVA_VERSION_PATH
1113N/A rm -rf jdk
1113N/A}
1113N/A
0N/A#
0N/A# Main test sequence starts here
0N/A#
0N/ARELEASE=`$JAVA -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | \
0N/A sed -e "s/\"//g"`
0N/ABASE_RELEASE=`echo $RELEASE | sed -e "s/-.*//g"`
0N/A
0N/A#
0N/A# Make sure that the generic jar/manifest reading code works. Test both
0N/A# compressed and "stored" jar files.
0N/A#
0N/A# The "Ugly" jar (long manifest line) tests are only run if the combination
0N/A# of the file name length restrictions and the length of the cwd allow it.
0N/A#
0N/ACreateJar "" ""
0N/ALaunchVM "" "${RELEASE}"
0N/ACreateJar "" "0"
0N/ALaunchVM "" "${RELEASE}"
1113N/Aif [ `IsWindows` = "true" ]; then
1113N/A MAXIMUM_PATH=255;
1113N/Aelse
1113N/A MAXIMUM_PATH=1024;
1113N/Afi
0N/A
0N/APATH_LENGTH=`printf "%s" "$UGLYCLASS" | wc -c`
0N/Aif [ ${PATH_LENGTH} -lt ${MAXIMUM_PATH} ]; then
0N/A CreateUglyJar "" ""
0N/A LaunchVM "" "${RELEASE}"
0N/A CreateUglyJar "" "0"
0N/A LaunchVM "" "${RELEASE}"
0N/Aelse
0N/A printf "Warning: Skipped UglyJar test, path length exceeded, %d" $MAXIMUM_PATH
0N/A printf " allowed, the current path is %d\n" $PATH_LENGTH
0N/Afi
0N/ACreateAlignedJar "" ""
0N/ALaunchVM "" "${RELEASE}"
0N/ACreateFullJar "" ""
0N/ALaunchVM "" "${RELEASE}"
0N/A
0N/A#
0N/A# 4998210 shows that some very strange behaviors are semi-supported.
0N/A# In this case, it's the ability to prepend any kind of stuff to the
0N/A# jar file and require that the jar file still work. Note that this
0N/A# "interface" isn't publically supported and we may choose to break
0N/A# it in the future, but this test guarantees that we won't break it
0N/A# without informed consent. We take advantage the fact that the
0N/A# "FullJar" we just tested is probably the best jar to begin with
0N/A# for this test.
0N/A#
0N/Aecho "This is just meaningless bytes to prepend to the jar" > meaningless
0N/Amv PrintVersion meaningfull
0N/Acat meaningless meaningfull > PrintVersion
0N/ALaunchVM "" "${RELEASE}"
0N/Arm meaningless meaningfull
0N/A
0N/A#
0N/A# Officially, one must use "the jar command to create a jar file. However,
0N/A# all the comments about jar commands **imply** that jar files and zip files
0N/A# are equivalent. (Note: this isn't true due to the "0xcafe" insertion.)
0N/A# On systems which have a command line zip, test the ability to use zip
0N/A# to construct a jar and then use it (6387069).
0N/A#
0N/Aif [ -x /usr/bin/zip ]; then
0N/A CreateZippyJar "" "-q"
0N/A LaunchVM "" "${RELEASE}"
0N/Afi
0N/A
0N/A#
0N/A# jar files shouldn't have comments, but it is possible that somebody added
0N/A# one by using zip -c, zip -z, zipnote or a similar utility. On systems
0N/A# that have "zipnote", verify this functionality.
0N/A#
0N/A# This serves a dual purpose of creating a very large "central directory
0N/A# entry" which validates to code to read such entries.
0N/A#
0N/Aif [ -x /usr/bin/zipnote ]; then
0N/A CreateFullJar "" ""
0N/A CommentZipFile "AfairlyLongNameEatsUpDirectorySpaceBetter20"
0N/A LaunchVM "" "${RELEASE}"
0N/Afi
0N/A
0N/A#
0N/A# Throw some syntactically challenged (illegal) version specifiers at
0N/A# the interface. Failure (of the launcher) is success for the test.
0N/A#
0N/ATestSyntax "1.2..3" # Two adjacent separators
0N/ATestSyntax "_1.2.3" # Begins with a separator
0N/ATestSyntax "1.2.3-" # Ends with a separator
0N/ATestSyntax "1.2+.3" # Embedded modifier
0N/ATestSyntax "1.2.4+&1.2*&1++" # Long and invalid
0N/A
1113N/A# On windows we see if there is another jre installed, usually
1113N/A# there is, then we test using that, otherwise links are created
1113N/A# to get through to SelectVersion.
1113N/Aif [ `IsWindows` = "false" ]; then
1113N/A TestLongMainClass "mklink"
1113N/Aelse
1113N/A $JAVAEXE -version:1.0+
1113N/A if [ $? -eq 0 ]; then
1113N/A TestLongMainClass "1.0+"
1113N/A else
1113N/A printf "Warning: TestLongMainClass skipped as there is no"
1113N/A printf "viable MJRE installed.\n"
1113N/A fi
1113N/Afi
1113N/A
0N/A#
0N/A# Because scribbling in the registry can be rather destructive, only a
0N/A# subset of the tests are run on Windows.
0N/A#
1113N/Aif [ `IsWindows` = "true" ]; then
1113N/A exit 0;
1113N/Afi
0N/A
0N/A#
0N/A# Additional version specifiers containing spaces. (Sigh, unable to
0N/A# figure out the glomming on Windows)
0N/A#
0N/ATestSyntax "1.2.3_99 1.3.2+ 1.2.4+&1.2*&1++" # Long and invalid
0N/A
0N/A#
0N/A# Create a mock installation of a number of shell scripts named as though
0N/A# they were installed JREs. Then test to see if the launcher can cause
0N/A# the right shell scripts to be invoked.
0N/A#
0N/A# Note, that as a side effect, this test verifies that JAVA_VERSION_PATH
0N/A# works.
0N/A#
0N/Arm -rf jdk
0N/AJAVA_VERSION_PATH="`pwd`/jdk"
0N/Aexport JAVA_VERSION_PATH
0N/A
0N/ACreateMockVM 1.10
0N/ACreateMockVM 1.11.3
0N/ACreateMockVM 1.11.3_03
0N/ACreateMockVM 1.11.4
0N/ACreateMockVM 1.12.3_03
0N/ACreateMockVM 1.12.3_03-lastweek
0N/ACreateMockVM 1.13.3_03
0N/ACreateMockVM 1.13.3_03-lastweek
0N/ACreateMockVM 1.13.3_03_lastweek
0N/ACreateMockVM 1.20.0
0N/A
0N/A#
0N/A# Test extracting the version information from the jar file:
0N/A#
0N/A# Requested Expected
0N/ACreateJar "1.10+" ""
0N/ALaunchVM "" "1.20.0"
0N/ACreateJar "1.11.3_03+&1.11*" ""
0N/ALaunchVM "" "1.11.4"
0N/ACreateJar "1.12.3_03+&1.12.3*" ""
0N/ALaunchVM "" "1.12.3_03"
0N/ACreateJar "1.13.3_03+&1.13.3*" ""
0N/ALaunchVM "" "1.13.3_03_lastweek" # Strange but true
0N/A
0N/A#
0N/A# Test obtaining the version information from the command line (and that
0N/A# it overrides the manifest).
0N/A#
0N/ACreateJar "${BASERELEASE}*" ""
0N/ALaunchVM "1.10+" "1.20.0"
0N/ALaunchVM "1.11.3_03+&1.11*" "1.11.4"
0N/ALaunchVM "1.12.3_03+&1.12.3*" "1.12.3_03"
0N/ALaunchVM "1.13.3_03+&1.13.3*" "1.13.3_03_lastweek" # Strange but true
0N/A
0N/A[ -d jdk ] && rm -rf jdk
0N/A[ -d META_INF ] && rm -rf META_INF
0N/A
0N/Aexit 0