Skip to content

Commit bccbf2e

Browse files
authored
[browser] Use standard xunit test runner on multithreaded runtime (#91317)
1 parent 9636262 commit bccbf2e

File tree

14 files changed

+73
-33
lines changed

14 files changed

+73
-33
lines changed

eng/testing/tests.browser.targets

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<WasmTestAppArgs Condition="'$(_XUnitBackgroundExec)' == 'true'">$(WasmTestAppArgs) -backgroundExec</WasmTestAppArgs>
9292
<_AppArgs Condition="'$(WasmTestAppArgs)' != ''">$(_AppArgs) $(WasmTestAppArgs)</_AppArgs>
9393

94-
<WasmXHarnessMonoArgs Condition="'$(XunitShowProgress)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=XHARNESS_LOG_TEST_START=1</WasmXHarnessMonoArgs>
94+
<WasmXHarnessMonoArgs Condition="'$(XunitShowProgress)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
9595
<!-- help unit test with PlatformDetection.IsThreadingSupported via IsBrowserThreadingSupported env variable -->
9696
<WasmXHarnessMonoArgs Condition="'$(WasmEnableThreads)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=IsBrowserThreadingSupported=true</WasmXHarnessMonoArgs>
9797
</PropertyGroup>
@@ -108,9 +108,11 @@
108108
<_XHarnessArgs Condition="'$(_UseWasmSymbolicator)' == 'true'" >$(_XHarnessArgs) --symbolicator WasmSymbolicator.dll,Microsoft.WebAssembly.Internal.SymbolicatorWrapperForXHarness</_XHarnessArgs>
109109
<_XHarnessArgs Condition="'$(_WasmBrowserPathForTests)' != ''" >$(_XHarnessArgs) &quot;--browser-path=$(_WasmBrowserPathForTests)&quot;</_XHarnessArgs>
110110
<_XHarnessArgs Condition="'$(WasmXHarnessTestsTimeout)' != ''" >$(_XHarnessArgs) &quot;--timeout=$(WasmXHarnessTestsTimeout)&quot;</_XHarnessArgs>
111+
<_XHarnessArgs Condition="'$(WasmXHarnessVerbosity)' != ''" >$(_XHarnessArgs) --verbosity=$(WasmXHarnessVerbosity)</_XHarnessArgs><!-- Trace, Debug, Information (default), Warning, Error, Critical -->
111112
<_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli)</_XHarnessArgs>
112113

113-
<!-- There two flavors of WasmXHarnessArgs and WasmXHarnessMonoArgs, one is MSBuild property and the other is environment variable -->
114+
<_AppArgs Condition="'$(WasmEnableThreads)' == 'true'">$(_AppArgs) -threads</_AppArgs>
115+
<!-- There are two flavors of WasmXHarnessArgs and WasmXHarnessMonoArgs, one is MSBuild property and the other is environment variable -->
114116
<RunScriptCommand Condition="'$(OS)' != 'Windows_NT'">$HARNESS_RUNNER $(_XHarnessArgs) %24XHARNESS_ARGS %24WasmXHarnessArgs -- $(WasmXHarnessMonoArgs) %24WasmXHarnessMonoArgs $(_AppArgs) %24WasmTestAppArgs</RunScriptCommand>
115117
<RunScriptCommand Condition="'$(OS)' == 'Windows_NT'">%HARNESS_RUNNER% $(_XHarnessArgs) %XHARNESS_ARGS% %WasmXHarnessArgs% -- $(WasmXHarnessMonoArgs) %WasmXHarnessMonoArgs% $(_AppArgs) %WasmTestAppArgs%</RunScriptCommand>
116118
</PropertyGroup>
@@ -147,6 +149,12 @@
147149
<WasmNestedPublishAppDependsOn>PrepareForWasmBuildApp;$(WasmNestedPublishAppDependsOn)</WasmNestedPublishAppDependsOn>
148150
</PropertyGroup>
149151

152+
<Target Name="IncludeTestAssemblyInVFS" BeforeTargets="PrepareForWasmBuildApp">
153+
<ItemGroup>
154+
<WasmFilesToIncludeFromPublishDir Include="$(AssemblyName).dll" Exclude="@(WasmFilesToIncludeFromPublishDir)" />
155+
</ItemGroup>
156+
</Target>
157+
150158
<Target Name="PrepareForWasmBuildApp">
151159
<PropertyGroup>
152160
<WasmAppDir>$(BundleDir)</WasmAppDir>
@@ -197,7 +205,7 @@
197205
<!-- Include files specified by test projects from publish dir -->
198206
<WasmFilesToIncludeInFileSystem
199207
Include="$(PublishDir)%(WasmFilesToIncludeFromPublishDir.Identity)"
200-
TargetPath="%(WasmFilesToIncludeFromPublishDir.Identity)"
208+
TargetPath="%(WasmFilesToIncludeFromPublishDir.TargetDir)/%(WasmFilesToIncludeFromPublishDir.Identity)"
201209
Condition="'%(WasmFilesToIncludeFromPublishDir.Identity)' != ''" />
202210
</ItemGroup>
203211

eng/testing/tests.wasi.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<_AppArgs Condition="'$(WasmTestAppArgs)' != ''">$(_AppArgs) -- $(WasmTestAppArgs)</_AppArgs>
3232

3333
<!-- FIXME: wasttime specific param name -->
34-
<WasmXHarnessMonoArgs Condition="'$(XunitShowProgress)' == 'true'">$(WasmXHarnessMonoArgs) --env=XHARNESS_LOG_TEST_START=1</WasmXHarnessMonoArgs>
34+
<WasmXHarnessMonoArgs Condition="'$(XunitShowProgress)' == 'true'">$(WasmXHarnessMonoArgs) --env=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
3535
</PropertyGroup>
3636

3737
<PropertyGroup Condition="'$(RunScriptCommand)' == ''">
@@ -51,7 +51,7 @@
5151

5252
<_InvariantGlobalization Condition="'$(InvariantGlobalization)' == 'true'">--env=DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true</_InvariantGlobalization>
5353

54-
<!-- There two flavors of WasmXHarnessArgs and WasmXHarnessMonoArgs, one is MSBuild property and the other is environment variable -->
54+
<!-- There are two flavors of WasmXHarnessArgs and WasmXHarnessMonoArgs, one is MSBuild property and the other is environment variable -->
5555
<RunScriptCommand Condition="'$(OS)' != 'Windows_NT'">$HARNESS_RUNNER $(_XHarnessArgs) %24XHARNESS_ARGS %24WasmXHarnessArgs -- $(WasmXHarnessMonoArgs) %24WasmXHarnessMonoArgs $(_InvariantGlobalization) %24_InvariantGlobalization $(_AppArgs) %24WasmTestAppArgs</RunScriptCommand>
5656
<RunScriptCommand Condition="'$(OS)' == 'Windows_NT'">%HARNESS_RUNNER% $(_XHarnessArgs) %XHARNESS_ARGS% %WasmXHarnessArgs% -- $(WasmXHarnessMonoArgs) %WasmXHarnessMonoArgs% $(_InvariantGlobalization) %_InvariantGlobalization% $(_AppArgs) %WasmTestAppArgs%</RunScriptCommand>
5757
</PropertyGroup>

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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,56 @@
55
using System.Collections.Generic;
66
using System.Threading.Tasks;
77
using Microsoft.DotNet.XHarness.TestRunners.Common;
8-
98
using Microsoft.DotNet.XHarness.TestRunners.Xunit;
109

11-
public class SimpleWasmTestRunner : WasmApplicationEntryPoint
10+
public class WasmTestRunner : WasmApplicationEntryPoint
1211
{
12+
// TODO: Set max threads for run in parallel
13+
// protected override int? MaxParallelThreads => RunInParallel ? 8 : base.MaxParallelThreads;
14+
1315
public static async Task<int> Main(string[] args)
1416
{
1517
if (args.Length == 0)
1618
{
17-
Console.WriteLine ($"No args given");
19+
Console.WriteLine($"No args given");
1820
return -1;
1921
}
2022

21-
var testAssembly = args[0];
23+
var runner = new WasmTestRunner();
24+
25+
runner.TestAssembly = args[0];
26+
2227
var excludedTraits = new List<string>();
2328
var includedTraits = new List<string>();
2429
var includedNamespaces = new List<string>();
2530
var includedClasses = new List<string>();
2631
var includedMethods = new List<string>();
2732
var backgroundExec = false;
2833
var untilFailed = false;
29-
var minimumLogLevel = MinimumLogLevel.Info;
3034

3135
for (int i = 1; i < args.Length; i++)
3236
{
3337
var option = args[i];
3438
switch (option)
3539
{
3640
case "-notrait":
37-
excludedTraits.Add (args[i + 1]);
41+
excludedTraits.Add(args[i + 1]);
3842
i++;
3943
break;
4044
case "-trait":
41-
includedTraits.Add (args[i + 1]);
45+
includedTraits.Add(args[i + 1]);
4246
i++;
4347
break;
4448
case "-namespace":
45-
includedNamespaces.Add (args[i + 1]);
49+
includedNamespaces.Add(args[i + 1]);
4650
i++;
4751
break;
4852
case "-class":
49-
includedClasses.Add (args[i + 1]);
53+
includedClasses.Add(args[i + 1]);
5054
i++;
5155
break;
5256
case "-method":
53-
includedMethods.Add (args[i + 1]);
57+
includedMethods.Add(args[i + 1]);
5458
i++;
5559
break;
5660
case "-backgroundExec":
@@ -59,25 +63,26 @@ public static async Task<int> Main(string[] args)
5963
case "-untilFailed":
6064
untilFailed = true;
6165
break;
66+
case "-threads":
67+
runner.IsThreadless = false;
68+
// TODO: Enable run in parallel
69+
// runner.RunInParallel = true;
70+
// Console.WriteLine($"Running in parallel with {runner.MaxParallelThreads} threads.");
71+
break;
6272
case "-verbosity":
63-
minimumLogLevel = Enum.Parse<MinimumLogLevel>(args[i + 1]);
73+
runner.MinimumLogLevel = Enum.Parse<MinimumLogLevel>(args[i + 1]);
6474
i++;
6575
break;
6676
default:
6777
throw new ArgumentException($"Invalid argument '{option}'.");
6878
}
6979
}
7080

71-
var runner = new SimpleWasmTestRunner()
72-
{
73-
TestAssembly = testAssembly,
74-
ExcludedTraits = excludedTraits,
75-
IncludedTraits = includedTraits,
76-
IncludedNamespaces = includedNamespaces,
77-
IncludedClasses = includedClasses,
78-
IncludedMethods = includedMethods,
79-
MinimumLogLevel = minimumLogLevel
80-
};
81+
runner.ExcludedTraits = excludedTraits;
82+
runner.IncludedTraits = includedTraits;
83+
runner.IncludedNamespaces = includedNamespaces;
84+
runner.IncludedClasses = includedClasses;
85+
runner.IncludedMethods = includedMethods;
8186

8287
if (OperatingSystem.IsBrowser())
8388
{

src/libraries/System.Collections.Immutable/tests/System.Collections.Immutable.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<PropertyGroup Condition="'$(TargetOS)' == 'browser'">
9-
<WasmXHarnessMonoArgs>--setenv=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
9+
<XunitShowProgress>true</XunitShowProgress>
1010
<!-- This WASM test is problematic and slow right now. This sets the xharness timeout but there is also override in sendtohelix-browser.targets -->
1111
<WasmXHarnessTestsTimeout>01:15:00</WasmXHarnessTestsTimeout>
1212
</PropertyGroup>

src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<TestArchiveTestsRoot>$(TestArchiveRoot)browserornodejs/</TestArchiveTestsRoot>
2525
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
2626
<DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants>
27-
<WasmXHarnessMonoArgs>--setenv=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
27+
<XunitShowProgress>true</XunitShowProgress>
2828
<!-- This WASM test is problematic and slow right now. This sets the xharness timeout but there is also override in sendtohelix-browser.targets -->
2929
<WasmXHarnessTestsTimeout>01:15:00</WasmXHarnessTestsTimeout>
3030
</PropertyGroup>

src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<TestArchiveTestsRoot>$(TestArchiveRoot)browserornodejs/</TestArchiveTestsRoot>
1414
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
1515
<DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants>
16-
<WasmXHarnessMonoArgs>--setenv=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
16+
<XunitShowProgress>true</XunitShowProgress>
1717

1818
<!-- This WASM test is problematic and slow right now. This sets the xharness timeout but there is also override in sendtohelix-browser.targets -->
1919
<WasmXHarnessTestsTimeout>01:15:00</WasmXHarnessTestsTimeout>

src/libraries/System.Private.Xml/tests/System.Private.Xml.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<TestArchiveTestsRoot>$(TestArchiveRoot)browserornodejs/</TestArchiveTestsRoot>
1515
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
1616
<DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants>
17-
<WasmXHarnessMonoArgs>--setenv=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
17+
<XunitShowProgress>true</XunitShowProgress>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<!-- Use following lines to write the generated files to disk. -->
1414
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
1515
<!-- to see timing and which test aborted the runtime -->
16-
<WasmXHarnessMonoArgs>$(WasmXHarnessMonoArgs) --setenv=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
16+
<XunitShowProgress>true</XunitShowProgress>
1717
</PropertyGroup>
1818
<!-- Make debugging easier -->
1919
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">

src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
<WasmXHarnessMonoArgs>--working-dir=/test-dir</WasmXHarnessMonoArgs>
99
</PropertyGroup>
10+
<ItemGroup Condition="'$(TargetOS)' == 'browser'">
11+
<WasmFilesToIncludeFromPublishDir Include="$(AssemblyName).dll" TargetDir="test-dir" />
12+
</ItemGroup>
1013
<ItemGroup>
1114
<Compile Include="DisabledFileLockingSwitchTests.cs" />
1215
<Compile Include="..\FSAssert.cs" />

src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/System.IO.FileSystem.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
<WasmXHarnessMonoArgs>--working-dir=/test-dir</WasmXHarnessMonoArgs>
88
</PropertyGroup>
9+
<ItemGroup Condition="'$(TargetOS)' == 'browser'">
10+
<WasmFilesToIncludeFromPublishDir Include="$(AssemblyName).dll" TargetDir="test-dir" />
11+
</ItemGroup>
912
<ItemGroup>
1013
<Compile Include="Base\BaseGetSetAttributes.cs" />
1114
<Compile Include="Base\BaseGetSetTimes.cs" />

0 commit comments

Comments
 (0)