Skip to content

Commit

Permalink
Convert all tests under baseservices to the merged test infrastructure (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
trylek authored Oct 30, 2023
1 parent b6b00ec commit 1a19c09
Show file tree
Hide file tree
Showing 373 changed files with 1,343 additions and 856 deletions.
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>
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

0 comments on commit 1a19c09

Please sign in to comment.