8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
authorjbachorik
Fri, 06 Nov 2015 14:34:06 +0100
changeset 34635 2dab71a66523
parent 34633 2a6c7c7b30a7
child 34636 445881c8c46e
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns Reviewed-by: dsamersoff
hotspot/test/serviceability/dcmd/gc/RunFinalizationTest.java
hotspot/test/testlibrary/jdk/test/lib/Asserts.java
hotspot/test/testlibrary/jdk/test/lib/JDKToolFinder.java
hotspot/test/testlibrary/jdk/test/lib/JDKToolLauncher.java
hotspot/test/testlibrary/jdk/test/lib/OutputAnalyzer.java
hotspot/test/testlibrary/jdk/test/lib/OutputBuffer.java
hotspot/test/testlibrary/jdk/test/lib/Platform.java
hotspot/test/testlibrary/jdk/test/lib/ProcessTools.java
hotspot/test/testlibrary/jdk/test/lib/StreamPumper.java
hotspot/test/testlibrary/jdk/test/lib/Utils.java
--- a/hotspot/test/serviceability/dcmd/gc/RunFinalizationTest.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/serviceability/dcmd/gc/RunFinalizationTest.java	Fri Nov 06 14:34:06 2015 +0100
@@ -23,20 +23,22 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
-import jdk.test.lib.OutputAnalyzer;
-import jdk.test.lib.ProcessTools;
+import jdk.test.lib.process.ProcessTools;
 
 /*
  * @test
  * @summary Test of diagnostic command GC.run_finalization
  * @library /testlibrary
+ * @library /test/lib/share/classes
  * @modules java.base/sun.misc
  *          java.compiler
  *          java.management
  *          jdk.jvmstat/sun.jvmstat.monitor
  * @build jdk.test.lib.*
  * @build jdk.test.lib.dcmd.*
+ * @build jdk.test.lib.process.*
  * @build RunFinalizationTest FinalizationRunner
  * @run main RunFinalizationTest
  */
@@ -50,8 +52,21 @@
         javaArgs.add(TEST_APP_NAME);
         ProcessBuilder testAppPb = ProcessTools.createJavaProcessBuilder(javaArgs.toArray(new String[javaArgs.size()]));
 
-        OutputAnalyzer out = ProcessTools.executeProcess(testAppPb);
-        out.stderrShouldNotMatch("^" + FinalizationRunner.FAILED + ".*")
-           .stdoutShouldMatch("^" + FinalizationRunner.PASSED + ".*");
+        final AtomicBoolean failed = new AtomicBoolean();
+        final AtomicBoolean passed = new AtomicBoolean();
+
+        Process runner = ProcessTools.startProcess(
+            "FinalizationRunner",
+            testAppPb,
+            l -> {
+                failed.compareAndSet(false, l.contains(FinalizationRunner.FAILED));
+                passed.compareAndSet(false, l.contains(FinalizationRunner.PASSED));
+            }
+        );
+        runner.waitFor();
+
+        if (failed.get() || !passed.get()) {
+            throw new Error("RunFinalizationTest failed");
+        }
     }
 }
--- a/hotspot/test/testlibrary/jdk/test/lib/Asserts.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/Asserts.java	Fri Nov 06 14:34:06 2015 +0100
@@ -41,7 +41,10 @@
  * multiple times, then the line number won't provide enough context to
  * understand the failure.
  * </pre>
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib}
  */
+@Deprecated
 public class Asserts {
 
     /**
--- a/hotspot/test/testlibrary/jdk/test/lib/JDKToolFinder.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/JDKToolFinder.java	Fri Nov 06 14:34:06 2015 +0100
@@ -27,6 +27,11 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
+/**
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib}
+ */
+@Deprecated
 public final class JDKToolFinder {
 
     private JDKToolFinder() {
--- a/hotspot/test/testlibrary/jdk/test/lib/JDKToolLauncher.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/JDKToolLauncher.java	Fri Nov 06 14:34:06 2015 +0100
@@ -46,7 +46,10 @@
  * Process p = pb.start();
  * }
  * </pre>
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib}
  */
+@Deprecated
 public class JDKToolLauncher {
     private final String executable;
     private final List<String> vmArgs = new ArrayList<String>();
--- a/hotspot/test/testlibrary/jdk/test/lib/OutputAnalyzer.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/OutputAnalyzer.java	Fri Nov 06 14:34:06 2015 +0100
@@ -41,7 +41,11 @@
    *
    * @param process Process to analyze
    * @throws IOException If an I/O error occurs.
+   *
+   * @deprecated This class is deprecated. Use the one from
+   *             {@code <root>/test/lib/share/classes/jdk/test/lib/process}
    */
+  @Deprecated
   public OutputAnalyzer(Process process) throws IOException {
     OutputBuffer output = ProcessTools.getOutput(process);
     exitValue = process.exitValue();
--- a/hotspot/test/testlibrary/jdk/test/lib/OutputBuffer.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/OutputBuffer.java	Fri Nov 06 14:34:06 2015 +0100
@@ -23,6 +23,11 @@
 
 package jdk.test.lib;
 
+/**
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib/process}
+ */
+@Deprecated
 public class OutputBuffer {
   private final String stdout;
   private final String stderr;
--- a/hotspot/test/testlibrary/jdk/test/lib/Platform.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/Platform.java	Fri Nov 06 14:34:06 2015 +0100
@@ -25,6 +25,11 @@
 
 import java.util.regex.Pattern;
 
+/**
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib}
+ */
+@Deprecated
 public class Platform {
     private static final String osName      = System.getProperty("os.name");
     private static final String dataModel   = System.getProperty("sun.arch.data.model");
--- a/hotspot/test/testlibrary/jdk/test/lib/ProcessTools.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/ProcessTools.java	Fri Nov 06 14:34:06 2015 +0100
@@ -31,6 +31,11 @@
 import java.util.Collections;
 import java.util.List;
 
+/**
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib/process}
+ */
+@Deprecated
 public final class ProcessTools {
 
   private ProcessTools() {
--- a/hotspot/test/testlibrary/jdk/test/lib/StreamPumper.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/StreamPumper.java	Fri Nov 06 14:34:06 2015 +0100
@@ -27,6 +27,11 @@
 import java.io.InputStream;
 import java.io.IOException;
 
+/**
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib/process}
+ */
+@Deprecated
 public final class StreamPumper implements Runnable {
 
   private static final int BUF_SIZE = 256;
--- a/hotspot/test/testlibrary/jdk/test/lib/Utils.java	Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/test/testlibrary/jdk/test/lib/Utils.java	Fri Nov 06 14:34:06 2015 +0100
@@ -55,7 +55,11 @@
 
 /**
  * Common library for various test helper functions.
+ *
+ * @deprecated This class is deprecated. Use the one from
+ *             {@code <root>/test/lib/share/classes/jdk/test/lib}
  */
+@Deprecated
 public final class Utils {
 
     /**