harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r578848 - in /harmony/enhanced/drlvm/trunk/src/test/regression/H4706: ./ Test.java ThreadArrayInterrupt.java
Date Mon, 24 Sep 2007 15:13:38 GMT
Author: gshimansky
Date: Mon Sep 24 08:13:36 2007
New Revision: 578848

URL: http://svn.apache.org/viewvc?rev=578848&view=rev
Log:
Added a regression test from HARMONY-4706


Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H4706/
    harmony/enhanced/drlvm/trunk/src/test/regression/H4706/Test.java   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H4706/ThreadArrayInterrupt.java   (with
props)

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H4706/Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H4706/Test.java?rev=578848&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H4706/Test.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H4706/Test.java Mon Sep 24 08:13:36 2007
@@ -0,0 +1,71 @@
+package org.apache.harmony.drlvm.tests.regression.h4706;
+
+import java.io.File;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+import junit.framework.TestCase;
+
+/**
+ * Runs VM in child process for the 'TestClass' and checks that it doesn't
+ * crash and returns zero exitValue.
+ * Child process for the test application is required because the crash doesn't
+ * reproduce in junit test.
+ */
+public class Test extends TestCase {
+
+    final static String testClass =
+       "org.apache.harmony.drlvm.tests.regression.h4706.ThreadArrayInterrupt";
+
+    public static void main(String[] args) {
+        (new Test()).test();
+    }
+
+    public void test() {
+        ProcessBuilder pb = new ProcessBuilder(
+            System.getProperty("java.home") + File.separator + "bin" +
+                    File.separator+"java",
+            "-XX:vm.assert_dialog=false",
+            "-cp",
+            System.getProperty("java.class.path"),
+            testClass
+        );
+
+        // merge stderr adn stdout for child VM process
+        pb.redirectErrorStream(true);
+
+        System.out.println("Command line for child VM:");
+
+        for (String arg : pb.command()) {
+            System.out.println("  " + arg);
+        }
+
+        int exitValue = -1;
+
+        try {
+            System.out.println("Launching child VM...");
+            Process p = pb.start();
+            System.out.println("Child VM started.");
+
+            BufferedReader childOut = new BufferedReader(new InputStreamReader(
+                    p.getInputStream()));
+
+            BufferedReader childErr = new BufferedReader(new InputStreamReader(
+                    p.getErrorStream()));
+
+            String outLine;
+
+            while (null != (outLine = childOut.readLine())) {
+                System.out.println("child-out>   " + outLine);
+            }
+
+            System.out.println("Waiting for child VM process to finish...");
+
+            exitValue = p.waitFor();
+            System.out.println("Child VM finished. Exit value = " + exitValue);
+        } catch (Throwable exc) {
+            exc.printStackTrace();
+        }
+
+        assertTrue(exitValue == 0);
+    }
+}

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H4706/Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H4706/ThreadArrayInterrupt.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H4706/ThreadArrayInterrupt.java?rev=578848&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H4706/ThreadArrayInterrupt.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H4706/ThreadArrayInterrupt.java Mon Sep
24 08:13:36 2007
@@ -0,0 +1,52 @@
+package org.apache.harmony.drlvm.tests.regression.h4706;
+
+/**
+ * Checks that interruption of several threads doesn't cause VM crash due to
+ * race condition in thread manager implementation for thread interrupting.
+ * First main thread creates and starts a number of test threads.
+ * Second main thead interrupts all of the test threads.
+ * Each of the test threads waits on the same monitor.
+ */
+public class ThreadArrayInterrupt {
+
+    static final int threadNum = 32;
+    static Object barrier = new Object();
+
+    public static void main(String[] args) {
+        Thread[] threads = new Thread[threadNum];
+
+        synchronized (barrier) {
+            System.out.println("starting threads...");
+
+            for (int i = 0; i < threadNum; i++) {
+                threads[i] = new TestThread("Thread-" + i);
+                threads[i].start();
+            }
+
+            System.out.println("all threads started");
+        }
+
+        System.out.println("Interrupting all threads...");
+
+        for (int i = 0; i < threadNum; i++) {
+            threads[i].interrupt();
+        }
+    }
+
+    static class TestThread extends Thread {
+
+        TestThread(String name) {
+            super(name);
+        }
+
+        public void run() {
+            synchronized (barrier) {
+                try {
+                    barrier.wait();
+                } catch (InterruptedException e) {
+                    System.out.println("Interrupted: " + getName());
+                }
+            }
+        }
+    }
+}

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H4706/ThreadArrayInterrupt.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message