Skip to content

Commit 4435799

Browse files
caaavik-msftadamsitniktimcassell
authored
Add Integration Test for WASM (#2532)
* Write failing wasm test * Use local dotnet installation to install workload * Add v8 to path * Add wasm-tools workload installation to build project, thanks @ilonatommy --------- Co-authored-by: Adam Sitnik <[email protected]> Co-authored-by: Tim Cassell <[email protected]>
1 parent f17d40e commit 4435799

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed

.github/workflows/run-tests.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ jobs:
6262
platform: x64
6363
- name: Set up zlib-static
6464
run: sudo apt-get install -y libkrb5-dev
65+
- name: Set up node
66+
uses: actions/setup-node@v4
67+
with:
68+
node-version: "20"
69+
- name: Set up v8
70+
run: npm install jsvu -g && jsvu --os=linux64 --engines=v8 && echo "$HOME/.jsvu/bin" >> $GITHUB_PATH
71+
- name: Install wasm-tools workload
72+
run: ./build.cmd install-wasm-tools
6573
- name: Run task 'build'
6674
run: ./build.cmd build
6775
- name: Run task 'unit-tests'
@@ -79,6 +87,14 @@ jobs:
7987
runs-on: macos-13
8088
steps:
8189
- uses: actions/checkout@v3
90+
- name: Set up node
91+
uses: actions/setup-node@v4
92+
with:
93+
node-version: "20"
94+
- name: Set up v8
95+
run: npm install jsvu -g && jsvu --os=mac64 --engines=v8 && echo "$HOME/.jsvu/bin" >> $GITHUB_PATH
96+
- name: Install wasm-tools workload
97+
run: ./build.cmd install-wasm-tools
8298
- name: Run task 'build'
8399
run: ./build.cmd build
84100
- name: Run task 'unit-tests'

build/BenchmarkDotNet.Build/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ public HelpInfo GetHelp()
5656
}
5757
}
5858

59+
[TaskName(Name)]
60+
[TaskDescription("Install wasm-tools workload")]
61+
public class InstallWasmToolsWorkload : FrostingTask<BuildContext>, IHelpProvider
62+
{
63+
private const string Name = "install-wasm-tools";
64+
65+
public override void Run(BuildContext context) => context.BuildRunner.InstallWorkload("wasm-tools");
66+
67+
public HelpInfo GetHelp()
68+
{
69+
return new HelpInfo
70+
{
71+
Examples = new[]
72+
{
73+
new Example(Name)
74+
}
75+
};
76+
}
77+
}
78+
5979
[TaskName(Name)]
6080
[TaskDescription("Run unit tests (fast)")]
6181
[IsDependentOn(typeof(BuildTask))]

build/BenchmarkDotNet.Build/Runners/BuildRunner.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Cake.Common.Tools.DotNet.Build;
66
using Cake.Common.Tools.DotNet.Pack;
77
using Cake.Common.Tools.DotNet.Restore;
8+
using Cake.Common.Tools.DotNet.Workload.Install;
89
using Cake.Core;
910
using Cake.Core.IO;
1011

@@ -28,6 +29,16 @@ public void Restore()
2829
});
2930
}
3031

32+
public void InstallWorkload(string workloadId)
33+
{
34+
context.DotNetWorkloadInstall(workloadId,
35+
new DotNetWorkloadInstallSettings
36+
{
37+
IncludePreviews = true,
38+
NoCache = true
39+
});
40+
}
41+
3142
public void Build()
3243
{
3344
context.Information("BuildSystemProvider: " + context.BuildSystem().Provider);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
import { dotnet } from './_framework/dotnet.js'
5+
6+
await dotnet
7+
.withDiagnosticTracing(false)
8+
.withApplicationArguments(...arguments)
9+
.run()

tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
</ItemGroup>
5757
<ItemGroup>
5858
<None Include="App.config" />
59+
<None Include="AppBundle\**" CopyToOutputDirectory="Always" />
5960
</ItemGroup>
6061
<ItemGroup>
6162
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.IO;
3+
using BenchmarkDotNet.Attributes;
4+
using BenchmarkDotNet.Configs;
5+
using BenchmarkDotNet.Environments;
6+
using BenchmarkDotNet.Jobs;
7+
using BenchmarkDotNet.Portability;
8+
using BenchmarkDotNet.Tests.Loggers;
9+
using BenchmarkDotNet.Tests.XUnit;
10+
using BenchmarkDotNet.Toolchains.DotNetCli;
11+
using BenchmarkDotNet.Toolchains.MonoWasm;
12+
using Xunit.Abstractions;
13+
14+
namespace BenchmarkDotNet.IntegrationTests
15+
{
16+
public class WasmTests : BenchmarkTestExecutor
17+
{
18+
public WasmTests(ITestOutputHelper output) : base(output) { }
19+
20+
[FactEnvSpecific("WASM is only supported on Unix", EnvRequirement.NonWindows)]
21+
public void WasmIsSupported()
22+
{
23+
var dotnetVersion = "net8.0";
24+
var logger = new OutputLogger(Output);
25+
var netCoreAppSettings = new NetCoreAppSettings(dotnetVersion, null, "Wasm");
26+
var mainJsPath = Path.Combine(AppContext.BaseDirectory, "AppBundle", "test-main.js");
27+
28+
var config = ManualConfig.CreateEmpty()
29+
.AddLogger(logger)
30+
.AddJob(Job.Dry
31+
.WithArguments([new MsBuildArgument($"/p:WasmMainJSPath={mainJsPath}")])
32+
.WithRuntime(new WasmRuntime(dotnetVersion, moniker: RuntimeMoniker.WasmNet80, javaScriptEngineArguments: "--expose_wasm --module"))
33+
.WithToolchain(WasmToolchain.From(netCoreAppSettings)))
34+
.WithOption(ConfigOptions.GenerateMSBuildBinLog, true);
35+
36+
CanExecute<WasmBenchmark>(config);
37+
}
38+
39+
public class WasmBenchmark
40+
{
41+
[Benchmark]
42+
public void Check()
43+
{
44+
if (!RuntimeInformation.IsWasm)
45+
{
46+
throw new Exception("Incorrect runtime detection");
47+
}
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)