Fix invalid emscripten path file name
[mono-project.git] / sdks / wasm / main.cs
blob1dd598a369c1d474fe9dace7007c6a5cc6566053
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 static string excludes = "";
118 public static string Send (string key, string val) {
119 if (key == "--exclude") {
120 excludes += val + ",";
122 if (key == "start-test") {
123 StartTest (val);
124 return "SUCCESS";
126 if (key == "pump-test") {
127 return PumpTest (val) ? "IN-PROGRESS" : "DONE" ;
129 if (key == "test-result") {
130 return latest_test_result;
133 return "INVALID-KEY";
136 public class TestSuite {
137 public string Name { get; set; }
138 public string File { get; set; }
141 static TestSuite[] suites = new TestSuite [] {
142 new TestSuite () { Name = "mini", File = "managed/mini_tests.dll" },
143 new TestSuite () { Name = "binding", File = "managed/binding_tests.dll" },
144 new TestSuite () { Name = "corlib", File = "managed/wasm_corlib_test.dll" },
145 new TestSuite () { Name = "system", File = "managed/wasm_System_test.dll" },
146 new TestSuite () { Name = "system-core", File = "managed/wasm_System.Core_test.dll" },
149 static IncrementalTestRunner testRunner;
150 static string latest_test_result;
152 public static bool PumpTest (string name) {
153 if (name == "tp")
154 return TPPump ();
155 if (name == "dele")
156 return DelePump ();
157 if (name == "gc")
158 return GcPump ();
159 if (name == "timer")
160 return TimerPump ();
162 if (testRunner == null)
163 return false;
164 try {
165 bool res = testRunner.Step ();
166 if (!res) {
167 latest_test_result = testRunner.Status;
168 testRunner = null;
170 return res;
171 } catch (Exception e) {
172 Console.WriteLine (e);
173 latest_test_result = "FAIL";
174 return true;
178 public static void StartTest (string name) {
179 var baseDir = AppDomain.CurrentDomain.BaseDirectory;
180 if (testRunner != null)
181 throw new Exception ("Test in progress");
183 if (name == "tp") {
184 TPStart ();
185 return;
187 if (name == "dele") {
188 DeleStart ();
189 return;
191 if (name == "gc") {
192 GcStart ();
193 return;
195 if (name == "timer") {
196 TimerStart ();
197 return;
200 string extra_disable = "";
201 latest_test_result = "IN-PROGRESS";
203 string[] args = name.Split (',');
204 var testsuite_name = suites.Where (ts => ts.Name == args [0]).Select (ts => ts.File).FirstOrDefault ();
205 if (testsuite_name == null)
206 throw new Exception ("NO SUITE NAMED " + args [0]);
208 string test_name = null;
209 int? range = null;
210 for (int i = 1; i < args.Length; ++i) {
211 int r;
212 if (int.TryParse (args [i], out r))
213 range = r;
214 else
215 test_name = args [i];
218 testRunner = new IncrementalTestRunner ();
219 // testRunner.PrintLabels ();
220 // if (test_name != null)
221 // testRunner.RunTest (test_name);
223 testRunner.Exclude ("NotWasm,WASM,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingRuntimeInterpreter,MultiThreaded,StackWalk,GetCallingAssembly,LargeFileSupport,MobileNotWorking,ManagedCollator," + excludes);
224 testRunner.Add (Assembly.LoadFrom (baseDir + "/" + testsuite_name));
225 // testRunner.RunOnly ("MonoTests.System.Threading.AutoResetEventTest.MultipleSet");
227 // This is useful if you need to skip to the middle of a huge test suite like corlib.
228 // testRunner.SkipFirst (4550);
229 testRunner.Start (10);