Merge
authorjwilhelm
Thu, 17 Jan 2019 15:44:29 +0100
changeset 53373 6d1c1f4fc3d5
parent 53370 687a5c204419 (current diff)
parent 53372 4003935e6e5f (diff)
child 53374 7c0d1f696dbc
Merge
.hgtags
test/jdk/tools/launcher/Test7029048.java
--- a/.hgtags	Thu Jan 17 08:48:56 2019 -0500
+++ b/.hgtags	Thu Jan 17 15:44:29 2019 +0100
@@ -535,3 +535,5 @@
 642346a11059b9f283110dc301a24ed43b76a94e jdk-13+3
 f15d443f97318e9b40e6f451e327ff69ed4ec361 jdk-12+27
 a47b8125b7cc9ef59619745c163975fe935b57ed jdk-13+4
+659b004b6a1bd8c31e766cbdf328d8f8473fd4d7 jdk-12+28
+
--- a/test/jdk/tools/launcher/Test7029048.java	Thu Jan 17 08:48:56 2019 -0500
+++ b/test/jdk/tools/launcher/Test7029048.java	Thu Jan 17 15:44:29 2019 +0100
@@ -24,17 +24,12 @@
 /**
  * @test
  * @bug 7029048
- * @summary Checks for LD_LIBRARY_PATH on *nixes
- * @library /test/lib
+ * @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
  */
 
-/*
- * 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;
@@ -68,7 +63,6 @@
 
     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("=");
@@ -100,37 +94,34 @@
         * 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");
+        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 " + values.length);
+                               + " but got " + len);
             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.
+     * 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 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 static enum TestCase {
+        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;
-        LLP_VAR(int i) {
+        TestCase(int i) {
             this.value = i;
         }
     }
@@ -140,16 +131,16 @@
      */
     static void test7029048() throws IOException {
         String desc = null;
-        for (LLP_VAR v : LLP_VAR.values()) {
+        for (TestCase v : TestCase.values()) {
             switch (v) {
-                case LLP_SET_WITH_JVM:
+                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 LLP_SET_EMPTY_PATH:
+                case NO_LIBJVM:
                     if (!dstClientDir.exists()) {
                         Files.createDirectories(dstClientDir.toPath());
                     } else {
@@ -162,13 +153,13 @@
                         Files.deleteIfExists(dstServerLibjvm.toPath());
                     }
 
-                    desc = "LD_LIBRARY_PATH should not be set";
+                    desc = "LD_LIBRARY_PATH should not be set (no libjvm.so)";
                     break;
-                case LLP_SET_NON_EXISTENT_PATH:
+                case NO_DIR:
                     if (dstLibDir.exists()) {
                         recursiveDelete(dstLibDir);
                     }
-                    desc = "LD_LIBRARY_PATH should not be set";
+                    desc = "LD_LIBRARY_PATH should not be set (no directory)";
                     break;
                 default:
                     throw new RuntimeException("unknown case");
@@ -179,14 +170,18 @@
              */
             env.clear();
             env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath());
-            run(env, v.value + 1, "Case 1: " + desc);
+            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, "Case 2: " + desc);
+            run(env,
+                v.value + 1,            // Add one to account for our setting
+                "Case 2: " + desc);
 
             if (isSolaris) {
                 /*
@@ -195,7 +190,10 @@
                  */
                 env.clear();
                 env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath());
-                run(env, v.value + 1, "Case 3: " + desc);
+                run(env,
+                    v.value,            // Do not add one, since we didn't set
+                                        // LD_LIBRARY_PATH here
+                    "Case 3: " + desc);
             }
         }
         return;