From 1e04132f2183b36a9aeb7af0e66c27ca3bd7c141 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 5 Dec 2022 17:58:44 +0000 Subject: [PATCH 1/5] Add net8.0 ILCompiler tests --- ...ndCreateBundledNETCoreAppPackageVersion.cs | 2 + .../GivenThatWeWantToPublishAnAotApp.cs | 49 +++++++++++++------ .../PublishTestUtils.cs | 7 +++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs index ab2075238adc..67f124e63f26 100644 --- a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs +++ b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs @@ -115,6 +115,8 @@ void CheckAndReplaceAttribute(XAttribute attribute) .Elements(ns + "KnownAppHostPack").First().Attribute("AppHostPackVersion")); CheckAndReplaceAttribute(itemGroup .Elements(ns + "KnownCrossgen2Pack").First().Attribute("Crossgen2PackVersion")); + CheckAndReplaceAttribute(itemGroup + .Elements(ns + "KnownILCompilerPack").First().Attribute("ILCompilerPackVersion")); // TODO: remove this once we're using an SDK that contains https://github.com/dotnet/installer/pull/10250 var crossgen2Rids = itemGroup.Elements(ns + "KnownCrossgen2Pack").First().Attribute("Crossgen2RuntimeIdentifiers"); diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index b1095087a0f5..cf6829f6eb9d 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -34,7 +34,7 @@ public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log) } [RequiresMSBuildVersionTheory("17.0.0.32901")] - [InlineData(ToolsetInfo.CurrentTargetFramework)] + [MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))] public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) @@ -58,7 +58,8 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string .Should().Pass() .And.NotHaveStdOutContaining("IL2026") .And.NotHaveStdErrContaining("NETSDK1179") - .And.NotHaveStdErrContaining("warning"); + .And.NotHaveStdErrContaining("warning") + .And.NotHaveStdOutContaining("warning"); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so"; @@ -74,6 +75,9 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string File.Exists(publishedDebugFile).Should().BeTrue(); IsNativeImage(publishedExe).Should().BeTrue(); + GetKnownILCompilerPackVersion(testAsset, targetFramework, out string expectedVersion); + CheckIlcVersions(testAsset, targetFramework, expectedVersion); + var command = new RunExeCommand(Log, publishedExe) .Execute().Should().Pass() .And.HaveStdOutContaining("Hello World"); @@ -81,7 +85,7 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string } [RequiresMSBuildVersionTheory("17.0.0.32901")] - [InlineData(ToolsetInfo.CurrentTargetFramework)] + [MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))] public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -99,7 +103,8 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false(string t .Should().Pass() .And.NotHaveStdOutContaining("IL2026") .And.NotHaveStdErrContaining("NETSDK1179") - .And.NotHaveStdErrContaining("warning"); + .And.NotHaveStdErrContaining("warning") + .And.NotHaveStdOutContaining("warning"); var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll"); @@ -310,7 +315,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string .Execute().Should().Pass() .And.HaveStdOutContaining("Hello World"); - CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion); + CheckIlcVersions(testAsset, targetFramework, ExplicitPackageVersion); } } @@ -355,7 +360,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t } [RequiresMSBuildVersionTheory("17.0.0.32901")] - [InlineData(ToolsetInfo.CurrentTargetFramework)] + [MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))] public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) @@ -377,12 +382,15 @@ public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string tar var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}"); File.Exists(publishedDll).Should().BeFalse(); File.Exists(publishedExe).Should().BeTrue(); + + GetKnownILCompilerPackVersion(testAsset, targetFramework, out string expectedVersion); + CheckIlcVersions(testAsset, targetFramework, expectedVersion); } } [RequiresMSBuildVersionTheory("17.0.0.32901")] - [InlineData(ToolsetInfo.CurrentTargetFramework)] + [MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))] public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)) @@ -413,7 +421,7 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled( File.Exists(publishedDll).Should().BeFalse(); File.Exists(publishedExe).Should().BeTrue(); - CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion); + CheckIlcVersions(testAsset, targetFramework, ExplicitPackageVersion); } } @@ -545,7 +553,7 @@ public void Requires_analyzers_produce_warnings_without_PublishAot_being_set(str } [RequiresMSBuildVersionTheory("17.0.0.32901")] - [InlineData(ToolsetInfo.CurrentTargetFramework)] + [MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))] public void NativeAot_compiler_runs_when_PublishAot_is_enabled(string targetFramework) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) @@ -704,20 +712,33 @@ public void It_publishes_with_implicit_rid_with_NativeAotApp(string targetFramew } } - private void CheckIlcVersions(string projectPath, string targetFramework, string expectedVersion) + private void GetKnownILCompilerPackVersion(TestAsset testAsset, string targetFramework, out string version) + { + var getKnownPacks = new GetValuesCommand(testAsset, "KnownILCompilerPack", GetValuesCommand.ValueType.Item, targetFramework) { + MetadataNames = new List { "TargetFramework", "ILCompilerPackVersion" } + }; + getKnownPacks.Execute().Should().Pass(); + var knownPacks = getKnownPacks.GetValuesWithMetadata(); + version = knownPacks + .Where(i => i.metadata["TargetFramework"] == targetFramework) + .Select(i => i.metadata["ILCompilerPackVersion"]) + .Single(); + } + + private void CheckIlcVersions(TestAsset testAsset, string targetFramework, string expectedVersion) { // Compiler version matches expected version - var ilcToolsPathCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcToolsPath") + var ilcToolsPathCommand = new GetValuesCommand(testAsset, "IlcToolsPath", targetFramework: targetFramework) { DependsOnTargets = "WriteIlcRspFileForCompilation" }; ilcToolsPathCommand.Execute().Should().Pass(); var ilcToolsPath = ilcToolsPathCommand.GetValues()[0]; var ilcVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(ilcToolsPath))); - ilcVersion.Should().Be(ExplicitPackageVersion); + ilcVersion.Should().Be(expectedVersion); // Compilation references (corelib) match expected version - var ilcReferenceCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcReference", GetValuesCommand.ValueType.Item) + var ilcReferenceCommand = new GetValuesCommand(testAsset, "IlcReference", GetValuesCommand.ValueType.Item, targetFramework) { DependsOnTargets = "WriteIlcRspFileForCompilation" }; @@ -725,7 +746,7 @@ private void CheckIlcVersions(string projectPath, string targetFramework, string var ilcReference = ilcReferenceCommand.GetValues(); var corelibReference = ilcReference.Where(r => Path.GetFileName(r).Equals("System.Private.CoreLib.dll")).Single(); var ilcReferenceVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(corelibReference))); - ilcReferenceVersion.Should().Be(ExplicitPackageVersion); + ilcReferenceVersion.Should().Be(expectedVersion); } private TestProject CreateHelloWorldTestProject(string targetFramework, string projectName, bool isExecutable) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs b/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs index 1539c70cdc9e..e469d5cf8642 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs @@ -36,6 +36,13 @@ internal static class PublishTestUtils new object[] { ToolsetInfo.CurrentTargetFramework }, new object[] { ToolsetInfo.NextTargetFramework } }; + + // This list should contain all supported TFMs after net7.0 + public static IEnumerable Net7Plus { get; } = new List + { + new object[] { ToolsetInfo.CurrentTargetFramework }, + new object[] { ToolsetInfo.NextTargetFramework } + }; #else #error If building for a newer TFM, please update the values above #endif From b9f71d09bb32b6b71d93f7e7be073f3339693c99 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 20 Dec 2022 18:12:37 +0000 Subject: [PATCH 2/5] Fix Net7Plus TFMs --- src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs b/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs index 097cb9f4f428..9a3fd4c2ad2a 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs @@ -37,8 +37,8 @@ internal static class PublishTestUtils // This list should contain all supported TFMs after net7.0 public static IEnumerable Net7Plus { get; } = new List { - new object[] { ToolsetInfo.CurrentTargetFramework }, - new object[] { ToolsetInfo.NextTargetFramework } + new object[] { "net7.0" }, + new object[] { ToolsetInfo.CurrentTargetFramework } }; #else #error If building for a newer TFM, please update the values above From 6742cd41d304c8a059a247f9193b601a2f2feb60 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 21 Dec 2022 02:03:34 +0000 Subject: [PATCH 3/5] Skip warning check when targeting .net7 --- .../GivenThatWeWantToPublishAnAotApp.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index cf6829f6eb9d..6a7760e04349 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -53,13 +53,18 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); - publishCommand + var result = publishCommand .Execute($"/p:RuntimeIdentifier={rid}") .Should().Pass() .And.NotHaveStdOutContaining("IL2026") - .And.NotHaveStdErrContaining("NETSDK1179") - .And.NotHaveStdErrContaining("warning") - .And.NotHaveStdOutContaining("warning"); + .And.NotHaveStdErrContaining("NETSDK1179"); + // Remove the net7.0 condition and add this check back for + // all TFMs once the warning fix exists in 7.0: + // https://github.com/dotnet/runtime/pull/79870 + if (targetFramework != "net7.0") { + result.And.NotHaveStdErrContaining("warning") + .And.NotHaveStdOutContaining("warning"); + } var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so"; From 4b941c5790154c817e7d6c5f048d4a226557985d Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 12 May 2023 00:07:54 +0000 Subject: [PATCH 4/5] Remove workaround for net7.0 Now that we have ingested https://github.com/dotnet/runtime/pull/79870. The test started warning that SelfContained is no longer the default due to recent changes, fixed by specifying SelfContained. --- .../GivenThatWeWantToPublishAnAotApp.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index ffce0143b953..bd7e1b0bd248 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -54,18 +54,13 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); - var result = publishCommand - .Execute($"/p:UseCurrentRuntimeIdentifier=true") + publishCommand + .Execute($"/p:UseCurrentRuntimeIdentifier=true", "/p:SelfContained=true") .Should().Pass() .And.NotHaveStdOutContaining("IL2026") - .And.NotHaveStdErrContaining("NETSDK1179"); - // Remove the net7.0 condition and add this check back for - // all TFMs once the warning fix exists in 7.0: - // https://github.com/dotnet/runtime/pull/79870 - if (targetFramework != "net7.0") { - result.And.NotHaveStdErrContaining("warning") - .And.NotHaveStdOutContaining("warning"); - } + .And.NotHaveStdErrContaining("NETSDK1179") + .And.NotHaveStdErrContaining("warning") + .And.NotHaveStdOutContaining("warning"); var buildProperties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework); var rid = buildProperties["NETCoreSdkPortableRuntimeIdentifier"]; From 4fb71e7bbdb3670efbbaa9bb8aaf4288f62fc232 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 15 May 2023 15:54:36 +0000 Subject: [PATCH 5/5] Prevent warning about SelfContained not being defaulted --- .../GivenThatWeWantToPublishAnAotApp.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index bd7e1b0bd248..1c41495ed24f 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -102,7 +102,7 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false(string t var publishCommand = new PublishCommand(testAsset); publishCommand - .Execute($"/p:RuntimeIdentifier={rid}") + .Execute($"/p:RuntimeIdentifier={rid}", "/p:SelfContained=true") .Should().Pass() .And.NotHaveStdOutContaining("IL2026") .And.NotHaveStdErrContaining("NETSDK1179")