Skip to content

Commit 4fb47b9

Browse files
Fix GenericsContextTest test bugs (#10)
- structures derive from System.ValueType not System.Valuetype - Expected strings need to handle generics a little bit more
1 parent 43c02cd commit 4fb47b9

File tree

4 files changed

+928
-8
lines changed

4 files changed

+928
-8
lines changed

src/tests/Loader/classloader/StaticVirtualMethods/GenericContext/Generator/Program.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ static void EmitCodeForCommonLibrary(TextWriter tw)
134134
tw.WriteLine(@" .method public newslot virtual abstract static void GenericMethod<U>() {}");
135135
tw.WriteLine(@"}");
136136
tw.WriteLine(@"");
137-
tw.WriteLine(@".class public auto ansi GenericStruct`1<T>");
138-
tw.WriteLine(@" extends[System.Runtime] System.Valuetype");
137+
tw.WriteLine(@".class public sealed auto ansi GenericStruct`1<T>");
138+
tw.WriteLine(@" extends[System.Runtime] System.ValueType");
139139
tw.WriteLine(@"{");
140140
tw.WriteLine(@"}");
141141
}
@@ -319,6 +319,27 @@ void GenerateMethodBody(bool genericMethod)
319319
methodNameToEmit = methodNameToEmit.Substring(0, methodNameToEmit.Length - 3);
320320
}
321321
implsGenerated.WriteLine($" ldstr \"{methodNameToEmit}\"");
322+
if (methodNameToEmit.Contains("!!0"))
323+
{
324+
implsGenerated.WriteLine($" ldstr \"!!0\"");
325+
implsGenerated.WriteLine($" ldtoken !!0");
326+
implsGenerated.WriteLine($" call string {CommonCsPrefix}Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)");
327+
implsGenerated.WriteLine($" call instance string [System.Runtime]System.String::Replace(string, string)");
328+
}
329+
if (methodNameToEmit.Contains("!!1"))
330+
{
331+
implsGenerated.WriteLine($" ldstr \"!!1\"");
332+
implsGenerated.WriteLine($" ldtoken !!1");
333+
implsGenerated.WriteLine($" call string {CommonCsPrefix}Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)");
334+
implsGenerated.WriteLine($" call instance string [System.Runtime]System.String::Replace(string, string)");
335+
}
336+
if (methodNameToEmit.Contains("!0"))
337+
{
338+
implsGenerated.WriteLine($" ldstr \"!0\"");
339+
implsGenerated.WriteLine($" ldtoken !0");
340+
implsGenerated.WriteLine($" call string {CommonCsPrefix}Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)");
341+
implsGenerated.WriteLine($" call instance string [System.Runtime]System.String::Replace(string, string)");
342+
}
322343
if (genericMethod)
323344
{
324345
implsGenerated.WriteLine($" ldstr \"<\"");
@@ -546,10 +567,22 @@ static void Main(string[] args)
546567

547568
EmitTestMethod();
548569

549-
string callCommand = $" call void TestEntrypoint::{basicTestMethodName}<{constrainedTypePrefix}{constrainedType},string>()";
570+
string callCommand = GetSetBangBang1IfNeeded("string") + $" call void TestEntrypoint::{basicTestMethodName}<{constrainedTypePrefix}{constrainedType},string>()";
550571
if (scenario.InterfaceType == InterfaceType.GenericOverObject)
551-
callCommand = callCommand + Environment.NewLine + $" call void TestEntrypoint::{basicTestMethodName}<{constrainedTypePrefix}{constrainedType},object>()";
572+
callCommand = callCommand + Environment.NewLine + GetSetBangBang1IfNeeded("object") + $" call void TestEntrypoint::{basicTestMethodName}<{constrainedTypePrefix}{constrainedType},object>()";
552573
CallTestEntrypoint(callCommand);
574+
575+
string GetSetBangBang1IfNeeded(string bangBang1Expected)
576+
{
577+
if (expectedString.Contains("!!1"))
578+
{
579+
return $" ldstr \"{bangBang1Expected}\"" + Environment.NewLine + " stsfld string [GenericContextCommonCs]Statics::BangBang1Param" + Environment.NewLine;
580+
}
581+
else
582+
{
583+
return "";
584+
}
585+
}
553586
break;
554587
default:
555588
throw new Exception("AACLL");
@@ -589,6 +622,12 @@ void EmitTestMethod()
589622
EmitILToCallActualMethod(swTestClassMethods);
590623
swTestClassMethods.WriteLine($" ldstr \"{scenario.ToString()}\"");
591624
swTestClassMethods.WriteLine($" ldstr \"{expectedString}\"");
625+
if (expectedString.Contains("!!1"))
626+
{
627+
swTestClassMethods.WriteLine(" ldstr \"!!1\"");
628+
swTestClassMethods.WriteLine(" ldsfld string [GenericContextCommonCs]Statics::BangBang1Param");
629+
swTestClassMethods.WriteLine(" call instance string [System.Runtime]System.String::Replace(string, string)");
630+
}
592631
swTestClassMethods.WriteLine($" call void {CommonCsPrefix}Statics::CheckForFailure(string,string)");
593632
swTestClassMethods.WriteLine($" ret");
594633
twIL = swTestClassMethods;

src/tests/Loader/classloader/StaticVirtualMethods/GenericContext/GenericContextCommonAndImplementation.il

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
.method public newslot virtual abstract static void GenericMethod<U>() {}
2626
}
2727

28-
.class public auto ansi GenericStruct`1<T>
29-
extends[System.Runtime] System.Valuetype
28+
.class public sealed auto ansi GenericStruct`1<T>
29+
extends[System.Runtime] System.ValueType
3030
{
3131
}
3232
.class public auto ansi NonGenericClass
@@ -351,6 +351,10 @@
351351
ldtoken class GenericClass`1<!0>
352352
call string [GenericContextCommonCs]Statics::MakeName(valuetype [System.Runtime]System.RuntimeTypeHandle)
353353
ldstr "'IFaceCuriouslyRecurringGeneric`1<class GenericClass`1<!0>>.NormalMethod'"
354+
ldstr "!0"
355+
ldtoken !0
356+
call string [GenericContextCommonCs]Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)
357+
call instance string [System.Runtime]System.String::Replace(string, string)
354358
call string[System.Runtime] System.String::Concat(string, string)
355359
stsfld string [GenericContextCommonCs]Statics::String
356360
ret
@@ -361,6 +365,10 @@
361365
ldtoken class GenericClass`1<!0>
362366
call string [GenericContextCommonCs]Statics::MakeName(valuetype [System.Runtime]System.RuntimeTypeHandle)
363367
ldstr "'IFaceCuriouslyRecurringGeneric`1<class GenericClass`1<!0>>.GenericMethod'"
368+
ldstr "!0"
369+
ldtoken !0
370+
call string [GenericContextCommonCs]Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)
371+
call instance string [System.Runtime]System.String::Replace(string, string)
364372
ldstr "<"
365373
ldtoken !!0
366374
call string [GenericContextCommonCs]Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)
@@ -460,6 +468,10 @@
460468
ldtoken valuetype GenericValuetype`1<!0>
461469
call string [GenericContextCommonCs]Statics::MakeName(valuetype [System.Runtime]System.RuntimeTypeHandle)
462470
ldstr "'IFaceCuriouslyRecurringGeneric`1<valuetype GenericValuetype`1<!0>>.NormalMethod'"
471+
ldstr "!0"
472+
ldtoken !0
473+
call string [GenericContextCommonCs]Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)
474+
call instance string [System.Runtime]System.String::Replace(string, string)
463475
call string[System.Runtime] System.String::Concat(string, string)
464476
stsfld string [GenericContextCommonCs]Statics::String
465477
ret
@@ -470,6 +482,10 @@
470482
ldtoken valuetype GenericValuetype`1<!0>
471483
call string [GenericContextCommonCs]Statics::MakeName(valuetype [System.Runtime]System.RuntimeTypeHandle)
472484
ldstr "'IFaceCuriouslyRecurringGeneric`1<valuetype GenericValuetype`1<!0>>.GenericMethod'"
485+
ldstr "!0"
486+
ldtoken !0
487+
call string [GenericContextCommonCs]Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)
488+
call instance string [System.Runtime]System.String::Replace(string, string)
473489
ldstr "<"
474490
ldtoken !!0
475491
call string [GenericContextCommonCs]Statics::MakeName(valuetype[System.Runtime]System.RuntimeTypeHandle)

src/tests/Loader/classloader/StaticVirtualMethods/GenericContext/GenericContextCommonCs.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ public static class Statics
99
public static string String;
1010
public static int Failures;
1111
public static int Successes;
12+
public static string BangBang1Param = "string";
1213
public static volatile IntPtr FtnHolder;
1314
public static volatile Action ActionHolder;
1415

1516
public static void CheckForFailure(string scenario, string expectedResult, string actualResult)
1617
{
1718
if (expectedResult != actualResult)
1819
{
19-
Console.WriteLine($"Scenario {scenario} failed - expected {expectedResult ?? "<null>"}, got {actualResult ?? "<null>"}");
20+
Console.WriteLine($"FAILURE({Failures}) - Scenario {scenario} failed - expected {expectedResult ?? "<null>"}, got {actualResult ?? "<null>"}");
2021
Failures++;
2122
}
2223
else
2324
{
24-
Console.WriteLine($"Scenario {scenario} succeeded ({expectedResult ?? "<null>"})");
25+
Console.WriteLine($"Scenario {scenario} succeeded ({expectedResult ?? "<null>"}) Success ({Successes})");
2526
Successes++;
2627
}
2728
}

0 commit comments

Comments
 (0)