From 43aa37935673802a8f36175463834fbbf9170d92 Mon Sep 17 00:00:00 2001 From: Mike Voorhees Date: Thu, 17 Aug 2017 13:23:13 -0400 Subject: Add ability to compile assemblies before and after a test case Can now compile .il files into assemblies Add support for [Define] to set defines for a test case Implement some basic type forwarding test cases --- .../Metadata/DefineAttribute.cs | 12 ++ .../Metadata/SetupCompileAfterAttribute.cs | 18 +++ .../Metadata/SetupCompileBeforeAttribute.cs | 18 +++ .../Mono.Linker.Tests.Cases.Expectations.csproj | 3 + .../Mono.Linker.Tests.Cases.csproj | 12 ++ .../TestFramework/CanCompileILAssembly.cs | 15 ++ .../TestFramework/Dependencies/ILAssemblySample.cs | 21 +++ .../TestFramework/Dependencies/ILAssemblySample.il | 73 ++++++++++ .../TestFramework/VerifyDefineAttributeBehavior.cs | 26 ++++ .../Dependencies/ForwarderLibrary.cs | 3 + .../Dependencies/ImplementationLibrary.cs | 12 ++ .../Dependencies/LibraryUsingForwarder.cs | 12 ++ .../Dependencies/ReferenceImplementationLibrary.cs | 17 +++ .../TypeForwarderOnlyAssembliesKept.cs | 28 ++++ .../TypeForwarderOnlyAssembliesRemoved.cs | 29 ++++ linker/Tests/Mono.Linker.Tests.csproj | 3 + linker/Tests/TestCases/TestDatabase.cs | 12 ++ linker/Tests/TestCases/TestSuites.cs | 12 ++ linker/Tests/TestCasesRunner/CompilerOptions.cs | 11 ++ linker/Tests/TestCasesRunner/ILCompiler.cs | 72 ++++++++++ linker/Tests/TestCasesRunner/ObjectFactory.cs | 4 +- linker/Tests/TestCasesRunner/SetupCompileInfo.cs | 12 ++ linker/Tests/TestCasesRunner/TestCaseCollector.cs | 8 ++ linker/Tests/TestCasesRunner/TestCaseCompiler.cs | 160 +++++++++++++++++++-- .../TestCasesRunner/TestCaseMetadaProvider.cs | 34 +++++ linker/Tests/TestCasesRunner/TestCaseSandbox.cs | 23 +++ linker/Tests/TestCasesRunner/TestRunner.cs | 2 +- 27 files changed, 640 insertions(+), 12 deletions(-) create mode 100644 linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/DefineAttribute.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TestFramework/CanCompileILAssembly.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TestFramework/Dependencies/ILAssemblySample.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TestFramework/Dependencies/ILAssemblySample.il create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TestFramework/VerifyDefineAttributeBehavior.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ForwarderLibrary.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ImplementationLibrary.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/LibraryUsingForwarder.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ReferenceImplementationLibrary.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesKept.cs create mode 100644 linker/Tests/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesRemoved.cs create mode 100644 linker/Tests/TestCasesRunner/CompilerOptions.cs create mode 100644 linker/Tests/TestCasesRunner/ILCompiler.cs create mode 100644 linker/Tests/TestCasesRunner/SetupCompileInfo.cs (limited to 'linker') diff --git a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/DefineAttribute.cs b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/DefineAttribute.cs new file mode 100644 index 000000000..14e95fd4d --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/DefineAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Metadata { + [AttributeUsage (AttributeTargets.Class, AllowMultiple = true)] + public class DefineAttribute : BaseMetadataAttribute { + public DefineAttribute (string name) + { + if (string.IsNullOrEmpty (name)) + throw new ArgumentException ("Value cannot be null or empty.", nameof (name)); + } + } +} diff --git a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs new file mode 100644 index 000000000..fa580a2f8 --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs @@ -0,0 +1,18 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Metadata { + /// + /// Use to compile an assembly after compiling the main test case executabe + /// + [AttributeUsage (AttributeTargets.Class, AllowMultiple = true)] + public class SetupCompileAfterAttribute : BaseMetadataAttribute { + public SetupCompileAfterAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null) + { + if (sourceFiles == null) + throw new ArgumentNullException (nameof (sourceFiles)); + + if (string.IsNullOrEmpty (outputName)) + throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); + } + } +} diff --git a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs new file mode 100644 index 000000000..d9a3bd658 --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs @@ -0,0 +1,18 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Metadata { + /// + /// Use to compile an assembly before compiling the main test case executabe + /// + [AttributeUsage (AttributeTargets.Class, AllowMultiple = true)] + public class SetupCompileBeforeAttribute : BaseMetadataAttribute { + public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, bool addAsReference = true) + { + if (sourceFiles == null) + throw new ArgumentNullException (nameof (sourceFiles)); + + if (string.IsNullOrEmpty (outputName)) + throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); + } + } +} diff --git a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj index fb1b6e3e1..20c4a9479 100644 --- a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj +++ b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj @@ -51,7 +51,10 @@ + + + diff --git a/linker/Tests/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj b/linker/Tests/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj index be75f1d64..364c892e9 100644 --- a/linker/Tests/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj +++ b/linker/Tests/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj @@ -60,6 +60,15 @@ + + + + + + + + + @@ -154,6 +163,9 @@ Mono.Linker.Tests.Cases.Expectations + + +