[System.Runtime.InteropServices.RuntimeInformation] Updated to reference copied files...
[mono-project.git] / mono / tests / process-stress-2.cs
blobd31e23a0904fa7d58443768d3331aef8dce78320
2 using System;
3 using System.Diagnostics;
4 using System.Text;
5 using System.Threading;
6 using System.Threading.Tasks;
8 class Driver
10 static void Main ()
12 Action<Process>[] tests = new Action<Process> [] {
13 new Action<Process> (Test1),
14 new Action<Process> (Test2),
17 ProcessStartInfo psi = new ProcessStartInfo () {
18 FileName = "echo",
19 Arguments = "hello",
20 UseShellExecute = false,
21 RedirectStandardOutput = true,
24 foreach (Action<Process> test in tests) {
25 for (int i = 0; i < 500; ++i) {
26 test (new Process () { StartInfo = psi });
31 static void Test1 (Process p)
33 StringBuilder sb = new StringBuilder ();
34 ManualResetEvent mre_exit = new ManualResetEvent (false);
35 ManualResetEvent mre_output = new ManualResetEvent (false);
37 p.EnableRaisingEvents = true;
38 p.Exited += (s, a) => mre_exit.Set ();
40 p.Start ();
42 p.OutputDataReceived += (s, a) => {
43 if (a.Data == null) {
44 mre_output.Set ();
45 return;
47 sb.Append (a.Data);
50 p.BeginOutputReadLine ();
52 if (!mre_exit.WaitOne (1000))
53 Environment.Exit (1);
54 if (!mre_output.WaitOne (1000))
55 Environment.Exit (2);
57 if (sb.ToString () != "hello") {
58 Console.WriteLine ("process output = '{0}'", sb.ToString ());
59 Environment.Exit (3);
63 static void Test2 (Process p)
65 StringBuilder sb = new StringBuilder ();
66 ManualResetEvent mre_output = new ManualResetEvent (false);
68 p.Start ();
70 p.OutputDataReceived += (s, a) => {
71 if (a.Data == null) {
72 mre_output.Set ();
73 return;
76 sb.Append (a.Data);
79 p.BeginOutputReadLine ();
81 if (!p.WaitForExit (1000))
82 Environment.Exit (4);
83 if (!mre_output.WaitOne (1000))
84 Environment.Exit (5);
86 if (sb.ToString () != "hello") {
87 Console.WriteLine ("process output = '{0}'", sb.ToString ());
88 Environment.Exit (6);