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:
authorMateo Torres-Ruiz <mateoatr@users.noreply.github.com>2020-03-19 10:20:54 +0300
committerGitHub <noreply@github.com>2020-03-19 10:20:54 +0300
commitced48a4fe1c19a23dc8f8a213060dc53502ae88b (patch)
treeb73f4453b59e20db137864f58598c3476d92f637 /test/Mono.Linker.Tests
parent461e313c839bac4ac9f53932ca5df1778a586dce (diff)
Add the command line option `--output-pinvokes` (#992)
* Add the command line option `--output-pinvokes` * Remove unnecessary memory stream * Address feedback * Sort list of pinvokes, add unreachable DllImports to the tests * Remove redundant if, change comparison order of PInvokeInfo * Use an overload of Zip that is compatible with .NET 4.7.71 * Use StringComparison.Ordinal when comparing PInvokeInfo fields Use List for storing PInvokeInfos * Copy PInvokes json to tests output directory
Diffstat (limited to 'test/Mono.Linker.Tests')
-rw-r--r--test/Mono.Linker.Tests/Mono.Linker.Tests.csproj9
-rw-r--r--test/Mono.Linker.Tests/TestCases/Dependencies/PInvokesExpectations.json32
-rw-r--r--test/Mono.Linker.Tests/TestCases/IndividualTests.cs28
3 files changed, 67 insertions, 2 deletions
diff --git a/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj b/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
index e4b13a53c..2e93533ee 100644
--- a/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
+++ b/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
@@ -64,6 +64,12 @@
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>
+ <ItemGroup>
+ <None Update="TestCases\Dependencies\PInvokesExpectations.json">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ </ItemGroup>
+
<Target Name="RunTestsOnMono" Condition="'$(MonoBuild)' != ''">
<Exec Command="mono $(PkgNUnit_ConsoleRunner)/tools/nunit3-console.exe --result=TestResults.xml $(OutputPath)Mono.Linker.Tests.dll" />
</Target>
@@ -72,8 +78,7 @@
<!-- Arcade's custom test imports assume that we are using xunit. -->
<!-- Map the Arcade "Test" target to the "VSTest" target used by "dotnet test" -->
- <Target Name="Test"
- Condition="'$(MonoBuild)' == ''">
+ <Target Name="Test" Condition="'$(MonoBuild)' == ''">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="VSTest" />
</Target>
diff --git a/test/Mono.Linker.Tests/TestCases/Dependencies/PInvokesExpectations.json b/test/Mono.Linker.Tests/TestCases/Dependencies/PInvokesExpectations.json
new file mode 100644
index 000000000..872915eca
--- /dev/null
+++ b/test/Mono.Linker.Tests/TestCases/Dependencies/PInvokesExpectations.json
@@ -0,0 +1,32 @@
+[
+ {
+ "assembly": "copyassembly.dll",
+ "entryPoint": "CustomEntryPoint",
+ "fullName": "Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.Dependencies.CanOutputPInvokes_CopyAssembly Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.Dependencies.CanOutputPInvokes_CopyAssembly::CustomEntryPoint()",
+ "moduleName": "lib_copyassembly"
+ },
+ {
+ "assembly": "copyassembly.dll",
+ "entryPoint": "FooEntryPoint",
+ "fullName": "Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.Dependencies.CanOutputPInvokes_CopyAssembly Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.Dependencies.CanOutputPInvokes_CopyAssembly::FooEntryPoint()",
+ "moduleName": "lib_copyassembly"
+ },
+ {
+ "assembly": "test.exe",
+ "entryPoint": "CustomEntryPoint",
+ "fullName": "Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.CanOutputPInvokes\/Foo Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.CanOutputPInvokes::CustomEntryPoint()",
+ "moduleName": "lib"
+ },
+ {
+ "assembly": "test.exe",
+ "entryPoint": "CustomEntryPoint",
+ "fullName": "Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.CanOutputPInvokes\/Foo Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.CanOutputPInvokes::CustomEntryPoint0()",
+ "moduleName": "lib"
+ },
+ {
+ "assembly": "test.exe",
+ "entryPoint": "FooEntryPoint",
+ "fullName": "Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.CanOutputPInvokes\/Foo Mono.Linker.Tests.Cases.Interop.PInvoke.Individual.CanOutputPInvokes::FooEntryPoint()",
+ "moduleName": "lib"
+ }
+] \ No newline at end of file
diff --git a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
index 439caf37e..7ded3ee80 100644
--- a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
+++ b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs
@@ -1,12 +1,18 @@
using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.Serialization.Json;
using System.Xml;
using Mono.Cecil;
using Mono.Linker.Tests.Cases.CommandLine.Mvid;
+using Mono.Linker.Tests.Cases.Interop.PInvoke.Individual;
using Mono.Linker.Tests.Cases.References.Individual;
using Mono.Linker.Tests.Cases.Tracing.Individual;
using Mono.Linker.Tests.Extensions;
using Mono.Linker.Tests.TestCasesRunner;
using NUnit.Framework;
+using NUnit.Framework.Internal;
namespace Mono.Linker.Tests.TestCases
{
@@ -27,6 +33,28 @@ namespace Mono.Linker.Tests.TestCases
}
[Test]
+ public void CanOutputPInvokes ()
+ {
+ var testcase = CreateIndividualCase (typeof (CanOutputPInvokes));
+ var result = Run (testcase);
+
+ var outputPath = result.OutputAssemblyPath.Parent.Combine ("pinvokes.json");
+ if (!outputPath.Exists ())
+ Assert.Fail ($"The json file with the list of all the PInvokes found by the linker is missing. Expected it to exist at {outputPath}");
+
+ var jsonSerializer = new DataContractJsonSerializer (typeof (List<PInvokeInfo>));
+
+ using (var fsActual = File.Open(outputPath, FileMode.Open))
+ using (var fsExpected = File.Open("TestCases/Dependencies/PInvokesExpectations.json", FileMode.Open)) {
+ var actual = jsonSerializer.ReadObject (fsActual) as List<PInvokeInfo>;
+ var expected = jsonSerializer.ReadObject (fsExpected) as List<PInvokeInfo>;
+ foreach (var pinvokePair in Enumerable.Zip(actual, expected, (fst, snd) => Tuple.Create(fst, snd))) {
+ Assert.That (pinvokePair.Item1.CompareTo (pinvokePair.Item2), Is.EqualTo (0));
+ }
+ }
+ }
+
+ [Test]
public void CanEnableDependenciesDump ()
{
var testcase = CreateIndividualCase (typeof (CanEnableDependenciesDump));