Skip to content

Commit

Permalink
[wasm] Add tests for build with SIMD disabled (#82845)
Browse files Browse the repository at this point in the history
* [wasm] Add tests for build with SIMD disabled

Add BuildWithoutSIMD_AOT and PublishWithoutSIMD_AOT tests

Also try to enable SIMD tests on V8 and node

* The BuildWithoutSIMD_AOT should be without AOT

* Feedback

* Removed too much

* Negate the assert, it should not relink

* Update src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs

Co-authored-by: Ankit Jain <radical@gmail.com>

---------

Co-authored-by: Ankit Jain <radical@gmail.com>
  • Loading branch information
radekdoulik and radical authored Mar 8, 2023
1 parent 14123c9 commit 633dcab
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,28 @@ public BuildTestBase(ITestOutputHelper output, SharedBuildPerTestClassFixture bu
- aot but no wrapper - check that AppBundle wasn't generated
*/

public static IEnumerable<IEnumerable<object?>> ConfigWithAOTData(bool aot, string? config=null)
public static IEnumerable<IEnumerable<object?>> ConfigWithAOTData(bool aot, string? config=null, string? extraArgs=null)
{
if (extraArgs == null)
extraArgs = string.Empty;

if (config == null)
{
return new IEnumerable<object?>[]
{
#if TEST_DEBUG_CONFIG_ALSO
// list of each member data - for Debug+@aot
new object?[] { new BuildArgs("placeholder", "Debug", aot, "placeholder", string.Empty) }.AsEnumerable(),
new object?[] { new BuildArgs("placeholder", "Debug", aot, "placeholder", extraArgs) }.AsEnumerable(),
#endif
// list of each member data - for Release+@aot
new object?[] { new BuildArgs("placeholder", "Release", aot, "placeholder", string.Empty) }.AsEnumerable()
new object?[] { new BuildArgs("placeholder", "Release", aot, "placeholder", extraArgs) }.AsEnumerable()
}.AsEnumerable();
}
else
{
return new IEnumerable<object?>[]
{
new object?[] { new BuildArgs("placeholder", config, aot, "placeholder", string.Empty) }.AsEnumerable()
new object?[] { new BuildArgs("placeholder", config, aot, "placeholder", extraArgs) }.AsEnumerable()
};
}
}
Expand Down
51 changes: 38 additions & 13 deletions src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.IO;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -16,13 +17,19 @@ public WasmSIMDTests(ITestOutputHelper output, SharedBuildPerTestClassFixture bu
{
}

public static IEnumerable<object?[]> MainMethodSimdTestData(bool aot, RunHost host, bool simd)
=> ConfigWithAOTData(aot, extraArgs: $"-p:WasmEnableSIMD={simd}")
.WithRunHosts(host)
.UnwrapItemsAsArrays();

[Theory]
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ false, RunHost.All })]
public void BuildWithSIMD_NoAOT_ShouldNotRelink(BuildArgs buildArgs, RunHost host, string id)
[MemberData(nameof(MainMethodSimdTestData), parameters: new object[] { /*aot*/ false, RunHost.All, true /* simd */ })]
[MemberData(nameof(MainMethodSimdTestData), parameters: new object[] { /*aot*/ false, RunHost.All, false /* simd */ })]
public void Build_NoAOT_ShouldNotRelink(BuildArgs buildArgs, RunHost host, string id)
{
string projectName = $"sim_with_workload_no_aot";
string projectName = $"build_with_workload_no_aot";
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs, "<WasmEnableSIMD>true</WasmEnableSIMD>");
buildArgs = ExpandBuildArgs(buildArgs);

(_, string output) = BuildProject(buildArgs,
id: id,
Expand All @@ -31,11 +38,8 @@ public void BuildWithSIMD_NoAOT_ShouldNotRelink(BuildArgs buildArgs, RunHost hos
Publish: false,
DotnetWasmFromRuntimePack: true));

if (!_buildContext.TryGetBuildFor(buildArgs, out _))
{
// Check if this is not a cached build
Assert.Contains("Compiling native assets with excc", output);
}
// Confirm that we didn't relink
Assert.DoesNotContain("Compiling native assets with emcc", output);

RunAndTestWasmApp(buildArgs,
extraXHarnessArgs: host == RunHost.NodeJS ? "--engine-arg=--experimental-wasm-simd" : "",
Expand All @@ -48,13 +52,11 @@ public void BuildWithSIMD_NoAOT_ShouldNotRelink(BuildArgs buildArgs, RunHost hos
}

[Theory]
// https://github.com/dotnet/runtime/issues/75044 - disabled for V8, and NodeJS
//[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ true, RunHost.All })]
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ true, RunHost.Chrome })]
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ true, RunHost.All })]
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ false, RunHost.All })]
public void PublishWithSIMD_AOT(BuildArgs buildArgs, RunHost host, string id)
{
string projectName = $"sim_with_workload_aot";
string projectName = $"simd_with_workload_aot";
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs, "<WasmEnableSIMD>true</WasmEnableSIMD>");

Expand All @@ -74,6 +76,29 @@ public void PublishWithSIMD_AOT(BuildArgs buildArgs, RunHost host, string id)
}, host: host, id: id);
}

[Theory]
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ true, RunHost.All })]
public void PublishWithoutSIMD_AOT(BuildArgs buildArgs, RunHost host, string id)
{
string projectName = $"nosimd_with_workload_aot";
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs, "<WasmEnableSIMD>false</WasmEnableSIMD>");

BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_simdProgramText),
DotnetWasmFromRuntimePack: false));

RunAndTestWasmApp(buildArgs,
expectedExitCode: 42,
test: output =>
{
Assert.Contains("<-2094756296, -2094756296, -2094756296, -2094756296>", output);
Assert.Contains("Hello, World!", output);
}, host: host, id: id);
}

[Theory, TestCategory("no-workload")]
[InlineData("Debug", /*aot*/true, /*publish*/true)]
[InlineData("Debug", /*aot*/false, /*publish*/false)]
Expand Down

0 comments on commit 633dcab

Please sign in to comment.