23 |
23 |
24 /* @test |
24 /* @test |
25 * @summary a jtreg wrapper for gtest tests |
25 * @summary a jtreg wrapper for gtest tests |
26 * @library /test/lib |
26 * @library /test/lib |
27 * @modules java.base/jdk.internal.misc |
27 * @modules java.base/jdk.internal.misc |
|
28 * java.xml |
28 * @run main/native GTestWrapper |
29 * @run main/native GTestWrapper |
29 */ |
30 */ |
30 |
|
31 import java.util.Arrays; |
|
32 import java.util.List; |
|
33 import java.util.Map; |
|
34 import java.util.stream.Stream; |
|
35 import java.util.stream.Collectors; |
|
36 |
|
37 import java.io.File; |
|
38 import java.nio.file.Paths; |
|
39 import java.nio.file.Path; |
|
40 |
31 |
41 import jdk.test.lib.Platform; |
32 import jdk.test.lib.Platform; |
42 import jdk.test.lib.Utils; |
33 import jdk.test.lib.Utils; |
43 import jdk.test.lib.process.ProcessTools; |
34 import jdk.test.lib.process.ProcessTools; |
44 import jdk.test.lib.process.OutputAnalyzer; |
35 |
|
36 import java.io.File; |
|
37 import java.nio.file.Files; |
|
38 import java.nio.file.Path; |
|
39 import java.nio.file.Paths; |
|
40 import java.util.Collections; |
|
41 import java.util.List; |
|
42 import java.util.Map; |
45 |
43 |
46 public class GTestWrapper { |
44 public class GTestWrapper { |
47 public static void main(String[] args) throws Throwable { |
45 public static void main(String[] args) throws Throwable { |
48 // gtestLauncher is located in <test_image>/hotspot/gtest/<vm_variant>/ |
46 // gtestLauncher is located in <test_image>/hotspot/gtest/<vm_variant>/ |
49 // nativePath points either to <test_image>/hotspot/jtreg/native or to <test_image>/hotspot/gtest |
47 // nativePath points either to <test_image>/hotspot/jtreg/native or to <test_image>/hotspot/gtest |
74 String ldLibraryPath = System.getenv(pathVar); |
72 String ldLibraryPath = System.getenv(pathVar); |
75 if (ldLibraryPath != null) { |
73 if (ldLibraryPath != null) { |
76 env.put(pathVar, path + File.pathSeparator + ldLibraryPath); |
74 env.put(pathVar, path + File.pathSeparator + ldLibraryPath); |
77 } |
75 } |
78 |
76 |
79 pb.command(new String[] { |
77 Path resultFile = Paths.get("test_result.xml"); |
80 execPath.toString(), |
78 pb.command(execPath.toAbsolutePath().toString(), |
81 "-jdk", |
79 "-jdk", Utils.TEST_JDK, |
82 System.getProperty("test.jdk") |
80 "--gtest_output=xml:" + resultFile); |
83 }); |
81 int exitCode = ProcessTools.executeCommand(pb).getExitValue(); |
84 ProcessTools.executeCommand(pb).shouldHaveExitValue(0); |
82 if (exitCode != 0) { |
|
83 List<String> failedTests = failedTests(resultFile); |
|
84 String message = "gtest execution failed; exit code = " + exitCode + "."; |
|
85 if (!failedTests.isEmpty()) { |
|
86 message += " the failed tests: " + failedTests; |
|
87 } |
|
88 throw new AssertionError(message); |
|
89 } |
|
90 } |
|
91 |
|
92 private static List<String> failedTests(Path xml) { |
|
93 if (!Files.exists(xml)) { |
|
94 System.err.println("WARNING: test result file (" + xml + ") hasn't been found"); |
|
95 } |
|
96 |
|
97 try { |
|
98 return new GTestResultParser(xml).failedTests(); |
|
99 } catch (Throwable t) { |
|
100 System.err.println("WARNING: failed to parse result file (" + xml + ") " + t); |
|
101 t.printStackTrace(); |
|
102 } |
|
103 return Collections.emptyList(); |
85 } |
104 } |
86 |
105 |
87 private static String getJVMVariantSubDir() { |
106 private static String getJVMVariantSubDir() { |
88 if (Platform.isServer()) { |
107 if (Platform.isServer()) { |
89 return "server"; |
108 return "server"; |