Thu, 18 Sep 2008 13:47:43 -0700
6728697: tools/javac/versionOpt.sh fails on OpenJDK builds
Reviewed-by: darcy
test/Makefile | file | annotate | diff | comparison | revisions | |
test/bootclasspath-exclude.jtx | file | annotate | diff | comparison | revisions | |
test/tools/javac/VersionOpt.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/versionOpt.sh | file | annotate | diff | comparison | revisions |
1.1 --- a/test/Makefile Tue Sep 16 18:35:18 2008 -0700 1.2 +++ b/test/Makefile Thu Sep 18 13:47:43 2008 -0700 1.3 @@ -105,7 +105,6 @@ 1.4 -w:$(TEST_OUTPUT_DIR)/JTwork \ 1.5 -jdk:$(TESTJAVA) \ 1.6 -Xbootclasspath/p:$(TESTBOOTCLASSPATH) \ 1.7 - -exclude:bootclasspath-exclude.jtx \ 1.8 $(JAVA_TOOL_OPTIONS:%=-vmoption:%) \ 1.9 $(JAVA_ARGS:%=-vmoption:%) \ 1.10 $(TESTDIRS)
2.1 --- a/test/bootclasspath-exclude.jtx Tue Sep 16 18:35:18 2008 -0700 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,7 +0,0 @@ 2.4 -# When you run the tests using a recent build of JDK and -Xbootclasspath/p:JAR 2.5 -# some tests may fail. Specifically, javac has a test which verifies the content 2.6 -# of the version string by comparing it against a value that is derived from 2.7 -# the JRE version string. This file can be given to jtreg to exclude such tests. 2.8 -# It should *NOT* be used in full SQE runs. 2.9 - 2.10 -tools/javac/versionOpt.sh
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/VersionOpt.java Thu Sep 18 13:47:43 2008 -0700 3.3 @@ -0,0 +1,104 @@ 3.4 + 3.5 +/* 3.6 + * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. 3.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 + * 3.9 + * This code is free software; you can redistribute it and/or modify it 3.10 + * under the terms of the GNU General Public License version 2 only, as 3.11 + * published by the Free Software Foundation. 3.12 + * 3.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.16 + * version 2 for more details (a copy is included in the LICENSE file that 3.17 + * accompanied this code). 3.18 + * 3.19 + * You should have received a copy of the GNU General Public License version 3.20 + * 2 along with this work; if not, write to the Free Software Foundation, 3.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.22 + * 3.23 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3.24 + * CA 95054 USA or visit www.sun.com if you need additional information or 3.25 + * have any questions. 3.26 + */ 3.27 + 3.28 +/* 3.29 + * @test 3.30 + * @bug 6728697 3.31 + * @summary tools/javac/versionOpt.sh fails on OpenJDK builds 3.32 + * Test checks the version strings displayed by javac, using 3.33 + * strings that come out of the Java runtime. 3.34 + */ 3.35 + 3.36 +import java.io.File; 3.37 +import java.io.PrintWriter; 3.38 +import java.io.StringWriter; 3.39 +import java.net.URL; 3.40 + 3.41 +public class VersionOpt { 3.42 + public static void main(String... args) throws Exception { 3.43 + new VersionOpt().run(); 3.44 + } 3.45 + 3.46 + void run() throws Exception { 3.47 + // Test functions by comparing the version string from javac against 3.48 + // a "golden" version generated automatically from the underlying JVM. 3.49 + // As such, it is only effective in testing the "standard" compiler, 3.50 + // and not any development version being tested via -Xbootclasspath. 3.51 + // Check the version of the compiler being used, and let the test pass 3.52 + // automatically if is is a development version. 3.53 + Class<?> javacClass = com.sun.tools.javac.Main.class; 3.54 + URL javacURL = getClass().getClassLoader().getResource(javacClass.getName().replace(".", "/") + ".class"); 3.55 + if (!javacURL.getProtocol().equals("jar") || !javacURL.getFile().contains("!")) { 3.56 + System.err.println("javac not found in tools.jar: " + javacURL); 3.57 + System.err.println("rest of test skipped"); 3.58 + return; 3.59 + } 3.60 + String javacHome = javacURL.getFile().substring(0, javacURL.getFile().indexOf("!")); 3.61 + 3.62 + File javaHome = new File(System.getProperty("java.home")); 3.63 + if (javaHome.getName().equals("jre")) 3.64 + javaHome = javaHome.getParentFile(); 3.65 + File toolsJar = new File(new File(javaHome, "lib"), "tools.jar"); 3.66 + 3.67 + if (!javacHome.equals(toolsJar.toURI().toString())){ 3.68 + System.err.println("javac not found in tools.jar: " + javacHome); 3.69 + System.err.println("rest of test skipped"); 3.70 + return; 3.71 + } 3.72 + 3.73 + System.out.println("javac found in " + toolsJar); 3.74 + 3.75 + String javaVersion = System.getProperty("java.version"); 3.76 + String javaRuntimeVersion = System.getProperty("java.runtime.version"); 3.77 + System.out.println("java.version: " + javaVersion); 3.78 + System.out.println("java.runtime.version: " + javaRuntimeVersion); 3.79 + 3.80 + StringWriter sw = new StringWriter(); 3.81 + com.sun.tools.javac.Main.compile(new String[] { "-version" }, new PrintWriter(sw)); 3.82 + String javacVersion = sw.toString().trim(); 3.83 + 3.84 + sw = new StringWriter(); 3.85 + com.sun.tools.javac.Main.compile(new String[] { "-fullversion" }, new PrintWriter(sw)); 3.86 + String javacFullVersion = sw.toString().trim(); 3.87 + System.out.println("javac -version: " + javacVersion); 3.88 + System.out.println("javac -fullversion: " + javacFullVersion); 3.89 + 3.90 + checkEqual("javac -version", javacVersion, "javac " + javaVersion); 3.91 + checkEqual("javac -fullversion", javacFullVersion, "javac full version \"" + javaRuntimeVersion + "\""); 3.92 + 3.93 + if (errors > 0) 3.94 + throw new Exception(errors + " errors found"); 3.95 + } 3.96 + 3.97 + void checkEqual(String kind, String found, String expect) { 3.98 + if (!found.equals(expect)) { 3.99 + System.err.println("error: unexpected value for " + kind); 3.100 + System.err.println("expect: >>" + expect + "<<"); 3.101 + System.err.println(" found: >>" + found + "<<"); 3.102 + errors++; 3.103 + } 3.104 + } 3.105 + 3.106 + int errors; 3.107 +}
4.1 --- a/test/tools/javac/versionOpt.sh Tue Sep 16 18:35:18 2008 -0700 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,87 +0,0 @@ 4.4 -#!/bin/sh 4.5 - 4.6 -# 4.7 -# Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. 4.8 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.9 -# 4.10 -# This code is free software; you can redistribute it and/or modify it 4.11 -# under the terms of the GNU General Public License version 2 only, as 4.12 -# published by the Free Software Foundation. 4.13 -# 4.14 -# This code is distributed in the hope that it will be useful, but WITHOUT 4.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.16 -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.17 -# version 2 for more details (a copy is included in the LICENSE file that 4.18 -# accompanied this code). 4.19 -# 4.20 -# You should have received a copy of the GNU General Public License version 4.21 -# 2 along with this work; if not, write to the Free Software Foundation, 4.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.23 -# 4.24 -# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4.25 -# CA 95054 USA or visit www.sun.com if you need additional information or 4.26 -# have any questions. 4.27 -# 4.28 - 4.29 - 4.30 -# @test 4.31 -# @bug 4461214 6227587 4.32 -# @summary support-version and -fullversion 4.33 -# @run shell versionOpt.sh 4.34 - 4.35 -if [ "${TESTJAVA}" = "" ] 4.36 -then 4.37 - echo "TESTJAVA not set. Test cannot execute. Failed." 4.38 - exit 1 4.39 -fi 4.40 -echo "TESTJAVA=${TESTJAVA}" 4.41 - 4.42 -# set platform-dependent variables 4.43 -OS=`uname -s` 4.44 -case "$OS" in 4.45 - SunOS | Linux ) 4.46 - NULL=/dev/null 4.47 - PS=":" 4.48 - FS="/" 4.49 - ;; 4.50 - Windows* ) 4.51 - NULL=NUL 4.52 - PS=";" 4.53 - FS="\\" 4.54 - ;; 4.55 - * ) 4.56 - echo "Unrecognized system!" 4.57 - exit 1; 4.58 - ;; 4.59 -esac 4.60 - 4.61 -# create reference files based on java values 4.62 -"${TESTJAVA}${FS}bin${FS}java" ${TESTVMOPTS} -version 2>&1 | \ 4.63 - sed -e 's/java version "\([^"]*\)"/javac \1/' -e '2,$d' > version.ref.out 4.64 - 4.65 -"${TESTJAVA}${FS}bin${FS}java" ${TESTVMOPTS} -fullversion 2>&1 | \ 4.66 - sed -e 's/java full version/javac full version/' -e '2,$d' > fullversion.ref.out 4.67 - 4.68 -# run javac 4.69 -"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -version 2> version.out 4.70 -cat version.out 4.71 -diff -c version.ref.out version.out 4.72 -version_result=$? 4.73 - 4.74 -"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -fullversion 2> fullversion.out 4.75 -cat fullversion.out 4.76 -diff -c fullversion.ref.out fullversion.out 4.77 -fullversion_result=$? 4.78 - 4.79 -if [ $version_result -eq 0 -a $fullversion_result -eq 0 ] 4.80 -then 4.81 - echo "Passed" 4.82 - exit 0 4.83 -else 4.84 - echo "Failed" 4.85 - exit 1 4.86 -fi 4.87 - 4.88 - 4.89 - 4.90 -