Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Stop testing with V8 and wasmconsole #108711

Merged
merged 16 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions eng/pipelines/common/templates/wasm-library-aot-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ jobs:
- ${{ if ne(parameters.scenarios[0], '') }}:
- ${{ parameters.scenarios }}
- ${{ else }}:
- ${{ if eq(platform, 'browser_wasm') }}:
- WasmTestOnV8
- ${{ if eq(platform, 'browser_wasm_win') }}:
- ${{ if or(eq(platform, 'browser_wasm'), eq(platform, 'browser_wasm_win')) }}:
- WasmTestOnChrome
- ${{ if or(eq(platform, 'wasi_wasm_win'), eq(platform, 'wasi_wasm')) }}:
- WasmTestOnWasmtime
2 changes: 1 addition & 1 deletion eng/pipelines/common/templates/wasm-library-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
isWasmOnlyBuild: false
nameSuffix: ''
platforms: []
scenarios: ['WasmTestOnV8']
scenarios: ['WasmTestOnChrome']
shouldContinueOnError: false
shouldRunSmokeOnly: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ jobs:
isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }}
isWasmOnlyBuild: ${{ parameters.isWasmOnlyBuild }}
scenarios:
- WasmTestOnV8
- WasmTestOnChrome

# EAT Library tests - only run on linux
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/libraries/outerloop-mono.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extends:
- template: /eng/pipelines/libraries/helix.yml
parameters:
scenarios:
- WasmTestOnV8
- WasmTestOnChrome
testScope: outerloop
creator: dotnet-bot
testRunNamePrefixSuffix: Mono_$(_BuildConfig)
1 change: 0 additions & 1 deletion eng/pipelines/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ extends:
alwaysRun: ${{ variables.isRollingBuild }}
extraBuildArgs: /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS)
scenarios:
- WasmTestOnV8
- WasmTestOnChrome
- WasmTestOnFirefox

Expand Down
3 changes: 1 addition & 2 deletions eng/testing/scenarios/BuildWasmAppsJobsList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ Wasm.Build.Tests.WasmSIMDTests
Wasm.Build.Tests.WasmTemplateTests
Wasm.Build.Tests.WorkloadTests
Wasm.Build.Tests.MT.Blazor.SimpleMultiThreadedTests
Wasm.Build.Tests.TestAppScenarios.WasmSdkDebugLevelTests
Wasm.Build.Tests.TestAppScenarios.WasmAppBuilderDebugLevelTests
Wasm.Build.Tests.DebugLevelTests
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.IO;
using Xunit.Abstractions;

#nullable enable
Expand All @@ -9,9 +10,9 @@ namespace Wasm.Build.Tests;

public class BlazorWasmProjectProvider : WasmSdkBasedProjectProvider
{
public BlazorWasmProjectProvider(ITestOutputHelper _testOutput, string? _projectDir = null)
: base(_testOutput, _projectDir)
{}
public BlazorWasmProjectProvider(ITestOutputHelper _testOutput, string defaultTargetFramework, string? _projectDir = null)
: base(_testOutput, defaultTargetFramework, _projectDir)
{ }

public void AssertBundle(BlazorBuildOptions options)
=> AssertBundle(new AssertWasmSdkBundleOptions(
Expand All @@ -28,4 +29,14 @@ public void AssertBundle(BlazorBuildOptions options)
AssertIcuAssets: true,
AssertSymbolsFile: false // FIXME: not supported yet
));

public override string FindBinFrameworkDir(string config, bool forPublish, string framework, string? projectDir = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to override it here? Blazor and Wasm SDK should behave the same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, originally I didn't notice they are the same, it can be left in WasmSdkBasedProjectProvider only.
Note for the future: once we will align BlazorBuildOptions and AssertWasmSdkBundleOptions then maybe we will even use WASM SDK provider in Blazor and drop BlazorWasmProjectProvider.

{
EnsureProjectDirIsSet();
string basePath = Path.Combine(projectDir ?? ProjectDir!, "bin", config, framework);
if (forPublish)
basePath = FindSubDirIgnoringCase(basePath, "publish");

return Path.Combine(basePath, BundleDirName, "_framework");
}
}
11 changes: 2 additions & 9 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@

namespace Wasm.Build.Tests;

public abstract class BlazorWasmTestBase : WasmTemplateTestBase
public abstract class BlazorWasmTestBase : WasmTemplateTestsBase
{
protected readonly BlazorWasmProjectProvider _provider;
protected BlazorWasmTestBase(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext, new BlazorWasmProjectProvider(output))
: base(output, buildContext, new BlazorWasmProjectProvider(output, DefaultTargetFrameworkForBlazor))
{
_provider = GetProvider<BlazorWasmProjectProvider>();
_provider.BundleDirName = "wwwroot";
}

public void InitBlazorWasmProjectDir(string id, string targetFramework = DefaultTargetFrameworkForBlazor)
Expand Down Expand Up @@ -250,10 +249,4 @@ void OnErrorMessage(string msg)

public string FindBlazorBinFrameworkDir(string config, bool forPublish, string framework = DefaultTargetFrameworkForBlazor, string? projectDir = null)
=> _provider.FindBinFrameworkDir(config: config, forPublish: forPublish, framework: framework, projectDir: projectDir);

public string FindBlazorHostedBinFrameworkDir(string config, bool forPublish, string clientDirRelativeToProjectDir, string framework = DefaultTargetFrameworkForBlazor)
{
string? clientProjectDir = _projectDir == null ? null : Path.Combine(_projectDir, clientDirRelativeToProjectDir);
return _provider.FindBinFrameworkDir(config: config, forPublish: forPublish, framework: framework, projectDir: clientProjectDir);
}
}
38 changes: 38 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/DebugLevelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Wasm.Build.Tests.TestAppScenarios;

#nullable enable

namespace Wasm.Build.Tests.Blazor;

public class DebugLevelTests : AppTestBase
{
public DebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should merge this one with Wasm.Build.Tests.DebugLevelTests and use "WasmBasicTestApp" for all of the tests.

  • Move it outside of Blazor namespace since it's not blazor specific

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not done because it would require more refactoring. In the feedback commit I moved them to one file and made them use WasBasicTestApp but it broke the base class, now it's DebugLevelTests : AppTestBase. Will be cleaned up better in a follow-up

: base(output, buildContext)
{
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public async Task PublishWithDefaultLevelAndPdbs(string configuration)
{
CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_PublishWithDefaultLevelAndPdbs_{configuration}", "App");
PublishProject(configuration, assertAppBundle: false, extraArgs: $"-p:CopyOutputSymbolsToPublishDirectory=true");

var result = await RunSdkStyleAppForBuild(new(
Configuration: configuration,
TestScenario: "DebugLevelTest"
));
Assert.Contains($"WasmDebugLevel: -1", result.TestOutput);
}
}
38 changes: 33 additions & 5 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class BrowserRunner : IAsyncDisposable
{
private static Regex s_blazorUrlRegex = new Regex("Now listening on: (?<url>https?://.*$)");
private static Regex s_appHostUrlRegex = new Regex("^App url: (?<url>https?://.*$)");
private static Regex s_appPublishedUrlRegex = new Regex(@"^\s{2}(?<url>https?://.*$)");
private static readonly Regex s_payloadRegex = new Regex("\"payload\":\"(?<payload>[^\"]*)\"", RegexOptions.Compiled);
private static Regex s_exitRegex = new Regex("WASM EXIT (?<exitCode>-?[0-9]+)$");
private static readonly Lazy<string> s_chromePath = new(() =>
{
Expand Down Expand Up @@ -52,9 +54,15 @@ public async Task<string> StartServerAndGetUrlAsync(
OutputLines.Add(msg);
}

Match m = s_appHostUrlRegex.Match(msg);
if (!m.Success)
m = s_blazorUrlRegex.Match(msg);
var regexes = new[] { s_appHostUrlRegex, s_blazorUrlRegex, s_appPublishedUrlRegex };
Match m = Match.Empty;

foreach (var regex in regexes)
{
m = regex.Match(msg);
if (m.Success)
break;
}

if (m.Success)
{
Expand Down Expand Up @@ -176,8 +184,28 @@ public async Task<IPage> RunAsync(

IPage page = await context.NewPageAsync();

if (onConsoleMessage is not null)
page.Console += (_, msg) => onConsoleMessage(page, msg);
page.Console += (_, msg) =>
{
Match payloadMatch = s_payloadRegex.Match(msg.Text);
if (payloadMatch.Success)
{
string payload = payloadMatch.Groups["payload"].Value;
lock (OutputLines)
{
OutputLines.Add(payload);
}

Match exitMatch = s_exitRegex.Match(payload);
if (exitMatch.Success)
{
_exited.TrySetResult(int.Parse(exitMatch.Groups["exitCode"].Value));
}
}
if (onConsoleMessage is not null)
{
onConsoleMessage(page, msg);
}
};

onError ??= _testOutput.WriteLine;
if (onError is not null)
Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public BuildTestBase(ProjectProviderBase providerBase, ITestOutputHelper output,
return (res, logFilePath);
}

protected bool IsDotnetWasmFromRuntimePack(BuildArgs buildArgs) => !(buildArgs.AOT || buildArgs.Config == "Release");

protected string RunAndTestWasmApp(BuildArgs buildArgs,
RunHost host,
string id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public record AssertTestMainJsAppBundleOptions(
bool AssertSymbolsFile = true,
bool HasV8Script = false,
bool IsBrowserProject = true)
: AssertBundleOptionsBase(
: AssertWasmSdkBundleOptions(
Config: Config,
IsPublish: IsPublish,
TargetFramework: TargetFramework,
Expand All @@ -32,7 +32,7 @@ public record AssertTestMainJsAppBundleOptions(
GlobalizationMode: GlobalizationMode,
ExpectedFileType: ExpectedFileType,
RuntimeType: RuntimeType,
BootJsonFileName: BootJsonFileName,
BootConfigFileName: BootJsonFileName,
ExpectFingerprintOnDotnetJs: ExpectFingerprintOnDotnetJs,
ExpectSymbolsFile: ExpectSymbolsFile,
AssertIcuAssets: AssertIcuAssets,
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/ConfigSrcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void ConfigSrcAbsolutePath(BuildArgs buildArgs, RunHost host, string id)
id: id,
new BuildProjectOptions(
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_mainReturns42),
DotnetWasmFromRuntimePack: !(buildArgs.AOT || buildArgs.Config == "Release")));
DotnetWasmFromRuntimePack: IsDotnetWasmFromRuntimePack(buildArgs)));

string binDir = GetBinDir(baseDir: _projectDir!, config: buildArgs.Config);
string bundleDir = Path.Combine(binDir, "AppBundle");
Expand Down
116 changes: 116 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/DebugLevelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

#nullable enable

namespace Wasm.Build.Tests;

public class DebugLevelTests : WasmTemplateTestsBase
{
public DebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
{
}

private string SetupBrowserProject(string projectId, string extraProperties = "")
{
string id = $"{projectId}_{GetRandomId()}";
string projectfile = CreateWasmTemplateProject(id, "wasmbrowser", extraProperties: extraProperties);

UpdateBrowserMainJs();
string mainJs = Path.Combine("wwwroot", "main.js");
UpdateFile(mainJs, new Dictionary<string, string>
{
{ "import { dotnet }", "import { dotnet, exit }" },
{"await dotnet.run()", "console.log('TestOutput -> WasmDebugLevel: ' + config.debugLevel); exit(42)" }
});
return projectfile;
}

private void AssertDebugLevel(string result, int value)
=> Assert.Contains($"WasmDebugLevel: {value}", result);

private BuildProjectOptions GetProjectOptions(bool isPublish = false) =>
new BuildProjectOptions(
DotnetWasmFromRuntimePack: !isPublish,
CreateProject: false,
HasV8Script: false,
MainJS: "main.js",
Publish: isPublish,
AssertAppBundle: false
);

private string BuildPublishProject(string projectFile, string config, bool isPublish = false)
{
string projectName = Path.GetFileNameWithoutExtension(projectFile);
var buildArgs = new BuildArgs(projectName, config, false, projectName, null);
buildArgs = ExpandBuildArgs(buildArgs);
(string _, string output) = BuildTemplateProject(buildArgs,
buildArgs.Id,
GetProjectOptions(isPublish)
);
return output;
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public async Task BuildWithDefaultLevel(string configuration)
{
string projectFile = SetupBrowserProject($"DebugLevelTests_BuildWithDefaultLevel_{configuration}");
BuildPublishProject(projectFile, configuration);

string result = await RunBuiltBrowserApp(configuration, projectFile);
AssertDebugLevel(result, -1);
}

[Theory]
[InlineData("Debug", 1)]
[InlineData("Release", 1)]
[InlineData("Debug", 0)]
[InlineData("Release", 0)]
public async Task BuildWithExplicitValue(string configuration, int debugLevel)
{
string debugLvlProp = $"<WasmDebugLevel>{debugLevel}</WasmDebugLevel>";
string projectFile = SetupBrowserProject($"DebugLevelTests_BuildWithExplicitValue_{configuration}", extraProperties: debugLvlProp);
BuildPublishProject(projectFile, configuration);

string result = await RunBuiltBrowserApp(configuration, projectFile);
AssertDebugLevel(result, debugLevel);
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public async Task PublishWithDefaultLevel(string configuration)
{
string projectFile = SetupBrowserProject($"DebugLevelTests_PublishWithDefaultLevel_{configuration}");
BuildPublishProject(projectFile, configuration, isPublish: true);

string result = await RunPublishedBrowserApp(configuration);
AssertDebugLevel(result, 0);
}

[Theory]
[InlineData("Debug", 1)]
[InlineData("Release", 1)]
[InlineData("Debug", -1)]
[InlineData("Release", -1)]
public async Task PublishWithExplicitValue(string configuration, int debugLevel)
{
string debugLvlProp = $"<WasmDebugLevel>{debugLevel}</WasmDebugLevel>";
string projectFile = SetupBrowserProject($"DebugLevelTests_PublishWithExplicitValue_{configuration}", debugLvlProp);
BuildPublishProject(projectFile, configuration, isPublish: true);

string result = await RunBuiltBrowserApp(configuration, projectFile);
AssertDebugLevel(result, debugLevel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void TestHybridGlobalizationTests(BuildArgs buildArgs, RunHost host, str
buildArgs = ExpandBuildArgs(buildArgs, extraProperties);

if (dotnetWasmFromRuntimePack == null)
dotnetWasmFromRuntimePack = !(buildArgs.AOT || buildArgs.Config == "Release");
dotnetWasmFromRuntimePack = IsDotnetWasmFromRuntimePack(buildArgs);

string programText = File.ReadAllText(Path.Combine(BuildEnvironment.TestAssetsPath, "Wasm.Buid.Tests.Programs", "HybridGlobalization.cs"));

Expand Down
1 change: 0 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/IcuShardingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static IEnumerable<object[]> IcuExpectedAndMissingAutomaticShardTestData(
{ "ja-JP", GetCjkTestedLocales(SundayNames.Japanese) },
{ "sk-SK", GetNocjkTestedLocales(SundayNames.Slovak) }
};
// "wasmconsole": https://github.com/dotnet/runtime/issues/82593
return from aot in boolOptions
from locale in locales
select new object[] { config, "wasmbrowser", aot, locale.Key, locale.Value };
Expand Down
5 changes: 2 additions & 3 deletions src/mono/wasm/Wasm.Build.Tests/IcuShardingTests2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ public static IEnumerable<object[]> IcuExpectedAndMissingShardFromRuntimePackTes
{ "icudt_no_CJK.dat", GetNocjkTestedLocales() }
};
return
// "wasmconsole": https://github.com/dotnet/runtime/issues/82593
// from templateType in templateTypes
from templateType in templateTypes
from aot in boolOptions
from locale in locales
select new object[] { config, "wasmbrowser", aot, locale.Key, locale.Value };
select new object[] { config, templateType, aot, locale.Key, locale.Value };
}

[Theory]
Expand Down
Loading
Loading