< prev index next >

test/native/GTestWrapper.java

Print this page
rev 11190 : 8156681: Add jtreg wrapper for hotspot gtest tests
Reviewed-by: jwilhelm
rev 11191 : [mq]: 8156681-2

@@ -22,11 +22,11 @@
  *
  */
 
 /* @test
  * @summary a jtreg wrapper for gtest tests
- * @library /testlibrary
+ * @library /test/lib/share/classes
  * @modules java.base/jdk.internal.misc
  * @run main/native GTestWrapper
  */
 
 import java.util.Arrays;

@@ -36,50 +36,50 @@
 
 import java.nio.file.Paths;
 import java.nio.file.Path;
 
 import jdk.test.lib.Platform;
-import jdk.test.lib.ProcessTools;
-import jdk.test.lib.OutputAnalyzer;
 import jdk.test.lib.Utils;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
 
 public class GTestWrapper {
     public static void main(String[] args) throws Throwable {
+        // gtestLauncher is located in <test_image>/hotspot/gtest/<vm_variant>/
         // nativePath points either to <test_image>/hotspot/jtreg/native or to <test_image>/hotspot/gtest
         Path nativePath = Paths.get(System.getProperty("test.nativepath"));
+        String jvmVariantDir = getJVMVariantSubDir();
         // let's assume it's <test_image>/hotspot/gtest
-        Path path = getJVMVariantSubDir(nativePath);
+        Path path = nativePath.resolve(jvmVariantDir);
         if (!path.toFile().exists()) {
             // maybe it is <test_image>/hotspot/jtreg/native
-            path = getJVMVariantSubDir(nativePath.getParent()
+            path = nativePath.getParent()
                                                  .getParent()
-                                                 .resolve("gtest"));
+                             .resolve("gtest")
+                             .resolve(jvmVariantDir);
         }
         if (!path.toFile().exists()) {
             throw new Error("TESTBUG: the library has not been found in " + nativePath);
         }
         path = path.resolve("gtestLauncher" + (Platform.isWindows() ? ".exe" : ""));
-        List<String> cmds = Stream.concat(
-                Stream.of(
-                        path.toString(),
-                        "-jdk",
-                        System.getProperty("test.jdk")),
-                Arrays.stream(Utils.getTestJavaOpts())
-                      .filter(s -> s.startsWith("-X") || s.startsWith("-D")))
-                .collect(Collectors.toList());
-        ProcessBuilder builder = new ProcessBuilder(cmds);
-        OutputAnalyzer oa = ProcessTools.executeProcess(builder);
-        oa.shouldHaveExitValue(0);
+        Stream<String> launcherArgs = Stream.of(path.toString(), "-jdk",
+                System.getProperty("test.jdk"));
+        // JVM accepts only -X and -D flags
+        Stream<String> vmFLags = Arrays.stream(Utils.getTestJavaOpts())
+                                       .filter(s -> s.startsWith("-X") || s.startsWith("-D"));
+        String[] cmds = Stream.concat(launcherArgs, vmFLags)
+                              .toArray(String[]::new);
+        ProcessTools.executeCommand(cmds).shouldHaveExitValue(0);
     }
 
-    private static Path getJVMVariantSubDir(Path root) {
+    private static String getJVMVariantSubDir() {
         if (Platform.isServer()) {
-            return root.resolve("server");
+            return "server";
         } else if (Platform.isClient()) {
-            return root.resolve("client");
+            return "client";
         } else if (Platform.isMinimal()) {
-            return root.resolve("minimal");
+            return "minimal";
         } else {
             throw new Error("TESTBUG: unsuppported vm variant");
         }
     }
 }
< prev index next >