This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Harness addition, System.err handling is back


This patch puts back functionality to handle data on the error stream
within test files.  This was removed when the busy waiting was removed
and is now reimplemented in a non-busy waiting manner.

2006-07-04  Anthony Balkissoon  <abalkiss@redhat.com>

	* Harness.java:
	(runner_in_err): Removed this field.
	(runner_esp): New field.
	(restartESP): New field.
	(finalize): Removed reference to runner_in_err.
	(initProcess): Removed reference to runner_in_err and created a new 
	ErrorStreamPrinter.
	(runTest): Restart the ErrorStreamPrinter if an IOException was caught
	during the last test run.
	(ErrorStreamPrinter): New class.

--Tony
Index: Harness.java
===================================================================
RCS file: /cvs/mauve/mauve/Harness.java,v
retrieving revision 1.17
diff -u -r1.17 Harness.java
--- Harness.java	30 Jun 2006 23:10:19 -0000	1.17
+++ Harness.java	4 Jul 2006 20:04:30 -0000
@@ -30,6 +30,7 @@
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
@@ -126,9 +127,13 @@
   // A way to listen to the runner process
   private static BufferedReader runner_in = null;
   
-  // A way to listen to the runner process' standard error stream
-  private static BufferedReader runner_in_err = null;
-
+  // A thread listening to the error stream of the RunnerProcess
+  private static ErrorStreamPrinter runner_esp = null;
+  
+  // A flag indicating whether or not we shoudl restart the error stream
+  // printer when we enter the runTest method
+  private static boolean restartESP = false;
+  
   // The process that will run the tests for us
   private static Process runnerProcess = null;
 
@@ -597,7 +602,6 @@
         runTest("_dump_data_");
         runnerProcess.destroy();
         runner_in.close();
-        runner_in_err.close();
         runner_out.close();                
       } 
     catch (IOException e) 
@@ -628,9 +632,9 @@
         runner_in = 
           new BufferedReader
           (new InputStreamReader(runnerProcess.getInputStream()));
-        runner_in_err = 
-            new BufferedReader
-            (new InputStreamReader(runnerProcess.getErrorStream()));                
+        runner_esp = new ErrorStreamPrinter(runnerProcess.getErrorStream());
+        runner_esp.start();
+        
       }
     catch (IOException e)
       {
@@ -739,6 +743,13 @@
     String outputFromTest;
     boolean invalidTest = false;
     int temp = -99;
+    
+    // Restart the error stream printer if necessary
+    if (restartESP)
+    {
+    	restartESP = false;
+    	runner_esp = new ErrorStreamPrinter(runnerProcess.getErrorStream());
+    }
 
     // Start the timeout watcher
     if (runner_watcher.isAlive())
@@ -1069,6 +1080,54 @@
         return x.startsWith(s);
       }
   }
+  
+  /**
+   * A class that implements Runnable and simply reads from an InputStream
+   * and redirects it to System.err.
+   * @author Anthony Balkissoon abalkiss at redhat dot com
+   *
+   */
+  private static class ErrorStreamPrinter
+  implements Runnable
+  {
+    private static BufferedReader in;    
+    private Thread printerThread;
+    
+    public ErrorStreamPrinter(InputStream input)
+    {
+      in = new BufferedReader
+        (new InputStreamReader(runnerProcess.getErrorStream()));
+      printerThread = new Thread(this);
+    }
+    
+    /**
+     * Starts the thread that reads and redirects input.
+     *
+     */
+    public void start()
+    {
+      printerThread.start();
+    }
+    
+    /**
+     * Reads from the error stream of the runnerProcess and redirects to
+     * System.err.
+     */
+    public void run()
+    {
+      try
+      {
+        while (true)
+          System.err.println(in.readLine());
+      }
+      catch (IOException ioe)
+      {
+        // Restart the runner error stream printer upon running
+        // the next test
+        restartESP = true;
+      }
+    }
+  }
 
   /**
    * This class is used for our timer to cancel tests that have hung.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]