Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all tests under baseservices to the merged test infrastructure #91560

Merged
merged 31 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
891eb5d
Remove unused args parameter from the Main method in 349379.cs
trylek Sep 1, 2023
fd7a035
Convert stackoverflowtester Main to individual test entrypoints
trylek Sep 1, 2023
4b33c72
Don't complain about Exe type for test components
trylek Sep 1, 2023
607fd21
Make dynamicmethodliveness and ParallelCrash merge-friendly
trylek Sep 1, 2023
5780f17
Adjust the Tier1StackTrace test to be tolerant to merged wrappers
trylek Sep 1, 2023
8b7b8e5
Convert baseservices/exceptions to merged mode
trylek Sep 1, 2023
c91f40a
Remove constant return value 100 from the test test448035
trylek Sep 1, 2023
3dcf689
Make UnsafeAccessorTests owner class public
trylek Sep 1, 2023
561ccc8
Make methods in RuntimeConfiguration/TestConfig public
trylek Sep 1, 2023
bd673ec
Make TieredCompilation/BasicTest public
trylek Sep 1, 2023
d19703a
Remove unused exit code of runmoduleconstructor
trylek Sep 1, 2023
fe3a07a
Remove unused exit code of RuntimeHelperTests
trylek Sep 1, 2023
32da5e8
Fix visibility in multidimarray/enum test
trylek Sep 1, 2023
e340f7e
Fix visibility in TestCallingConventions test
trylek Sep 1, 2023
2fe3767
Fix visibility in CriticalFinalizer test
trylek Sep 1, 2023
e0bacc0
Simplify RuntimeConfiguration/TestConfig
trylek Sep 1, 2023
65d2a7a
Clean up TieredCompilation tests
trylek Sep 1, 2023
6897201
Convert istypeequivalent to use ConditionalFact clauses
trylek Sep 1, 2023
c72d876
Fix visibility in RuntimeHelpersTests
trylek Sep 1, 2023
573730a
Add CoreCLRTestLibrary as a dependency of istypeequivalent
trylek Sep 1, 2023
c43b1d7
Fix merged behavior of test448035
trylek Sep 1, 2023
c2d27d4
Fix entrypoint in 305155
trylek Sep 1, 2023
e41e8f2
Modify TestConfig to use a separate TestConfigTester app
trylek Sep 3, 2023
cbf2417
Additional fixes to TestConfig / TestConfigTester
trylek Sep 4, 2023
d30f9c6
Mechanically merge all remaining tests under baseservices
trylek Sep 4, 2023
02ffa17
Fix BasicTestWithMcj, address initial Mark's PR feedback
trylek Sep 5, 2023
c9854b2
Remove superfluous OutputType=Library annotations per Marks' PR feedback
trylek Sep 5, 2023
02e17cf
Fix the baseservices/exceptions/unhandled test
trylek Sep 5, 2023
be2a499
Fix stackoverflow3 and unhandled exception tests
trylek Oct 12, 2023
2d85c95
Remove unnecessary check from Directory.Build.targets
trylek Oct 12, 2023
38e77a4
Fix stackoverflowtester per Mark's PR feedback
trylek Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions src/tests/baseservices/CET/CheckCETPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

using System;
using System.Runtime.InteropServices;
using Xunit;

static class Program
public static class Program
{
[DllImport("cet_check.dll")]
private static extern long ReadShadowStackPointer();

public static int Main()
[Fact]
public static int TestEntryPoint()
{
Console.WriteLine("Checking whether codeflow enforcement technology (CET) is active");
long ssp = ReadShadowStackPointer();
Expand Down
1 change: 0 additions & 1 deletion src/tests/baseservices/CET/CheckCETPresence.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RequiresCodeFlowEnforcement>true</RequiresCodeFlowEnforcement>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64' or '$(TargetOS)' != 'windows'">true</CLRTestTargetUnsupported>
Expand Down
11 changes: 11 additions & 0 deletions src/tests/baseservices/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Merged.props', $(MSBuildThisFileDirectory)..))" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<RunAnalyzers>true</RunAnalyzers>
<NoWarn>$(NoWarn);xUnit1013</NoWarn>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
</PropertyGroup>
</Project>
100 changes: 13 additions & 87 deletions src/tests/baseservices/RuntimeConfiguration/TestConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,152 +11,78 @@

using Xunit;

class TestConfig
public class TestConfig
{
const int Success = 100;
const int Fail = 101;
public const int Success = 100;
public const int Fail = 101;

[Fact]
[EnvVar("DOTNET_gcServer", "1")]
static int Verify_ServerGC_Env_Enable(string[] _)
public static int Verify_ServerGC_Env_Enable()
{
return GCSettings.IsServerGC
? Success
: Fail;
}

[Fact]
[EnvVar("DOTNET_gcServer", "0")]
static int Verify_ServerGC_Env_Disable(string[] _)
public static int Verify_ServerGC_Env_Disable()
{
return GCSettings.IsServerGC
? Fail
: Success;
}

[Fact]
[ConfigProperty("System.GC.Server", "true")]
static int Verify_ServerGC_Prop_Enable(string[] _)
public static int Verify_ServerGC_Prop_Enable()
{
return GCSettings.IsServerGC
? Success
: Fail;
}

[Fact]
[ConfigProperty("System.GC.Server", "false")]
static int Verify_ServerGC_Prop_Disable(string[] _)
public static int Verify_ServerGC_Prop_Disable()
{
return GCSettings.IsServerGC
? Fail
: Success;
}

[Fact]
[EnvVar("DOTNET_gcServer", "0")]
[ConfigProperty("System.GC.Server", "true")]
static int Verify_ServerGC_Env_Override_Prop(string[] _)
public static int Verify_ServerGC_Env_Override_Prop()
{
return GCSettings.IsServerGC
? Fail
: Success;
}

#if !IS_TESTER_APP
static int Main(string[] args)
{
if (args.Length == 0)
{
return RunTests();
}

MethodInfo infos = typeof(TestConfig).GetMethod(args[0], BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
if (infos is null)
{
return Fail;
}
return (int)infos.Invoke(null, new object[] { args[1..] });
return (int)infos.Invoke(null, Array.Empty<object>());
}
#endif

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
class EnvVarAttribute : Attribute
public class EnvVarAttribute : Attribute
{
public EnvVarAttribute(string name, string value) { Name = name; Value = value; }
public string Name { get; init; }
public string Value { get; init; }
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
class ConfigPropertyAttribute : Attribute
public class ConfigPropertyAttribute : Attribute
{
public ConfigPropertyAttribute(string name, string value) { Name = name; Value = value; }
public string Name { get; init; }
public string Value { get; init; }
}

static int RunTests()
{
// clear some environment variables that we will set during the test run
Environment.SetEnvironmentVariable("DOTNET_gcServer", null);

string corerunPath = GetCorerunPath();
MethodInfo[] infos = typeof(TestConfig).GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
foreach (var mi in infos)
{
var factMaybe = mi.GetCustomAttributes(typeof(FactAttribute));
if (!factMaybe.Any())
{
continue;
}

using Process process = new();

StringBuilder arguments = new();
var configProperties = mi.GetCustomAttributes(typeof(ConfigPropertyAttribute));

foreach (Attribute cp in configProperties)
{
ConfigPropertyAttribute configProp = (ConfigPropertyAttribute)cp;
arguments.Append($"-p {configProp.Name}={configProp.Value} ");
}

arguments.Append($"\"{System.Reflection.Assembly.GetExecutingAssembly().Location}\" {mi.Name}");

process.StartInfo.FileName = corerunPath;
process.StartInfo.Arguments = arguments.ToString();

var envVariables = mi.GetCustomAttributes(typeof(EnvVarAttribute));
foreach (string key in Environment.GetEnvironmentVariables().Keys)
{
process.StartInfo.EnvironmentVariables[key] = Environment.GetEnvironmentVariable(key);
}

Console.WriteLine($"Running: {process.StartInfo.Arguments}");
foreach (Attribute ev in envVariables)
{
EnvVarAttribute envVar = (EnvVarAttribute)ev;
process.StartInfo.EnvironmentVariables[envVar.Name] = envVar.Value;
Console.WriteLine($" set {envVar.Name}={envVar.Value}");
}

process.Start();
process.WaitForExit();
if (process.ExitCode != Success)
{
Console.WriteLine($"Failed: {mi.Name}");
return process.ExitCode;
}
}

return Success;
}

static string GetCorerunPath()
{
string corerunName = "corerun";
if (TestLibrary.Utilities.IsWindows)
{
corerunName += ".exe";
}
return Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"), corerunName);
}
}
12 changes: 4 additions & 8 deletions src/tests/baseservices/RuntimeConfiguration/TestConfig.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- This test provides no interesting scenarios for GCStress -->
<GCStressIncompatible>true</GCStressIncompatible>
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
<DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'Mono'">true</DisableProjectBuild>
<!-- This is a separate app launched by the actual test in TestConfigTester.csproj -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>
<CLRTestKind>BuildOnly</CLRTestKind>
</PropertyGroup>
<ItemGroup>
<Compile Include="TestConfig.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>
83 changes: 83 additions & 0 deletions src/tests/baseservices/RuntimeConfiguration/TestConfigTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime;
using System.Text;

using Xunit;

public class TestConfigTester
{
[Fact]
public static void RunTests()
{
// clear some environment variables that we will set during the test run
Environment.SetEnvironmentVariable("DOTNET_gcServer", null);

string testConfigApp = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestConfig.dll");

MethodInfo[] infos = typeof(TestConfig).GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

string corerunPath = GetCorerunPath();
foreach (var mi in infos)
{
var configProperties = mi.GetCustomAttributes(typeof(TestConfig.ConfigPropertyAttribute));
var envVariables = mi.GetCustomAttributes(typeof(TestConfig.EnvVarAttribute));

if (configProperties.Count() == 0 && envVariables.Count() == 0)
{
continue;
}

using Process process = new();

StringBuilder arguments = new();

foreach (Attribute cp in configProperties)
{
TestConfig.ConfigPropertyAttribute configProp = (TestConfig.ConfigPropertyAttribute)cp;
arguments.Append($"-p {configProp.Name}={configProp.Value} ");
}

arguments.Append($"\"{testConfigApp}\" {mi.Name}");

process.StartInfo.FileName = corerunPath;
process.StartInfo.Arguments = arguments.ToString();

foreach (string key in Environment.GetEnvironmentVariables().Keys)
{
process.StartInfo.EnvironmentVariables[key] = Environment.GetEnvironmentVariable(key);
}

Console.WriteLine($"Running: {process.StartInfo.Arguments}");
foreach (Attribute ev in envVariables)
{
TestConfig.EnvVarAttribute envVar = (TestConfig.EnvVarAttribute)ev;
process.StartInfo.EnvironmentVariables[envVar.Name] = envVar.Value;
Console.WriteLine($" set {envVar.Name}={envVar.Value}");
}

process.Start();
process.WaitForExit();
if (process.ExitCode != TestConfig.Success)
{
throw new Exception($"Failed: {mi.Name}: exit code = {process.ExitCode}");
}
}
}

static string GetCorerunPath()
{
string corerunName = "corerun";
if (TestLibrary.Utilities.IsWindows)
{
corerunName += ".exe";
}
return Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"), corerunName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- This test provides no interesting scenarios for GCStress -->
<GCStressIncompatible>true</GCStressIncompatible>
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
<DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'Mono'">true</DisableProjectBuild>
<DefineConstants>$(DefineConstants);IS_TESTER_APP</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
<Compile Include="TestConfig.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)TestConfig.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Content</OutputItemType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</ProjectReference>
</ItemGroup>
</Project>
trylek marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 3 additions & 5 deletions src/tests/baseservices/TieredCompilation/BasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using Xunit;

public static class BasicTest
{
private static int Main()
[Fact]
public static void TestEntryPoint()
{
const int Pass = 100;

PromoteToTier1(Foo, () => FooWithLoop(2));
Foo();
FooWithLoop(2);

return Pass;
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down
3 changes: 2 additions & 1 deletion src/tests/baseservices/TieredCompilation/BasicTestWithMcj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct MCJTestStruct
{
}

private static int Main()
public static int Main()
{
const int Pass = 100;

Expand Down Expand Up @@ -45,6 +45,7 @@ private static int Main()
FooWithGeneric(RegexOptions.IgnoreCase);

ProfileOptimization.StartProfile(null);

return Pass;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needs to build an exe with explicit Main as the MCJ functionality seems not to play well -->
<!-- with the Roslyn-generated wrapper. -->
<!-- Needed for CLRTestTargetUnsupported -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<OutputType>Exe</OutputType>
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<!-- Generated shell script and corresponding assembly have different names -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>

Expand Down
Loading
Loading