Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Adding signature matching unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Nov 6, 2019
1 parent 1d77950 commit 0f3853c
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
Expand Up @@ -15,6 +15,7 @@
<Compile Include="InstanceFieldLayout.il" />
<Compile Include="StaticFieldLayout.il" />
<Compile Include="VirtualFunctionOverride.il" />
<Compile Include="Signature.il" />
</ItemGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
Expand Down
86 changes: 86 additions & 0 deletions src/ILCompiler.TypeSystem/tests/ILTestAssembly/Signature.il
@@ -0,0 +1,86 @@
.class private auto ansi beforefieldinit Atom
extends [CoreTestAssembly]System.Object
{
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [CoreTestAssembly]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method I::.ctor

} // end of class Atom

.class private auto ansi beforefieldinit A`1<U>
extends [CoreTestAssembly]System.Object
{
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [CoreTestAssembly]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method A`1::.ctor

} // end of class A`1

.class private auto ansi beforefieldinit BaseClass`2<U,T>
extends [CoreTestAssembly]System.Object
{
.method public hidebysig newslot virtual
instance void Method(!U u,
!T modopt (FooModifier) t) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method BaseClass`2::Method

.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [CoreTestAssembly]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method BaseClass`2::.ctor

} // end of class BaseClass`2

.class private auto ansi beforefieldinit DerivedClass
extends class BaseClass`2<class A`1<class Atom>,class Atom>
{
.method public hidebysig virtual instance void
Method(class A`1<class Atom> u,
class Atom modopt (FooModifier) t) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method DerivedClass::Method

.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void class BaseClass`2<class A`1<class Atom>,class Atom>::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method DerivedClass::.ctor

} // end of DerivedClass

.class public FooModifier { }
.class public BarModifier { }
53 changes: 53 additions & 0 deletions src/ILCompiler.TypeSystem/tests/SignatureTests.cs
@@ -0,0 +1,53 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Internal.IL;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

using Xunit;

namespace TypeSystemTests
{
public class SignatureTests
{
private TestTypeSystemContext _context;
private ModuleDesc _testModule;

public SignatureTests()
{
_context = new TestTypeSystemContext(TargetArchitecture.X64);
var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly");
_context.SetSystemModule(systemModule);

_testModule = _context.GetModuleForSimpleName("ILTestAssembly");
}

[Fact]
public void TestSignatureMatches()
{
MetadataType atomType = _testModule.GetType("", "Atom");
MetadataType aType = _testModule.GetType("", "A`1");
MetadataType aOfAtomType = aType.MakeInstantiatedType(new Instantiation(atomType));


MetadataType baseClassType = _testModule.GetType("", "BaseClass`2");
MethodDesc baseClassMethod = baseClassType.GetMethods().Single(m => string.Equals(m.Name, "Method"));
MethodSignature baseClassMethodSignature = baseClassMethod.Signature;
MethodSignatureBuilder matchingSignatureBuilder = new MethodSignatureBuilder(baseClassMethodSignature);
matchingSignatureBuilder[0] = aOfAtomType;
matchingSignatureBuilder[1] = atomType;
MethodSignature matchingSignature = matchingSignatureBuilder.ToSignature();

MetadataType derivedClassType = _testModule.GetType("", "DerivedClass");
MethodDesc derivedClassMethod = derivedClassType.GetMethods().Single(m => string.Equals(m.Name, "Method"));
MethodSignature derivedClassMethodSignature = derivedClassMethod.Signature;

Assert.True(matchingSignature.Equals(derivedClassMethodSignature));
}
}
}
3 changes: 2 additions & 1 deletion src/ILCompiler.TypeSystem/tests/TypeSystem.Tests.csproj
@@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<OutputType>Library</OutputType>
Expand Down Expand Up @@ -46,6 +46,7 @@
<Compile Include="ILDisassemblerTests.cs" />
<Compile Include="InterfacesTests.cs" />
<Compile Include="RuntimeDeterminedTypesTests.cs" />
<Compile Include="SignatureTests.cs" />
<Compile Include="SyntheticVirtualOverrideTests.cs" />
<Compile Include="TestMetadataFieldLayoutAlgorithm.cs" />
<Compile Include="TypeNameParsingTests.cs" />
Expand Down

0 comments on commit 0f3853c

Please sign in to comment.