-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Environment variable should override property for gcServer. #61950
Merged
Merged
Changes from all commits
Commits
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
159 changes: 159 additions & 0 deletions
159
src/tests/baseservices/RuntimeConfiguration/TestConfig.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,159 @@ | ||
// 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.Text; | ||
using System.Reflection; | ||
using System.Runtime; | ||
|
||
using Xunit; | ||
|
||
class TestConfig | ||
{ | ||
const int Success = 100; | ||
const int Fail = 101; | ||
|
||
[Fact] | ||
[EnvVar("DOTNET_gcServer", "1")] | ||
static int Verify_ServerGC_Env_Enable(string[] _) | ||
{ | ||
return GCSettings.IsServerGC | ||
? Success | ||
: Fail; | ||
} | ||
|
||
[Fact] | ||
[ConfigProperty("DOTNET_gcServer", "0")] | ||
static int Verify_ServerGC_Env_Disable(string[] _) | ||
{ | ||
return GCSettings.IsServerGC | ||
? Fail | ||
: Success; | ||
} | ||
|
||
[Fact] | ||
[ConfigProperty("System.GC.Server", "true")] | ||
static int Verify_ServerGC_Prop_Enable(string[] _) | ||
{ | ||
return GCSettings.IsServerGC | ||
? Success | ||
: Fail; | ||
} | ||
|
||
[Fact] | ||
[ConfigProperty("System.GC.Server", "false")] | ||
static int Verify_ServerGC_Prop_Disable(string[] _) | ||
{ | ||
return GCSettings.IsServerGC | ||
? Fail | ||
: Success; | ||
} | ||
|
||
[Fact] | ||
[EnvVar("DOTNET_gcServer", "0")] | ||
[ConfigProperty("System.GC.Server", "true")] | ||
static int Verify_ServerGC_Env_Override_Prop(string[] _) | ||
{ | ||
return GCSettings.IsServerGC | ||
? Fail | ||
: Success; | ||
} | ||
|
||
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..] }); | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)] | ||
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 ConfigPropertyAttribute(string name, string value) { Name = name; Value = value; } | ||
public string Name { get; init; } | ||
public string Value { get; init; } | ||
} | ||
|
||
static int RunTests() | ||
{ | ||
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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tests/baseservices/RuntimeConfiguration/TestConfig.csproj
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,15 @@ | ||
<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> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="TestConfig.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> | ||
</ItemGroup> | ||
</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
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.
@AaronRobinsonMSFT, FYI, this test failed on GCStandAloneServer legs:
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.
@cshung this seems like something the GC team should investigate. I am unclear why this would be occurring but given the simplicity of the test I'd wager it is unlikely a test issue.
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.
@mangod9 It looks like the GCStandAloneServer set
COMPlus_gcServer=1
, so even when the code setDOTNET_gcServer=0
, we are still unable to disable it.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.
ok makes sense. @am11 what CI job was failing due to this issue? Is the failure only after this change or unrelated to this?
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.
@mangod9, it's a new test added by this PR, which started to fail in outerloop test when this PR was merged. Perhaps the root-cause was preexisting and the test has surfaced the problem.
Based on the config parsing implementation:
runtime/src/coreclr/inc/clrconfignocache.h
Lines 75 to 86 in 4da6b9a
first
DOTNET_gcServer
will be checked and if the value isNULL
, it will fallback to legacy,COMPlus_gcServer
. It isLPCSTR
, so=0
shouldn't be confused by NULL/0, right?