Skip to content

Commit f2d4f88

Browse files
Merge a couple NativeAOT smoke tests (#65426)
Shaves off a couple dozen seconds of test build time.
1 parent f1337d9 commit f2d4f88

File tree

12 files changed

+62
-66
lines changed

12 files changed

+62
-66
lines changed

src/tests/nativeaot/SmokeTests/BasicThreading/BasicThreading.csproj

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/tests/nativeaot/SmokeTests/ControlFlowGuard/ControlFlowGuard.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Runtime.CompilerServices;
78
using System.Runtime.InteropServices;
89
using System.Text;
@@ -129,6 +130,10 @@ class Test<T>
129130
public override string ToString() => "TotallyUniqueString";
130131
}
131132

133+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:UnrecognizedReflectionPattern",
134+
Justification = "Hiding the parameter to Type.GetType on purpose")]
135+
[UnconditionalSuppressMessage("AotAnalysis", "IL3050:UnrecognizedReflectionPattern",
136+
Justification = "MakeGenericType is over a reference type")]
132137
public static int Run()
133138
{
134139
// Obscure `typeof(string)` so that dataflow analysis can't see it and the MakeGenericType

src/tests/nativeaot/SmokeTests/Delegates/Delegates.csproj

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/tests/nativeaot/SmokeTests/Interfaces/Interfaces.csproj

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/tests/nativeaot/SmokeTests/Threading/Threading.csproj

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/tests/nativeaot/SmokeTests/BasicThreading/BasicThreading.cs renamed to src/tests/nativeaot/SmokeTests/UnitTests/BasicThreading.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99

10-
class Program
10+
class BasicThreading
1111
{
1212
public const int Pass = 100;
1313
public const int Fail = -1;
1414

15-
static int Main()
15+
internal static int Run()
1616
{
1717
SimpleReadWriteThreadStaticTest.Run(42, "SimpleReadWriteThreadStatic");
1818

@@ -54,12 +54,12 @@ public static int Run()
5454
if (visited)
5555
{
5656
Console.WriteLine("FinalizeTest passed");
57-
return Program.Pass;
57+
return BasicThreading.Pass;
5858
}
5959
else
6060
{
6161
Console.WriteLine("FinalizeTest failed");
62-
return Program.Fail;
62+
return BasicThreading.Fail;
6363
}
6464
}
6565
}
@@ -510,7 +510,7 @@ public static int Run()
510510

511511
TestConcurrentIsBackgroundProperty();
512512

513-
return (s_failed == 0) ? Program.Pass : Program.Fail;
513+
return (s_failed == 0) ? BasicThreading.Pass : BasicThreading.Fail;
514514
}
515515

516516
/// <summary>
@@ -605,7 +605,7 @@ public static int Run()
605605
if (!timerFired)
606606
{
607607
Console.WriteLine("The timer test failed: timer has not fired.");
608-
return Program.Fail;
608+
return BasicThreading.Fail;
609609
}
610610

611611
// Change the timer to a very long value
@@ -615,7 +615,7 @@ public static int Run()
615615
if (timerFired)
616616
{
617617
Console.WriteLine("The timer test failed: timer fired earlier than expected.");
618-
return Program.Fail;
618+
return BasicThreading.Fail;
619619
}
620620

621621
// Try change existing timer to a small value and make sure it fires
@@ -625,7 +625,7 @@ public static int Run()
625625
if (!timerFired)
626626
{
627627
Console.WriteLine("The timer test failed: failed to change the existing timer.");
628-
return Program.Fail;
628+
return BasicThreading.Fail;
629629
}
630630

631631
// Test a periodic timer
@@ -638,14 +638,14 @@ public static int Run()
638638
if (!timerFired)
639639
{
640640
Console.WriteLine("The timer test failed: the periodic timer has not fired.");
641-
return Program.Fail;
641+
return BasicThreading.Fail;
642642
}
643643
}
644644

645645
// Stop the periodic timer
646646
s_timer.Change(Timeout.Infinite, Timeout.Infinite);
647647

648-
return Program.Pass;
648+
return BasicThreading.Pass;
649649
}
650650

651651
private static void TimerCallback(object state)

src/tests/nativeaot/SmokeTests/Delegates/Delegates.cs renamed to src/tests/nativeaot/SmokeTests/UnitTests/Delegates.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
using Pointer = System.Reflection.Pointer;
88

9-
public class BringUpTests
9+
public class Delegates
1010
{
1111
const int Pass = 100;
1212
const int Fail = -1;
1313

14-
public static int Main()
14+
public static int Run()
1515
{
1616
int result = Pass;
1717

src/tests/nativeaot/SmokeTests/Generics/Generics.cs renamed to src/tests/nativeaot/SmokeTests/UnitTests/Generics.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using System.Collections.Generic;
77
using System.Runtime.CompilerServices;
88

9-
class Program
9+
class Generics
1010
{
11-
static int Main()
11+
internal static int Run()
1212
{
1313
TestDictionaryDependencyTracking.Run();
1414
TestStaticBaseLookups.Run();
@@ -2748,9 +2748,9 @@ class Atom3 { }
27482748
public static void Run()
27492749
{
27502750
var derived = new Derived<Atom1, Atom2>();
2751-
if (ConstrainedCall<Derived<Atom1, Atom2>, Atom2, Atom3>(ref derived) != "Derived<Program+TestConstrainedGvmCalls+Atom1,Program+TestConstrainedGvmCalls+Atom2>.Method<Program+TestConstrainedGvmCalls+Atom3>()")
2751+
if (ConstrainedCall<Derived<Atom1, Atom2>, Atom2, Atom3>(ref derived) != "Derived<Generics+TestConstrainedGvmCalls+Atom1,Generics+TestConstrainedGvmCalls+Atom2>.Method<Generics+TestConstrainedGvmCalls+Atom3>()")
27522752
throw new Exception();
2753-
if (ConstrainedCall<Derived<Atom1, Atom2>, Atom1, Atom3>(ref derived) != "Base<Program+TestConstrainedGvmCalls+Atom1>.Method<Program+TestConstrainedGvmCalls+Atom3>()")
2753+
if (ConstrainedCall<Derived<Atom1, Atom2>, Atom1, Atom3>(ref derived) != "Base<Generics+TestConstrainedGvmCalls+Atom1>.Method<Generics+TestConstrainedGvmCalls+Atom3>()")
27542754
throw new Exception();
27552755
}
27562756
}

src/tests/nativeaot/SmokeTests/Interfaces/Interfaces.cs renamed to src/tests/nativeaot/SmokeTests/UnitTests/Interfaces.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
using System.Runtime.CompilerServices;
88
using System.Runtime.InteropServices;
99

10-
public class BringUpTest
10+
public class Interfaces
1111
{
1212
const int Pass = 100;
1313
const int Fail = -1;
1414

15-
public static int Main()
15+
public static int Run()
1616
{
1717
if (TestInterfaceCache() == Fail)
1818
return Fail;
@@ -576,10 +576,10 @@ public static void Run()
576576

577577
var x = new Derived<Atom1, Atom2>() { InnerValue = "My inner value" };
578578
string r1 = ((IFace<Atom1>)x).GrabValue(new Atom1());
579-
if (r1 != "'My inner value' over 'BringUpTest+TestSharedIntefaceMethods+Atom1' with 'The Atom1'")
579+
if (r1 != "'My inner value' over 'Interfaces+TestSharedIntefaceMethods+Atom1' with 'The Atom1'")
580580
throw new Exception();
581581
string r2 = ((IFace<Atom2>)x).GrabValue(new Atom2());
582-
if (r2 != "'My inner value' over 'BringUpTest+TestSharedIntefaceMethods+Atom2' with 'The Atom2'")
582+
if (r2 != "'My inner value' over 'Interfaces+TestSharedIntefaceMethods+Atom2' with 'The Atom2'")
583583
throw new Exception();
584584

585585
IFace<object> o = new Yadda() { InnerValue = "SomeString" };
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
7+
bool success = RunTest(BasicThreading.Run);
8+
success &= RunTest(Delegates.Run);
9+
success &= RunTest(Generics.Run);
10+
success &= RunTest(Interfaces.Run);
11+
success &= RunTest(Threading.Run);
12+
13+
return success ? 100 : 1;
14+
15+
static bool RunTest(Func<int> t, [CallerArgumentExpression("t")] string name = null)
16+
{
17+
Console.WriteLine($"===== Running test {name} =====");
18+
bool success = true;
19+
try
20+
{
21+
success = t() == 100;
22+
}
23+
catch (Exception ex)
24+
{
25+
Console.WriteLine(ex.ToString());
26+
success = false;
27+
}
28+
Console.WriteLine($"===== Test {name} {(success ? "succeeded" : "failed")} =====");
29+
return success;
30+
}

src/tests/nativeaot/SmokeTests/Threading/Threading.cs renamed to src/tests/nativeaot/SmokeTests/UnitTests/Threading.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
// TODO: Move these tests to CoreFX once they can be run on CoreRT
1111

12-
internal static class Runner
12+
internal static class Threading
1313
{
1414
private const int Pass = 100;
1515

16-
public static int Main()
16+
public static int Run()
1717
{
1818
Console.WriteLine(" WaitSubsystemTests.DoubleSetOnEventWithTimedOutWaiterShouldNotStayInWaitersList");
1919
WaitSubsystemTests.DoubleSetOnEventWithTimedOutWaiterShouldNotStayInWaitersList();

src/tests/nativeaot/SmokeTests/Generics/Generics.csproj renamed to src/tests/nativeaot/SmokeTests/UnitTests/UnitTests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
</PropertyGroup>
1313
<ItemGroup>
14+
<Compile Include="BasicThreading.cs" />
15+
<Compile Include="Delegates.cs" />
1416
<Compile Include="Generics.cs" />
17+
<Compile Include="Interfaces.cs" />
18+
<Compile Include="Threading.cs" />
19+
<Compile Include="Main.cs" />
1520
</ItemGroup>
1621
</Project>

0 commit comments

Comments
 (0)