Skip to content

Commit

Permalink
[wasm] Standup EnableAgressiveTrimming for library tests (#46367)
Browse files Browse the repository at this point in the history
* Trim wasm library tests

* Add SystemBuffers HelloTest and only test that

* Import linker from nuget to override sdk linker

* Remove redundant assembly inclusions

* Add WasmTestRunner referenced assemblies

* Add properties to reduce library size

* Updates

* Configure trimming for library tests

* Link assemblies except for test assembly

* Use another path to WasmTestRunner.dll

* Fix typo

* Setup correctly rooted assemblies

* Don't copy WasmTestRunner.dll from wrong patch when using linker

* Don't inflate publish output with packages which are not used for tests runs

* Fix xunit framework files copying to publish location to not overwrite
version copied as part of trimming publish

* Add linker descriptor for xunit code which linker cannot track

* Add tested assembly to the test payload closure

* One more method to preserve

* Preserving some xunit types to make sure we can actually discover the tests

* Put Wasm.targets import in the right spot

* Add a mode where we can run the regular system.buffers tests

* Dont link out Microsoft.DotNet.RemoteExecutor

* Move Microsoft.DotNet.RemoteExecutor inclusion to xml

* Consolidate ConfigureTrimming itemgroups

* Build PrepareForWasmBuildApp before WasmBuildApp

* Remove manual import of WasmTestRunner assemblies

* Remove temporary HelloTest from System.Buffers

* Added flag to not aggressively link by default

* Revert import and build order changes

* Condition trimming related changes on EnableAggressiveTrimming

* Revert "Don't copy WasmTestRunner.dll from wrong patch when using linker" as MainAssembly is back to $(PublishDir)\WasmTestRunner.dll
This reverts commit 79dc240.

* Add comment to note temporary RemoteExecutor assembly inclusion

* Move props from general tests to mobile tests

* Revert "Condition trimming related changes on EnableAggressiveTrimming"

This reverts commit a97fb56.

* Broaden trimming options for all mobile targets

* Enable PublishTrimmed regardless of OS when aggressively trimming

* Move trimming specific property to ConfigureTrimming

* Import NuGet linker in mobile tests by default

* Add file description

* Add detail to ILLink XML descriptor file

* Reformat ConfigureTrimming target tag

* Fix typo

Co-authored-by: Mitchell Hwang <mitchell.hwang@microsoft.com>
Co-authored-by: Steve Pfister <steve.pfister@microsoft.com>
Co-authored-by: Marek Safar <marek.safar@gmail.com>
  • Loading branch information
4 people committed Jan 4, 2021
1 parent 32586d6 commit 1e6826a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
21 changes: 21 additions & 0 deletions eng/testing/ILLink.Descriptor.xunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- xunit 2.x version is not under development. We make xunit trimming compatible in methods which ILLink cannot track by providing XML descriptor to keep the dependencies -->
<linker>
<assembly fullname="xunit.execution.dotnet">
<type fullname="Xunit.Sdk.ReflectionAssemblyInfo">
<method signature="System.Void .ctor(System.String)" />
</type>
<type fullname="Xunit.Sdk.TestFrameworkProxy">
<method signature="System.Void .ctor(System.Object,System.Object,System.Object)" />
</type>
<type fullname="Xunit.Sdk.FactDiscoverer" />
</assembly>
<assembly fullname="xunit.core">
<namespace fullname="Xunit" />
</assembly>
<!-- Temporary until https://github.com/mono/linker/issues/1713 is resolved -->
<assembly fullname="Microsoft.DotNet.RemoteExecutor">
<type fullname="Microsoft.DotNet.RemoteExecutor.Program">
<method signature="System.Int32 Main(System.String[])" />
</type>
</assembly>
</linker>
40 changes: 38 additions & 2 deletions eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
<RunAOTCompilation Condition="'$(TargetOS)' == 'iOS' and $(TargetArchitecture.StartsWith('arm'))">true</RunAOTCompilation>
<JSEngine Condition="'$(TargetOS)' == 'Browser' and '$(JSEngine)' == ''">V8</JSEngine>
<JSEngineArgs Condition="'$(JSEngine)' == 'V8'">$(JSEngineArgs) --engine-arg=--stack-trace-limit=1000</JSEngineArgs>

<PublishingTestsRun>true</PublishingTestsRun>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
<!-- We need to set this in order to get extensibility on xunit category traits and other arguments we pass down to xunit via MSBuild properties -->
<RunScriptCommand>$HARNESS_RUNNER wasm $XHARNESS_COMMAND --app=. --engine=$(JSEngine) $(JSEngineArgs) --js-file=runtime.js --output-directory=$XHARNESS_OUT -- $(RunTestsJSArguments) --run WasmTestRunner.dll $(AssemblyName).dll</RunScriptCommand>
<EventSourceSupport>false</EventSourceSupport>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
<EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
<DebuggerSupport>false</DebuggerSupport>
</PropertyGroup>

<PropertyGroup Condition="'$(EnableAggressiveTrimming)' == 'true'">
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

<!-- Generate a self-contained app bundle for Android with tests. -->
Expand Down Expand Up @@ -137,6 +148,30 @@

</Target>

<Target Name="ConfigureTrimming" Condition="'$(EnableAggressiveTrimming)' == 'true'" BeforeTargets="PrepareForILLink">
<PropertyGroup>
<TrimMode>link</TrimMode>
</PropertyGroup>

<ItemGroup>
<ManagedAssemblyToLink Include="$(OutDir)\*xunit*">
<IsTrimmable>true</IsTrimmable>
<TrimMode>link</TrimMode>
</ManagedAssemblyToLink>
<ManagedAssemblyToLink Condition="('%(ManagedAssemblyToLink.FileName).dll' != '$(MSBuildProjectName).dll')" >
<TrimMode>link</TrimMode>
</ManagedAssemblyToLink>
<ManagedAssemblyToLink Condition="('%(ManagedAssemblyToLink.FileName).dll' == '$(AssemblyName).dll')" >
<TrimMode>copy</TrimMode>
</ManagedAssemblyToLink>
<TrimmerRootAssembly Condition="'$(TargetOS)' == 'Android'" Include="AndroidTestRunner"/>
<TrimmerRootAssembly Condition="'$(TargetOS)' == 'Browser'" Include="WasmTestRunner"/>
<TrimmerRootAssembly Condition="'$(TargetOS)' == 'iOS'" Include="AppleTestRunner"/>
<TrimmerRootAssembly Include="$(AssemblyName)"/>
<TrimmerRootDescriptor Include="$(MSBuildThisFileDirectory)ILLink.Descriptor.xunit.xml" />
</ItemGroup>
</Target>

<Import Project="$(MonoProjectRoot)\wasm\build\WasmApp.targets" Condition="'$(TargetOS)' == 'Browser'" />
<PropertyGroup>
<WasmBuildAppDependsOn>PrepareForWasmBuildApp;$(WasmBuildAppDependsOn)</WasmBuildAppDependsOn>
Expand Down Expand Up @@ -177,13 +212,14 @@
<_runnerFilesToPublish Include="$(AppleTestRunnerDir)*" Condition="'$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'tvOS'" />
<_runnerFilesToPublish Include="$(WasmTestRunnerDir)*" Condition="'$(TargetOS)' == 'Browser'" />

<!-- Exclude xunit assemblies as those should be resolved by our own package references -->
<ResolvedFileToPublish Include="@(_runnerFilesToPublish)" Condition="!$([System.String]::Copy('%(Filename)').StartsWith('xunit.'))" RelativePath="%(FileName)%(Extension)" CopyToPublishDirectory="PreserveNewest" PostprocessAssembly="true" />
<ResolvedFileToPublish Include="@(_runnerFilesToPublish)" RelativePath="%(FileName)%(Extension)" CopyToPublishDirectory="PreserveNewest" PostprocessAssembly="true" />
</ItemGroup>
</Target>

<Target Name="PublishTestAsSelfContained"
Condition="'$(IsCrossTargetingBuild)' != 'true'"
AfterTargets="Build"
DependsOnTargets="Publish;BundleTestAppleApp;BundleTestAndroidApp;BundleTestWasmApp;ArchiveTests" />

<Import Project="$(RepositoryEngineeringDir)illink.targets" />
</Project>
4 changes: 2 additions & 2 deletions eng/testing/xunit/xunit.console.targets
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<!-- Overwrite the runner config file with the app local one. -->
<Target Name="OverwriteDesktopTestRunnerConfigs"
Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and
Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and
'$(GenerateAppConfigurationFile)' == 'true' and
'@(AppConfigWithTargetPath)' != ''"
AfterTargets="CopyFilesToOutputDirectory">
Expand All @@ -62,7 +62,7 @@
</Target>

<!-- ResolveAssemblyReferences is the target that populates ReferenceCopyLocalPaths which is what is copied to output directory. -->
<Target Name="CopyRunnerToOutputDirectory" BeforeTargets="ResolveAssemblyReferences">
<Target Name="CopyRunnerToOutputDirectory" BeforeTargets="ResolveAssemblyReferences" Condition="'$(TargetsMobile)' != 'true'">
<ItemGroup>
<!-- Copy test runner to output directory -->
<None Include="$([System.IO.Path]::GetDirectoryName('$(XunitConsole472Path)'))\*"
Expand Down
2 changes: 1 addition & 1 deletion eng/testing/xunit/xunit.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(ArchiveTests)' != 'true'">
<ItemGroup Condition="'$(ArchiveTests)' != 'true' AND '$(PublishingTestsRun)' != 'true'">
<!-- Microsoft.Net.Test.Sdk brings a lot of assemblies with it. To reduce helix payload submission size we disable it on CI. -->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)" GeneratePathProperty="true" />
Expand Down

0 comments on commit 1e6826a

Please sign in to comment.