Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Testing test runner changes #53044

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/wasm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ run-browser:
echo "The tool dotnet-serve could not be found. Install with: $(DOTNET) tool install --global dotnet-serve"; \
exit 1; \
else \
$(DOTNET) serve -d bin/$(CONFIG)/AppBundle -p 8000; \
$(DOTNET) serve -d=bin/$(CONFIG)/AppBundle -p 8000; \
fi

run-console:
Expand Down
158 changes: 89 additions & 69 deletions src/mono/wasm/runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
//

//glue code to deal with the differences between chrome, ch, d8, jsc and sm.
var is_browser = typeof window != "undefined";
const is_browser = typeof window != "undefined";
const is_node = !is_browser && typeof process != 'undefined';

// if the engine doesn't provide a console
if (typeof (console) === "undefined") {
var console = {
console = {
log: globalThis.print,
clear: function () { }
};
}


globalThis.testConsole = console;

function proxyMethod (prefix, func, asJson) {
function proxyMethod (prefix, proxyFunc, asJson) {
return function() {
var args = [...arguments];
if (asJson) {
func (JSON.stringify({
proxyFunc (JSON.stringify({
method: prefix,
payload: args[0],
arguments: args
}));
} else {
func([prefix + args[0], ...args.slice(1)]);
proxyFunc([prefix + args[0], ...args.slice(1)]);
}
};
};
Expand All @@ -38,9 +40,9 @@ for (var m of methods) {
}
}

function proxyJson (func) {
function proxyJson (consoleFunc) {
for (var m of ["log", ...methods])
console[m] = proxyMethod(`console.${m}`,func, true);
console[m] = proxyMethod(`console.${m}`, consolefunc, true);
}

if (is_browser) {
Expand All @@ -49,7 +51,7 @@ if (is_browser) {
let consoleWebSocket = new WebSocket(consoleUrl);
consoleWebSocket.onopen = function(event) {
proxyJson(function (msg) { consoleWebSocket.send (msg); });
globalThis.testConsole.log("browser: Console websocket connected.");
testConsole.log("browser: Console websocket connected.");
};
consoleWebSocket.onerror = function(event) {
console.log(`websocket error: ${event}`);
Expand All @@ -64,6 +66,18 @@ if (is_browser) {
}
}
}

if (is_node) {
arguments = process.argv.slice (2);
var fs = require ('fs');
function load (file) {
eval (fs.readFileSync(file).toString());
};
function read (path) {
return fs.readFileSync(path);
};
const { performance, PerformanceObserver } = require("perf_hooks")
}
//proxyJson(console.log);


Expand Down Expand Up @@ -91,22 +105,20 @@ if (typeof performance == 'undefined') {
}
}

try {
if (typeof arguments == "undefined")
arguments = WScript.Arguments;
load = WScript.LoadScriptFile;
read = WScript.LoadBinaryFile;
} catch (e) {
}

try {
if (typeof arguments == "undefined") {
if (typeof scriptArgs !== "undefined")
if (typeof (WScript) != "undefined") {
arguments = WScript.Arguments;
load = WScript.LoadScriptFile;
read = WScript.LoadBinaryFile;
} else if (typeof (scriptArgs) != "undefined") {
arguments = scriptArgs;
}
}
} catch (e) {
}


if (arguments === undefined)
arguments = [];

Expand All @@ -119,7 +131,7 @@ function test_exit (exit_code) {
if (is_browser) {
// Notify the selenium script
Module.exit_code = exit_code;
Module.print ("WASM EXIT " + exit_code);
console.log ("WASM EXIT " + exit_code);
var tests_done_elem = document.createElement ("label");
tests_done_elem.id = "tests_done";
tests_done_elem.innerHTML = exit_code.toString ();
Expand All @@ -130,7 +142,7 @@ function test_exit (exit_code) {
}

function fail_exec (reason) {
Module.print (reason);
console.log (reason);
test_exit (1);
}

Expand All @@ -144,37 +156,38 @@ function inspect_object (o) {
}

// Preprocess arguments
var args = testArguments;
console.info("Arguments: " + testArguments);
var args = [...testArguments];
//console.info("Arguments: " + testArguments);
profilers = [];
setenv = {};
runtime_args = [];
enable_gc = true;
enable_zoneinfo = false;
working_dir='/';
while (args !== undefined && args.length > 0) {
if (args [0].startsWith ("--profile=")) {
var arg = args [0].substring ("--profile=".length);
let currentArg = args [0].toString();
if (currentArg.startsWith ("--profile=")) {
var arg = currentArg.substring ("--profile=".length);

profilers.push (arg);

args = args.slice (1);
} else if (args [0].startsWith ("--setenv=")) {
var arg = args [0].substring ("--setenv=".length);
} else if (currentArg.startsWith ("--setenv=")) {
var arg = currentArg.substring ("--setenv=".length);
var parts = arg.split ('=');
if (parts.length != 2)
fail_exec ("Error: malformed argument: '" + args [0]);
fail_exec ("Error: malformed argument: '" + currentArg);
setenv [parts [0]] = parts [1];
args = args.slice (1);
} else if (args [0].startsWith ("--runtime-arg=")) {
var arg = args [0].substring ("--runtime-arg=".length);
} else if (currentArg.startsWith ("--runtime-arg=")) {
var arg = currentArg.substring ("--runtime-arg=".length);
runtime_args.push (arg);
args = args.slice (1);
} else if (args [0] == "--disable-on-demand-gc") {
} else if (currentArg == "--disable-on-demand-gc") {
enable_gc = false;
args = args.slice (1);
} else if (args [0].startsWith ("--working-dir=")) {
var arg = args [0].substring ("--working-dir=".length);
} else if (currentArg.startsWith ("--working-dir=")) {
var arg = currentArg.substring ("--working-dir=".length);
working_dir = arg;
args = args.slice (1);
} else {
Expand All @@ -186,15 +199,13 @@ testArguments = args;
// cheap way to let the testing infrastructure know we're running in a browser context (or not)
setenv["IsBrowserDomSupported"] = is_browser.toString().toLowerCase();

function writeContentToFile(content, path)
{
function writeContentToFile(content, path) {
var stream = FS.open(path, 'w+');
FS.write(stream, content, 0, content.length, 0);
FS.close(stream);
}

function loadScript (url)
{
function loadScript (url){
if (is_browser) {
var script = document.createElement ("script");
script.src = url;
Expand All @@ -204,26 +215,32 @@ function loadScript (url)
}
}

loadScript ("mono-config.js");
if (is_node) {
eval (read ("mono-config.js").toString());
} else {
loadScript("mono-config.js");
}

var Module = {
mainScriptUrlOrBlob: "dotnet.js",

print,
printErr,

config,
setenv,
read,
arguments,
onAbort: function(x) {
print ("ABORT: " + x);
console.log ("ABORT: " + x);
var err = new Error();
print ("Stacktrace: \n");
print (err.stack);
console.log ("Stacktrace: \n");
console.log (err.stack);
test_exit (1);
},

onRuntimeInitialized: function () {
try {

// Have to set env vars here to enable setting MONO_LOG_LEVEL etc.
for (var variable in setenv) {
MONO.mono_wasm_setenv (variable, setenv [variable]);
Module._mono_wasm_setenv (variable, setenv [variable]);
}

if (!enable_gc) {
Expand All @@ -241,7 +258,7 @@ var Module = {
App.init ();
};
config.fetch_file_cb = function (asset) {
// console.log("fetch_file_cb('" + asset + "')");
//console.log("fetch_file_cb('" + asset + "')");
// for testing purposes add BCL assets to VFS until we special case File.Open
// to identify when an assembly from the BCL is being open and resolve it correctly.
/*
Expand All @@ -261,30 +278,33 @@ var Module = {
return new Promise ((resolve, reject) => {
var bytes = null, error = null;
try {
bytes = read (asset, 'binary');
bytes = Module.read (asset, 'binary');
} catch (exc) {
error = exc;
}
var response = { ok: (bytes && !error), url: asset,
arrayBuffer: function () {
return new Promise ((resolve2, reject2) => {
if (error)
reject2 (error);
else
resolve2 (new Uint8Array (bytes));
}
)}
reject (exc);
}
resolve (response);
})
resolve ({
ok: (bytes && !error),
url: asset,
arrayBuffer: () => Promise.resolve (new Uint8Array (bytes))
});
});
}
};

MONO.mono_load_runtime_and_bcl_args (config);
Module.mono_load_runtime_and_bcl_args (config);
} catch (e) {
console.log (e);
}
},
};

loadScript ("dotnet.js");
if (is_node) {
eval (read ("dotnet.js").toString());
} else {
loadScript ("dotnet.js");
}
//var module = require ('./dotnet.js')(Module).then ((va) => console.log (va));
//globalThis.Module = Module;

const IGNORE_PARAM_COUNT = -1;

Expand Down Expand Up @@ -314,10 +334,10 @@ var App = {
var res = 0;
try {
res = exec_regression (10, args[1]);
Module.print ("REGRESSION RESULT: " + res);
console.log ("REGRESSION RESULT: " + res);
} catch (e) {
Module.print ("ABORT: " + e);
print (e.stack);
console.log ("ABORT: " + e);
console.log (e.stack);
res = 1;
}

Expand Down Expand Up @@ -352,23 +372,23 @@ var App = {
wasm_set_main_args (main_argc, main_argv);

// Automatic signature isn't working correctly
let result = Module.mono_call_assembly_entry_point (main_assembly_name, [app_args], "m");
let onError = function (error)
{
let onError = function (error) {
console.error (error);
if (error.stack)
console.error (error.stack);

test_exit (1);
}
try {
result.then (test_exit).catch (onError);
Module.mono_call_assembly_entry_point (main_assembly_name, [app_args], "m")
.then (test_exit)
.catch (onError);
} catch (error) {
onError(error);
}

} else {
fail_exec ("Unhandled argument: " + args [0]);
fail_exec ("Unhandled argument: " + args[0]);
}
},
call_test_method: function (method_name, args, signature) {
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/binding_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ var BindingSupportLib = {
// ensure the indirect values are 8-byte aligned so that aligned loads and stores will work
var indirectBaseOffset = ((((args_marshal.length * 4) + 7) / 8) | 0) * 8;

var closure = {};
var closure = { Module };
var indirectLocalOffset = 0;

body.push (
Expand Down Expand Up @@ -1349,6 +1349,7 @@ var BindingSupportLib = {
library_mono: MONO,
binding_support: this,
method: method,
Module: Module,
this_arg: this_arg
};

Expand Down
Loading