blob: 0c8e95d29fb07c824394b48b3cd5a97cdcdc1e92 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001# @test MultipleJRE.sh
ksrini8760ca92008-09-04 09:43:32 -07002# @bug 4811102 4953711 4955505 4956301 4991229 4998210 5018605 6387069 6733959
duke6e45e102007-12-01 00:00:00 +00003# @build PrintVersion
4# @build UglyPrintVersion
ksrini8760ca92008-09-04 09:43:32 -07005# @build ZipMeUp
duke6e45e102007-12-01 00:00:00 +00006# @run shell MultipleJRE.sh
7# @summary Verify Multiple JRE version support
8# @author Joseph E. Kowalski
9
duke6e45e102007-12-01 00:00:00 +000010#
ohair2283b9d2010-05-25 15:58:33 -070011# Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
duke6e45e102007-12-01 00:00:00 +000012# 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 it
15# under the terms of the GNU General Public License version 2 only, as
16# published by the Free Software Foundation.
17#
18# This code is distributed in the hope that it will be useful, but WITHOUT
19# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21# version 2 for more details (a copy is included in the LICENSE file that
22# accompanied this code).
23#
24# You should have received a copy of the GNU General Public License version
25# 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#
ohair2283b9d2010-05-25 15:58:33 -070028# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
29# or visit www.oracle.com if you need additional information or have any
30# questions.
duke6e45e102007-12-01 00:00:00 +000031#
32
33# Verify directory context variables are set
34if [ "${TESTJAVA}" = "" ]
35then
36 echo "TESTJAVA not set. Test cannot execute. Failed."
37 exit 1
38fi
39
alanb303e05f2013-01-11 20:19:55 +000040if [ "${COMPILEJAVA}" = "" ]; then
41 COMPILEJAVA="${TESTJAVA}"
42fi
43
duke6e45e102007-12-01 00:00:00 +000044if [ "${TESTSRC}" = "" ]
45then
46 echo "TESTSRC not set. Test cannot execute. Failed."
47 exit 1
48fi
49
50if [ "${TESTCLASSES}" = "" ]
51then
52 echo "TESTCLASSES not set. Test cannot execute. Failed."
53 exit 1
54fi
55
chegar3f6cad72012-12-13 14:47:35 +000056JAVAEXE="$TESTJAVA/bin/java ${TESTVMOPTS}"
57JAVA="$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES"
alanb303e05f2013-01-11 20:19:55 +000058JAR="$COMPILEJAVA/bin/jar ${TESTTOOLVMOPTS}"
duke6e45e102007-12-01 00:00:00 +000059OS=`uname -s`;
60
61#
ksrini8760ca92008-09-04 09:43:32 -070062# Tests whether we are on windows (true) or not.
63#
64IsWindows() {
65 case "$OS" in
66 Windows* | CYGWIN* )
67 printf "true"
68 ;;
69 * )
70 printf "false"
71 ;;
72 esac
73}
74
75#
duke6e45e102007-12-01 00:00:00 +000076# Shell routine to test for the proper rejection of syntactically incorrect
77# version specifications.
78#
79TestSyntax() {
80 mess="`$JAVA -version:\"$1\" -version 2>&1`"
81 if [ $? -eq 0 ]; then
82 echo "Invalid version syntax $1 accepted"
83 exit 1
84 fi
85 prefix="`echo "$mess" | cut -d ' ' -f 1-3`"
86 if [ "$prefix" != "Error: Syntax error" ]; then
87 echo "Unexpected error message for invalid syntax $1"
88 exit 1
89 fi
90}
91
92#
93# Just as the name says. We sprinkle these in the appropriate location
94# in the test file system and they just say who they are pretending to be.
95#
96CreateMockVM() {
97 mkdir -p jdk/j2re$1/bin
98 echo "#!/bin/sh" > jdk/j2re$1/bin/java
99 echo "echo \"$1\"" >> jdk/j2re$1/bin/java
100 chmod +x jdk/j2re$1/bin/java
101}
102
103#
104# Constructs the jar file needed by these tests.
105#
106CreateJar() {
107 mkdir -p META-INF
108 echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
109 echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
110 if [ "$1" != "" ]; then
111 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
112 fi
113 cp $TESTCLASSES/PrintVersion.class .
114 $JAR $2cmf META-INF/MANIFEST.MF PrintVersion PrintVersion.class
115}
116
117#
118# Constructs a jar file using zip.
119#
120CreateZippyJar() {
121 mkdir -p META-INF
122 echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
123 echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
124 if [ "$1" != "" ]; then
125 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
126 fi
127 cp $TESTCLASSES/PrintVersion.class .
128 /usr/bin/zip $2 PrintVersion META-INF/MANIFEST.MF PrintVersion.class
129}
130
131#
132# Constructs a jar file with a Main-Class attribute of greater than
133# 80 characters to validate the continuation line processing.
134#
135# Make this just long enough to require two continuation lines. Longer
136# 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 sections
140# in the Manifest which contain the same names as those allowed in the
141# main section.
142#
143PACKAGE=reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongpackagename
144UGLYCLASS=$TESTCLASSES/$PACKAGE/UglyPrintVersion.class
145CreateUglyJar() {
146 mkdir -p META-INF
147 echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
148 echo "Main-Class: $PACKAGE.UglyPrintVersion" >> META-INF/MANIFEST.MF
149 if [ "$1" != "" ]; then
150 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
151 fi
152 echo "" >> META-INF/MANIFEST.MF
153 echo "Name: NotToBeFound.class" >> META-INF/MANIFEST.MF
154 echo "Main-Class: NotToBeFound" >> META-INF/MANIFEST.MF
155 mkdir -p $PACKAGE
156 cp $UGLYCLASS $PACKAGE
157 $JAR $2cmf META-INF/MANIFEST.MF PrintVersion \
158 $PACKAGE/UglyPrintVersion.class
159}
160
duke6e45e102007-12-01 00:00:00 +0000161#
162# Constructs a jar file with a fair number of "zip directory" entries and
163# the MANIFEST.MF entry at or near the end of that directory to validate
164# the ability to transverse that directory.
165#
166CreateFullJar() {
167 mkdir -p META-INF
168 echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
169 echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
170 if [ "$1" != "" ]; then
171 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
172 fi
173 cp $TESTCLASSES/PrintVersion.class .
174 for i in 0 1 2 3 4 5 6 7 8 9 ; do
175 for j in 0 1 2 3 4 5 6 7 8 9 ; do
176 touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j
177 done
178 done
179 $JAR $2cMf PrintVersion PrintVersion.class AfairlyLong*
180 $JAR $2umf META-INF/MANIFEST.MF PrintVersion
181 rm -f AfairlyLong*
182}
183
184#
185# Creates a jar file with the attributes which caused the failure
186# described in 4991229.
187#
188# Generate a bunch of CENTAB entries, each of which is 64 bytes long
189# which practically guarentees we will hit the appropriate power of
190# two buffer (initially 1K). Note that due to the perversity of
191# zip/jar files, the first entry gets extra stuff so it needs a
192# shorter name to compensate.
193#
194CreateAlignedJar() {
195 mkdir -p META-INF
196 echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
197 echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
198 if [ "$1" != "" ]; then
199 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
200 fi
201 cp $TESTCLASSES/PrintVersion.class .
202 touch 57BytesSpecial
203 for i in 0 1 2 3 4 5 6 7 8 9 ; do
204 for j in 0 1 2 3 4 5 6 7 8 9 ; do
205 touch 64BytesPerEntry-$i$j
206 done
207 done
208 $JAR $2cMf PrintVersion 57* 64* PrintVersion.class
209 $JAR $2umf META-INF/MANIFEST.MF PrintVersion
210 rm -f 57* 64*
211}
212
213#
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) are
217# properly processed and ignored.
218#
219# 2) A long file comment creates a mondo "Central Directory" entry in
220# the zip file. Such a "mondo" entry could also be due to a very
221# long file name (path) or a long "Ext" entry, but adding the long
222# comment is the easiest way.
223#
224CommentZipFile() {
225 file=
226 tail="is designed to take up space - lots and lots of space."
227 mv PrintVersion PrintVersion.zip
228 /usr/bin/zipnote PrintVersion.zip > zipout
229 while read ampersand line; do
230 if [ "$ampersand" = "@" ]; then
231 if [ "$line" = "(comment above this line)" ]; then
232 echo "File Comment Line." >> zipin
233 if [ "$file" = "$1" ]; then
234 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
235 for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
236 echo "Mondo comment line $i$j $tail" >> zipin
237 done
238 done
239 fi
240 else
241 file=$line
242 fi
243 fi
244 echo "$ampersand $line" >> zipin
245 if [ "$ampersand" = "@" ]; then
246 if [ "$line" = "(zip file comment below this line)" ]; then
247 echo "Zip File Comment Line number 1" >> zipin
248 echo "Zip File Comment Line number 2" >> zipin
249 fi
250 fi
251 done < zipout
252 /usr/bin/zipnote -w PrintVersion.zip < zipin
253 mv PrintVersion.zip PrintVersion
254 rm zipout zipin
255}
256
257#
258# Attempt to launch a vm using a version specifier and make sure the
259# resultant launch (probably a "mock vm") is appropriate.
260#
261LaunchVM() {
262 if [ "$1" != "" ]; then
263 mess="`$JAVA -version:\"$1\" -jar PrintVersion 2>&1`"
264 else
265 mess="`$JAVA -jar PrintVersion 2>&1`"
266 fi
267 if [ $? -ne 0 ]; then
268 prefix=`echo "$mess" | cut -d ' ' -f 1-3`
269 if [ "$prefix" != "Unable to locate" ]; then
270 echo "$mess"
271 exit 1
272 fi
273 echo "Unexpected error in attempting to locate $1"
274 exit 1
275 fi
276 echo $mess | grep "$2" > /dev/null 2>&1
277 if [ $? != 0 ]; then
278 echo "Launched $mess, expected $2"
279 exit 1
280 fi
281}
282
ksrini8760ca92008-09-04 09:43:32 -0700283# Tests very long Main-Class attribute in the jar
284TestLongMainClass() {
285 JVER=$1
286 if [ "$JVER" = "mklink" ]; then
287 JVER=XX
288 JDKXX=jdk/j2re$JVER
289 rm -rf jdk
290 mkdir jdk
291 ln -s $TESTJAVA $JDKXX
292 JAVA_VERSION_PATH="`pwd`/jdk"
293 export JAVA_VERSION_PATH
294 fi
295 $JAVAEXE -cp $TESTCLASSES ZipMeUp UglyBetty.jar 4097
296 message="`$JAVAEXE -version:$JVER -jar UglyBetty.jar 2>&1`"
297 echo $message | grep "Error: main-class: attribute exceeds system limits" > /dev/null 2>&1
298 if [ $? -ne 0 ]; then
299 printf "Long manifest test did not get expected error"
300 exit 1
301 fi
302 unset JAVA_VERSION_PATH
303 rm -rf jdk
304}
305
duke6e45e102007-12-01 00:00:00 +0000306#
307# Main test sequence starts here
308#
309RELEASE=`$JAVA -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | \
310 sed -e "s/\"//g"`
311BASE_RELEASE=`echo $RELEASE | sed -e "s/-.*//g"`
312
313#
314# Make sure that the generic jar/manifest reading code works. Test both
315# compressed and "stored" jar files.
316#
317# The "Ugly" jar (long manifest line) tests are only run if the combination
318# of the file name length restrictions and the length of the cwd allow it.
319#
320CreateJar "" ""
321LaunchVM "" "${RELEASE}"
322CreateJar "" "0"
323LaunchVM "" "${RELEASE}"
ksrini8760ca92008-09-04 09:43:32 -0700324if [ `IsWindows` = "true" ]; then
325 MAXIMUM_PATH=255;
326else
327 MAXIMUM_PATH=1024;
328fi
duke6e45e102007-12-01 00:00:00 +0000329
330PATH_LENGTH=`printf "%s" "$UGLYCLASS" | wc -c`
331if [ ${PATH_LENGTH} -lt ${MAXIMUM_PATH} ]; then
332 CreateUglyJar "" ""
333 LaunchVM "" "${RELEASE}"
334 CreateUglyJar "" "0"
335 LaunchVM "" "${RELEASE}"
336else
337 printf "Warning: Skipped UglyJar test, path length exceeded, %d" $MAXIMUM_PATH
338 printf " allowed, the current path is %d\n" $PATH_LENGTH
339fi
340CreateAlignedJar "" ""
341LaunchVM "" "${RELEASE}"
342CreateFullJar "" ""
343LaunchVM "" "${RELEASE}"
344
345#
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 the
348# jar file and require that the jar file still work. Note that this
349# "interface" isn't publically supported and we may choose to break
350# it in the future, but this test guarantees that we won't break it
351# without informed consent. We take advantage the fact that the
352# "FullJar" we just tested is probably the best jar to begin with
353# for this test.
354#
355echo "This is just meaningless bytes to prepend to the jar" > meaningless
356mv PrintVersion meaningfull
357cat meaningless meaningfull > PrintVersion
358LaunchVM "" "${RELEASE}"
359rm meaningless meaningfull
360
361#
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 files
364# 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 zip
366# to construct a jar and then use it (6387069).
367#
368if [ -x /usr/bin/zip ]; then
369 CreateZippyJar "" "-q"
370 LaunchVM "" "${RELEASE}"
371fi
372
373#
374# jar files shouldn't have comments, but it is possible that somebody added
375# one by using zip -c, zip -z, zipnote or a similar utility. On systems
376# that have "zipnote", verify this functionality.
377#
378# This serves a dual purpose of creating a very large "central directory
379# entry" which validates to code to read such entries.
380#
381if [ -x /usr/bin/zipnote ]; then
382 CreateFullJar "" ""
383 CommentZipFile "AfairlyLongNameEatsUpDirectorySpaceBetter20"
384 LaunchVM "" "${RELEASE}"
385fi
386
duke6e45e102007-12-01 00:00:00 +0000387#
388# Throw some syntactically challenged (illegal) version specifiers at
389# the interface. Failure (of the launcher) is success for the test.
390#
391TestSyntax "1.2..3" # Two adjacent separators
392TestSyntax "_1.2.3" # Begins with a separator
393TestSyntax "1.2.3-" # Ends with a separator
394TestSyntax "1.2+.3" # Embedded modifier
395TestSyntax "1.2.4+&1.2*&1++" # Long and invalid
396
ksrini8760ca92008-09-04 09:43:32 -0700397# On windows we see if there is another jre installed, usually
398# there is, then we test using that, otherwise links are created
399# to get through to SelectVersion.
400if [ `IsWindows` = "false" ]; then
401 TestLongMainClass "mklink"
402else
403 $JAVAEXE -version:1.0+
404 if [ $? -eq 0 ]; then
405 TestLongMainClass "1.0+"
406 else
407 printf "Warning: TestLongMainClass skipped as there is no"
408 printf "viable MJRE installed.\n"
409 fi
410fi
411
duke6e45e102007-12-01 00:00:00 +0000412#
413# Because scribbling in the registry can be rather destructive, only a
414# subset of the tests are run on Windows.
415#
ksrini8760ca92008-09-04 09:43:32 -0700416if [ `IsWindows` = "true" ]; then
417 exit 0;
418fi
duke6e45e102007-12-01 00:00:00 +0000419
420#
421# Additional version specifiers containing spaces. (Sigh, unable to
422# figure out the glomming on Windows)
423#
424TestSyntax "1.2.3_99 1.3.2+ 1.2.4+&1.2*&1++" # Long and invalid
425
426#
427# Create a mock installation of a number of shell scripts named as though
428# they were installed JREs. Then test to see if the launcher can cause
429# the right shell scripts to be invoked.
430#
431# Note, that as a side effect, this test verifies that JAVA_VERSION_PATH
432# works.
433#
434rm -rf jdk
435JAVA_VERSION_PATH="`pwd`/jdk"
436export JAVA_VERSION_PATH
437
438CreateMockVM 1.10
439CreateMockVM 1.11.3
440CreateMockVM 1.11.3_03
441CreateMockVM 1.11.4
442CreateMockVM 1.12.3_03
443CreateMockVM 1.12.3_03-lastweek
444CreateMockVM 1.13.3_03
445CreateMockVM 1.13.3_03-lastweek
446CreateMockVM 1.13.3_03_lastweek
447CreateMockVM 1.20.0
448
449#
450# Test extracting the version information from the jar file:
451#
452# Requested Expected
453CreateJar "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 true
461
462#
463# Test obtaining the version information from the command line (and that
464# 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 true
471
472[ -d jdk ] && rm -rf jdk
473[ -d META_INF ] && rm -rf META_INF
474
475exit 0