-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
src/tests tree test xunit-based source generated runner #60846
Merged
jkoritzinsky
merged 39 commits into
dotnet:main
from
jkoritzinsky:xunit-runner-generator
Nov 17, 2021
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
1bbfc9c
Add a basic xunit runner generator that generates a top-level-stateme…
jkoritzinsky 6523a11
Fix some bugs in the generator. Convert the Interop/PInvoke/Vector2_3…
jkoritzinsky 6143a48
Implement support for [Fact] methods that are instance methods on IDi…
jkoritzinsky 9b9ae95
Import enum sources from XUnitExtensions and hook up support for some…
jkoritzinsky 54e93eb
Add one more newline
jkoritzinsky 14ca067
Add preliminary support for building an IL test runner using the sour…
jkoritzinsky 149ffe2
Rename to make the logic clearer.
jkoritzinsky 23b7975
Update src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs
jkoritzinsky 623cc48
Add support for extern-alias with references (to handle conflicting n…
jkoritzinsky a20864e
Apply suggestions from code review
jkoritzinsky 4a7ebe9
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky f5009c8
Update src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs
jkoritzinsky 59960aa
Add the XUnit wrapper generator to the list of ambient project depend…
trylek 191ac42
Fix nullability bug in XUnitWrapperGenerator
trylek a2bdb78
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky e597fec
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky e783f9e
Write out the exception that caused the test to fail to the console.
jkoritzinsky c978193
Convert the Castable test to use the generator
jkoritzinsky 270144b
Support running the xunit wrapper generator in "standalone" mode for …
jkoritzinsky 4c73d6f
Add first draft of result reporting infrastructure.
jkoritzinsky e81deda
Fix IL .assembly directive to be the assembly name that can be resolv…
jkoritzinsky 4f9dcbb
Add test reporting for "merged test runner" assemblies.
jkoritzinsky d5961f6
Add Microsoft.DotNet.XUnitExtensions to the targetting pack.
jkoritzinsky 4d412d0
Add support for the rest of ActiveIssueAttribute
jkoritzinsky 377b8a0
Add support for more attributes and clean up code.
jkoritzinsky 835f56d
Add support for SkipOnCoreClrAttribute.
jkoritzinsky c84c5d1
Merge branch 'main' of github.com:dotnet/runtime into xunit-runner-ge…
jkoritzinsky b7fb243
Support running tests with the [Fact] attribute that return 100 for s…
jkoritzinsky d49c1f4
Fix failures and update comment
jkoritzinsky 1b19bed
Update src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs
jkoritzinsky 040877c
Fix handling of SkipOnCoreClrAttribute and SkipOnMonoAttribute with R…
jkoritzinsky d736995
Add support for running tests marked with <RequiresProcessIsolation>t…
jkoritzinsky a77d13c
Merge branch 'main' into xunit-runner-generator
jkoritzinsky 04650fd
Add support for substring-based test filtering and add infrastructure…
jkoritzinsky 8ef73bd
Integrate work from #61224 with some modifications based on offline d…
jkoritzinsky 5881fa1
Fix Castable.csproj and fix SkipOnMono/SkipOnCoreCLR attribute support.
jkoritzinsky eccf29a
Work around tests that hit compiler limits. Move tests that used Xuni…
jkoritzinsky ccd08a2
Rewrite how superpmicollect sets up its testing to make it more frien…
jkoritzinsky db68ce4
Add back the _BuildSpmiTestProjectScripts target since I'm not sure w…
jkoritzinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like that all these duplication is at some point somehow shared with arcade code, it would be really painful to expand this support and have it to do it twice and maybe forget or have these files go out of sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this file in particular, we can refactor this API surface out of the implementation in dotnet/arcade and use it from the Arcade package directly since this file is referenced by the tests, not the generator. For the enums, there's really not any code sharing we can do at the assembly level, but we could share at the source level if we so desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'd work. Can we do that? Maybe the source sharing we can do it later once this is baked in, but it would be nice to avoid duplicating this file's specific logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, once I finish the last part of the work I'm trying to get done here, I'll do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!