< prev index next >

test/jdk/tools/launcher/Test7029048.java

Print this page
rev 53150 : 8216532: tools/launcher/Test7029048.java fails (Solaris)

*** 22,41 **** */ /* * @test * @bug 7029048 ! * @summary Checks for LD_LIBRARY_PATH on *nixes * @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java * @run main Test7029048 */ - /* - * 7029048: test for LD_LIBRARY_PATH set to different paths which may or - * may not contain a libjvm.so, but we test to ensure that the launcher - * behaves correctly in all cases. - */ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; --- 22,37 ---- */ /* * @test * @bug 7029048 ! * @summary Ensure that the launcher defends against user settings of the ! * LD_LIBRARY_PATH environment variable on Unixes * @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java * @run main Test7029048 */ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap;
*** 65,75 **** private static final File dstClientDir = new File(dstLibDir, "client"); private static final File dstClientLibjvm = new File(dstClientDir, LIBJVM); private static final Map<String, String> env = new HashMap<>(); - static String getValue(String name, List<String> in) { for (String x : in) { String[] s = x.split("="); if (name.equals(s[0].trim())) { return s[1].trim(); --- 61,70 ----
*** 97,156 **** /* * the envValue can never be null, since the test code should always * print a "null" string. */ if (envValue == null) { - System.out.println(tr); throw new RuntimeException("NPE, likely a program crash ??"); } ! String values[] = envValue.split(File.pathSeparator); ! if (values.length == nLLPComponents) { ! System.out.println(caseID + " :OK"); passes++; } else { System.out.println("FAIL: test7029048, " + caseID); System.out.println(" expected " + nLLPComponents ! + " but got " + values.length); System.out.println(envValue); - System.out.println(tr); errors++; } } /* ! * A crucial piece, specifies what we should expect, given the conditions. ! * That is for a given enum type, the value indicates how many absolute ! * environment variables that can be expected. This value is used to base ! * the actual expected values by adding the set environment variable usually ! * it is 1, but it could be more if the test wishes to set more paths in ! * the future. ! */ ! private static enum LLP_VAR { ! LLP_SET_NON_EXISTENT_PATH(0), // env set, but the path does not exist ! LLP_SET_EMPTY_PATH(0), // env set, with a path but no libjvm.so ! LLP_SET_WITH_JVM(3); // env set, with a libjvm.so private final int value; ! LLP_VAR(int i) { this.value = i; } } /* * test for 7029048 */ static void test7029048() throws IOException { String desc = null; ! for (LLP_VAR v : LLP_VAR.values()) { switch (v) { ! case LLP_SET_WITH_JVM: // copy the files into the directory structures copyFile(srcLibjvmSo, dstServerLibjvm); // does not matter if it is client or a server copyFile(srcLibjvmSo, dstClientLibjvm); desc = "LD_LIBRARY_PATH should be set"; break; ! case LLP_SET_EMPTY_PATH: if (!dstClientDir.exists()) { Files.createDirectories(dstClientDir.toPath()); } else { Files.deleteIfExists(dstClientLibjvm.toPath()); } --- 92,148 ---- /* * the envValue can never be null, since the test code should always * print a "null" string. */ if (envValue == null) { throw new RuntimeException("NPE, likely a program crash ??"); } ! int len = (envValue.equals("null") ! ? 0 : envValue.split(File.pathSeparator).length); ! if (len == nLLPComponents) { ! System.out.println(caseID + ": OK"); passes++; } else { System.out.println("FAIL: test7029048, " + caseID); System.out.println(" expected " + nLLPComponents ! + " but got " + len); System.out.println(envValue); errors++; } } /* ! * Describe the cases that we test. Each case sets the environment ! * variable LD_LIBRARY_PATH to a different value. The value associated ! * with a case is the number of path elements that we expect the launcher ! * to add to that variable. ! */ ! private static enum CASE { ! NO_DIR(0), // Directory does not exist ! NO_LIBJVM(0), // Directory exists, but no libjvm.so ! LIBJVM(3); // Directory exists, with a libjvm.so private final int value; ! CASE(int i) { this.value = i; } } /* * test for 7029048 */ static void test7029048() throws IOException { String desc = null; ! for (CASE v : CASE.values()) { switch (v) { ! case LIBJVM: // copy the files into the directory structures copyFile(srcLibjvmSo, dstServerLibjvm); // does not matter if it is client or a server copyFile(srcLibjvmSo, dstClientLibjvm); desc = "LD_LIBRARY_PATH should be set"; break; ! case NO_LIBJVM: if (!dstClientDir.exists()) { Files.createDirectories(dstClientDir.toPath()); } else { Files.deleteIfExists(dstClientLibjvm.toPath()); }
*** 159,202 **** Files.createDirectories(dstServerDir.toPath()); } else { Files.deleteIfExists(dstServerLibjvm.toPath()); } ! desc = "LD_LIBRARY_PATH should not be set"; break; ! case LLP_SET_NON_EXISTENT_PATH: if (dstLibDir.exists()) { recursiveDelete(dstLibDir); } ! desc = "LD_LIBRARY_PATH should not be set"; break; default: throw new RuntimeException("unknown case"); } /* * Case 1: set the server path */ env.clear(); env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath()); ! run(env, v.value + 1, "Case 1: " + desc); /* * Case 2: repeat with client path */ env.clear(); env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath()); ! run(env, v.value + 1, "Case 2: " + desc); if (isSolaris) { /* * Case 3: set the appropriate LLP_XX flag, * java64 LLP_64 is relevant, LLP_32 is ignored */ env.clear(); env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath()); ! run(env, v.value + 1, "Case 3: " + desc); } } return; } --- 151,201 ---- Files.createDirectories(dstServerDir.toPath()); } else { Files.deleteIfExists(dstServerLibjvm.toPath()); } ! desc = "LD_LIBRARY_PATH should not be set (no libjvm.so)"; break; ! case NO_DIR: if (dstLibDir.exists()) { recursiveDelete(dstLibDir); } ! desc = "LD_LIBRARY_PATH should not be set (no directory)"; break; default: throw new RuntimeException("unknown case"); } /* * Case 1: set the server path */ env.clear(); env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath()); ! run(env, ! v.value + 1, // Add one to account for our setting ! "Case 1: " + desc); /* * Case 2: repeat with client path */ env.clear(); env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath()); ! run(env, ! v.value + 1, // Add one to account for our setting ! "Case 2: " + desc); if (isSolaris) { /* * Case 3: set the appropriate LLP_XX flag, * java64 LLP_64 is relevant, LLP_32 is ignored */ env.clear(); env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath()); ! run(env, ! v.value, // Do not add one, since we didn't set ! // LD_LIBRARY_PATH here ! "Case 3: " + desc); } } return; }
*** 225,230 **** --- 224,230 ---- "all tests did not run, expected " + 6 + " got " + passes); } else { System.out.println("Test7029048: PASS " + passes); } } + }
< prev index next >