Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Voorhees <michaelv@unity3d.com>2019-05-28 17:07:15 +0300
committerMarek Safar <marek.safar@gmail.com>2019-05-28 20:13:29 +0300
commit02e203cf4002861ff6b5ef134a8aa314d3dfb616 (patch)
treec84d25ea5a130f501a83a9e3679c852a760b5d62 /test/Mono.Linker.Tests
parent5e4dcbfdcd82e61277683dd7c0eb6222cc634c68 (diff)
Add mvid tests
Diffstat (limited to 'test/Mono.Linker.Tests')
-rw-r--r--test/Mono.Linker.Tests/TestCases/IndividualTests.cs84
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs8
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs8
3 files changed, 98 insertions, 2 deletions
diff --git a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
index cdc269de6..2badf7322 100644
--- a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
+++ b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
@@ -1,8 +1,11 @@
using System;
using System.IO;
using System.Xml;
+using Mono.Cecil;
+using Mono.Linker.Tests.Cases.CommandLine.Mvid;
using Mono.Linker.Tests.Cases.References.Individual;
using Mono.Linker.Tests.Cases.Tracing.Individual;
+using Mono.Linker.Tests.Extensions;
using Mono.Linker.Tests.TestCases;
using Mono.Linker.Tests.TestCasesRunner;
using NUnit.Framework;
@@ -79,6 +82,87 @@ namespace Mono.Linker.Tests.TestCases
Assert.That (lineCount, Is.LessThan (expectedMaxLines), $"There were `{lineCount}` lines in the dump file. This is more than expected max of {expectedMaxLines} and likely indicates reduced tracing was not enabled. Dump file can be found at: {outputPath}");
}
+ [Test]
+ public void DeterministicMvidWorks()
+ {
+ var testCase = CreateIndividualCase (typeof (DeterministicMvidWorks));
+ var runner = new TestRunner (new ObjectFactory ());
+ var result = runner.Run (testCase);
+
+ var originalMvid = GetMvid (result.InputAssemblyPath);
+ var firstOutputMvid = GetMvid (result.OutputAssemblyPath);
+ Assert.That (firstOutputMvid, Is.Not.EqualTo (originalMvid));
+
+ var result2 = runner.Relink(result);
+
+ var secondOutputMvid = GetMvid(result2.OutputAssemblyPath);
+ Assert.That (secondOutputMvid, Is.Not.EqualTo (originalMvid));
+ // The id should match the first output since we relinked the same assembly
+ Assert.That (secondOutputMvid, Is.EqualTo (firstOutputMvid));
+ }
+
+ [Test]
+ public void NewMvidWorks ()
+ {
+ var testCase = CreateIndividualCase (typeof (NewMvidWorks));
+ var runner = new TestRunner (new ObjectFactory ());
+ var result = runner.Run (testCase);
+
+ var originalMvid = GetMvid (result.InputAssemblyPath);
+ var firstOutputMvid = GetMvid (result.OutputAssemblyPath);
+ Assert.That (firstOutputMvid, Is.Not.EqualTo (originalMvid));
+
+ var result2 = runner.Relink (result);
+
+ var secondOutputMvid = GetMvid (result2.OutputAssemblyPath);
+ Assert.That (secondOutputMvid, Is.Not.EqualTo (originalMvid));
+ Assert.That (secondOutputMvid, Is.Not.EqualTo (firstOutputMvid));
+ }
+
+ [Test]
+ public void RetainMvidWorks ()
+ {
+ var testCase = CreateIndividualCase (typeof (RetainMvid));
+ var runner = new TestRunner (new ObjectFactory ());
+ var result = runner.Run (testCase);
+
+ var originalMvid = GetMvid (result.InputAssemblyPath);
+ var firstOutputMvid = GetMvid (result.OutputAssemblyPath);
+ Assert.That (firstOutputMvid, Is.EqualTo (originalMvid));
+
+ var result2 = runner.Relink (result);
+
+ var secondOutputMvid = GetMvid (result2.OutputAssemblyPath);
+ Assert.That (secondOutputMvid, Is.EqualTo (originalMvid));
+ Assert.That (secondOutputMvid, Is.EqualTo (firstOutputMvid));
+ }
+
+ [Test]
+ public void DefaultMvidBehavior ()
+ {
+ var testCase = CreateIndividualCase (typeof (NewMvidWorks));
+ var runner = new TestRunner (new ObjectFactory ());
+ var result = runner.Run (testCase);
+
+ var originalMvid = GetMvid (result.InputAssemblyPath);
+ var firstOutputMvid = GetMvid (result.OutputAssemblyPath);
+ Assert.That (firstOutputMvid, Is.Not.EqualTo (originalMvid));
+
+ var result2 = runner.Relink (result);
+
+ var secondOutputMvid = GetMvid (result2.OutputAssemblyPath);
+ Assert.That (secondOutputMvid, Is.Not.EqualTo (originalMvid));
+ Assert.That (secondOutputMvid, Is.Not.EqualTo (firstOutputMvid));
+ }
+
+ protected Guid GetMvid (NPath assemblyPath)
+ {
+ using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath))
+ {
+ return assembly.MainModule.Mvid;
+ }
+ }
+
private TestCase CreateIndividualCase (Type testCaseType)
{
return TestDatabase.CreateCollector ().CreateIndividualCase (testCaseType);
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs b/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs
index 2d05f6d09..821334c12 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs
@@ -7,13 +7,19 @@ namespace Mono.Linker.Tests.TestCasesRunner {
public readonly NPath InputAssemblyPath;
public readonly NPath OutputAssemblyPath;
public readonly NPath ExpectationsAssemblyPath;
+ public readonly TestCaseSandbox Sandbox;
+ public readonly TestCaseMetadaProvider MetadataProvider;
+ public readonly ManagedCompilationResult CompilationResult;
- public LinkedTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath)
+ public LinkedTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadaProvider metadaProvider, ManagedCompilationResult compilationResult)
{
TestCase = testCase;
InputAssemblyPath = inputAssemblyPath;
OutputAssemblyPath = outputAssemblyPath;
ExpectationsAssemblyPath = expectationsAssemblyPath;
+ Sandbox = sandbox;
+ MetadataProvider = metadaProvider;
+ CompilationResult = compilationResult;
}
}
} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs
index fc421882e..1ce4a2c68 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs
@@ -31,6 +31,12 @@ namespace Mono.Linker.Tests.TestCasesRunner {
}
}
+ public virtual LinkedTestCaseResult Relink (LinkedTestCaseResult result)
+ {
+ PrepForLink (result.Sandbox, result.CompilationResult);
+ return Link (result.TestCase, result.Sandbox, result.CompilationResult, result.MetadataProvider);
+ }
+
private TestCaseSandbox Sandbox (TestCase testCase, TestCaseMetadaProvider metadataProvider)
{
var sandbox = _factory.CreateSandbox (testCase);
@@ -92,7 +98,7 @@ namespace Mono.Linker.Tests.TestCasesRunner {
linker.Link (builder.ToArgs ());
- return new LinkedTestCaseResult (testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath);
+ return new LinkedTestCaseResult (testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult);
}
protected virtual void AddLinkOptions (TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadaProvider metadataProvider)