[sdb] Avoid calling into the debuggee from VirtualMachine.GetObject () while holding...
[mono-project.git] / sdks / wasm / main.cs
blob4a2fc59833e4c1722ae41dae1fdb278c526db0f1
1 using System;
2 using System.Text;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Threading;
6 using System.Threading.Tasks;
7 using System.Reflection;
8 using NUnitLite.Runner;
9 using NUnit.Framework.Internal;
10 using NUnit.Framework.Api;
11 using System.Runtime.InteropServices;
12 using System.Runtime.CompilerServices;
14 public class Driver {
15 static void Main () {
16 Console.WriteLine ("hello");
17 Send ("run", "mini");
21 static int step_count, tp_pump_count;
22 static Task cur_task;
24 static void TPStart () {
25 var l = new List<Task> ();
26 for (int i = 0; i < 5; ++i) {
27 l.Add (Task.Run (() => {
28 ++step_count;
29 }));
30 l.Add (Task.Factory.StartNew (() => {
31 ++step_count;
32 }, TaskCreationOptions.LongRunning));
34 cur_task = Task.WhenAll (l).ContinueWith (t => {
35 });
38 static bool TPPump () {
39 if (tp_pump_count > 10) {
40 Console.WriteLine ("Pumped the TP test 10 times and no progress <o> giving up");
41 latest_test_result = "FAIL";
42 return false;
45 tp_pump_count++;
46 latest_test_result = "PASS";
47 return !cur_task.IsCompleted;
51 static Action dele;
52 static IAsyncResult dele_result;
53 static void BeginSomething () {
56 static void DeleStart ()
58 dele = new Action (BeginSomething);
59 dele_result = dele.BeginInvoke (null, null);
62 static bool DelePump ()
64 if (dele_result.IsCompleted) {
65 dele.EndInvoke (dele_result);
66 return false;
68 return true;
72 static int fin_count;
73 interface IFoo {}
74 class Foo : IFoo {
75 ~Foo () {
76 ++fin_count;
79 static void GcStart ()
81 IFoo[] arr = new IFoo [10];
82 Volatile.Write (ref arr [1], new Foo ());
83 for (int i = 0; i < 100; ++i) {
84 var x = new Foo ();
88 static bool GcPump ()
90 GC.Collect ();
91 return fin_count < 100;
94 static bool timer_called;
95 static int pump_count;
97 static void TimerStart () {
98 Timer t = new Timer ((_) => {
99 timer_called = true;
101 t.Change (10, Timeout.Infinite);
102 latest_test_result = "EITA";
105 static bool TimerPump () {
106 ++pump_count;
107 if (pump_count > 5 || timer_called) {
108 latest_test_result = timer_called ? "PASS" : "FAIL";
109 return false;
112 return true;
115 static int run_count;
116 public static string Send (string key, string val) {
117 if (key == "start-test") {
118 StartTest (val);
119 return "SUCCESS";
121 if (key == "pump-test") {
122 return PumpTest (val) ? "IN-PROGRESS" : "DONE" ;
124 if (key == "test-result") {
125 return latest_test_result;
128 return "INVALID-KEY";
131 public class TestSuite {
132 public string Name { get; set; }
133 public string File { get; set; }
136 static TestSuite[] suites = new TestSuite [] {
137 new TestSuite () { Name = "mini", File = "managed/mini_tests.dll" },
138 new TestSuite () { Name = "binding", File = "managed/binding_tests.dll" },
139 new TestSuite () { Name = "corlib", File = "managed/wasm_corlib_test.dll" },
140 new TestSuite () { Name = "system", File = "managed/wasm_System_test.dll" },
141 new TestSuite () { Name = "system-core", File = "managed/wasm_System.Core_test.dll" },
144 static IncrementalTestRunner testRunner;
145 static string latest_test_result;
147 public static bool PumpTest (string name) {
148 if (name == "tp")
149 return TPPump ();
150 if (name == "dele")
151 return DelePump ();
152 if (name == "gc")
153 return GcPump ();
154 if (name == "timer")
155 return TimerPump ();
157 if (testRunner == null)
158 return false;
159 try {
160 bool res = testRunner.Step ();
161 if (!res) {
162 latest_test_result = testRunner.Status;
163 testRunner = null;
165 return res;
166 } catch (Exception e) {
167 Console.WriteLine (e);
168 latest_test_result = "FAIL";
169 return true;
173 public static void StartTest (string name) {
174 var baseDir = AppDomain.CurrentDomain.BaseDirectory;
175 if (testRunner != null)
176 throw new Exception ("Test in progress");
178 if (name == "tp") {
179 TPStart ();
180 return;
182 if (name == "dele") {
183 DeleStart ();
184 return;
186 if (name == "gc") {
187 GcStart ();
188 return;
190 if (name == "timer") {
191 TimerStart ();
192 return;
195 string extra_disable = "";
196 latest_test_result = "IN-PROGRESS";
198 string[] args = name.Split (',');
199 var testsuite_name = suites.Where (ts => ts.Name == args [0]).Select (ts => ts.File).FirstOrDefault ();
200 if (testsuite_name == null)
201 throw new Exception ("NO SUITE NAMED " + args [0]);
203 string test_name = null;
204 int? range = null;
205 for (int i = 1; i < args.Length; ++i) {
206 int r;
207 if (int.TryParse (args [i], out r))
208 range = r;
209 else
210 test_name = args [i];
213 testRunner = new IncrementalTestRunner ();
214 // testRunner.PrintLabels ();
215 // if (test_name != null)
216 // testRunner.RunTest (test_name);
218 testRunner.Exclude ("NotWasm,WASM,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingRuntimeInterpreter,MultiThreaded");
219 testRunner.Add (Assembly.LoadFrom (baseDir + "/" + testsuite_name));
220 // testRunner.RunOnly ("MonoTests.System.Threading.AutoResetEventTest.MultipleSet");
222 // This is useful if you need to skip to the middle of a huge test suite like corlib.
223 // testRunner.SkipFirst (4550);
224 testRunner.Start (10);