From cde9eb0a14d68cf6241d8bd8e2141b6b125ccb12 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 10 May 2024 13:45:06 -0700 Subject: [PATCH] Add test for IlcLinkServerGC --- .../GivenThatWeWantToPublishAnAotApp.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index d9a9011ff7b7..dc95066601d8 100644 --- a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -19,6 +19,48 @@ public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log) { } + [Fact] + public void LinkInServerGc() + { + const string projectName = "PrintGc"; + const string targetFramework = "net9.0"; + var testProject = new TestProject() + { + Name = projectName, + TargetFrameworks = targetFramework, + IsExe = true + }; + + testProject.SourceFiles[$"{projectName}.cs"] = """ +using System; +Console.WriteLine("IsServerGC: " + System.Runtime.GCSettings.IsServerGc); +"""; + + testProject.RecordProperties("NETCoreSdkPortableRuntimeIdentifier"); + testProject.AdditionalProperties["PublishAot"] = "true"; + testProject.AdditionalProperties["IlcLinkServerGc"] = "true"; + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + publishCommand + .Execute($"/p:UseCurrentRuntimeIdentifier=true", "/p:SelfContained=true") + .Should().Pass(); + + var buildProperties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework); + var rid = buildProperties["NETCoreSdkPortableRuntimeIdentifier"]; + var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; + var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); + + var command = new RunExeCommand(Log, publishedExe) + .Execute().Should().Pass() + .And.HaveStdOutContaining("IsServerGC: false"); + + command = new RunExeCommand(Log, publishedExe) + .WithEnvironmentVariable("DOTNET_gcServer", "1") + .Execute().Should().Pass() + .And.HaveStdOutContaining("IsServerGC: true"); + } + [RequiresMSBuildVersionTheory("17.8.0")] [MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))] public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string targetFramework)