-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/tests tree test xunit-based source generated runner (#60846)
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com> Co-authored-by: Santiago Fernandez Madero <safern@microsoft.com> Co-authored-by: Tomas <trylek@microsoft.com>
- Loading branch information
1 parent
f9e3e28
commit 9962c10
Showing
48 changed files
with
1,746 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/tests/Common/CoreCLRTestLibrary/CoreClrConfigurationDetection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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.Globalization; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Security; | ||
using System.Text; | ||
|
||
namespace TestLibrary; | ||
|
||
public static class CoreClrConfigurationDetection | ||
{ | ||
public static bool IsJitStress => !string.Equals(GetEnvironmentVariableValue("JitStress"), "0", StringComparison.InvariantCulture); | ||
public static bool IsJitStressRegs => !string.Equals(GetEnvironmentVariableValue("JitStressRegs"), "0", StringComparison.InvariantCulture); | ||
public static bool IsJitMinOpts => string.Equals(GetEnvironmentVariableValue("JITMinOpts"), "1", StringComparison.InvariantCulture); | ||
public static bool IsTailCallStress => string.Equals(GetEnvironmentVariableValue("TailcallStress"), "1", StringComparison.InvariantCulture); | ||
public static bool IsZapDisable => string.Equals(GetEnvironmentVariableValue("ZapDisable"), "1", StringComparison.InvariantCulture); | ||
public static bool IsGCStress3 => CompareGCStressModeAsLower(GetEnvironmentVariableValue("GCStress"), "0x3", "3"); | ||
public static bool IsGCStressC => CompareGCStressModeAsLower(GetEnvironmentVariableValue("GCStress"), "0xC", "C"); | ||
|
||
public static bool IsGCStress => GetEnvironmentVariableValue("GCStress") != string.Empty; | ||
|
||
public static bool IsCheckedRuntime => AssemblyConfigurationEquals("Checked"); | ||
public static bool IsReleaseRuntime => AssemblyConfigurationEquals("Release"); | ||
public static bool IsDebugRuntime => AssemblyConfigurationEquals("Debug"); | ||
|
||
public static bool IsStressTest => | ||
IsGCStress || | ||
IsZapDisable || | ||
IsTailCallStress || | ||
IsJitStressRegs || | ||
IsJitStress || | ||
IsJitMinOpts; | ||
|
||
private static string GetEnvironmentVariableValue(string name) => | ||
Environment.GetEnvironmentVariable("DOTNET_" + name) ?? Environment.GetEnvironmentVariable("COMPlus_" + name) ?? "0"; | ||
|
||
private static bool AssemblyConfigurationEquals(string configuration) | ||
{ | ||
AssemblyConfigurationAttribute assemblyConfigurationAttribute = typeof(string).Assembly.GetCustomAttribute<AssemblyConfigurationAttribute>(); | ||
|
||
return assemblyConfigurationAttribute != null && | ||
string.Equals(assemblyConfigurationAttribute.Configuration, configuration, StringComparison.InvariantCulture); | ||
} | ||
|
||
private static bool CompareGCStressModeAsLower(string value, string first, string second) | ||
{ | ||
value = value.ToLowerInvariant(); | ||
return string.Equals(value, first.ToLowerInvariant(), StringComparison.InvariantCulture) || | ||
string.Equals(value, second.ToLowerInvariant(), StringComparison.InvariantCulture) || | ||
string.Equals(value, "0xf", StringComparison.InvariantCulture) || | ||
string.Equals(value, "f", StringComparison.InvariantCulture); | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
src/tests/Common/CoreCLRTestLibrary/OutOfProcessTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// 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.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using CoreclrTestLib; | ||
using Xunit; | ||
|
||
namespace TestLibrary | ||
{ | ||
public static class OutOfProcessTest | ||
{ | ||
internal static bool runningInWindows; | ||
internal static string reportBase; | ||
internal static string testBinaryBase; | ||
internal static string helixUploadRoot; | ||
|
||
static OutOfProcessTest() | ||
{ | ||
reportBase = Directory.GetCurrentDirectory(); | ||
testBinaryBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; | ||
helixUploadRoot = Environment.GetEnvironmentVariable("HELIX_WORKITEM_UPLOAD_ROOT"); | ||
if (!String.IsNullOrEmpty(helixUploadRoot)) | ||
{ | ||
reportBase = Path.Combine(Path.GetFullPath(helixUploadRoot), "Reports"); | ||
} | ||
|
||
if (String.IsNullOrEmpty(reportBase)) | ||
{ | ||
reportBase = Path.Combine(testBinaryBase, "Reports"); | ||
} | ||
else | ||
{ | ||
reportBase = Path.GetFullPath(reportBase); | ||
} | ||
} | ||
|
||
public static void RunOutOfProcessTest(string basePath, string assemblyPath) | ||
{ | ||
int ret = -100; | ||
string outputFile = System.IO.Path.GetFullPath(reportBase + assemblyPath + "output.txt"); | ||
string errorFile = System.IO.Path.GetFullPath(reportBase + assemblyPath + "error.txt"); | ||
string outputDir = System.IO.Path.GetDirectoryName(outputFile)!; | ||
string testExecutable = null; | ||
Exception infraEx = null; | ||
|
||
try | ||
{ | ||
CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib(); | ||
|
||
if (OperatingSystem.IsWindows()) | ||
{ | ||
testExecutable = Path.Combine(basePath, Path.ChangeExtension(assemblyPath, ".cmd")); | ||
} | ||
else | ||
{ | ||
testExecutable = Path.Combine(basePath, Path.ChangeExtension(assemblyPath.Replace("\\", "/"), ".sh")); | ||
} | ||
|
||
System.IO.Directory.CreateDirectory(reportBase + Path.GetDirectoryName(assemblyPath)); | ||
|
||
ret = wrapper.RunTest(testExecutable, outputFile, errorFile, Assembly.GetEntryAssembly()!.FullName!, testBinaryBase, outputDir); | ||
} | ||
catch (Exception ex) | ||
{ | ||
infraEx = ex; | ||
} | ||
|
||
if (infraEx != null) | ||
{ | ||
Assert.True(false, "Test Infrastructure Failure: " + infraEx.ToString()); | ||
} | ||
else | ||
{ | ||
List<string> testOutput = new List<string>(); | ||
|
||
try | ||
{ | ||
testOutput.AddRange(System.IO.File.ReadAllLines(errorFile)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
testOutput.Add("Unable to read error file: " + errorFile); | ||
testOutput.Add(ex.ToString()); | ||
} | ||
|
||
testOutput.Add(string.Empty); | ||
testOutput.Add("Return code: " + ret); | ||
testOutput.Add("Raw output file: " + outputFile); | ||
testOutput.Add("Raw output:"); | ||
|
||
try | ||
{ | ||
testOutput.AddRange(System.IO.File.ReadAllLines(outputFile)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
testOutput.Add("Unable to read output file: " + outputFile); | ||
testOutput.Add(ex.ToString()); | ||
} | ||
|
||
testOutput.Add("To run the test:"); | ||
testOutput.Add("Set up CORE_ROOT and run."); | ||
testOutput.Add("> " + testExecutable); | ||
|
||
var unicodeControlCharsRegex = new Regex("%5C%5Cp{C}+"); | ||
|
||
// Remove all characters that have no visual or spatial representation. | ||
for (int i = 0; i < testOutput.Count; i++) | ||
{ | ||
string line = testOutput[i]; | ||
line = unicodeControlCharsRegex.Replace(line, string.Empty); | ||
testOutput[i] = line; | ||
} | ||
|
||
foreach (string line in testOutput) | ||
{ | ||
Console.WriteLine(line); | ||
} | ||
|
||
Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, string.Join(Environment.NewLine, testOutput)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<IsTestsCommonProject>true</IsTestsCommonProject> | ||
</PropertyGroup> | ||
|
||
<!-- SDK Style projects auto-magically include this file. --> | ||
<Import Project="..\Directory.Build.props" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsMergedTestRunnerAssembly>true</IsMergedTestRunnerAssembly> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="$(RepoRoot)/src/tests/Common/XUnitWrapperLibrary/XUnitWrapperLibrary.csproj" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props" /> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(RepoRoot)\src\tests\JIT\IL_Conformance\Old\directed\AutoInit.ilproj" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.