diff options
author | Kenneth Pouncey <kjpou@pt.lu> | 2018-09-13 17:10:31 +0300 |
---|---|---|
committer | Alexis Christoforides <alexis@thenull.net> | 2018-09-13 17:10:31 +0300 |
commit | 8fe989cb70a54d4c46f27de2229895fef5db5635 (patch) | |
tree | 13cc6016d520d730b8daaa21daef724f52f804d0 /sdks | |
parent | 15bcc4f55da50e799cc232d8af0bec41b6ec0302 (diff) |
[WASM] Make test-suite use generated driver and bindings. (#10558)
* Make test.js use generated driver and bindings.
- bindings_tests.dll uses the generated bindings.dll.
- Modify packager to accept a template parameter that overrides the default `runtime.g.js`.
- Modify the tests to call runtime.js in the test-suite directory
- The runtime.js is automatically created in the test-suite library so no need to do extra copies.
- resolves https://github.com/mono/mono/issues/10244
* Add -template option to packager
- Part of merge conflict resolution
* Add -asset option that allows an extra asset to be copied to the output directory.
- --asset=x Add specified asset 'x' to list of assets to be copied
- An asset option needs to be specified for each asset to be copied.
Diffstat (limited to 'sdks')
-rw-r--r-- | sdks/wasm/Makefile | 18 | ||||
-rw-r--r-- | sdks/wasm/bindings.cs | 2 | ||||
-rw-r--r-- | sdks/wasm/packager.cs | 15 | ||||
-rw-r--r-- | sdks/wasm/runtime-tests.g.js | 208 |
4 files changed, 231 insertions, 12 deletions
diff --git a/sdks/wasm/Makefile b/sdks/wasm/Makefile index 4eb98cdcfff..b5be353bd61 100644 --- a/sdks/wasm/Makefile +++ b/sdks/wasm/Makefile @@ -44,7 +44,6 @@ APP_SOURCES = \ incrementalrunner.cs BINDING_TEST_SOURCES = \ - bindings.cs \ bindings-test.cs MINI_TEST_SOURCES = $(patsubst %,$(MINI_PATH)/%,$(MINI_TEST_FILES)) @@ -109,8 +108,8 @@ main.exe: $(APP_SOURCES) mini_tests.dll: $(MINI_TEST_SOURCES) mini-test-runner.cs $(CSC) $(CSC_FLAGS) /unsafe -target:library -out:$@ -define:__MOBILE__,ARCH_32 $(BCL_DEPS) /r:$(WASM_BCL_DIR)/nunitlite.dll $(MINI_TEST_SOURCES) mini-test-runner.cs -binding_tests.dll: $(BINDING_TEST_SOURCES) - $(CSC) $(CSC_FLAGS) /unsafe -target:library -out:$@ $(BCL_DEPS) /r:$(WASM_BCL_DIR)/nunitlite.dll $(BINDING_TEST_SOURCES) +binding_tests.dll: bindings.dll $(BINDING_TEST_SOURCES) + $(CSC) $(CSC_FLAGS) /unsafe -target:library -out:$@ /r:bindings.dll $(BCL_DEPS) /r:$(WASM_BCL_DIR)/nunitlite.dll $(BINDING_TEST_SOURCES) bindings.dll: bindings.cs $(CSC) /debug:portable /noconfig /nostdlib /target:library -out:$@ /r:$(WASM_BCL_DIR)/mscorlib.dll bindings.cs @@ -138,9 +137,8 @@ packager.exe: packager.cs Mono.Cecil.dll $(OPTIONS_CS) TEST_ASSEMBLIES = $(WASM_BCL_DIR)/nunitlite.dll $(WASM_BCL_DIR)/tests/wasm_corlib_test.dll $(WASM_BCL_DIR)/tests/wasm_System_test.dll $(WASM_BCL_DIR)/tests/wasm_System.Core_test.dll -.stamp-build-test-suite: $(DRIVER_CONF)/.stamp-build packager.exe bindings.dll binding_tests.dll mini_tests.dll main.exe runtime.g.js - mono packager.exe -out=test-suite binding_tests.dll mini_tests.dll main.exe $(TEST_ASSEMBLIES) - cp test.js test-suite/ +.stamp-build-test-suite: $(DRIVER_CONF)/.stamp-build packager.exe bindings.dll binding_tests.dll mini_tests.dll main.exe runtime-tests.g.js + mono packager.exe -template=runtime-tests.g.js -out=test-suite binding_tests.dll mini_tests.dll main.exe $(TEST_ASSEMBLIES) touch $@ MINI_BASIC_TEST_FILES= \ @@ -181,16 +179,16 @@ JSC=~/.jsvu/jsc SM=~/.jsvu/sm run-ch-%: toolchain build-test-suite - (cd test-suite && $(CHAKRA) test.js -args $*) + (cd test-suite && $(CHAKRA) runtime.js -args $*) run-v8-%: toolchain build-test-suite - (cd test-suite && $(D8) --expose_wasm test.js -- $*) + (cd test-suite && $(D8) --expose_wasm runtime.js -- $*) run-jsc-%: toolchain build-test-suite - (cd test-suite && $(JSC) test.js -- $*) + (cd test-suite && $(JSC) runtime.js -- $*) run-sm-%: toolchain build-test-suite - (cd test-suite && $(SM) test.js $*) + (cd test-suite && $(SM) runtime.js $*) # Leaving JSC for now cuz it aborts when it encounters wasm run-all-%: diff --git a/sdks/wasm/bindings.cs b/sdks/wasm/bindings.cs index 9306fbfcb2a..db5605802d3 100644 --- a/sdks/wasm/bindings.cs +++ b/sdks/wasm/bindings.cs @@ -227,7 +227,7 @@ namespace WebAssembly { } public class JSObject : IDisposable { - internal int JSHandle; + public int JSHandle {get; internal set; } internal GCHandle Handle; internal object RawObject; diff --git a/sdks/wasm/packager.cs b/sdks/wasm/packager.cs index 9b865b004c6..9445311581a 100644 --- a/sdks/wasm/packager.cs +++ b/sdks/wasm/packager.cs @@ -35,6 +35,8 @@ class Driver { Console.WriteLine ("\t--mono-sdkdir=x Set the mono sdk directory to 'x'"); Console.WriteLine ("\t--deploy=x Set the deploy prefix to 'x' (default to 'managed')"); Console.WriteLine ("\t--vfs=x Set the VFS prefix to 'x' (default to 'managed')"); + Console.WriteLine ("\t--template=x Set the template name to 'x' (default to 'runtime.g.js')"); + Console.WriteLine ("\t--asset=x Add specified asset 'x' to list of assets to be copied"); Console.WriteLine ("foo.dll Include foo.dll as one of the root assemblies"); } @@ -173,6 +175,8 @@ class Driver { var enable_aot = false; var print_usage = false; var emit_ninja = false; + var runtimeTemplate = "runtime.g.js"; + var assets = new List<string> (); var p = new OptionSet () { { "debug", s => enable_debug = true }, @@ -187,6 +191,8 @@ class Driver { { "deploy=", s => deploy_prefix = s }, { "vfs=", s => vfs_prefix = s }, { "aot", s => enable_aot = true }, + { "template=", s => runtimeTemplate = s }, + { "asset=", s => assets.Add(s) }, { "help", s => print_usage = true }, }; @@ -247,7 +253,7 @@ class Driver { if (vfs_prefix.EndsWith ("/")) vfs_prefix = vfs_prefix.Substring (0, vfs_prefix.Length - 1); - var template = File.ReadAllText (Path.Combine (tool_prefix, "runtime.g.js")); + var template = File.ReadAllText (Path.Combine (tool_prefix, runtimeTemplate)); var file_list_str = string.Join (",", file_list.Select (f => $"\"{Path.GetFileName (f)}\"")); template = template.Replace ("@FILE_LIST@", file_list_str); @@ -275,6 +281,13 @@ class Driver { File.Copy ( Path.Combine (runtime_dir, "mono.wasm"), Path.Combine (out_prefix, "mono.wasm")); + + foreach(var asset in assets) + { + Console.WriteLine ($"Asset: cp {asset} -> {Path.Combine (out_prefix, Path.GetFileName (asset))}"); + File.Copy (asset, + Path.Combine (out_prefix, asset)); + } } if (!emit_ninja) diff --git a/sdks/wasm/runtime-tests.g.js b/sdks/wasm/runtime-tests.g.js new file mode 100644 index 00000000000..f666172f14c --- /dev/null +++ b/sdks/wasm/runtime-tests.g.js @@ -0,0 +1,208 @@ + +//glue code to deal with the differences between ch, d8, jsc and sm. +if (typeof print === "undefined") + print = console.log; + +// JavaScript core does not have a console defined +if (typeof console === "undefined") { + var Console = function () { + this.log = function(msg){ print(msg) }; + }; + console = new Console(); +} + +if (typeof console !== "undefined") { + var has_console_warn = false; + try { + if (typeof console.warn !== "undefined") + has_console_warn = true; + } catch(e) {} + + if (!has_console_warn) + console.warn = console.log; +} + +fail_exec = function(reason) { + print (reason); + throw "FAIL"; +} + +try { + arguments = WScript.Arguments; + load = WScript.LoadScriptFile; + read = WScript.LoadBinaryFile; + fail_exec = function(reason) { + print (reason); + WScript.Quit(1); + } +} catch(e) {} + +try { + if (typeof scriptArgs !== "undefined") + arguments = scriptArgs; +} catch(e) {} +//end of all the nice shell glue code. + +// set up a global variable to be accessed in the App.init +var testArguments = arguments; + +function inspect_object (o){ + var r=""; + for(var p in o) { + var t = typeof o[p]; + r += "'" + p + "' => '" + t + "', "; + } + return r; +} + + +var Module = { + print: function(x) { print ("WASM: " + x) }, + printErr: function(x) { print ("WASM-ERR: " + x) }, + + instantiateWasm: function (env, receiveInstance) { + //merge Module's env with emcc's env + env.env = Object.assign({}, env.env, this.env); + var module = new WebAssembly.Module (read ('mono.wasm', 'binary')) + this.wasm_instance = new WebAssembly.Instance (module, env); + this.em_cb = receiveInstance; + return this + }, + + finish_loading: function () { + this.em_cb (this.wasm_instance); + }, + + env: { + }, + onRuntimeInitialized: function () { + MONO.mono_load_runtime_and_bcl ( + "@VFS_PREFIX@", + "@DEPLOY_PREFIX@", + @ENABLE_DEBUGGING@, + [ @FILE_LIST@ ], + function () { + @BINDINGS_LOADING@ + App.init (); + }, + function (asset ) + { + // The default mono_load_runtime_and_bcl defaults to using + // fetch to load the assets. It also provides a way to set a + // fetch promise callback. + // Here we wrap the file read in a promise and fake a fetch response + // structure. + return new Promise((resolve, reject) => { + var response = { ok: true, url: asset, + arrayBuffer: function() { + return new Promise((resolve2, reject2) => { + resolve2(new Uint8Array (read (asset, 'binary'))); + } + )} + } + resolve(response) + }) + } + ); + }, + +}; + +load ("mono.js"); +Module.finish_loading (); + +var assembly_load = Module.cwrap ('mono_wasm_assembly_load', 'number', ['string']) +var find_class = Module.cwrap ('mono_wasm_assembly_find_class', 'number', ['number', 'string', 'string']) +var find_method = Module.cwrap ('mono_wasm_assembly_find_method', 'number', ['number', 'string', 'number']) +const IGNORE_PARAM_COUNT = -1; + + +var App = { + init: function () { + + Module.print("Initializing....."); + Module.print("Arguments: " + testArguments); + + Module.print("Initializing Binding Test Suite support....."); + + //binding test suite support code + binding_test_module = assembly_load ("binding_tests"); + if (!binding_test_module) + { + Module.printErr("Binding tests module 'binding_tests' not found. Exiting Tests.") + throw new Error("Binding tests module 'binding_tests' not found. Exiting Tests."); + } + + binding_test_class = find_class (binding_test_module, "", "TestClass"); + if (!binding_test_class) + { + Module.printErr("Binding tests class 'TestClass' not found. Exiting Tests.") + throw new Error("Binding tests class 'TestClass' not found. Exiting Tests."); + } + + Module.print("Binding support complete."); + + + Module.print("Checking for [main]Driver:Send ...."); + + var send_message = undefined; + + try + { + send_message = BINDING.bind_static_method("[main]Driver:Send"); + } + catch (e) + { + Module.printErr("[main]Driver:Send not found: " + e); + throw e; + + } + + Module.print("Driver binding complete."); + + var bad_send_msg_detected = false; + for (var i = 0; i < testArguments.length; ++i) { + + var res = ""; + try + { + res = send_message("start-test", testArguments [i]) + } catch (e) { + printErr ("BAD SEND MSG: " + e); + bad_send_msg_detected = true; + } + print ("-----STARTED " + testArguments [i] + "---- " + res); + + if (res == "SUCCESS") { + while (send_message ("pump-test", testArguments [i]) != "DONE") + { + Module.pump_message (); + print ("|"); + } + print ("\nDONE") + } + } + + var status = send_message ("test-result", ""); + print ("Test status " + status) + if (status != "PASS") + fail_exec ("BAD TEST STATUS"); + + if (bad_send_msg_detected) + fail_exec ("BAD MSG SEND DETECTED"); + }, +}; + +//binding test suite support code +var binding_test_module = undefined; +var binding_test_class = undefined; + +// This function is called from the binding test suite +function call_test_method(method_name, signature, args) +{ + var target_method = find_method (binding_test_class, method_name, IGNORE_PARAM_COUNT) + if (!target_method) + throw "Could not find " + method_name; + + return Module.mono_method_invoke (target_method, null, signature, args); +} |