Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
Test="true" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true'"/>
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler.Compiler.Tests\ILCompiler.Compiler.Tests.csproj"
Test="true" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(NativeAotSupported)' == 'true'"/>
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\Mono.Linker.Tests\Mono.Linker.Tests.csproj"
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler.Tests\ILCompiler.Tests.csproj"
Comment thread
sbomer marked this conversation as resolved.
Test="true" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(NativeAotSupported)' == 'true'"/>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersion)" />

<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="Microsoft.DotNet.Cecil" Version="$(MicrosoftDotNetCecilVersion)" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="5.0.1" />
<ProjectReference Include="$(RepoRoot)/src/tools/illink/test/Mono.Linker.Tests.Cases/**/*.csproj" />
<ProjectReference Include="$(RepoRoot)/src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj" />
<ProjectReference Include="$(ToolsProjectRoot)illink/test/Mono.Linker.Tests.Cases/**/*.csproj" />
<ProjectReference Include="$(ToolsProjectRoot)illink/test/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj" />
<ProjectReference Include="../ILCompiler.Compiler/ILCompiler.Compiler.csproj" />
<ProjectReference Include="../ILCompiler.RyuJit/ILCompiler.RyuJit.csproj" />

Expand All @@ -45,8 +45,10 @@
<Value>$(ArtifactsBinDir)</Value>
</RuntimeHostConfigurationOption>
<RuntimeHostConfigurationOption Include="Mono.Linker.Tests.LinkerTestDir">
<Value>$(RepoRoot)/src/tools/illink/test/</Value>
<Value>$(ToolsProjectRoot)illink/test/</Value>
</RuntimeHostConfigurationOption>
</ItemGroup>

<Import Project="$(ToolsProjectRoot)illink\test\Mono.Linker.Tests.Shared\Mono.Linker.Tests.Shared.projitems" Label="Shared" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LinkedMethodEntity : LinkedEntity
private readonly BaseAssemblyResolver originalsResolver;
private readonly ReaderParameters originalReaderParameters;
private readonly AssemblyDefinition originalAssembly;
private readonly ILCompilerTestCaseResult testResult;
private readonly TrimmedTestCaseResult testResult;

private readonly Dictionary<AssemblyQualifiedToken, LinkedEntity> linkedMembers;
private readonly HashSet<string> verifiedGeneratedFields = new HashSet<string> ();
Expand All @@ -67,7 +67,7 @@ public AssemblyChecker (
BaseAssemblyResolver originalsResolver,
ReaderParameters originalReaderParameters,
AssemblyDefinition original,
ILCompilerTestCaseResult testResult)
TrimmedTestCaseResult testResult)
{
this.originalsResolver = originalsResolver;
this.originalReaderParameters = originalReaderParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public MemberAssertionsCollector(Type type)

private CompilerTypeSystemContext CreateTypeSystemContext ()
{
ILCompilerDriver.ComputeDefaultOptions (out var targetOS, out var targetArchitecture);
TrimmingDriver.ComputeDefaultOptions (out var targetOS, out var targetArchitecture);
var targetDetails = new TargetDetails (targetArchitecture, targetOS, TargetAbi.NativeAot);
CompilerTypeSystemContext typeSystemContext =
new CompilerTypeSystemContext (targetDetails, SharedGenericsMode.CanonicalReferenceTypes, DelegateFeature.All);
Expand All @@ -49,7 +49,7 @@ private CompilerTypeSystemContext CreateTypeSystemContext ()
references.Add (assembly.GetName ().Name!, assembly.Location!);
}
typeSystemContext.ReferenceFilePaths = references;
typeSystemContext.SetSystemModule (typeSystemContext.GetModuleForSimpleName (ILCompilerDriver.DefaultSystemModule));
typeSystemContext.SetSystemModule (typeSystemContext.GetModuleForSimpleName (TrimmingDriver.DefaultSystemModule));

return typeSystemContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public virtual TestCaseCompiler CreateCompiler (TestCaseSandbox sandbox, TestCas
return new TestCaseCompiler (sandbox, metadataProvider);
}

public virtual ILCompilerDriver CreateTrimmer ()
public virtual TrimmingDriver CreateTrimmer ()
{
return new ILCompilerDriver ();
return new TrimmingDriver ();
}

public virtual TestCaseMetadataProvider CreateMetadataProvider (TestCase testCase, AssemblyDefinition expectationsAssemblyDefinition)
Expand All @@ -33,9 +33,9 @@ public virtual TestCaseCompilationMetadataProvider CreateCompilationMetadataProv
return new TestCaseCompilationMetadataProvider (testCase, fullTestCaseAssemblyDefinition);
}

public virtual ILCompilerOptionsBuilder CreateTrimmerOptionsBuilder (TestCaseMetadataProvider metadataProvider)
public virtual TrimmingArgumentBuilder CreateTrimmingArgumentBuilder (TestCaseMetadataProvider metadataProvider)
{
return new ILCompilerOptionsBuilder (metadataProvider);
return new TrimmingArgumentBuilder (metadataProvider);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ResultChecker (BaseAssemblyResolver originalsResolver,
_linkedReaderParameters = linkedReaderParameters;
}

public virtual void Check (ILCompilerTestCaseResult testResult)
public virtual void Check (TrimmedTestCaseResult testResult)
{
InitializeResolvers (testResult);

Expand Down Expand Up @@ -85,12 +85,12 @@ bool HasActiveSkipKeptItemsValidationAttribute(ICustomAttributeProvider provider
}
}

protected virtual AssemblyChecker CreateAssemblyChecker (AssemblyDefinition original, ILCompilerTestCaseResult testResult)
protected virtual AssemblyChecker CreateAssemblyChecker (AssemblyDefinition original, TrimmedTestCaseResult testResult)
{
return new AssemblyChecker (_originalsResolver, _originalReaderParameters, original, testResult);
}

private void InitializeResolvers (ILCompilerTestCaseResult linkedResult)
private void InitializeResolvers (TrimmedTestCaseResult linkedResult)
{
_originalsResolver.AddSearchDirectory (linkedResult.ExpectationsAssemblyPath.Parent.ToString ());
}
Expand All @@ -103,7 +103,7 @@ protected AssemblyDefinition ResolveOriginalsAssembly (string assemblyName)
return _originalsResolver.Resolve (new AssemblyNameReference (cleanAssemblyName, null), _originalReaderParameters);
}

private static void PerformOutputAssemblyChecks (AssemblyDefinition original, ILCompilerTestCaseResult testResult)
private static void PerformOutputAssemblyChecks (AssemblyDefinition original, TrimmedTestCaseResult testResult)
{
var assembliesToCheck = original.MainModule.Types.SelectMany (t => t.CustomAttributes).Where (ExpectationsProvider.IsAssemblyAssertion);
var actionAssemblies = new HashSet<string> ();
Expand Down Expand Up @@ -147,13 +147,13 @@ private static void PerformOutputAssemblyChecks (AssemblyDefinition original, IL
}

#pragma warning disable IDE0060 // Remove unused parameter
private static void PerformOutputSymbolChecks (AssemblyDefinition original, ILCompilerTestCaseResult testResult)
private static void PerformOutputSymbolChecks (AssemblyDefinition original, TrimmedTestCaseResult testResult)
#pragma warning restore IDE0060 // Remove unused parameter
{
// While NativeAOT has symbols, verifying them is rather difficult
}

protected virtual void AdditionalChecking (ILCompilerTestCaseResult linkResult, AssemblyDefinition original)
protected virtual void AdditionalChecking (TrimmedTestCaseResult linkResult, AssemblyDefinition original)
{
bool checkRemainingErrors = !HasAttribute (linkResult.TestCase.FindTypeDefinition (original), nameof (SkipRemainingErrorsValidationAttribute));
VerifyLoggedMessages (original, linkResult.LogWriter, checkRemainingErrors);
Expand All @@ -180,12 +180,12 @@ private static IEnumerable<ICustomAttributeProvider> GetAttributeProviders (Asse
yield return assembly;
}

protected virtual void InitialChecking (ILCompilerTestCaseResult testResult, AssemblyDefinition original)
protected virtual void InitialChecking (TrimmedTestCaseResult testResult, AssemblyDefinition original)
{
// PE verifier is done here in ILLinker, but that's not possible with NativeAOT
}

private void VerifyLoggedMessages (AssemblyDefinition original, TestLogWriter logger, bool checkRemainingErrors)
private void VerifyLoggedMessages (AssemblyDefinition original, TrimmingTestLogger logger, bool checkRemainingErrors)
{
List<MessageContainer> loggedMessages = logger.GetLoggedMessages ();
List<(ICustomAttributeProvider, CustomAttribute)> expectedNoWarningsAttributes = new ();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mono.Cecil;
using Mono.Linker.Tests.Extensions;
using Mono.Linker.Tests.TestCases;
using Xunit.Sdk;

namespace Mono.Linker.Tests.TestCasesRunner
{
public partial class TestRunner
{
partial void IgnoreTest (string reason)
{
throw new IgnoreTestException (reason);
}

static IEnumerable<string> additionalDefines = new string[] { "NATIVEAOT" };
private partial IEnumerable<string>? GetAdditionalDefines () => additionalDefines;

private static T GetResultOfTaskThatMakesAssertions<T> (Task<T> task)
{
try {
return task.Result;
} catch (AggregateException e) {
if (e.InnerException != null) {
if (e.InnerException is XunitException)
throw e.InnerException;
}

throw;
}
}

protected partial TrimmingCustomizations? CustomizeLinker (TrimmingDriver linker, TestCaseMetadataProvider metadataProvider)
=> null;

static partial void AddOutputDirectory (TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TrimmingArgumentBuilder builder)
{
builder.AddOutputDirectory (sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileNameWithoutExtension + ".obj"));
}

static partial void AddInputReference (NPath inputReference, TrimmingArgumentBuilder builder)
{
// It's important to add all assemblies as "link" assemblies since the default configuration
// is to run the compiler in multi-file mode which will not process anything which is just in the reference set.
builder.AddLinkAssembly (inputReference);
builder.AddReference (inputReference);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,39 @@

namespace Mono.Linker.Tests.TestCasesRunner
{
public class ILCompilerTestCaseResult
public class TrimmedTestCaseResult
{
public readonly TestCase TestCase;
public readonly NPath InputAssemblyPath;
public readonly NPath ExpectationsAssemblyPath;
public readonly TestCaseSandbox Sandbox;
public readonly TestCaseMetadataProvider MetadataProvider;
public readonly ManagedCompilationResult CompilationResult;
public readonly TrimmingTestLogger LogWriter;
public readonly ILScanResults TrimmingResults;
public readonly TestLogWriter LogWriter;

public ILCompilerTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadataProvider metadataProvider, ManagedCompilationResult compilationResult, ILScanResults trimmingResults, TestLogWriter logWriter)
public TrimmedTestCaseResult (
TestCase testCase,
NPath inputAssemblyPath,
NPath outputAssemblyPath,
NPath expectationsAssemblyPath,
TestCaseSandbox sandbox,
TestCaseMetadataProvider metadataProvider,
ManagedCompilationResult compilationResult,
TrimmingTestLogger logWriter,
TrimmingCustomizations? customizations,
ILScanResults trimmingResults)
{
// Ignore outputAssemblyPath because ILCompiler trimming tests don't write output assemblies.
// Ignore TrimmingCustomizatoins which are not used by ILCompiler trimming tests.
TestCase = testCase;
InputAssemblyPath = inputAssemblyPath;
ExpectationsAssemblyPath = expectationsAssemblyPath;
Sandbox = sandbox;
MetadataProvider = metadataProvider;
CompilationResult = compilationResult;
TrimmingResults = trimmingResults;
CompilationResult = compilationResult;
LogWriter = logWriter;
TrimmingResults = trimmingResults;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

namespace Mono.Linker.Tests.TestCasesRunner
{
public class ILCompilerOptionsBuilder
public class TrimmingArgumentBuilder
{
//public TrimmerOptions Options { get; } = new();
private readonly TestCaseMetadataProvider _metadataProvider;

public readonly ILCompilerOptions Options;
private ILCompilerOptions? _options;
private ILCompilerOptions Options => _options ?? throw new InvalidOperationException ("Invalid state: Build() was already called");

public ILCompilerOptionsBuilder (TestCaseMetadataProvider metadataProvider)
public TrimmingArgumentBuilder (TestCaseMetadataProvider metadataProvider)
{
Options = new ILCompilerOptions ();
_options = new ILCompilerOptions ();
_metadataProvider = metadataProvider;

string runtimeBinDir = (string) AppContext.GetData ("Mono.Linker.Tests.RuntimeBinDirectory")!;
Expand Down Expand Up @@ -260,5 +260,12 @@ private static void AppendExpandedPaths (Dictionary<string, string> dictionary,
throw new Exception ("No files matching " + pattern);
}
}

public ILCompilerOptions Build ()
{
var options = Options;
_options = null;
return options;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

namespace Mono.Linker.Tests.TestCasesRunner
{
public class ILCompilerDriver
public class TrimmingDriver
{
internal const string DefaultSystemModule = "System.Private.CoreLib";

public ILScanResults Trim (ILCompilerOptions options, ILogWriter logWriter)
public ILScanResults Trim (ILCompilerOptions options, TrimmingCustomizations? customizations, ILogWriter logWriter)
{
ComputeDefaultOptions (out var targetOS, out var targetArchitecture);
var targetDetails = new TargetDetails (targetArchitecture, targetOS, TargetAbi.NativeAot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

namespace Mono.Linker.Tests.TestCasesRunner
{
public class TestLogWriter : ILogWriter
public class TrimmingTestLogger : ILogWriter
{
private readonly StringWriter _infoStringWriter;
private readonly TextWriter _infoWriter;

private readonly List<MessageContainer> _messageContainers;

public TestLogWriter ()
public TrimmingTestLogger ()
{
_infoStringWriter = new StringWriter ();
_infoWriter = TextWriter.Synchronized (_infoStringWriter);
Expand Down
11 changes: 11 additions & 0 deletions src/coreclr/tools/aot/ILCompiler.Tests/TrimmingCustomizations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.TestCasesRunner
{
public class TrimmingCustomizations
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
Comment thread
sbomer marked this conversation as resolved.
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)/**/*.cs" />
</ItemGroup>
</Project>
Loading