-
-
Notifications
You must be signed in to change notification settings - Fork 987
/
Copy pathWasmTests.cs
57 lines (53 loc) · 2.17 KB
/
WasmTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.IO;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Tests.Loggers;
using BenchmarkDotNet.Tests.XUnit;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Toolchains.MonoWasm;
using Xunit.Abstractions;
namespace BenchmarkDotNet.IntegrationTests
{
/// <summary>
/// In order to run WasmTests locally, the following prerequisites are required:
/// * Install wasm-tools workload: `BenchmarkDotNet/build.cmd install-wasm-tools`
/// * Install npm
/// * Install v8: `npm install jsvu -g && jsvu --os=default --engines=v8`
/// * Add `$HOME/.jsvu/bin` to PATH
/// * Run tests using .NET SDK from `BenchmarkDotNet/.dotnet/`
/// </summary>
public class WasmTests(ITestOutputHelper output) : BenchmarkTestExecutor(output)
{
[FactEnvSpecific("WASM is only supported on Unix", EnvRequirement.NonWindows)]
public void WasmIsSupported()
{
var dotnetVersion = "net8.0";
var logger = new OutputLogger(Output);
var netCoreAppSettings = new NetCoreAppSettings(dotnetVersion, null, "Wasm");
var mainJsPath = Path.Combine(AppContext.BaseDirectory, "AppBundle", "test-main.js");
var config = ManualConfig.CreateEmpty()
.AddLogger(logger)
.AddJob(Job.Dry
.WithArguments([new MsBuildArgument($"/p:WasmMainJSPath={mainJsPath}")])
.WithRuntime(new WasmRuntime(dotnetVersion, moniker: RuntimeMoniker.WasmNet80, javaScriptEngineArguments: "--expose_wasm --module"))
.WithToolchain(WasmToolchain.From(netCoreAppSettings)))
.WithOption(ConfigOptions.GenerateMSBuildBinLog, true);
CanExecute<WasmBenchmark>(config);
}
public class WasmBenchmark
{
[Benchmark]
public void Check()
{
if (!RuntimeInformation.IsWasm)
{
throw new Exception("Incorrect runtime detection");
}
}
}
}
}