Skip to content

Commit 1a19c09

Browse files
authored
Convert all tests under baseservices to the merged test infrastructure (#91560)
* Remove unused args parameter from the Main method in 349379.cs * Convert stackoverflowtester Main to individual test entrypoints * Don't complain about Exe type for test components Some tests have exe components - if these aren't marked with the CLRTestKind BuildAndRun, we shouldn't complain about them. Thanks Tomas * Make dynamicmethodliveness and ParallelCrash merge-friendly * Adjust the Tier1StackTrace test to be tolerant to merged wrappers * Convert baseservices/exceptions to merged mode * Remove constant return value 100 from the test test448035 * Make UnsafeAccessorTests owner class public * Make methods in RuntimeConfiguration/TestConfig public * Make TieredCompilation/BasicTest public * Remove unused exit code of runmoduleconstructor * Remove unused exit code of RuntimeHelperTests * Fix visibility in multidimarray/enum test * Fix visibility in TestCallingConventions test * Fix visibility in CriticalFinalizer test * Simplify RuntimeConfiguration/TestConfig * Clean up TieredCompilation tests * Convert istypeequivalent to use ConditionalFact clauses * Fix visibility in RuntimeHelpersTests * Add CoreCLRTestLibrary as a dependency of istypeequivalent * Fix merged behavior of test448035 * Fix entrypoint in 305155 * Modify TestConfig to use a separate TestConfigTester app * Additional fixes to TestConfig / TestConfigTester * Mechanically merge all remaining tests under baseservices * Fix BasicTestWithMcj, address initial Mark's PR feedback * Remove superfluous OutputType=Library annotations per Marks' PR feedback * Fix the baseservices/exceptions/unhandled test * Fix stackoverflow3 and unhandled exception tests * Remove unnecessary check from Directory.Build.targets * Fix stackoverflowtester per Mark's PR feedback
1 parent b6b00ec commit 1a19c09

File tree

373 files changed

+1343
-856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

373 files changed

+1343
-856
lines changed

src/tests/baseservices/CET/CheckCETPresence.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
using System;
55
using System.Runtime.InteropServices;
6+
using Xunit;
67

7-
static class Program
8+
public static class Program
89
{
910
[DllImport("cet_check.dll")]
1011
private static extern long ReadShadowStackPointer();
1112

12-
public static int Main()
13+
[Fact]
14+
public static int TestEntryPoint()
1315
{
1416
Console.WriteLine("Checking whether codeflow enforcement technology (CET) is active");
1517
long ssp = ReadShadowStackPointer();

src/tests/baseservices/CET/CheckCETPresence.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
43
<RequiresCodeFlowEnforcement>true</RequiresCodeFlowEnforcement>
54
<RequiresProcessIsolation>true</RequiresProcessIsolation>
65
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64' or '$(TargetOS)' != 'windows'">true</CLRTestTargetUnsupported>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Merged.props', $(MSBuildThisFileDirectory)..))" />
4+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', $(MSBuildThisFileDirectory)..))" />
5+
6+
<PropertyGroup>
7+
<RunAnalyzers>true</RunAnalyzers>
8+
<NoWarn>$(NoWarn);xUnit1013</NoWarn>
9+
<EnableNETAnalyzers>false</EnableNETAnalyzers>
10+
</PropertyGroup>
11+
</Project>

src/tests/baseservices/RuntimeConfiguration/TestConfig.cs

Lines changed: 13 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -11,152 +11,78 @@
1111

1212
using Xunit;
1313

14-
class TestConfig
14+
public class TestConfig
1515
{
16-
const int Success = 100;
17-
const int Fail = 101;
16+
public const int Success = 100;
17+
public const int Fail = 101;
1818

19-
[Fact]
2019
[EnvVar("DOTNET_gcServer", "1")]
21-
static int Verify_ServerGC_Env_Enable(string[] _)
20+
public static int Verify_ServerGC_Env_Enable()
2221
{
2322
return GCSettings.IsServerGC
2423
? Success
2524
: Fail;
2625
}
2726

28-
[Fact]
2927
[EnvVar("DOTNET_gcServer", "0")]
30-
static int Verify_ServerGC_Env_Disable(string[] _)
28+
public static int Verify_ServerGC_Env_Disable()
3129
{
3230
return GCSettings.IsServerGC
3331
? Fail
3432
: Success;
3533
}
3634

37-
[Fact]
3835
[ConfigProperty("System.GC.Server", "true")]
39-
static int Verify_ServerGC_Prop_Enable(string[] _)
36+
public static int Verify_ServerGC_Prop_Enable()
4037
{
4138
return GCSettings.IsServerGC
4239
? Success
4340
: Fail;
4441
}
4542

46-
[Fact]
4743
[ConfigProperty("System.GC.Server", "false")]
48-
static int Verify_ServerGC_Prop_Disable(string[] _)
44+
public static int Verify_ServerGC_Prop_Disable()
4945
{
5046
return GCSettings.IsServerGC
5147
? Fail
5248
: Success;
5349
}
5450

55-
[Fact]
5651
[EnvVar("DOTNET_gcServer", "0")]
5752
[ConfigProperty("System.GC.Server", "true")]
58-
static int Verify_ServerGC_Env_Override_Prop(string[] _)
53+
public static int Verify_ServerGC_Env_Override_Prop()
5954
{
6055
return GCSettings.IsServerGC
6156
? Fail
6257
: Success;
6358
}
6459

60+
#if !IS_TESTER_APP
6561
static int Main(string[] args)
6662
{
67-
if (args.Length == 0)
68-
{
69-
return RunTests();
70-
}
71-
7263
MethodInfo infos = typeof(TestConfig).GetMethod(args[0], BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
7364
if (infos is null)
7465
{
7566
return Fail;
7667
}
77-
return (int)infos.Invoke(null, new object[] { args[1..] });
68+
return (int)infos.Invoke(null, Array.Empty<object>());
7869
}
70+
#endif
7971

8072
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
81-
class EnvVarAttribute : Attribute
73+
public class EnvVarAttribute : Attribute
8274
{
8375
public EnvVarAttribute(string name, string value) { Name = name; Value = value; }
8476
public string Name { get; init; }
8577
public string Value { get; init; }
8678
}
8779

8880
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
89-
class ConfigPropertyAttribute : Attribute
81+
public class ConfigPropertyAttribute : Attribute
9082
{
9183
public ConfigPropertyAttribute(string name, string value) { Name = name; Value = value; }
9284
public string Name { get; init; }
9385
public string Value { get; init; }
9486
}
9587

96-
static int RunTests()
97-
{
98-
// clear some environment variables that we will set during the test run
99-
Environment.SetEnvironmentVariable("DOTNET_gcServer", null);
100-
101-
string corerunPath = GetCorerunPath();
102-
MethodInfo[] infos = typeof(TestConfig).GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
103-
foreach (var mi in infos)
104-
{
105-
var factMaybe = mi.GetCustomAttributes(typeof(FactAttribute));
106-
if (!factMaybe.Any())
107-
{
108-
continue;
109-
}
110-
111-
using Process process = new();
112-
113-
StringBuilder arguments = new();
114-
var configProperties = mi.GetCustomAttributes(typeof(ConfigPropertyAttribute));
115-
116-
foreach (Attribute cp in configProperties)
117-
{
118-
ConfigPropertyAttribute configProp = (ConfigPropertyAttribute)cp;
119-
arguments.Append($"-p {configProp.Name}={configProp.Value} ");
120-
}
121-
122-
arguments.Append($"\"{System.Reflection.Assembly.GetExecutingAssembly().Location}\" {mi.Name}");
123-
124-
process.StartInfo.FileName = corerunPath;
125-
process.StartInfo.Arguments = arguments.ToString();
126-
127-
var envVariables = mi.GetCustomAttributes(typeof(EnvVarAttribute));
128-
foreach (string key in Environment.GetEnvironmentVariables().Keys)
129-
{
130-
process.StartInfo.EnvironmentVariables[key] = Environment.GetEnvironmentVariable(key);
131-
}
132-
133-
Console.WriteLine($"Running: {process.StartInfo.Arguments}");
134-
foreach (Attribute ev in envVariables)
135-
{
136-
EnvVarAttribute envVar = (EnvVarAttribute)ev;
137-
process.StartInfo.EnvironmentVariables[envVar.Name] = envVar.Value;
138-
Console.WriteLine($" set {envVar.Name}={envVar.Value}");
139-
}
140-
141-
process.Start();
142-
process.WaitForExit();
143-
if (process.ExitCode != Success)
144-
{
145-
Console.WriteLine($"Failed: {mi.Name}");
146-
return process.ExitCode;
147-
}
148-
}
149-
150-
return Success;
151-
}
152-
153-
static string GetCorerunPath()
154-
{
155-
string corerunName = "corerun";
156-
if (TestLibrary.Utilities.IsWindows)
157-
{
158-
corerunName += ".exe";
159-
}
160-
return Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"), corerunName);
161-
}
16288
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
4-
<!-- This test provides no interesting scenarios for GCStress -->
5-
<GCStressIncompatible>true</GCStressIncompatible>
6-
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
7-
<DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'Mono'">true</DisableProjectBuild>
3+
<!-- This is a separate app launched by the actual test in TestConfigTester.csproj -->
4+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
5+
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>
6+
<CLRTestKind>BuildOnly</CLRTestKind>
87
</PropertyGroup>
98
<ItemGroup>
109
<Compile Include="TestConfig.cs" />
1110
</ItemGroup>
12-
<ItemGroup>
13-
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
14-
</ItemGroup>
1511
</Project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.Diagnostics;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Reflection;
9+
using System.Runtime;
10+
using System.Text;
11+
12+
using Xunit;
13+
14+
public class TestConfigTester
15+
{
16+
[Fact]
17+
public static void RunTests()
18+
{
19+
// clear some environment variables that we will set during the test run
20+
Environment.SetEnvironmentVariable("DOTNET_gcServer", null);
21+
22+
string testConfigApp = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestConfig.dll");
23+
24+
MethodInfo[] infos = typeof(TestConfig).GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
25+
26+
string corerunPath = GetCorerunPath();
27+
foreach (var mi in infos)
28+
{
29+
var configProperties = mi.GetCustomAttributes(typeof(TestConfig.ConfigPropertyAttribute));
30+
var envVariables = mi.GetCustomAttributes(typeof(TestConfig.EnvVarAttribute));
31+
32+
if (configProperties.Count() == 0 && envVariables.Count() == 0)
33+
{
34+
continue;
35+
}
36+
37+
using Process process = new();
38+
39+
StringBuilder arguments = new();
40+
41+
foreach (Attribute cp in configProperties)
42+
{
43+
TestConfig.ConfigPropertyAttribute configProp = (TestConfig.ConfigPropertyAttribute)cp;
44+
arguments.Append($"-p {configProp.Name}={configProp.Value} ");
45+
}
46+
47+
arguments.Append($"\"{testConfigApp}\" {mi.Name}");
48+
49+
process.StartInfo.FileName = corerunPath;
50+
process.StartInfo.Arguments = arguments.ToString();
51+
52+
foreach (string key in Environment.GetEnvironmentVariables().Keys)
53+
{
54+
process.StartInfo.EnvironmentVariables[key] = Environment.GetEnvironmentVariable(key);
55+
}
56+
57+
Console.WriteLine($"Running: {process.StartInfo.Arguments}");
58+
foreach (Attribute ev in envVariables)
59+
{
60+
TestConfig.EnvVarAttribute envVar = (TestConfig.EnvVarAttribute)ev;
61+
process.StartInfo.EnvironmentVariables[envVar.Name] = envVar.Value;
62+
Console.WriteLine($" set {envVar.Name}={envVar.Value}");
63+
}
64+
65+
process.Start();
66+
process.WaitForExit();
67+
if (process.ExitCode != TestConfig.Success)
68+
{
69+
throw new Exception($"Failed: {mi.Name}: exit code = {process.ExitCode}");
70+
}
71+
}
72+
}
73+
74+
static string GetCorerunPath()
75+
{
76+
string corerunName = "corerun";
77+
if (TestLibrary.Utilities.IsWindows)
78+
{
79+
corerunName += ".exe";
80+
}
81+
return Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"), corerunName);
82+
}
83+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<!-- This test provides no interesting scenarios for GCStress -->
4+
<GCStressIncompatible>true</GCStressIncompatible>
5+
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
6+
<DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'Mono'">true</DisableProjectBuild>
7+
<DefineConstants>$(DefineConstants);IS_TESTER_APP</DefineConstants>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="$(MSBuildProjectName).cs" />
11+
<Compile Include="TestConfig.cs" />
12+
</ItemGroup>
13+
<ItemGroup>
14+
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
15+
<ProjectReference Include="$(MSBuildThisFileDirectory)TestConfig.csproj">
16+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
17+
<OutputItemType>Content</OutputItemType>
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</ProjectReference>
20+
</ItemGroup>
21+
</Project>

src/tests/baseservices/TieredCompilation/BasicTest.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
using System;
55
using System.Runtime.CompilerServices;
66
using System.Threading;
7+
using Xunit;
78

89
public static class BasicTest
910
{
10-
private static int Main()
11+
[Fact]
12+
public static void TestEntryPoint()
1113
{
12-
const int Pass = 100;
13-
1414
PromoteToTier1(Foo, () => FooWithLoop(2));
1515
Foo();
1616
FooWithLoop(2);
17-
18-
return Pass;
1917
}
2018

2119
[MethodImpl(MethodImplOptions.NoInlining)]

src/tests/baseservices/TieredCompilation/BasicTestWithMcj.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public struct MCJTestStruct
1717
{
1818
}
1919

20-
private static int Main()
20+
public static int Main()
2121
{
2222
const int Pass = 100;
2323

@@ -45,6 +45,7 @@ private static int Main()
4545
FooWithGeneric(RegexOptions.IgnoreCase);
4646

4747
ProfileOptimization.StartProfile(null);
48+
4849
return Pass;
4950
}
5051

src/tests/baseservices/TieredCompilation/BasicTestWithMcj.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3+
<!-- Needs to build an exe with explicit Main as the MCJ functionality seems not to play well -->
4+
<!-- with the Roslyn-generated wrapper. -->
5+
<!-- Needed for CLRTestTargetUnsupported -->
6+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
37
<OutputType>Exe</OutputType>
8+
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>
9+
410
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
511
<Optimize>true</Optimize>
612
<!-- Generated shell script and corresponding assembly have different names -->

0 commit comments

Comments
 (0)