From 8aa80a9245798ef7895c06a11705c651b79aa1c2 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Fri, 6 Nov 2015 14:32:34 +0100 Subject: [PATCH 1/2] 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns Reviewed-by: dsamersoff --- jdk/test/lib/testlibrary/jdk/testlibrary/Asserts.java | 4 ++++ .../lib/testlibrary/jdk/testlibrary/JDKToolFinder.java | 5 +++++ .../lib/testlibrary/jdk/testlibrary/JDKToolLauncher.java | 3 +++ .../lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java | 5 +++++ .../lib/testlibrary/jdk/testlibrary/OutputBuffer.java | 5 +++++ jdk/test/lib/testlibrary/jdk/testlibrary/Platform.java | 5 +++++ .../lib/testlibrary/jdk/testlibrary/ProcessTools.java | 8 ++++++-- .../lib/testlibrary/jdk/testlibrary/StreamPumper.java | 5 +++++ jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java | 4 ++++ 9 files changed, 42 insertions(+), 2 deletions(-) diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/Asserts.java b/jdk/test/lib/testlibrary/jdk/testlibrary/Asserts.java index 52b8fb0103c..594b12e3ede 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/Asserts.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/Asserts.java @@ -42,7 +42,11 @@ import java.util.Objects; * multiple times, then the line number won't provide enough context to * understand the failure. * + * + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib} */ +@Deprecated public class Asserts { /** diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolFinder.java b/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolFinder.java index 69839d8e5d1..c4815229eb7 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolFinder.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolFinder.java @@ -27,6 +27,11 @@ import java.io.FileNotFoundException; import java.nio.file.Path; import java.nio.file.Paths; +/** + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib} + */ +@Deprecated public final class JDKToolFinder { private JDKToolFinder() { diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolLauncher.java b/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolLauncher.java index fcee2222b16..43f1ddb97d6 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolLauncher.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/JDKToolLauncher.java @@ -46,7 +46,10 @@ import java.util.List; * Process p = pb.start(); * } * + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib} */ +@Deprecated public class JDKToolLauncher { private final String executable; private final List vmArgs = new ArrayList(); diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java b/jdk/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java index 523f61c58e3..58ef07a710c 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java @@ -33,7 +33,12 @@ import java.util.regex.Pattern; /** * Utility class for verifying output and exit value from a {@code Process}. + * + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib/process} + * */ +@Deprecated public final class OutputAnalyzer { private final OutputBuffer output; private final String stdout; diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/OutputBuffer.java b/jdk/test/lib/testlibrary/jdk/testlibrary/OutputBuffer.java index 5595d5cb35c..c8a5d7aab12 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/OutputBuffer.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/OutputBuffer.java @@ -28,6 +28,11 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +/** + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib/process} + */ +@Deprecated class OutputBuffer { private static class OutputBufferException extends RuntimeException { private static final long serialVersionUID = 8528687792643129571L; diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/Platform.java b/jdk/test/lib/testlibrary/jdk/testlibrary/Platform.java index c56697adb1b..2d9352c59b9 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/Platform.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/Platform.java @@ -27,6 +27,11 @@ import java.io.RandomAccessFile; import java.io.FileNotFoundException; import java.io.IOException; +/** + * @deprecated This class is deprecated. Use the one from + * {@code /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"); diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java index 9556f22f15f..6842de26bd4 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java @@ -27,8 +27,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -42,6 +40,12 @@ import java.util.function.Predicate; import java.util.function.Consumer; import java.util.stream.Collectors; + +/** + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib/process} + */ +@Deprecated public final class ProcessTools { private static final class LineForwarder extends StreamPumper.LinePump { private final PrintStream ps; diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/StreamPumper.java b/jdk/test/lib/testlibrary/jdk/testlibrary/StreamPumper.java index 7f76c6912b9..2f3c205db3c 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/StreamPumper.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/StreamPumper.java @@ -34,6 +34,11 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicBoolean; +/** + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib/process} + */ +@Deprecated public final class StreamPumper implements Runnable { private static final int BUF_SIZE = 256; diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java b/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java index 780d704e1ef..c76339107c8 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java @@ -41,7 +41,11 @@ import java.util.function.Function; /** * Common library for various test helper functions. + * + * @deprecated This class is deprecated. Use the one from + * {@code /test/lib/share/classes/jdk/test/lib} */ +@Deprecated public final class Utils { /** From e12241b6136000a4804f81e32a92b1dc5c863bc8 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Mon, 7 Dec 2015 12:31:25 +0100 Subject: [PATCH 2/2] 8144308: com/sun/jdi/SuspendThreadTest.java failed with "transport error 202: send failed: Broken pipe" Reviewed-by: sla --- jdk/test/com/sun/jdi/SuspendThreadTest.java | 119 +++++++++++--------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/jdk/test/com/sun/jdi/SuspendThreadTest.java b/jdk/test/com/sun/jdi/SuspendThreadTest.java index c70a58bff37..49b488864d5 100644 --- a/jdk/test/com/sun/jdi/SuspendThreadTest.java +++ b/jdk/test/com/sun/jdi/SuspendThreadTest.java @@ -42,6 +42,7 @@ import com.sun.jdi.request.*; class SuspendThreadTarg { public static long count; + public static boolean active = true; public static void bkpt() { count++; @@ -53,7 +54,7 @@ class SuspendThreadTarg { // We need this to be running so the bkpt // can be hit immediately when it is enabled // in the back-end. - while(count >= 0) { + while(active) { bkpt(); } System.out.println("Goodbye from SuspendThreadTarg, count = " + count); @@ -82,9 +83,9 @@ public class SuspendThreadTest extends TestScaffold { // to guard against spurious wakeups from bkptSignal.wait() boolean signalSent; // signal that a breakpoint has happened - Object bkptSignal = new Object() {}; + final private Object bkptSignal = new Object() {}; BreakpointRequest bkptRequest; - Field debuggeeCountField; + Field debuggeeCountField, debuggeeActiveField; // When we get a bkpt we want to disable the request, // resume the debuggee, and then re-enable the request @@ -119,65 +120,71 @@ public class SuspendThreadTest extends TestScaffold { /********** test core **********/ protected void runTests() throws Exception { - /* - * Get to the top of main() - * to determine targetClass and mainThread - */ - BreakpointEvent bpe = startToMain("SuspendThreadTarg"); - targetClass = (ClassType)bpe.location().declaringType(); - mainThread = bpe.thread(); - EventRequestManager erm = vm().eventRequestManager(); - - Location loc1 = findMethod(targetClass, "bkpt", "()V").location(); - - bkptRequest = erm.createBreakpointRequest(loc1); - - // Without this, it is a SUSPEND_ALL bkpt and the test will pass - bkptRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); - bkptRequest.enable(); - - debuggeeCountField = targetClass.fieldByName("count"); try { - addListener (this); - } catch (Exception ex){ - ex.printStackTrace(); - failure("failure: Could not add listener"); - throw new Exception("SuspendThreadTest: failed", ex); - } + /* + * Get to the top of main() + * to determine targetClass and mainThread + */ + BreakpointEvent bpe = startToMain("SuspendThreadTarg"); + targetClass = (ClassType)bpe.location().declaringType(); + mainThread = bpe.thread(); + EventRequestManager erm = vm().eventRequestManager(); - int prevBkptCount; - vm().resume(); - synchronized (bkptSignal) { - while (bkptCount < maxBkpts) { - prevBkptCount = bkptCount; - // If we don't get a bkpt within 5 secs, - // the test fails - signalSent = false; - do { - try { - bkptSignal.wait(5000); - } catch (InterruptedException ee) { + Location loc1 = findMethod(targetClass, "bkpt", "()V").location(); + + bkptRequest = erm.createBreakpointRequest(loc1); + + // Without this, it is a SUSPEND_ALL bkpt and the test will pass + bkptRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); + bkptRequest.enable(); + + debuggeeCountField = targetClass.fieldByName("count"); + debuggeeActiveField = targetClass.fieldByName("active"); + try { + addListener (this); + } catch (Exception ex){ + ex.printStackTrace(); + failure("failure: Could not add listener"); + throw new Exception("SuspendThreadTest: failed", ex); + } + + int prevBkptCount; + vm().resume(); + synchronized (bkptSignal) { + while (bkptCount < maxBkpts) { + prevBkptCount = bkptCount; + // If we don't get a bkpt within 5 secs, + // the test fails + signalSent = false; + do { + try { + bkptSignal.wait(5000); + } catch (InterruptedException ee) { + } + } while (signalSent == false); + if (prevBkptCount == bkptCount) { + failure("failure: test hung"); + break; } - } while (signalSent == false); - if (prevBkptCount == bkptCount) { - failure("failure: test hung"); - break; } } - } - println("done with loop"); - bkptRequest.disable(); - removeListener(this); + println("done with loop"); + bkptRequest.disable(); + removeListener(this); - - /* - * deal with results of test - * if anything has called failure("foo") testFailed will be true - */ - if (!testFailed) { - println("SuspendThreadTest: passed"); - } else { - throw new Exception("SuspendThreadTest: failed"); + /* + * deal with results of test + * if anything has called failure("foo") testFailed will be true + */ + if (!testFailed) { + println("SuspendThreadTest: passed"); + } else { + throw new Exception("SuspendThreadTest: failed"); + } + } finally { + if (targetClass != null && debuggeeActiveField != null) { + targetClass.setValue(debuggeeActiveField, vm().mirrorOf(false)); + } } } }