--- old/test/tools/launcher/ExecutionEnvironment.java Tue Sep 10 11:09:17 2013 +++ new/test/tools/launcher/ExecutionEnvironment.java Tue Sep 10 11:09:17 2013 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,7 @@ * @bug 4780570 4731671 6354700 6367077 6670965 4882974 * @summary Checks for LD_LIBRARY_PATH and execution on *nixes * @compile -XDignore.symbol.file ExecutionEnvironment.java - * @run main ExecutionEnvironment + * @run main/othervm ExecutionEnvironment */ /* @@ -46,6 +46,9 @@ * b. LD_LIBRARY_PATH32 is ignored if set * 5. no extra symlink exists on Solaris ie. * jre/lib/$arch/libjvm.so -> client/libjvm.so + * 6. Since 32-bit Solaris is no longer supported we continue to ensure that + * the appropriate paths are ignored or used, additionally we also test to + * ensure the 64-bit isadir exists and contains appropriate links. * TODO: * a. perhaps we need to add a test to audit all environment variables are * in pristine condition after the launch, there may be a few that the @@ -54,10 +57,16 @@ */ import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static java.nio.file.LinkOption.*; +import java.util.regex.Pattern; public class ExecutionEnvironment extends TestHelper { @@ -80,13 +89,14 @@ static final File testJarFile = new File("EcoFriendly.jar"); - static int errors = 0; - static int passes = 0; - static final String LIBJVM = TestHelper.isWindows ? "jvm.dll" : "libjvm" + (TestHelper.isMacOSX ? ".dylib" : ".so"); + public ExecutionEnvironment() { + createTestJar(); + } + static void createTestJar() { try { List codeList = new ArrayList<>(); @@ -111,13 +121,17 @@ throw new RuntimeException(fnfe); } } - + private void flagError(TestResult tr, String message) { + System.err.println(tr); + throw new RuntimeException(message); + } /* * tests if the launcher pollutes the LD_LIBRARY_PATH variables ie. there * should not be any new variables or pollution/mutations of any kind, the * environment should be pristine. */ - private static void ensureEcoFriendly() { + @Test + void testEcoFriendly() { TestResult tr = null; Map env = new HashMap<>(); @@ -129,17 +143,12 @@ tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath()); if (!tr.isNotZeroOutput()) { - System.out.println(tr); - throw new RuntimeException("Error: No output at all. Did the test execute ?"); + flagError(tr, "Error: No output at all. Did the test execute ?"); } for (String x : LD_PATH_STRINGS) { if (!tr.contains(x)) { - System.out.println("FAIL: did not get <" + x + ">"); - System.out.println(tr); - errors++; - } else { - passes++; + flagError(tr, "FAIL: did not get <" + x + ">"); } } } @@ -148,19 +157,15 @@ * ensures that there are no execs as long as we are in the same * data model */ - static void ensureNoExec() { + @Test + void testNoExec() { Map env = new HashMap<>(); env.put(JLDEBUG_KEY, "true"); TestResult tr = doExec(env, javaCmd, "-version"); if (tr.testOutput.contains(EXPECTED_MARKER)) { - System.out.println("FAIL: EnsureNoExecs: found expected warning <" + - EXPECTED_MARKER + + flagError(tr, "testNoExec: found warning <" + EXPECTED_MARKER + "> the process execing ?"); - errors++; - } else { - passes++; } - return; } /* @@ -173,8 +178,8 @@ * For Solaris 64-bit * * The LD_LIBRARY_PATH_64 should override LD_LIBRARY_PATH if specified */ - - static void verifyJavaLibraryPath() { + @Test + void testJavaLibraryPath() { TestResult tr = null; Map env = new HashMap<>(); @@ -200,88 +205,33 @@ env.put(pairs[0], pairs[1]); } - // verify the override occurs, since we know the invocation always - // uses by default is 32-bit, therefore we also set the test - // expectation to be the same. + // verify the override occurs for 64-bit system tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath()); - verifyJavaLibraryPathOverride(tr, true); - - // try changing the model from 32 to 64 bit - if (dualModePresent() && is32Bit) { - // verify the override occurs - env.clear(); - for (String x : LD_PATH_STRINGS) { - String pairs[] = x.split("="); - env.put(pairs[0], pairs[1]); - } - tr = doExec(env, javaCmd, "-d64", "-jar", - testJarFile.getAbsolutePath()); - verifyJavaLibraryPathOverride(tr, false); - - // no override - env.clear(); - env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); - tr = doExec(env, javaCmd, "-jar", - testJarFile.getAbsolutePath()); - verifyJavaLibraryPathGeneric(tr); - } - - // try changing the model from 64 to 32 bit - if (java64Cmd != null && is64Bit) { - // verify the override occurs - env.clear(); - for (String x : LD_PATH_STRINGS) { - String pairs[] = x.split("="); - env.put(pairs[0], pairs[1]); - } - tr = doExec(env, java64Cmd, "-d32", "-jar", - testJarFile.getAbsolutePath()); - verifyJavaLibraryPathOverride(tr, true); - - // no override - env.clear(); - env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); - tr = doExec(env, java64Cmd, "-d32", "-jar", - testJarFile.getAbsolutePath()); - verifyJavaLibraryPathGeneric(tr); - } + verifyJavaLibraryPathOverride(tr, false); } } - private static void verifyJavaLibraryPathGeneric(TestResult tr) { + private void verifyJavaLibraryPathGeneric(TestResult tr) { if (!tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) { - System.out.print("FAIL: verifyJavaLibraryPath: "); - System.out.println(" java.library.path does not contain " + + flagError(tr, "testJavaLibraryPath: java.library.path does not contain " + LD_LIBRARY_PATH_VALUE); - System.out.println(tr); - errors++; - } else { - passes++; } } - private static void verifyJavaLibraryPathOverride(TestResult tr, + private void verifyJavaLibraryPathOverride(TestResult tr, boolean is32Bit) { // make sure the 32/64 bit value exists if (!tr.matches("java.library.path=.*" + (is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE) + ".*")) { - System.out.print("FAIL: verifyJavaLibraryPathOverride: "); - System.out.println(" java.library.path does not contain " + + flagError(tr, "verifyJavaLibraryPathOverride: " + + " java.library.path does not contain " + (is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE)); - System.out.println(tr); - errors++; - } else { - passes++; + } // make sure the generic value is absent - if (tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) { - System.out.print("FAIL: verifyJavaLibraryPathOverride: "); - System.out.println(" java.library.path contains " + - LD_LIBRARY_PATH_VALUE); - System.out.println(tr); - errors++; - } else { - passes++; + if (!tr.notMatches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) { + flagError(tr, "verifyJavaLibraryPathOverride: " + + " java.library.path contains " + LD_LIBRARY_PATH_VALUE); } } @@ -289,7 +239,8 @@ * ensures we have indeed exec'ed the correct vm of choice, all VMs support * -server, however 32-bit VMs support -client and -server. */ - static void verifyVmSelection() { + @Test + void testVmSelection() { TestResult tr = null; @@ -296,20 +247,12 @@ if (is32Bit) { tr = doExec(javaCmd, "-client", "-version"); if (!tr.matches(".*Client VM.*")) { - System.out.println("FAIL: the expected vm -client did not launch"); - System.out.println(tr); - errors++; - } else { - passes++; + flagError(tr, "the expected vm -client did not launch"); } } tr = doExec(javaCmd, "-server", "-version"); if (!tr.matches(".*Server VM.*")) { - System.out.println("FAIL: the expected vm -server did not launch"); - System.out.println(tr); - errors++; - } else { - passes++; + flagError(tr, "the expected vm -server did not launch"); } } @@ -316,7 +259,8 @@ /* * checks to see there is no extra libjvm.so than needed */ - static void verifyNoSymLink() { + @Test + void testNoSymLink() { if (is64Bit) { return; } @@ -326,31 +270,65 @@ symLink = new File(JAVAHOME, libPathPrefix + getJreArch() + "/" + LIBJVM); if (symLink.exists()) { - System.out.println("FAIL: The symlink exists " + - symLink.getAbsolutePath()); - errors++; - } else { - passes++; + throw new RuntimeException("symlink exists " + symLink.getAbsolutePath()); } } + /* + * verify if all the symlinks in the images are created correctly, + * only on solaris, this test works only on images. + */ + @Test + void testSymLinks() throws Exception { + if (!isSolaris) + return; + verifySymLinks(JAVA_BIN); + verifySymLinks(JAVA_JRE_BIN); + } + // exclude non-consequential binaries or scripts co-packaged in other + // build phases + private final String excludeRE = + ".*jvisualvm.*" + + "|.*javaws.*" + + "|.*ControlPanel.*" + + "|.*java-rmi.cgi" + + "|.*jcontrol.*"; + private final Pattern symlinkExcludes = Pattern.compile(excludeRE); + + private void verifySymLinks(String bindir) throws IOException { + File binDir = new File(bindir); + System.err.println("verifying links in: " + bindir); + File isaDir = new File(binDir, getArch()).getAbsoluteFile(); + if (!isaDir.exists()) { + throw new RuntimeException("dir: " + isaDir + " does not exist"); + } + try (DirectoryStream ds = Files.newDirectoryStream(binDir.toPath())) { + for (Path p : ds) { + if (symlinkExcludes.matcher(p.toString()).matches() || + Files.isDirectory(p, NOFOLLOW_LINKS)) { + continue; + } + Path link = new File(isaDir, p.getFileName().toString()).toPath(); + if (Files.isSymbolicLink(link)) { + Path target = Files.readSymbolicLink(link); + if (target.startsWith("..") && p.endsWith(target.getFileName())) { + // System.out.println(target + " OK"); + continue; + } + System.err.println("target:" + target); + System.err.println("file:" + p); + } + throw new RuntimeException("could not find link to " + p); + } + } + + } public static void main(String... args) throws Exception { if (isWindows) { - System.out.println("Warning: noop on windows"); + System.err.println("Warning: test not applicable to windows"); return; } - // create our test jar first - createTestJar(); - ensureNoExec(); - verifyVmSelection(); - ensureEcoFriendly(); - verifyJavaLibraryPath(); - verifyNoSymLink(); - if (errors > 0) { - throw new Exception("ExecutionEnvironment: FAIL: with " + - errors + " errors and passes " + passes ); - } else { - System.out.println("ExecutionEnvironment: PASS " + passes); - } + ExecutionEnvironment ee = new ExecutionEnvironment(); + ee.run(args); } }