-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor out the CoreCLR configuration detection so we can re-use it …
…in dotnet/runtime without having to copy it. (#8176) * Refactor out the CoreCLR configuration detection so we can re-use it in dotnet/runtime without having to copy it. * Update src/Microsoft.DotNet.XUnitExtensions/src/Discoverers/SkipOnCoreClrDiscoverer.cs
- Loading branch information
1 parent
fd5a907
commit 16988fc
Showing
2 changed files
with
70 additions
and
46 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Microsoft.DotNet.XUnitExtensions/src/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,58 @@ | ||
// 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 Xunit | ||
{ | ||
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); | ||
} | ||
} | ||
} |
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