From faa03cf1b40e800415540d92b100ad1e545c0d56 Mon Sep 17 00:00:00 2001 From: David Daney Date: Thu, 12 Aug 2004 16:24:56 +0000 Subject: [PATCH] Process_1.java: New test. 2004-08-03 David Daney * testsuite/libjava.lang/Process_1.java: New test. * testsuite/libjava.lang/Process_2.java: New test. * testsuite/libjava.lang/Process_3.java: New test. * testsuite/libjava.lang/Process_4.java: New test. * testsuite/libjava.lang/Process_5.java: New test. * testsuite/libjava.lang/Process_6.java: New test. * testsuite/libjava.lang/Process_1.out: Expected result. * testsuite/libjava.lang/Process_2.out: Expected result. * testsuite/libjava.lang/Process_3.out: Expected result. * testsuite/libjava.lang/Process_4.out: Expected result. * testsuite/libjava.lang/Process_5.out: Expected result. * testsuite/libjava.lang/Process_6.out: Expected result. From-SVN: r85881 --- libjava/ChangeLog | 34 +++++++++ libjava/testsuite/libjava.lang/Process_1.java | 41 +++++++++++ libjava/testsuite/libjava.lang/Process_1.out | 1 + libjava/testsuite/libjava.lang/Process_2.java | 40 +++++++++++ libjava/testsuite/libjava.lang/Process_2.out | 1 + libjava/testsuite/libjava.lang/Process_3.java | 72 +++++++++++++++++++ libjava/testsuite/libjava.lang/Process_3.out | 1 + libjava/testsuite/libjava.lang/Process_4.java | 19 +++++ libjava/testsuite/libjava.lang/Process_4.out | 1 + libjava/testsuite/libjava.lang/Process_5.java | 43 +++++++++++ libjava/testsuite/libjava.lang/Process_5.out | 1 + libjava/testsuite/libjava.lang/Process_6.java | 31 ++++++++ libjava/testsuite/libjava.lang/Process_6.out | 1 + 13 files changed, 286 insertions(+) create mode 100644 libjava/testsuite/libjava.lang/Process_1.java create mode 100644 libjava/testsuite/libjava.lang/Process_1.out create mode 100644 libjava/testsuite/libjava.lang/Process_2.java create mode 100644 libjava/testsuite/libjava.lang/Process_2.out create mode 100644 libjava/testsuite/libjava.lang/Process_3.java create mode 100644 libjava/testsuite/libjava.lang/Process_3.out create mode 100644 libjava/testsuite/libjava.lang/Process_4.java create mode 100644 libjava/testsuite/libjava.lang/Process_4.out create mode 100644 libjava/testsuite/libjava.lang/Process_5.java create mode 100644 libjava/testsuite/libjava.lang/Process_5.out create mode 100644 libjava/testsuite/libjava.lang/Process_6.java create mode 100644 libjava/testsuite/libjava.lang/Process_6.out diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 54e307cc844..2c55540b355 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,37 @@ +2004-08-12 David Daney + + * testsuite/libjava.lang/Process_1.java: New test. + * testsuite/libjava.lang/Process_2.java: New test. + * testsuite/libjava.lang/Process_3.java: New test. + * testsuite/libjava.lang/Process_4.java: New test. + * testsuite/libjava.lang/Process_5.java: New test. + * testsuite/libjava.lang/Process_6.java: New test. + * testsuite/libjava.lang/Process_1.out: Expected result. + * testsuite/libjava.lang/Process_2.out: Expected result. + * testsuite/libjava.lang/Process_3.out: Expected result. + * testsuite/libjava.lang/Process_4.out: Expected result. + * testsuite/libjava.lang/Process_5.out: Expected result. + * testsuite/libjava.lang/Process_6.out: Expected result. + +2004-08-12 David Daney + + PR libgcj/11801 + * java/lang/PosixProcess.java: Rewrote. + * java/lang/natPosixProcess.cc: Rewrote. + * java/lang/Runtime.java (execInternal): Declare throws IOException. + * gcj/javaprims.h (ConcreteProcess$ProcessManager): Declare. + * posix-threads.cc (block_sigchld) New function. + (_Jv_ThreadRegister) Use it. + (_Jv_ThreadStart) Use it. + * configure.in (PLATFORM_INNER_NAT_HDRS): New AC_SUBST() used in... + * Makefile.am: ... to specify extra native headers. + * configure: Regenerated. + * include/config.h: Regenerated. + * Makefile.in: Regenerated. + * gcj/Makefile.in: Regenerated. + * include/Makefile.in: Regenerated. + * testsuite/Makefile.in: Regenerated. + 2004-08-12 Diego Novillo PR tree-optimization/16867 diff --git a/libjava/testsuite/libjava.lang/Process_1.java b/libjava/testsuite/libjava.lang/Process_1.java new file mode 100644 index 00000000000..adc6354660d --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_1.java @@ -0,0 +1,41 @@ +// Create a process and read from its standard output. +// +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + + +public class Process_1 +{ + public static void main(String[] args) + { + try + { + Runtime r = Runtime.getRuntime(); + String s = "Hello World"; + String[] a = { "echo", s }; + Process p = r.exec(a); + InputStream is = p.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String result = br.readLine(); + if (! s.equals(result)) + { + System.out.println("bad 1"); + return; + } + result = br.readLine(); + if (result != null) + { + System.out.println("bad 2"); + return; + } + int c = p.waitFor(); + System.out.println(c == 0 ? "ok" : "bad 3"); + } + catch (Exception ex) + { + System.out.println(ex.toString()); + } + } +} diff --git a/libjava/testsuite/libjava.lang/Process_1.out b/libjava/testsuite/libjava.lang/Process_1.out new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_1.out @@ -0,0 +1 @@ +ok diff --git a/libjava/testsuite/libjava.lang/Process_2.java b/libjava/testsuite/libjava.lang/Process_2.java new file mode 100644 index 00000000000..d90e653a40e --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_2.java @@ -0,0 +1,40 @@ +// Create a process and read from its standard error. +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + + +public class Process_2 +{ + public static void main(String[] args) + { + try + { + Runtime r = Runtime.getRuntime(); + String s = "Hello World"; + String[] a = { "sh", "-c", "echo " + s + " >&2" }; + Process p = r.exec(a); + InputStream is = p.getErrorStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String result = br.readLine(); + if (! s.equals(result)) + { + System.out.println("bad 1"); + return; + } + result = br.readLine(); + if (result != null) + { + System.out.println("bad 2"); + return; + } + int c = p.waitFor(); + System.out.println(c == 0 ? "ok" : "bad 3"); + } + catch (Exception ex) + { + System.out.println(ex.toString()); + } + } +} diff --git a/libjava/testsuite/libjava.lang/Process_2.out b/libjava/testsuite/libjava.lang/Process_2.out new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_2.out @@ -0,0 +1 @@ +ok diff --git a/libjava/testsuite/libjava.lang/Process_3.java b/libjava/testsuite/libjava.lang/Process_3.java new file mode 100644 index 00000000000..669e1dc7e29 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_3.java @@ -0,0 +1,72 @@ +// Create a process and pipe data through it. waitFor() the process +// in a different thread than the one that created it. +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; + + +public class Process_3 implements Runnable +{ + Process p; + + public void run() + { + try + { + Runtime r = Runtime.getRuntime(); + String[] a = { "sed", "-e", "s/Hello/Goodbye/" }; + synchronized (this) + { + p = r.exec(a); + this.notifyAll(); + } + OutputStream os = p.getOutputStream(); + PrintStream ps = new PrintStream(os); + ps.println("Hello World"); + ps.close(); + } + catch (Exception ex) + { + System.out.println(ex.toString()); + } + } + + public static void main(String[] args) + { + try + { + Process_3 p3 = new Process_3(); + Thread t = new Thread(p3); + t.start(); + synchronized (p3) + { + while (p3.p == null) + p3.wait(); + } + + InputStream is = p3.p.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String result = br.readLine(); + if (! "Goodbye World".equals(result)) + { + System.out.println("bad 1"); + return; + } + result = br.readLine(); + if (result != null) + { + System.out.println("bad 2"); + return; + } + int c = p3.p.waitFor(); + System.out.println(c == 0 ? "ok" : "bad 3"); + } + catch (Exception ex) + { + System.out.println(ex.toString()); + } + } +} diff --git a/libjava/testsuite/libjava.lang/Process_3.out b/libjava/testsuite/libjava.lang/Process_3.out new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_3.out @@ -0,0 +1 @@ +ok diff --git a/libjava/testsuite/libjava.lang/Process_4.java b/libjava/testsuite/libjava.lang/Process_4.java new file mode 100644 index 00000000000..241dfde816d --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_4.java @@ -0,0 +1,19 @@ +// Create a process and verify failure exit code. +public class Process_4 +{ + public static void main(String[] args) + { + try + { + Runtime r = Runtime.getRuntime(); + String[] a = { "false" }; + Process p = r.exec(a); + int c = p.waitFor(); + System.out.println(c == 1 ? "ok" : "bad"); + } + catch (Exception ex) + { + System.out.println(ex.toString()); + } + } +} diff --git a/libjava/testsuite/libjava.lang/Process_4.out b/libjava/testsuite/libjava.lang/Process_4.out new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_4.out @@ -0,0 +1 @@ +ok diff --git a/libjava/testsuite/libjava.lang/Process_5.java b/libjava/testsuite/libjava.lang/Process_5.java new file mode 100644 index 00000000000..61fd5b7409f --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_5.java @@ -0,0 +1,43 @@ +// Create a long running process and verify that the exitValue is not +// immediately available. Then destroy() it and verify that it +// terminates quickly with a non-zero exitValue. +public class Process_5 +{ + public static void main(String[] args) + { + try + { + int c; + long startTime = System.currentTimeMillis(); + Runtime r = Runtime.getRuntime(); + String[] a = { "sleep", "120" }; + Process p = r.exec(a); + + try + { + c = p.exitValue(); + System.out.println("bad 1"); + return; + } + catch (IllegalThreadStateException itse) + { + // Ignore as this is good here. + } + + p.destroy(); + + c = p.waitFor(); + + long endTime = System.currentTimeMillis(); + + if (endTime - startTime > 110000L) + System.out.println("bad 2"); + + System.out.println(c != 0 ? "ok" : "bad 3"); + } + catch (Exception ex) + { + System.out.println(ex.toString()); + } + } +} diff --git a/libjava/testsuite/libjava.lang/Process_5.out b/libjava/testsuite/libjava.lang/Process_5.out new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_5.out @@ -0,0 +1 @@ +ok diff --git a/libjava/testsuite/libjava.lang/Process_6.java b/libjava/testsuite/libjava.lang/Process_6.java new file mode 100644 index 00000000000..3bf015f760b --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_6.java @@ -0,0 +1,31 @@ +// Create a running process for a non existent executable. +// Verify that IOException is thrown. +import java.io.IOException; + + +public class Process_6 +{ + public static void main(String[] args) + { + try + { + int c; + Runtime r = Runtime.getRuntime(); + String[] a = { "blablabla_failure" }; + + try + { + Process p = r.exec(a); + System.out.println("bad"); + } + catch (IOException ioe) + { + System.out.println("ok"); + } + } + catch (Exception ex) + { + System.out.println(ex.toString()); + } + } +} diff --git a/libjava/testsuite/libjava.lang/Process_6.out b/libjava/testsuite/libjava.lang/Process_6.out new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Process_6.out @@ -0,0 +1 @@ +ok -- 2.30.2