Skip to content
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
20 changes: 19 additions & 1 deletion src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.DotNet.XHarness.TestRunners.Xunit;
Expand Down Expand Up @@ -58,6 +59,23 @@ public static async Task<int> Main(string[] args)
IncludedMethods = includedMethods
};

return await runner.Run();
int result = await runner.Run();

// if the execution doesn't finish on the main thread, the test runner
// doesn't exit correctly and the test time outs
await SwitchToMainThreadAsync();

return result;
}

private static async Task SwitchToMainThreadAsync()
{
// TODO: is there a better way to do this? this works but it feels very hacky...
// it would be best to ensure switching threads in the mono driver so that it works for _all_
// WASM programs running on Mono
while (Thread.CurrentThread.IsBackground)
{
await Task.Delay(1);
}
}
}
14 changes: 8 additions & 6 deletions src/mono/wasm/runtime/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ export function mono_wasm_trace_logger(log_domain_ptr: CharPtr, log_level_ptr: C
}

export function setup_proxy_console(id: string, originalConsole: Console, origin: string): void {
const originalConsoleLog = originalConsole.log;
const originalConsoleError = originalConsole.error;

function proxyConsoleMethod(prefix: string, func: any, asJson: boolean) {
return function (...args: any[]) {
try {
Expand Down Expand Up @@ -525,21 +528,20 @@ export function setup_proxy_console(id: string, originalConsole: Console, origin

const consoleWebSocket = new WebSocket(consoleUrl);
consoleWebSocket.onopen = function () {
originalConsole.log(`browser: [${id}] Console websocket connected.`);
originalConsoleLog(`browser: [${id}] Console websocket connected.`);
};
consoleWebSocket.onerror = function (event) {
originalConsole.error(`[${id}] websocket error: ${event}`, event);
originalConsoleError(`[${id}] websocket error: ${event}`, event);
};
consoleWebSocket.onclose = function (event) {
originalConsole.error(`[${id}] websocket closed: ${event}`, event);
originalConsoleError(`[${id}] websocket closed: ${event}`, event);
};

const send = (msg: string) => {
if (consoleWebSocket.readyState === WebSocket.OPEN) {
consoleWebSocket.send(msg);
}
else {
originalConsole.log(msg);
} else {
originalConsoleLog(msg);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/mono/wasm/wasm.proj
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@
<_EmccCommonFlags Condition="'$(WasmEnableSIMD)' == 'true'" Include="-msimd128" />
<_EmccCommonFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s USE_PTHREADS=1" />
<_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" />
<_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=4" />
<_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE_STRICT=2" /> <!-- hard error if worker pool is exhausted -->
<_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=32" />
<!--
<_EmccLinkFlags Include="-s EXPORT_ES6=1" Condition="'$(WasmEnableES6)' == 'true'" />
-->
Expand Down