[System] Tweak socket test
[mono-project.git] / mono / tests / process-stress-3.cs
blob41d540ae1cd59195c75af64e68073d73c14a290d
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 = "find",
19 Arguments = "../.. -maxdepth 3", // this test should be run from mono/tests, so that will list all files in the repo
20 UseShellExecute = false,
21 RedirectStandardOutput = true,
22 RedirectStandardError = true,
25 foreach (Action<Process> test in tests) {
26 for (int i = 0; i < 200; ++i) {
27 test (new Process () { StartInfo = psi });
32 static void Test1 (Process p)
34 ManualResetEvent mre_exit = new ManualResetEvent (false);
35 ManualResetEvent mre_output = new ManualResetEvent (false);
36 ManualResetEvent mre_error = new ManualResetEvent (false);
38 p.EnableRaisingEvents = true;
39 p.Exited += (s, a) => mre_exit.Set ();
41 p.Start ();
43 p.OutputDataReceived += (s, a) => {
44 if (a.Data == null) {
45 mre_output.Set ();
46 return;
50 p.ErrorDataReceived += (s, a) => {
51 if (a.Data == null) {
52 mre_error.Set ();
53 return;
57 p.BeginOutputReadLine ();
58 p.BeginErrorReadLine ();
60 if (!mre_exit.WaitOne (10000))
61 Environment.Exit (1);
62 if (!mre_output.WaitOne (1000))
63 Environment.Exit (2);
64 if (!mre_error.WaitOne (1000))
65 Environment.Exit (3);
68 static void Test2 (Process p)
70 ManualResetEvent mre_output = new ManualResetEvent (false);
71 ManualResetEvent mre_error = new ManualResetEvent (false);
73 p.Start ();
75 p.OutputDataReceived += (s, a) => {
76 if (a.Data == null) {
77 mre_output.Set ();
78 return;
82 p.ErrorDataReceived += (s, a) => {
83 if (a.Data == null) {
84 mre_error.Set ();
85 return;
89 p.BeginOutputReadLine ();
90 p.BeginErrorReadLine ();
92 if (!p.WaitForExit (10000))
93 Environment.Exit (4);
94 if (!mre_output.WaitOne (1000))
95 Environment.Exit (5);
96 if (!mre_error.WaitOne (1000))
97 Environment.Exit (6);