Skip to content

Commit b331283

Browse files
committed
- mono_wasm_init_finalizer_thread for MT
- -backgroundExec for Wasm test runner triggered via </_XUnitBackgroundExec>
1 parent 6253efe commit b331283

File tree

11 files changed

+29
-16
lines changed

11 files changed

+29
-16
lines changed

eng/testing/tests.browser.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
<_AppArgs Condition="'$(IsFunctionalTest)' != 'true' and '$(WasmMainAssemblyFileName)' != ''">--run $(WasmMainAssemblyFileName)</_AppArgs>
106106
<_AppArgs Condition="'$(IsFunctionalTest)' == 'true'">--run $(AssemblyName).dll</_AppArgs>
107107

108+
<_XUnitBackgroundExec Condition="'$(_XUnitBackgroundExec)' == '' and '$(MonoWasmBuildVariant)' == 'multithread'">true</_XUnitBackgroundExec>
109+
<WasmTestAppArgs Condition="'$(_XUnitBackgroundExec)' == 'true'">$(WasmTestAppArgs) -backgroundExec</WasmTestAppArgs>
108110
<_AppArgs Condition="'$(WasmTestAppArgs)' != ''">$(_AppArgs) $(WasmTestAppArgs)</_AppArgs>
109111

110112
<WasmXHarnessMonoArgs Condition="'$(XunitShowProgress)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=XHARNESS_LOG_TEST_START=1</WasmXHarnessMonoArgs>

src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static async Task<int> Main(string[] args)
2323
var includedNamespaces = new List<string>();
2424
var includedClasses = new List<string>();
2525
var includedMethods = new List<string>();
26+
var backgroundExec = false;
2627

2728
for (int i = 1; i < args.Length; i++)
2829
{
@@ -49,6 +50,9 @@ public static async Task<int> Main(string[] args)
4950
includedMethods.Add (args[i + 1]);
5051
i++;
5152
break;
53+
case "-backgroundExec":
54+
backgroundExec = true;
55+
break;
5256
default:
5357
throw new ArgumentException($"Invalid argument '{option}'.");
5458
}
@@ -68,7 +72,10 @@ public static async Task<int> Main(string[] args)
6872
{
6973
await Task.Yield();
7074
}
71-
75+
if (backgroundExec)
76+
{
77+
return await Task.Run(() => runner.Run());
78+
}
7279
return await runner.Run();
7380
}
7481
}

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System.Runtime.InteropServices.JavaScript.Legacy.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<WasmEnableLegacyJsInterop Condition="'$(WasmEnableLegacyJsInterop)' == ''">true</WasmEnableLegacyJsInterop>
99
<DefineConstants Condition="'$(WasmEnableLegacyJsInterop)' == 'false'">$(DefineConstants);DISABLE_LEGACY_JS_INTEROP</DefineConstants>
1010
<Scenario>WasmTestOnBrowser</Scenario>
11+
<_XUnitBackgroundExec>false</_XUnitBackgroundExec>
1112
</PropertyGroup>
1213

1314
<ItemGroup Condition="'$(WasmEnableLegacyJsInterop)' != 'false'">

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<DefineConstants Condition="'$(WasmEnableLegacyJsInterop)' == 'false'">$(DefineConstants);DISABLE_LEGACY_JS_INTEROP</DefineConstants>
1111
<!-- Use following lines to write the generated files to disk. -->
1212
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
13+
<_XUnitBackgroundExec>false</_XUnitBackgroundExec>
1314
</PropertyGroup>
1415
<ItemGroup>
1516
<Compile Include="System\Runtime\InteropServices\JavaScript\JavaScriptTestHelper.cs" />

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ public static async Task InitializeAsync()
10041004
await Setup();
10051005
// Log("JavaScriptTestHelper.mjs imported");
10061006
}
1007+
await Task.Yield();
10071008
}
10081009

10091010
public static Task DisposeAsync()

src/libraries/tests.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@
592592
<SmokeTestProject Include="$(MonoProjectRoot)sample\wasm\browser-threads-minimal\Wasm.Browser.Threads.Minimal.Sample.csproj" />
593593
-->
594594
<SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />
595+
<SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices.JavaScript\tests\System.Runtime.InteropServices.JavaScript.UnitTests\System.Runtime.InteropServices.JavaScript.Tests.csproj" />
595596
<!-- ActiveIssue https://github.com/dotnet/runtime/issues/88084
596597
<SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Net.Http\tests\FunctionalTests\System.Net.Http.Functional.Tests.csproj" />
597598
-->

src/mono/wasm/runtime/cwraps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const threading_cwraps: SigLine[] = MonoWasmThreads ? [
4141
[true, "mono_wasm_diagnostic_server_thread_attach_to_runtime", "void", []],
4242
[true, "mono_wasm_diagnostic_server_post_resume_runtime", "void", []],
4343
[true, "mono_wasm_diagnostic_server_create_stream", "number", []],
44+
[false, "mono_wasm_init_finalizer_thread", null, []],
4445
] : [];
4546

4647
// when the method is assigned/cached at usage, instead of being invoked directly from cwraps, it can't be marked lazy, because it would be re-bound on each call
@@ -181,6 +182,7 @@ export interface t_ThreadingCwraps {
181182
mono_wasm_diagnostic_server_thread_attach_to_runtime(): void;
182183
mono_wasm_diagnostic_server_post_resume_runtime(): void;
183184
mono_wasm_diagnostic_server_create_stream(): VoidPtr;
185+
mono_wasm_init_finalizer_thread(): void;
184186
}
185187

186188
export interface t_ProfilerCwraps {

src/mono/wasm/runtime/driver.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ char *mono_method_get_full_name (MonoMethod *method);
5858
extern void mono_register_timezones_bundle (void);
5959
#endif /* INVARIANT_TIMEZONE */
6060
extern void mono_wasm_set_entrypoint_breakpoint (const char* assembly_name, int method_token);
61-
static void mono_wasm_init_finalizer_thread (void);
6261

6362
extern void mono_bundled_resources_add_assembly_resource (const char *id, const char *name, const uint8_t *data, uint32_t size, void (*free_func)(void *, void*), void *free_data);
6463
extern void mono_bundled_resources_add_assembly_symbol_resource (const char *id, const uint8_t *data, uint32_t size, void (*free_func)(void *, void *), void *free_data);
@@ -542,9 +541,6 @@ mono_wasm_load_runtime (const char *unused, int debug_level)
542541

543542
mono_thread_set_main (mono_thread_current ());
544543

545-
// TODO: we can probably delay starting the finalizer thread even longer - maybe from JS
546-
// once we're done with loading and are about to begin running some managed code.
547-
mono_wasm_init_finalizer_thread ();
548544
}
549545

550546
EMSCRIPTEN_KEEPALIVE MonoAssembly*
@@ -1296,12 +1292,12 @@ mono_wasm_profiler_init_browser (const char *desc)
12961292

12971293
#endif
12981294

1299-
static void
1295+
EMSCRIPTEN_KEEPALIVE void
13001296
mono_wasm_init_finalizer_thread (void)
13011297
{
13021298
// At this time we don't use a dedicated thread for finalization even if threading is enabled.
13031299
// Finalizers periodically run on the main thread
1304-
#if 0
1300+
#ifndef DISABLE_THREADS
13051301
mono_gc_init_finalizer_thread ();
13061302
#endif
13071303
}

src/mono/wasm/runtime/exports-binding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { mono_wasm_asm_loaded } from "./startup";
1919
import { mono_wasm_diagnostic_server_on_server_thread_created } from "./diagnostics/server_pthread";
2020
import { mono_wasm_diagnostic_server_on_runtime_server_init, mono_wasm_event_pipe_early_startup_callback } from "./diagnostics";
2121
import { mono_wasm_diagnostic_server_stream_signal_work_available } from "./diagnostics/server_pthread/stream-queue";
22-
import { mono_log_debug, mono_log_warn, mono_wasm_trace_logger } from "./logging";
22+
import { mono_log_warn, mono_wasm_trace_logger } from "./logging";
2323
import { mono_wasm_profiler_leave, mono_wasm_profiler_enter } from "./profiler";
2424
import { mono_wasm_change_case, mono_wasm_change_case_invariant } from "./hybrid-globalization/change-case";
2525
import { mono_wasm_compare_string, mono_wasm_ends_with, mono_wasm_starts_with, mono_wasm_index_of } from "./hybrid-globalization/collations";
@@ -163,7 +163,7 @@ export function replace_linker_placeholders(imports: WebAssembly.Imports) {
163163
const stubFn = env[shortName];
164164
if (typeof stubFn !== "function") throw new Error(`Expected ${shortName} to be a function`);
165165
env[shortName] = realFn;
166-
mono_log_debug(`Replaced WASM import ${shortName} stub ${stubFn.name} with ${realFn.name || "minified implementation"}`);
166+
// mono_log_debug(`Replaced WASM import ${shortName} stub ${stubFn.name} with ${realFn.name || "minified implementation"}`);
167167
}
168168
}
169169

src/mono/wasm/runtime/startup.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import WasmEnableLegacyJsInterop from "consts:wasmEnableLegacyJsInterop";
66

77
import { DotnetModuleInternal, CharPtrNull } from "./types/internal";
88
import { linkerDisableLegacyJsInterop, ENVIRONMENT_IS_PTHREAD, ENVIRONMENT_IS_NODE, exportedRuntimeAPI, INTERNAL, loaderHelpers, Module, runtimeHelpers, createPromiseController, mono_assert, linkerWasmEnableSIMD, linkerWasmEnableEH, ENVIRONMENT_IS_WORKER } from "./globals";
9-
import cwraps, { init_c_exports } from "./cwraps";
9+
import cwraps, { init_c_exports, threads_c_functions as tcwraps } from "./cwraps";
1010
import { mono_wasm_raise_debug_event, mono_wasm_runtime_ready } from "./debug";
1111
import { toBase64StringImpl } from "./base64";
1212
import { mono_wasm_init_aot_profiler, mono_wasm_init_browser_profiler } from "./profiler";
@@ -334,6 +334,8 @@ async function postRunAsync(userpostRun: (() => void)[]) {
334334
Module["FS_createPath"]("/", "usr", true, true);
335335
Module["FS_createPath"]("/", "usr/share", true, true);
336336

337+
if (MonoWasmThreads) tcwraps.mono_wasm_init_finalizer_thread();
338+
337339
// all user Module.postRun callbacks
338340
userpostRun.map(fn => fn());
339341
endMeasure(mark, MeasuredBlock.postRun);
@@ -561,7 +563,7 @@ async function mono_wasm_before_memory_snapshot() {
561563
endMeasure(mark, MeasuredBlock.memorySnapshot);
562564
}
563565

564-
async function maybeSaveInterpPgoTable () {
566+
async function maybeSaveInterpPgoTable() {
565567
// If the application exited abnormally, don't save the table. It probably doesn't contain useful data,
566568
// and saving would overwrite any existing table from a previous successful run.
567569
// We treat exiting with a code of 0 as equivalent to if the app is still running - it's perfectly fine

0 commit comments

Comments
 (0)