diff options
author | Ankit Jain <radical@gmail.com> | 2022-05-25 23:23:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-25 23:23:57 +0300 |
commit | 6b3ea401ca20c26dbb5497b0fbbf77b3afc73374 (patch) | |
tree | e6ef7e7144028b686e43d1dda9e41aac8d42cf6c /eng/testing | |
parent | 637f8f241146e467d6a603394d63ff716838c0c6 (diff) |
[wasm] First attempt at a wasm app host (#68696)
First attempt at implementing a wasm app host
Regular dotnet apps can be run with `dotnet run`. But this is not the case for
wasm apps. We use `xharness` to run the test apps that we generate for library
tests.
Templates for browser, and console wasm projects were added recently, but they
have to be run manually by either invoking a v8 script, or running a
`http-server` in the bundle directory. Though to use a debugger with this
requires starting the debug proxy separately, and connecting few bits.
# WasmAppHost
This PR adds a new `WasmAppHost`, which can be used through `dotnet run`:
- it can run "wasm app" from it's `AppBundle` directory, using various hosts
like `v8`, `node`, or a browser. An example use:
```
$ dotnet new wasmconsole
$ dotnet run
WasmAppHost --runtime-config /tmp/c0/bin/Debug/net7.0/browser-wasm/AppBundle//c0.runtimeconfig.json
[02:26:40] info: host[0] Running: node main.cjs
[02:26:40] dbug: host[0] Using working directory: /tmp/c0/bin/Debug/net7.0/browser-wasm/AppBundle
Incoming arguments:
Application arguments:
Debugger.Debug: DEBUGGING ENABLED
mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
Could not find symbols file dotnet.js.symbols. Ignoring.
Initializing.....
Hello, Console!
```
The console template project is run with `node` by default.
- it supports a `--debug` parameter, which (for the browser case) would startup
a webserver, and the debug proxy for Chrome, and firefox.
```
$ dotnet new wasmbrowser
$ dotnet run --debug
WasmAppHost --runtime-config /workspaces/test/br0/bin/Debug/net7.0/browser-wasm/AppBundle//br0.runtimeconfig.json --debug --forward-console
Debug proxy for chrome now listening on http://127.0.0.1:9300/. And expecting chrome at http://localhost:9222/
Hosting environment: Production
Content root path: /workspaces/test/br0/bin/Debug/net7.0/browser-wasm/AppBundle
Now listening on: http://127.0.0.1:9300
Debug proxy for firefox now listening on tcp://127.0.0.1:6300. And expecting firefox at port 6000 .
App url: http://127.0.0.1:9000/index.html
App url: https://127.0.0.1:38331/index.html
```
- This enables using `dotnet run` with wasm samples, and library tests too.
## How do I try this out?
You'll need a dotnet with the updated packs. For now, you can use:
```
$ ./dotnet.sh build -p:TargetOS=Browser -p:TargetArchitecture=wasm -p:Configuration=Release src/tests/BuildWasmApps/Wasm.Build.Tests/Wasm.Build.Tests.csproj /t:InstallWorkloadUsingArtifacts
```
.. which would install a sdk in `artifacts/bin/dotnet-workload` with all the packs installed.
- Use that dotnet to create console, or browser wasm apps from templates, for example `dotnet new wasmconsole`, or `dotnet new wasmbrowser`.
### Debugging library tests
```
runtime$ ./artifacts/bin/dotnet-workload/dotnet run -f net7.0 -r browser-wasm -c $YourRuntimeConfig --project src/libraries/System.Buffers/tests/System.Buffers.Tests.csproj -p:DebuggerSupport=true --debug --host browser
```
- If the runtime was built in `Release` config, then you need to add `-p:DebuggerSupport=true`, so the pdbs would get deployed
- And use `--debug` to start the debugger
- Opening the url will show a `Run tests` button, which you can click after connecting with the IDE, to start running the tests
## Notes, and TODO
- `WasmAppHost`, along with the debug proxy are bundled in the `WebAssembly.Sdk` pack right now.
- This might be changed in the future to use the dotnet app host pack pattern, and with
additional support adding in the Sdk.
- This would also allow using `launchSettings.json`, similar to blazor
- `WasmAppHost` depends on host config in `runtimeconfig.json`, which can be
controlled by a `runtimeconfig.template.json` in the project directory.
- Needs more tests, cleanup, `--help` for command line arguments
- `app-support.*js` in templates, and `test-main.js` need more work to share the code
Fixes https://github.com/dotnet/runtime/issues/67236
Diffstat (limited to 'eng/testing')
-rw-r--r-- | eng/testing/tests.wasm.targets | 24 | ||||
-rw-r--r-- | eng/testing/xunit/xunit.targets | 4 |
2 files changed, 18 insertions, 10 deletions
diff --git a/eng/testing/tests.wasm.targets b/eng/testing/tests.wasm.targets index 0981950df46..f4a2c8beea2 100644 --- a/eng/testing/tests.wasm.targets +++ b/eng/testing/tests.wasm.targets @@ -55,15 +55,8 @@ <SetScriptCommands Condition="'$(JSEngineArgs)' != ''" Include="set "JS_ENGINE_ARGS=$(JSEngineArgs)"" /> <SetScriptCommands Condition="'$(_WasmMainJSFileName)' != ''" Include="set "MAIN_JS=--js-file^=$(_WasmMainJSFileName)"" /> </ItemGroup> - <PropertyGroup Condition="'$(RunScriptCommand)' == ''"> - <_XHarnessArgs Condition="'$(OS)' != 'Windows_NT'">wasm $XHARNESS_COMMAND --app=. --output-directory=$XHARNESS_OUT</_XHarnessArgs> - <_XHarnessArgs Condition="'$(OS)' == 'Windows_NT'">wasm %XHARNESS_COMMAND% --app=. --output-directory=%XHARNESS_OUT%</_XHarnessArgs> - - <_XHarnessArgs Condition="'$(IsFunctionalTest)' == 'true'" >$(_XHarnessArgs) --expected-exit-code=$(ExpectedExitCode)</_XHarnessArgs> - <_XHarnessArgs Condition="'$(WasmXHarnessArgs)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgs)</_XHarnessArgs> - <_XHarnessArgs >$(_XHarnessArgs) -s dotnet.js.symbols</_XHarnessArgs> - <_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli)</_XHarnessArgs> + <PropertyGroup> <_AppArgs Condition="'$(IsFunctionalTest)' != 'true' and '$(Scenario)' != 'BuildWasmApps' and '$(WasmMainAssemblyFileName)' == ''">--run WasmTestRunner.dll $(AssemblyName).dll</_AppArgs> <_AppArgs Condition="'$(IsFunctionalTest)' != 'true' and '$(WasmMainAssemblyFileName)' != ''">--run $(WasmMainAssemblyFileName)</_AppArgs> <_AppArgs Condition="'$(IsFunctionalTest)' == 'true'">--run $(AssemblyName).dll</_AppArgs> @@ -71,6 +64,16 @@ <_AppArgs Condition="'$(WasmTestAppArgs)' != ''">$(_AppArgs) $(WasmTestAppArgs)</_AppArgs> <WasmXHarnessMonoArgs Condition="'$(XunitShowProgress)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=XHARNESS_LOG_TEST_START=1</WasmXHarnessMonoArgs> + </PropertyGroup> + + <PropertyGroup Condition="'$(RunScriptCommand)' == ''"> + <_XHarnessArgs Condition="'$(OS)' != 'Windows_NT'">wasm $XHARNESS_COMMAND --app=. --output-directory=$XHARNESS_OUT</_XHarnessArgs> + <_XHarnessArgs Condition="'$(OS)' == 'Windows_NT'">wasm %XHARNESS_COMMAND% --app=. --output-directory=%XHARNESS_OUT%</_XHarnessArgs> + + <_XHarnessArgs Condition="'$(IsFunctionalTest)' == 'true'" >$(_XHarnessArgs) --expected-exit-code=$(ExpectedExitCode)</_XHarnessArgs> + <_XHarnessArgs Condition="'$(WasmXHarnessArgs)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgs)</_XHarnessArgs> + <_XHarnessArgs >$(_XHarnessArgs) -s dotnet.js.symbols</_XHarnessArgs> + <_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli)</_XHarnessArgs> <!-- There two flavors of WasmXHarnessArgs and WasmXHarnessMonoArgs, one is MSBuild property and the other is environment variable --> <RunScriptCommand Condition="'$(OS)' != 'Windows_NT'">$HARNESS_RUNNER $(_XHarnessArgs) %24XHARNESS_ARGS %24WasmXHarnessArgs -- $(WasmXHarnessMonoArgs) %24WasmXHarnessMonoArgs $(_AppArgs) %24WasmTestAppArgs</RunScriptCommand> @@ -102,6 +105,11 @@ <PropertyGroup> <BundleTestWasmAppDependsOn Condition="'$(BuildAOTTestsOn)' == 'local'">WasmTriggerPublishApp</BundleTestWasmAppDependsOn> <BundleTestWasmAppDependsOn Condition="'$(BuildAOTTestsOnHelix)' == 'true'">$(BundleTestWasmAppDependsOn);_BundleAOTTestWasmAppForHelix</BundleTestWasmAppDependsOn> + + <RunCommand>$(WasmAppHostDir)/WasmAppHost</RunCommand> + <!-- Use BundleDir here, since WasmAppDir is set in a target, and `dotnet run` reads + $(Run*) without running any targets --> + <RunArguments>--runtime-config $(BundleDir)/WasmTestRunner.runtimeconfig.json $(WasmHostArguments) $(StartArguments) $(WasmXHarnessMonoArgs) $(_AppArgs)</RunArguments> </PropertyGroup> <PropertyGroup Condition="'$(BuildAOTTestsOnHelix)' == 'true'"> diff --git a/eng/testing/xunit/xunit.targets b/eng/testing/xunit/xunit.targets index 8a950eb58ef..6b048e6f6a9 100644 --- a/eng/testing/xunit/xunit.targets +++ b/eng/testing/xunit/xunit.targets @@ -8,10 +8,10 @@ <!-- Run target (F5) support. --> <PropertyGroup> - <RunWorkingDirectory>$(OutDir)</RunWorkingDirectory> + <RunWorkingDirectory Condition="'$(RunWorkingDirectory)' == ''">$(OutDir)</RunWorkingDirectory> </PropertyGroup> - <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'"> + <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(RunCommand)' == ''"> <RunCommand>$(DotNetTool)</RunCommand> <RunArguments>test $(TargetPath) --settings $(OutDir).runsettings</RunArguments> </PropertyGroup> |