diff -r d109188f6480 -r 139f21bad9fd test/hotspot/jtreg/gtest/GTestWrapper.java --- a/test/hotspot/jtreg/gtest/GTestWrapper.java Wed Jun 12 10:45:46 2019 -0700 +++ b/test/hotspot/jtreg/gtest/GTestWrapper.java Wed Jun 12 11:48:14 2019 -0700 @@ -25,23 +25,21 @@ * @summary a jtreg wrapper for gtest tests * @library /test/lib * @modules java.base/jdk.internal.misc + * java.xml * @run main/native GTestWrapper */ -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; -import java.util.stream.Collectors; - -import java.io.File; -import java.nio.file.Paths; -import java.nio.file.Path; - import jdk.test.lib.Platform; import jdk.test.lib.Utils; import jdk.test.lib.process.ProcessTools; -import jdk.test.lib.process.OutputAnalyzer; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.List; +import java.util.Map; public class GTestWrapper { public static void main(String[] args) throws Throwable { @@ -76,12 +74,33 @@ env.put(pathVar, path + File.pathSeparator + ldLibraryPath); } - pb.command(new String[] { - execPath.toString(), - "-jdk", - System.getProperty("test.jdk") - }); - ProcessTools.executeCommand(pb).shouldHaveExitValue(0); + Path resultFile = Paths.get("test_result.xml"); + pb.command(execPath.toAbsolutePath().toString(), + "-jdk", Utils.TEST_JDK, + "--gtest_output=xml:" + resultFile); + int exitCode = ProcessTools.executeCommand(pb).getExitValue(); + if (exitCode != 0) { + List failedTests = failedTests(resultFile); + String message = "gtest execution failed; exit code = " + exitCode + "."; + if (!failedTests.isEmpty()) { + message += " the failed tests: " + failedTests; + } + throw new AssertionError(message); + } + } + + private static List failedTests(Path xml) { + if (!Files.exists(xml)) { + System.err.println("WARNING: test result file (" + xml + ") hasn't been found"); + } + + try { + return new GTestResultParser(xml).failedTests(); + } catch (Throwable t) { + System.err.println("WARNING: failed to parse result file (" + xml + ") " + t); + t.printStackTrace(); + } + return Collections.emptyList(); } private static String getJVMVariantSubDir() {