Skip to content

Commit

Permalink
Fix linker tests not running and show full path during trimming test …
Browse files Browse the repository at this point in the history
…execution (#69118)

* Show full path during trimming test execution

Fixes #38377. Also addresses @danmoseley's additional feedback regarding separating the "..." from the path.

* Fix linker tests not running 
   Update tests.proj
   Update InvariantGlobalizationTrue.cs
  • Loading branch information
ViktorHofer authored May 12, 2022
1 parent 5f58404 commit 35e4779
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
14 changes: 7 additions & 7 deletions eng/testing/linker/trimmingTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
<!-- We need to separate Item metadata declaration in two in order to be able to use ProjectDir and TestRuntimeIdentifier below -->
<TestConsoleAppSourceFiles>
<ProjectFile>%(ProjectDir)project.csproj</ProjectFile>
<TestCommand Condition="'$(TargetArchitecture)' != 'wasm' Or '$(TargetOs)' != 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish', 'project'))</TestCommand>
<TestCommand Condition="'$(TargetArchitecture)' == 'wasm' And '$(TargetOs)' == 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'AppBundle', 'run-v8.sh'))</TestCommand>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' != 'wasm' Or '$(TargetOs)' != 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish'))</TestExecutionDirectory>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' == 'wasm' And '$(TargetOs)' == 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'AppBundle'))</TestExecutionDirectory>
<TestCommand Condition="'$(TargetArchitecture)' != 'wasm' or '$(TargetOS)' != 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish', 'project'))</TestCommand>
<TestCommand Condition="'$(TargetArchitecture)' == 'wasm' and '$(TargetOS)' == 'browser'">$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'AppBundle', 'run-v8.sh'))</TestCommand>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' != 'wasm' or '$(TargetOS)' != 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish'))</TestExecutionDirectory>
<TestExecutionDirectory Condition="'$(TargetArchitecture)' == 'wasm' and '$(TargetOS)' == 'browser'">$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'AppBundle'))</TestExecutionDirectory>
</TestConsoleAppSourceFiles>
</ItemGroup>

<ItemGroup Condition="!$(SkipOnTestRuntimes.Contains('$(PackageRID)'))">
<TestConsoleApps Include="@(TestConsoleAppSourceFiles->'%(ProjectFile)')" Condition="!$([System.String]::Copy('%(TestConsoleAppSourceFiles.SkipOnTestRuntimes)').Contains('$(PackageRID)'))">
<ProjectCompileItems>%(Identity)</ProjectCompileItems>
<ProjectCompileItems>%(FullPath)</ProjectCompileItems>
</TestConsoleApps>
<TestConsoleApps AdditionalProperties="MSBuildEnableWorkloadResolver=$(MSBuildEnableWorkloadResolver)" Condition="'$(MSBuildEnableWorkloadResolver)' != ''" />
</ItemGroup>
Expand Down Expand Up @@ -134,12 +134,12 @@
Outputs="_unused"
Condition="'$(ArchiveTests)' != 'true'">

<Message Importance="High" Text="[Trimming Tests] Running test: %(TestConsoleApps.ProjectCompileItems)..." />
<Message Importance="High" Text="[Trimming Tests] Running test: %(TestConsoleApps.ProjectCompileItems) ..." />
<Exec IgnoreExitCode="true" Command="%(TestConsoleApps.TestCommand)" StandardOutputImportance="Low" WorkingDirectory="%(TestConsoleApps.TestExecutionDirectory)">
<Output TaskParameter="ExitCode" PropertyName="ExecutionExitCode" />
</Exec>

<Error Condition="'$(ExecutionExitCode)' != '100'" Text="Error: [Failed Test]: %(TestConsoleApps.ProjectCompileItems) The Command %(TestConsoleApps.TestCommand) return a non-success exit code." ContinueOnError="ErrorAndContinue" />
<Error Condition="'$(ExecutionExitCode)' != '100'" Text="Error: [Failed Test]: %(TestConsoleApps.ProjectCompileItems). The Command %(TestConsoleApps.TestCommand) return a non-success exit code." ContinueOnError="ErrorAndContinue" />
</Target>

<Target Name="Build" DependsOnTargets="ExecuteApplications" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Program
{
static int Main(string[] args)
{
// Ensure the internal GlobalizationMode class is trimmed correctly
Type globalizationMode = GetCoreLibType("System.Globalization.GlobalizationMode");
const BindingFlags allStatics = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;

try
Expand All @@ -29,32 +27,42 @@ static int Main(string[] args)
{
return -3;
}

// Ensure the internal GlobalizationMode class is trimmed correctly.
Type globalizationMode = GetCoreLibType("System.Globalization.GlobalizationMode");

foreach (MemberInfo member in globalizationMode.GetMembers(allStatics))
if (OperatingSystem.IsWindows())
{
// properties and their backing getter methods are OK
if (member is PropertyInfo || member.Name.StartsWith("get_"))
foreach (MemberInfo member in globalizationMode.GetMembers(allStatics))
{
continue;
}
// properties and their backing getter methods are OK
if (member is PropertyInfo || member.Name.StartsWith("get_"))
{
continue;
}

if (OperatingSystem.IsWindows())
{
// Windows still contains a static cctor and a backing field for UseNls
// Windows still contains a static cctor and a backing field for UseNls.
if (member is ConstructorInfo || (member is FieldInfo field && field.Name.Contains("UseNls")))
{
continue;
}
}

// Some unexpected member was left on GlobalizationMode, fail
Console.WriteLine($"Member '{member.Name}' was not trimmed from GlobalizationMode, but should have been.");
return -4;
// Some unexpected member was left on GlobalizationMode, fail
Console.WriteLine($"Member '{member.Name}' was not trimmed from GlobalizationMode, but should have been.");
return -4;
}
}
// On non Windows platforms, the full type is trimmed.
else if (globalizationMode is not null)
{
Console.WriteLine("It is expected to have System.Globalization.GlobalizationMode type trimmed in non-Windows platforms");
return -5;
}

return 100;
}

// The intention of this method is to ensure the trimmer doesn't preserve the Type.
private static Type GetCoreLibType(string name) =>
typeof(object).Assembly.GetType(name, throwOnError: true);
typeof(object).Assembly.GetType(name, throwOnError: false);
}
2 changes: 1 addition & 1 deletion src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Build for NetCoreAppCurrent by default if no BuildTargetFramework is supplied or if not all configurations are built. -->
<TargetFramework>$([MSBuild]::ValueOrDefault('$(BuildTargetFramework)', '$(NetCoreAppCurrent)'))-$(TargetOS)</TargetFramework>
<!-- Filter ProjectReferences to build the best matching target framework only. -->
<FilterTraversalProjectReferences>true</FilterTraversalProjectReferences>
<FilterTraversalProjectReferences Condition="'$(TestTrimming)' != 'true'">true</FilterTraversalProjectReferences>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 35e4779

Please sign in to comment.