Skip to content

Commit d73e625

Browse files
ilonatommylewing
andauthored
[browser] Trigger relink on EmccMaximumHeapSize change (#105027)
* Edit test + trigger relink. * Remove logging to speed up the test + decrease loop runs to prevent "Browser has been disconnected" error. * Feedback - properties are not bool-only anymore. * Fix: workload needed when heap size set. --------- Co-authored-by: Larry Ewing <[email protected]>
1 parent 4072e73 commit d73e625

File tree

11 files changed

+49
-29
lines changed

11 files changed

+49
-29
lines changed

eng/testing/linker/project.csproj.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
<Target Name="RemoveInvariantGlobalization" BeforeTargets="_SetWasmBuildNativeDefaults" Condition="'$(TargetArchitecture)' == 'wasm'">
7979
<ItemGroup>
80-
<_BoolPropertiesThatTriggerRelinking Remove="InvariantGlobalization" />
80+
<_PropertiesThatTriggerRelinking Remove="InvariantGlobalization" />
8181
</ItemGroup>
8282
</Target>
8383

src/mono/browser/browser.proj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<WasmSingleFileBundle Condition="'$(WasmSingleFileBundle)' == ''">false</WasmSingleFileBundle>
3030
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">true</WasmEnableSIMD>
3131
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">true</WasmEnableExceptionHandling>
32+
<EmccMaximumHeapSize Condition="'$(EmccMaximumHeapSize)' == ''">2147483648</EmccMaximumHeapSize>
3233
<WasmEnableJsInteropByValue Condition="'$(WasmEnableJsInteropByValue)' == '' and '$(WasmEnableThreads)' == 'true'">true</WasmEnableJsInteropByValue>
3334
<WasmEnableJsInteropByValue Condition="'$(WasmEnableJsInteropByValue)' == ''">false</WasmEnableJsInteropByValue>
3435
<FilterSystemTimeZones Condition="'$(FilterSystemTimeZones)' == ''">false</FilterSystemTimeZones>
@@ -334,13 +335,14 @@
334335
"WasmOptConfigurationFlags": [@(WasmOptConfigurationFlags -> '%22%(Identity)%22', ',')],
335336
"EmccDefaultExportedFunctions": [@(EmccExportedFunction -> '%22%(Identity)%22', ',')],
336337
"EmccDefaultExportedRuntimeMethods": [@(EmccExportedRuntimeMethod -> '%22%(Identity)%22', ',')],
337-
"BoolPropertiesThatTriggerRelinking": [
338+
"PropertiesThatTriggerRelinking": [
338339
{ "identity": "InvariantTimezone", "defaultValueInRuntimePack": "$(InvariantTimezone)" },
339340
{ "identity": "InvariantGlobalization", "defaultValueInRuntimePack": "$(InvariantGlobalization)" },
340341
{ "identity": "WasmNativeStrip", "defaultValueInRuntimePack": "$(WasmNativeStrip)" },
341342
{ "identity": "WasmSingleFileBundle", "defaultValueInRuntimePack": "$(WasmSingleFileBundle)" },
342343
{ "identity": "WasmEnableSIMD", "defaultValueInRuntimePack": "$(WasmEnableSIMD)" },
343-
{ "identity": "WasmEnableExceptionHandling", "defaultValueInRuntimePack": "$(WasmEnableExceptionHandling)" }
344+
{ "identity": "WasmEnableExceptionHandling", "defaultValueInRuntimePack": "$(WasmEnableExceptionHandling)" },
345+
{ "identity": "EmccMaximumHeapSize", "defaultValueInRuntimePack": "$(EmccMaximumHeapSize)" }
344346
]
345347
}
346348
}

src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/WorkloadManifest.targets.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
'$(RunAOTCompilation)' == 'true' or
5959
'$(WasmBuildNative)' == 'true' or
6060
'$(WasmGenerateAppBundle)' == 'true' or
61-
'$(_UsingBlazorOrWasmSdk)' != 'true'" >true</_WasmNativeWorkloadNeeded>
61+
'$(_UsingBlazorOrWasmSdk)' != 'true' or
62+
'$(EmccMaximumHeapSize)' != '' " >true</_WasmNativeWorkloadNeeded>
6263

6364
<UsingBrowserRuntimeWorkload Condition="'$(_BrowserWorkloadNotSupportedForTFM)' == 'true'">false</UsingBrowserRuntimeWorkload>
6465
<UsingBrowserRuntimeWorkload Condition="'$(UsingBrowserRuntimeWorkload)' == '' and '$(_WasmNativeWorkloadNeeded)' == 'true'">true</UsingBrowserRuntimeWorkload>

src/mono/wasi/wasi.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
{
159159
"items": {
160160
"WasmOptConfigurationFlags": [@(WasmOptConfigurationFlags -> '%22%(Identity)%22', ',')],
161-
"BoolPropertiesThatTriggerRelinking": [
161+
"PropertiesThatTriggerRelinking": [
162162
{ "identity": "InvariantTimezone", "defaultValueInRuntimePack": "$(InvariantTimezone)" },
163163
{ "identity": "InvariantGlobalization", "defaultValueInRuntimePack": "$(InvariantGlobalization)" },
164164
{ "identity": "WasmNativeStrip", "defaultValueInRuntimePack": "$(WasmNativeStrip)" },

src/mono/wasm/Wasm.Build.Tests/Common/CommandResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public CommandResult(ProcessStartInfo startInfo, int exitCode, string output)
2727
public CommandResult EnsureSuccessful(string messagePrefix = "", bool suppressOutput = false)
2828
=> EnsureExitCode(0, messagePrefix, suppressOutput);
2929

30+
public CommandResult EnsureFailed(string messagePrefix = "", bool suppressOutput = false)
31+
{
32+
if (ExitCode == 0)
33+
throw new XunitException($"{messagePrefix} Expected non-zero exit code but got 0: {StartInfo.FileName} {StartInfo.Arguments}");
34+
return this;
35+
}
36+
3037
public CommandResult EnsureExitCode(int expectedExitCode = 0, string messagePrefix = "", bool suppressOutput = false)
3138
{
3239
if (ExitCode != expectedExitCode)

src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,24 @@ protected void BuildProject(
5959
string? binFrameworkDir = null,
6060
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded,
6161
bool assertAppBundle = true,
62+
bool expectSuccess = true,
6263
params string[] extraArgs)
6364
{
6465
(CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(
6566
Id: Id,
6667
Config: configuration,
6768
BinFrameworkDir: binFrameworkDir,
6869
RuntimeType: runtimeType,
69-
AssertAppBundle: assertAppBundle), extraArgs);
70-
result.EnsureSuccessful();
70+
AssertAppBundle: assertAppBundle,
71+
ExpectSuccess: expectSuccess), extraArgs);
72+
if (expectSuccess)
73+
{
74+
result.EnsureSuccessful();
75+
}
76+
else
77+
{
78+
result.EnsureFailed();
79+
}
7180
}
7281

7382
protected void PublishProject(

src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/MemoryTests.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ public MemoryTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buil
1919
{
2020
}
2121

22-
[Theory]
23-
[InlineData("Release", true)]
24-
[InlineData("Release", false)]
25-
[ActiveIssue("https://github.com/dotnet/runtime/issues/105283")]
26-
public async Task AllocateLargeHeapThenRepeatedlyInterop(string config, bool buildNative)
22+
// ActiveIssue: https://github.com/dotnet/runtime/issues/104618
23+
[Fact, TestCategory("no-workload")]
24+
public async Task AllocateLargeHeapThenRepeatedlyInterop_NoWorkload() =>
25+
await AllocateLargeHeapThenRepeatedlyInterop();
26+
27+
[Fact]
28+
public async Task AllocateLargeHeapThenRepeatedlyInterop()
2729
{
28-
// native build triggers passing value form EmccMaximumHeapSize to MAXIMUM_MEMORY that is set in emscripten
29-
// in non-native build EmccMaximumHeapSize does not have an effect, so the test will fail with "out of memory"
30+
string config = "Release";
3031
CopyTestAsset("WasmBasicTestApp", "MemoryTests", "App");
31-
string extraArgs = $"-p:EmccMaximumHeapSize=4294901760 -p:WasmBuildNative={buildNative}";
32-
BuildProject(config, assertAppBundle: false, extraArgs: extraArgs);
32+
string extraArgs = BuildTestBase.IsUsingWorkloads ? "-p:EmccMaximumHeapSize=4294901760" : "-p:EmccMaximumHeapSize=4294901760";
33+
BuildProject(config, assertAppBundle: false, extraArgs: extraArgs, expectSuccess: BuildTestBase.IsUsingWorkloads);
3334

34-
var result = await RunSdkStyleAppForBuild(new (Configuration: config, TestScenario: "AllocateLargeHeapThenInterop", ExpectedExitCode: buildNative ? 0 : 1));
35-
if (!buildNative)
36-
Assert.Contains(result.TestOutput, item => item.Contains("Exception System.OutOfMemoryException: Out of memory"));
35+
if (BuildTestBase.IsUsingWorkloads)
36+
{
37+
await RunSdkStyleAppForBuild(new (Configuration: config, TestScenario: "AllocateLargeHeapThenInterop"));
38+
}
3739
}
3840
}

src/mono/wasm/build/WasmApp.Common.targets

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
<WasmOptConfigurationFlags ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" Output="true" />
394394
<EmccDefaultExportedFunctions ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" Output="true" />
395395
<EmccDefaultExportedRuntimeMethods ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" Output="true" />
396-
<BoolPropertiesThatTriggerRelinking ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" Output="true" />
396+
<PropertiesThatTriggerRelinking ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" Output="true" />
397397
</ParameterGroup>
398398
</UsingTask>
399399

@@ -405,7 +405,7 @@
405405

406406
<!-- shared by browser/wasi -->
407407
<Output TaskParameter="WasmOptConfigurationFlags" ItemName="_DefaulWasmOptConfigurationFlags" />
408-
<Output TaskParameter="BoolPropertiesThatTriggerRelinking" ItemName="_BoolPropertiesThatTriggerRelinking" />
408+
<Output TaskParameter="PropertiesThatTriggerRelinking" ItemName="_PropertiesThatTriggerRelinking" />
409409
</ReadWasmProps>
410410

411411
<CreateProperty Value="%(_EmccPropItems.Value)" Condition="%(_EmccPropItems.Identity) != ''">
@@ -511,15 +511,15 @@
511511
Text="$(_ToolchainMissingErrorMessage) SDK is required for AOT'ing assemblies." />
512512

513513
<ItemGroup>
514-
<_ChangedBoolPropertiesThatTriggerRelinking Include="%(_BoolPropertiesThatTriggerRelinking.Identity)" Condition="'$(%(_BoolPropertiesThatTriggerRelinking.Identity))' != '' and
515-
'$(%(_BoolPropertiesThatTriggerRelinking.Identity))' != '%(_BoolPropertiesThatTriggerRelinking.DefaultValueInRuntimePack)'" />
514+
<_ChangedPropertiesThatTriggerRelinking Include="%(_PropertiesThatTriggerRelinking.Identity)" Condition="'$(%(_PropertiesThatTriggerRelinking.Identity))' != '' and
515+
'$(%(_PropertiesThatTriggerRelinking.Identity))' != '%(_PropertiesThatTriggerRelinking.DefaultValueInRuntimePack)'" />
516516
</ItemGroup>
517517
<PropertyGroup>
518-
<_WasmBuildNativeRequired Condition="@(_ChangedBoolPropertiesThatTriggerRelinking->Count()) > 0">true</_WasmBuildNativeRequired>
518+
<_WasmBuildNativeRequired Condition="@(_ChangedPropertiesThatTriggerRelinking->Count()) > 0">true</_WasmBuildNativeRequired>
519519
</PropertyGroup>
520520

521521
<Error Condition="'$(WasmBuildNative)' == 'false' and '$(_WasmBuildNativeRequired)' == 'true'"
522-
Text="WasmBuildNative is required because %(_ChangedBoolPropertiesThatTriggerRelinking.Identity)=$(%(_ChangedBoolPropertiesThatTriggerRelinking.Identity)), but WasmBuildNative is already set to 'false'." />
522+
Text="WasmBuildNative is required because %(_ChangedPropertiesThatTriggerRelinking.Identity)=$(%(_ChangedPropertiesThatTriggerRelinking.Identity)), but WasmBuildNative is already set to 'false'." />
523523

524524
<PropertyGroup>
525525
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(_WasmBuildNativeRequired)' == 'true'">true</WasmBuildNative>

src/mono/wasm/testassets/WasmBasicTestApp/App/MemoryTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Text;
88
using System.Runtime.InteropServices.JavaScript;
99

10-
public partial class MemoryTest // ?test=AllocateLargeHeapThenInterop
10+
public partial class MemoryTest
1111
{
1212
[JSImport("countChars", "main.js")]
1313
internal static partial int CountChars(string testArray);
@@ -37,7 +37,7 @@ internal static void Run()
3737
string randomString = GenerateRandomString(1000);
3838
try
3939
{
40-
for (int i = 0; i < 10000; i++)
40+
for (int i = 0; i < 1000; i++)
4141
{
4242
int count = CountChars(randomString);
4343
if (count != randomString.Length)

src/mono/wasm/testassets/WasmBasicTestApp/App/WasmBasicTestApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<BlazorWebAssemblyLazyLoad Include="Json$(LazyAssemblyExtension)" />
22+
<BlazorWebAssemblyLazyLoad Include="Json$(WasmAssemblyExtension)" />
2323
</ItemGroup>
2424
</Project>

src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function testOutput(msg) {
1616

1717
function countChars(str) {
1818
const length = str.length;
19-
testOutput(`JS received str of ${length} length`);
2019
return length;
2120
}
2221

0 commit comments

Comments
 (0)