- Notifications
You must be signed in to change notification settings - Fork5.3k
[browser][coreCLR] running main/exit/abort/logging and infra for unit testing#122646
[browser][coreCLR] running main/exit/abort/logging and infra for unit testing#122646pavelsavara merged 14 commits intodotnet:mainfrom
Conversation
6b91c6a to3a18853CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull request overview
This PR adds comprehensive exit/abort/logging infrastructure for unit testing in browser/CoreCLR environments, enabling better diagnostics and test harness integration.
Key Changes:
- Introduces new test instrumentation via
dotnet.diagnostics.jsmodule with exit handlers, console forwarding, and symbolication skeleton - Breaking API change:
dotnet.run()now keeps the runtime alive; newdotnet.runAndExit()method exits runtime after Main() completes - Adds internal MSBuild properties (
WasmTestSupport,WasmTestExitOnUnhandledError, etc.) to control test behavior and diagnostics deployment
Reviewed changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs | Adds five new boolean properties for test instrumentation flags, gated by version 11.0+ |
| src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs | Defines the five new test instrumentation properties in boot config JSON schema |
| src/native/libs/System.Native.Browser/utils/index.ts | Replacesexit export withabortTimers andabortPosix for better separation of concerns |
| src/native/libs/System.Native.Browser/utils/host.ts | Removes oldexit() function, addsabortTimers() andabortPosix() for cleanup |
| src/native/libs/System.Native.Browser/native/cross-linked.ts | Declares globalABORT andEXITSTATUS variables for emscripten integration |
| src/native/libs/System.Native.Browser/diagnostics/types.ts | New file defining types for marshaling, diagnostics exports, and measured blocks |
| src/native/libs/System.Native.Browser/diagnostics/symbolicate.ts | Skeleton implementation of stack trace symbolication (placeholder for future work) |
| src/native/libs/System.Native.Browser/diagnostics/per-module.ts | Re-exports common per-module definitions for diagnostics |
| src/native/libs/System.Native.Browser/diagnostics/index.ts | Main entry point for diagnostics module initialization |
| src/native/libs/System.Native.Browser/diagnostics/exit.ts | Implements exit handlers, unhandled error handlers, and exit code logging |
| src/native/libs/System.Native.Browser/diagnostics/cross-module.ts | Re-exports common cross-module definitions for diagnostics |
| src/native/libs/System.Native.Browser/diagnostics/console-proxy.ts | Implements console forwarding to WebSocket for test runners |
| src/native/libs/Common/JavaScript/types/public-api.ts | Updates API: removeswithConfigSrc() docs, addsrun() andrunAndExit() with clear behavior distinction |
| src/native/libs/Common/JavaScript/types/internal.ts | AddsDiagnosticsExportsTable to internal exchange, updates asset entry fields, addsOnExitListener type |
| src/native/libs/Common/JavaScript/types/exchange.ts | Adds diagnostics exports, exit lifecycle functions, and additional browser host exports |
| src/native/libs/Common/JavaScript/cross-module/index.ts | Integrates diagnostics exports into cross-module exchange system |
| src/native/libs/Common/JavaScript/CMakeLists.txt | Adds new diagnostics TypeScript source files to build |
| src/native/corehost/browserhost/loader/run.ts | Major refactoring: moves runtime creation logic here, addscreateRuntime() andabortStartup(), improvedinitializeCoreCLR() |
| src/native/corehost/browserhost/loader/lib-initializers.ts | Adds comment clarifying expected function names |
| src/native/corehost/browserhost/loader/index.ts | Registers exit handlers, adds exit-related exports, changes defaultruntimeId to undefined |
| src/native/corehost/browserhost/loader/host-builder.ts | Implements newrun() (keeps runtime alive) andrunAndExit() methods, exportsloadBootResourceCallback |
| src/native/corehost/browserhost/loader/exit.ts | Complete rewrite withruntimeState, exit listeners, Emscripten integration, proper exit/abort handling |
| src/native/corehost/browserhost/loader/dotnet.d.ts | Updates type definitions forrun() andrunAndExit() methods, removeswithConfigSrc() |
| src/native/corehost/browserhost/loader/config.ts | RenamesnetLoaderConfig toloaderConfig for consistency |
| src/native/corehost/browserhost/loader/bootstrap.ts | FixeslocateFile() to properly handle query strings for modules vs. assets |
| src/native/corehost/browserhost/loader/assets.ts | Moves runtime creation to run.ts, implements BlazorloadBootResourceCallback support, adds proper cache/integrity handling |
| src/native/corehost/browserhost/libBrowserHost.footer.js | HidesBrowserHost_InitializeCoreCLR andBrowserHost_ExecuteAssembly from Module exports |
| src/native/corehost/browserhost/host/index.ts | ExportsgetExitStatus andinitializeCoreCLR functions |
| src/native/corehost/browserhost/host/host.ts | ImplementsgetExitStatus(),initializeCoreCLR(), improves assembly probing with debug logging, refactorsrunMain() andrunMainAndExit() error handling |
| src/native/corehost/browserhost/host/cross-linked.ts | Declares_BrowserHost_InitializeCoreCLR,_BrowserHost_ExecuteAssembly, andExitStatus globals |
| src/native/corehost/browserhost/CMakeLists.txt | Removes specific functions from exported list, relying on generic export configuration |
| src/mono/wasm/testassets/WasmBrowserRunMainOnly/wwwroot/main.js | Simplifies to singlerunAndExit() call instead of manual error handling |
| src/mono/wasm/testassets/WasmBrowserRunMainOnly/WasmBrowserRunMainOnly.csproj | Enables all test instrumentation flags |
| src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs | EnablesWasmTestSupport for CoreCLR builds |
| src/mono/sample/wasm/Directory.Build.targets | Adds test support properties to nested build |
| src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | Wires up test instrumentation properties to boot config generation, conditionally includes diagnostics module |
| src/mono/browser/test-main.js | Changes defaultforwardConsole to only enable on Firefox (not for other browsers in debug mode) |
| eng/testing/tests.browser.targets | EnablesWasmTestSupport for CoreCLR library tests |
Uh oh!
There was an error while loading.Please reload this page.
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
javiercn left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good to me. Is it fair to assume that most of the testing is essentially existing tests continue to pass?
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
pavelsavara commentedDec 30, 2025
/ba-g unrelated failures |
3cacfdd intodotnet:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
dotnet.runMainAndExit()anddotnet.runMain()APIs. For Mono too.dotnet.run()to not callexit()and keep runtime alive, only for CoreCLRrunMain()<WasmTestSupport>true</WasmTestSupport>which deploysdotnet.diagnostics.jsdotnet.diagnostics.jsearly when available in the boot configdotnet.diagnostics.jssymbolicateStackTraceexitOnUnhandledErrorappendElementOnExitlogExitCodeasyncFlushOnExitforwardConsoleWasmTestExitOnUnhandledError,WasmTestAppendElementOnExit,WasmTestLogExitCode,WasmTestAsyncFlushOnExit,WasmTestForwardConsoleWasmTestSupportfor library tests and WBT-sEXIT_RUNTIME=1- this enables C++ global destructorsabortStartup(),abortTimers(),abortPosix()isExited(),isRuntimeRunning()LoadBootResourceCallbackfor BlazorModule.onConfigLoadedandModule.onDotnetReadyExitStatustypeabort()/exit()eventslocateFile- for query string propagationBrowserHost_InitializeCoreCLR,BrowserHost_ExecuteAssemblyfrom Module exportsFixes#101169
Fixes#75335
On top of#122616
On top of#122495