changeset 58078:7ff60204a181 tip

Fix test/jdk/tools/launcher/Test7029048.java
author alexsch
date Tue, 18 Feb 2020 16:19:57 -0800
parents 10e04ae0d8e1
children
files test/jdk/tools/launcher/ExecutionEnvironment.java test/jdk/tools/launcher/Test7029048.java test/jdk/tools/launcher/TestHelper.java
diffstat 3 files changed, 44 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/tools/launcher/ExecutionEnvironment.java	Sat Feb 15 13:51:31 2020 -0800
+++ b/test/jdk/tools/launcher/ExecutionEnvironment.java	Tue Feb 18 16:19:57 2020 -0800
@@ -135,16 +135,22 @@
             flagError(tr, "Error: No output at all. Did the test execute ?");
         }
 
+        boolean isExpandedLibPath = TestHelper.isExpandedSharedLibraryPath;
+
         for (String x : LD_PATH_STRINGS) {
             if (!tr.contains(x)) {
-                if (TestHelper.isAIX && x.startsWith(LD_LIBRARY_PATH)) {
+                if (isExpandedLibPath && x.startsWith(LD_LIBRARY_PATH)) {
                     // AIX does not support the '-rpath' linker options so the
                     // launchers have to prepend the jdk library path to 'LIBPATH'.
-                    String aixLibPath = LD_LIBRARY_PATH + "=" +
-                        System.getenv(LD_LIBRARY_PATH) +
-                        System.getProperty("path.separator") + LD_LIBRARY_PATH_VALUE;
-                    if (!tr.matches(aixLibPath)) {
-                        flagError(tr, "FAIL: did not get <" + aixLibPath + ">");
+                    // The musl library loader requires LD_LIBRARY_PATH to be set in
+                    // order to correctly resolve the dependency libjava.so has on libjvm.so.
+                    String expandedLibPath = String.format("%s=%s%c%s",
+                            LD_LIBRARY_PATH,
+                            System.getenv(LD_LIBRARY_PATH),
+                            File.pathSeparatorChar,
+                            LD_LIBRARY_PATH_VALUE);
+                    if (!tr.matches(expandedLibPath)) {
+                        flagError(tr, "FAIL: did not get <" + expandedLibPath + ">");
                     }
                 }
                 else {
--- a/test/jdk/tools/launcher/Test7029048.java	Sat Feb 15 13:51:31 2020 -0800
+++ b/test/jdk/tools/launcher/Test7029048.java	Tue Feb 18 16:19:57 2020 -0800
@@ -178,9 +178,9 @@
                     }
 
                     desc = "LD_LIBRARY_PATH should not be set (no libjvm.so)";
-                    if (TestHelper.isAIX) {
+                    if (TestHelper.isExpandedSharedLibraryPath) {
                         System.out.println("Skipping test case \"" + desc +
-                                           "\" because the Aix launcher adds the paths in any case.");
+                                           "\" because the Aix and Musl launchers add the paths in any case.");
                         continue;
                     }
                     break;
@@ -189,9 +189,9 @@
                         recursiveDelete(dstLibDir);
                     }
                     desc = "LD_LIBRARY_PATH should not be set (no directory)";
-                    if (TestHelper.isAIX) {
+                    if (TestHelper.isExpandedSharedLibraryPath) {
                         System.out.println("Skipping test case \"" + desc +
-                                           "\" because the Aix launcher adds the paths in any case.");
+                                           "\" because the Aix and Musl launchers add the paths in any case.");
                         continue;
                     }
                     break;
@@ -247,15 +247,18 @@
 
         // run the tests
         test7029048();
+
+        int passesLinux = TestHelper.isMusl ? 2 : 6;
+
         if (errors > 0) {
             throw new Exception("Test7029048: FAIL: with "
                     + errors + " errors and passes " + passes);
         } else if (isSolaris && passes < 9) {
             throw new Exception("Test7029048: FAIL: " +
                     "all tests did not run, expected " + 9 + " got " + passes);
-        } else if (isLinux && passes < 6) {
+        } else if (isLinux && passes < passesLinux) {
              throw new Exception("Test7029048: FAIL: " +
-                    "all tests did not run, expected " + 6 + " got " + passes);
+                    "all tests did not run, expected " + passesLinux + " got " + passes);
         } else {
             System.out.println("Test7029048: PASS " + passes);
         }
--- a/test/jdk/tools/launcher/TestHelper.java	Sat Feb 15 13:51:31 2020 -0800
+++ b/test/jdk/tools/launcher/TestHelper.java	Tue Feb 18 16:19:57 2020 -0800
@@ -91,9 +91,11 @@
             System.getProperty("os.name", "unknown").startsWith("Linux");
     static final boolean isAIX =
             System.getProperty("os.name", "unknown").startsWith("AIX");
+    static final boolean isMusl = isMuslLibc();
     static final String LIBJVM = isWindows
                         ? "jvm.dll"
                         : "libjvm" + (isMacOSX ? ".dylib" : ".so");
+    static final boolean isExpandedSharedLibraryPath = isAIX || isMusl;
 
     static final boolean isSparc = System.getProperty("os.arch").startsWith("sparc");
 
@@ -534,6 +536,27 @@
         createFile(new File(launcherTestDir, "Main.java"), Arrays.asList(moduleCode));
     }
 
+    /**
+     * Check if we run with musl libc.
+     *
+     * @return true if we run with musl libc.
+     */
+    private static boolean isMuslLibc() {
+        try {
+            ProcessBuilder pb = new ProcessBuilder("ldd", "--version");
+            pb.redirectErrorStream(true);
+            final Process p = pb.start();
+            try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
+                return br.lines()
+                        .findFirst()
+                        .filter(line -> line.contains("musl"))
+                        .isPresent();
+            }
+        } catch (Exception ignore) {
+        }
+        return false;
+    }
+
     /*
      * A class to encapsulate the test results and stuff, with some ease
      * of use methods to check the test results.