Skip to content

Commit

Permalink
[wasm] Stop testing with V8 and wasmconsole (#108711)
Browse files Browse the repository at this point in the history
* Do not run tests with v8 scenario on CI. Leave code that supports running v8 scenario.

* Remove console app, consolidate template base class, order inheritance, clean the code.

* Fix build error: Keep all types of bundle options in `Common` dir.

* Rename the param after merge with main.

* Fix cast errors in providers.

* Blazor and Browser bundle names got unified some time ago.

* Fix running of browser published apps.

* Fix the test transformed from console to browser.

* Browser sdk does not allow appending RID.

* Fix "item was already added" in build.
  • Loading branch information
ilonatommy authored Oct 16, 2024
1 parent 588bc45 commit 0290065
Show file tree
Hide file tree
Showing 36 changed files with 554 additions and 939 deletions.
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 Down
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);
}
}
46 changes: 41 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,36 @@ public async Task<IPage> RunAsync(

IPage page = await context.NewPageAsync();

if (onConsoleMessage is not null)
page.Console += (_, msg) => onConsoleMessage(page, msg);
page.Console += (_, msg) =>
{
string message = msg.Text;
Match payloadMatch = s_payloadRegex.Match(message);
if (payloadMatch.Success)
{
message = payloadMatch.Groups["payload"].Value;
}
if (message.StartsWith("TestOutput -> "))
{
lock (OutputLines)
{
OutputLines.Add(message);
}
}
Match exitMatch = s_exitRegex.Match(message);
if (exitMatch.Success)
{
lock (OutputLines)
{
OutputLines.Add(message);
}
int exitCode = int.Parse(exitMatch.Groups["exitCode"].Value);
_exited.TrySetResult(exitCode);
}
if (onConsoleMessage is not null)
{
onConsoleMessage(page, msg);
}
};

onError ??= _testOutput.WriteLine;
if (onError is not null)
Expand Down
3 changes: 3 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,9 @@ public BuildTestBase(ProjectProviderBase providerBase, ITestOutputHelper output,
return (res, logFilePath);
}

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

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
125 changes: 125 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/DebugLevelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// 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;

// ToDo: fix to be based on WasmTemplateTestBase
public class DebugLevelTests : AppTestBase
{
public DebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
{
}

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

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

private string BuildPublishProject(string projectName, string config, bool isPublish = false, params string[] extraArgs)
{
var buildArgs = new BuildArgs(projectName, config, false, projectName, null);
buildArgs = ExpandBuildArgs(buildArgs);
(string _, string output) = BuildTemplateProject(buildArgs,
buildArgs.Id,
GetProjectOptions(isPublish),
extraArgs: extraArgs
);
return output;
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public async Task BuildWithDefaultLevel(string configuration)
{
string testAssetName = "WasmBasicTestApp";
string projectFile = $"{testAssetName}.csproj";
CopyTestAsset(testAssetName, $"DebugLevelTests_BuildWithDefaultLevel_{configuration}", "App");
BuildPublishProject(projectFile, configuration);

string result = await RunBuiltBrowserApp(configuration, projectFile, testScenario: "DebugLevelTest");
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 testAssetName = "WasmBasicTestApp";
string projectFile = $"{testAssetName}.csproj";
CopyTestAsset(testAssetName, $"DebugLevelTests_BuildWithExplicitValue_{configuration}", "App");
BuildPublishProject(projectFile, configuration, extraArgs: $"-p:WasmDebugLevel={debugLevel}");

string result = await RunBuiltBrowserApp(configuration, projectFile, testScenario: "DebugLevelTest");
AssertDebugLevel(result, debugLevel);
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public async Task PublishWithDefaultLevel(string configuration)
{
string testAssetName = "WasmBasicTestApp";
string projectFile = $"{testAssetName}.csproj";
CopyTestAsset(testAssetName, $"DebugLevelTests_PublishWithDefaultLevel_{configuration}", "App");
BuildPublishProject(projectFile, configuration, isPublish: true);

string result = await RunPublishedBrowserApp(configuration, testScenario: "DebugLevelTest");
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 testAssetName = "WasmBasicTestApp";
string projectFile = $"{testAssetName}.csproj";
CopyTestAsset(testAssetName, $"DebugLevelTests_PublishWithExplicitValue_{configuration}", "App");
BuildPublishProject(projectFile, configuration, isPublish: true, extraArgs: $"-p:WasmDebugLevel={debugLevel}");

string result = await RunBuiltBrowserApp(configuration, projectFile, testScenario: "DebugLevelTest");
AssertDebugLevel(result, debugLevel);
}


[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public async Task PublishWithDefaultLevelAndPdbs(string configuration)
{
string testAssetName = "WasmBasicTestApp";
string projectFile = $"{testAssetName}.csproj";
CopyTestAsset(testAssetName, $"DebugLevelTests_PublishWithDefaultLevelAndPdbs_{configuration}", "App");
BuildPublishProject(projectFile, configuration, isPublish: true, extraArgs: $"-p:CopyOutputSymbolsToPublishDirectory=true");

var result = await RunPublishedBrowserApp(configuration, testScenario: "DebugLevelTest");
AssertDebugLevel(result, -1);
}
}
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/HybridGlobalizationTests.cs
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

0 comments on commit 0290065

Please sign in to comment.