Skip to content

Commit

Permalink
Merge branch 'icsharpcode:master' into GuessFakeMethodAccessor
Browse files Browse the repository at this point in the history
  • Loading branch information
fowl2 authored May 20, 2022
2 parents e563294 + c0f0135 commit 4aaf452
Show file tree
Hide file tree
Showing 35 changed files with 649 additions and 137 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/build-ilspy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: msbuild ILSpy.sln /p:Configuration=${{ matrix.configuration }} /p:Platform=$env:BuildPlatform /m

- name: Execute unit tests
run: dotnet test --logger "trx;LogFileName=${{ matrix.configuration }}-test-results.trx" $env:Tests1 $env:Tests2 $env:Tests3
run: dotnet test --logger "junit;LogFileName=${{ matrix.configuration }}.xml" --results-directory test-results $env:Tests1 $env:Tests2 $env:Tests3
env:
Tests1: ICSharpCode.Decompiler.Tests\bin\${{ matrix.configuration }}\net6.0-windows\win-x64\ICSharpCode.Decompiler.Tests.dll
Tests2: ILSpy.Tests\bin\${{ matrix.configuration }}\net6.0-windows\ILSpy.Tests.dll
Expand All @@ -58,17 +58,13 @@ jobs:
if: success() || failure()
with:
name: test-results-${{ matrix.configuration }}
path: '**/*.trx'
path: 'test-results/${{ matrix.configuration }}.xml'

- name: Create Test Report
uses: phoenix-actions/test-reporting@v6
if: github.event_name != 'pull_request' && (success() || failure())
uses: test-summary/action@v1
if: always()
with:
name: Unit Test Results (${{ matrix.configuration }})
path: '**/*.trx'
reporter: dotnet-trx
list-suites: 'all'
list-tests: 'failed'
paths: "test-results/${{ matrix.configuration }}.xml"

- name: Format check
run: python BuildTools\tidy.py
Expand Down
5 changes: 4 additions & 1 deletion ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ public static List<string> GetPreprocessorSymbols(CompilerOptions flags)
}
if ((flags & CompilerOptions.UseRoslynMask) != 0)
{
preprocessorSymbols.Add("NETCORE");
if (!flags.HasFlag(CompilerOptions.TargetNet40))
{
preprocessorSymbols.Add("NETCORE");
}
preprocessorSymbols.Add("ROSLYN");
preprocessorSymbols.Add("CS60");
preprocessorSymbols.Add("VB11");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnitAdapterVersion)" />
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<!-- used for xml test result files -->
<PackageReference Include="JunitXml.TestLogger" Version="$(JUnitXmlTestLoggerVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" />
Expand Down Expand Up @@ -108,6 +110,7 @@
<Compile Include="Output\InsertParenthesesVisitorTests.cs" />
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
<Compile Include="TestAssemblyResolver.cs" />
<None Include="TestCases\Pretty\MetadataAttributes.cs" />
<None Include="TestCases\Correctness\ComInterop.cs" />
<Compile Include="TestCases\Correctness\DeconstructionTests.cs" />
<Compile Include="TestCases\Correctness\DynamicTests.cs" />
Expand Down Expand Up @@ -309,6 +312,7 @@

<ItemGroup>
<Content Include="TestCases\PdbGen\ForLoopTests.xml" />
<Content Include="TestCases\PdbGen\CustomPdbId.xml" />
<Content Include="TestCases\PdbGen\HelloWorld.xml" />
<Content Include="TestCases\PdbGen\LambdaCapturing.xml" />
</ItemGroup>
Expand Down
47 changes: 41 additions & 6 deletions ICSharpCode.Decompiler.Tests/PdbGenerationTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down Expand Up @@ -46,18 +47,38 @@ public void LambdaCapturing()
TestGeneratePdb();
}

[Test]
public void CustomPdbId()
{
// Generate a PDB for an assembly using a randomly-generated ID, then validate that the PDB uses the specified ID
(string peFileName, string pdbFileName) = CompileTestCase(nameof(CustomPdbId));

var moduleDefinition = new PEFile(peFileName);
var resolver = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Metadata.DetectTargetFrameworkId(), null, PEStreamOptions.PrefetchEntireImage);
var decompiler = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings());
var expectedPdbId = new BlobContentId(Guid.NewGuid(), (uint)Random.Shared.Next());

using (FileStream pdbStream = File.Open(Path.Combine(TestCasePath, nameof(CustomPdbId) + ".pdb"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
pdbStream.SetLength(0);
PortablePdbWriter.WritePdb(moduleDefinition, decompiler, new DecompilerSettings(), pdbStream, noLogo: true, pdbId: expectedPdbId);

pdbStream.Position = 0;
var metadataReader = MetadataReaderProvider.FromPortablePdbStream(pdbStream).GetMetadataReader();
var generatedPdbId = new BlobContentId(metadataReader.DebugMetadataHeader.Id);

Assert.AreEqual(expectedPdbId.Guid, generatedPdbId.Guid);
Assert.AreEqual(expectedPdbId.Stamp, generatedPdbId.Stamp);
}
}

private void TestGeneratePdb([CallerMemberName] string testName = null)
{
const PdbToXmlOptions options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeMethodSpans;

string xmlFile = Path.Combine(TestCasePath, testName + ".xml");
string xmlContent = File.ReadAllText(xmlFile);
XDocument document = XDocument.Parse(xmlContent);
var files = document.Descendants("file").ToDictionary(f => f.Attribute("name").Value, f => f.Value);
Tester.CompileCSharpWithPdb(Path.Combine(TestCasePath, testName + ".expected"), files);
(string peFileName, string pdbFileName) = CompileTestCase(testName);

string peFileName = Path.Combine(TestCasePath, testName + ".expected.dll");
string pdbFileName = Path.Combine(TestCasePath, testName + ".expected.pdb");
var moduleDefinition = new PEFile(peFileName);
var resolver = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Metadata.DetectTargetFrameworkId(), null, PEStreamOptions.PrefetchEntireImage);
var decompiler = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings());
Expand Down Expand Up @@ -87,6 +108,20 @@ private void TestGeneratePdb([CallerMemberName] string testName = null)
Assert.AreEqual(Normalize(expectedFileName), Normalize(generatedFileName));
}

private (string peFileName, string pdbFileName) CompileTestCase(string testName)
{
string xmlFile = Path.Combine(TestCasePath, testName + ".xml");
string xmlContent = File.ReadAllText(xmlFile);
XDocument document = XDocument.Parse(xmlContent);
var files = document.Descendants("file").ToDictionary(f => f.Attribute("name").Value, f => f.Value);
Tester.CompileCSharpWithPdb(Path.Combine(TestCasePath, testName + ".expected"), files);

string peFileName = Path.Combine(TestCasePath, testName + ".expected.dll");
string pdbFileName = Path.Combine(TestCasePath, testName + ".expected.pdb");

return (peFileName, pdbFileName);
}

private void ProcessXmlFile(string fileName)
{
var document = XDocument.Load(fileName);
Expand Down
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,12 @@ public async Task StaticAbstractInterfaceMembers([ValueSource(nameof(roslynLates
await RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview);
}

[Test]
public async Task MetadataAttributes([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions);
}

async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
{
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override void Close()
pc = 2;
}

public override bool get_CheckClose()
public bool get_CheckClose()
{
switch (pc)
{
Expand All @@ -106,7 +106,7 @@ public override bool get_CheckClose()

[DebuggerNonUserCode]
[CompilerGenerated]
public override int get_LastGenerated()
public int get_LastGenerated()
{
return current;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public override void Close()
pc = 2;
}

public override bool get_CheckClose()
public bool get_CheckClose()
{
switch (pc)
{
Expand All @@ -107,7 +107,7 @@ public override bool get_CheckClose()

[DebuggerNonUserCode]
[CompilerGenerated]
public override int get_LastGenerated()
public int get_LastGenerated()
{
return current;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class SequenceOfNestedIfs
{
public bool _clear;
public Material _material;
public override bool CheckShader()
public virtual bool CheckShader()
{
return false;
}
public override void CreateMaterials()
public virtual void CreateMaterials()
{
if (!_clear)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ internal class UnknownTypes
{
private readonly IInterface memberField;

public override bool CanExecute(CallbackQuery message)
public virtual bool CanExecute(CallbackQuery message)
{
return ((IInterface<SomeClass, bool>)(object)memberField).Execute(new SomeClass {
ChatId = StaticClass.GetChatId(message),
Expand Down
19 changes: 19 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/PdbGen/CustomPdbId.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<symbols>
<files>
<file id="1" name="ICSharpCode.Decompiler.Tests.TestCases.PdbGen\HelloWorld.cs" language="C#" checksumAlgorithm="SHA256"><![CDATA[using System;
namespace ICSharpCode.Decompiler.Tests.TestCases.PdbGen;
public class HelloWorld
{
public static void Main(string[] args)
{
Console.ReadKey();
Console.WriteLine("Hello World!");
Console.ReadKey();
}
}
]]></file>
</files>
</symbols>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal class MetadataAttributes
{
private class MethodImplAttr
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public extern void A();
#if NETCORE
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public extern void B();
#endif
[MethodImpl(MethodImplOptions.ForwardRef)]
public extern void D();
[MethodImpl(MethodImplOptions.InternalCall)]
public extern void E();
[MethodImpl(MethodImplOptions.NoInlining)]
public extern void F();
[MethodImpl(MethodImplOptions.NoOptimization)]
public extern void G();
[PreserveSig]
public extern void H();
[MethodImpl(MethodImplOptions.Synchronized)]
public extern void I();
[MethodImpl(MethodImplOptions.Unmanaged)]
public extern void J();
[MethodImpl(MethodImplOptions.AggressiveInlining, MethodCodeType = MethodCodeType.Native)]
public extern void A1();
#if NETCORE
[MethodImpl(MethodImplOptions.AggressiveOptimization, MethodCodeType = MethodCodeType.Native)]
public extern void B1();
#endif
[MethodImpl(MethodImplOptions.ForwardRef, MethodCodeType = MethodCodeType.Native)]
public extern void D1();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Native)]
public extern void E1();
[MethodImpl(MethodImplOptions.NoInlining, MethodCodeType = MethodCodeType.Native)]
public extern void F1();
[MethodImpl(MethodImplOptions.NoOptimization, MethodCodeType = MethodCodeType.Native)]
public extern void G1();
[MethodImpl(MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.Native)]
public extern void H1();
[MethodImpl(MethodImplOptions.Synchronized, MethodCodeType = MethodCodeType.Native)]
public extern void I1();
[MethodImpl(MethodImplOptions.Unmanaged, MethodCodeType = MethodCodeType.Native)]
public extern void J1();
[MethodImpl(MethodImplOptions.AggressiveInlining, MethodCodeType = MethodCodeType.OPTIL)]
public extern void A2();
#if NETCORE
[MethodImpl(MethodImplOptions.AggressiveOptimization, MethodCodeType = MethodCodeType.OPTIL)]
public extern void B2();
#endif
[MethodImpl(MethodImplOptions.ForwardRef, MethodCodeType = MethodCodeType.OPTIL)]
public extern void D2();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.OPTIL)]
public extern void E2();
[MethodImpl(MethodImplOptions.NoInlining, MethodCodeType = MethodCodeType.OPTIL)]
public extern void F2();
[MethodImpl(MethodImplOptions.NoOptimization, MethodCodeType = MethodCodeType.OPTIL)]
public extern void G2();
[MethodImpl(MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.OPTIL)]
public extern void H2();
[MethodImpl(MethodImplOptions.Synchronized, MethodCodeType = MethodCodeType.OPTIL)]
public extern void I2();
[MethodImpl(MethodImplOptions.Unmanaged, MethodCodeType = MethodCodeType.OPTIL)]
public extern void J2();
[MethodImpl(MethodImplOptions.AggressiveInlining, MethodCodeType = MethodCodeType.OPTIL)]
public extern void A3();
#if NETCORE
[MethodImpl(MethodImplOptions.AggressiveOptimization, MethodCodeType = MethodCodeType.Runtime)]
public extern void B3();
#endif
[MethodImpl(MethodImplOptions.ForwardRef, MethodCodeType = MethodCodeType.Runtime)]
public extern void D3();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern void E3();
[MethodImpl(MethodImplOptions.NoInlining, MethodCodeType = MethodCodeType.Runtime)]
public extern void F3();
[MethodImpl(MethodImplOptions.NoOptimization, MethodCodeType = MethodCodeType.Runtime)]
public extern void G3();
[MethodImpl(MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.Runtime)]
public extern void H3();
[MethodImpl(MethodImplOptions.Synchronized, MethodCodeType = MethodCodeType.Runtime)]
public extern void I3();
[MethodImpl(MethodImplOptions.Unmanaged, MethodCodeType = MethodCodeType.Runtime)]
public extern void J3();
}
}
}
Loading

0 comments on commit 4aaf452

Please sign in to comment.