Skip to content
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

Backport #113 (NativeAOT test) and #108 (Skip on community architectures) to release/9.0. #119

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions src/Microsoft.DotNet.ScenarioTests.Common/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static int Invoke(string dotnetRoot,
discoverer.Find(false, discoverySink, TestFrameworkOptions.ForDiscovery(assemblyConfig));
discoverySink.Finished.WaitOne();

XunitFilters filters = CreateFilters(noTraits, traits, offlineOnly, platform);
XunitFilters filters = CreateFilters(noTraits, traits, offlineOnly, platform, dotnetRoot, targetRid);

var filteredTestCases = discoverySink.TestCases.Where(filters.Filter).ToList();

Expand Down Expand Up @@ -217,7 +217,7 @@ private static void SetupTestEnvironment(string dotnetRoot, string testRoot, str
}


private static XunitFilters CreateFilters(IList<string> excludedTraits, IList<string> includedTraits, bool offlineOnly, OSPlatform platform)
private static XunitFilters CreateFilters(IList<string> excludedTraits, IList<string> includedTraits, bool offlineOnly, OSPlatform platform, string dotnetRoot, string targetRid)
{
XunitFilters filters = new XunitFilters();

Expand All @@ -234,6 +234,8 @@ private static XunitFilters CreateFilters(IList<string> excludedTraits, IList<st

filters.ExcludedTraits.Add("SkipIfPlatform", new List<string>() {$"{platform}"});

filters.ExcludedTraits.Add("SkipIfBuild", CreateBuildTraits(dotnetRoot, targetRid));

Dictionary<string, List<string>> includedTraitsMap = ParseTraitKeyValuePairs(includedTraits);
foreach (KeyValuePair<string, List<string>> kvp in includedTraitsMap)
{
Expand All @@ -243,6 +245,57 @@ private static XunitFilters CreateFilters(IList<string> excludedTraits, IList<st
return filters;
}

private static List<string> CreateBuildTraits(string dotnetRoot, string targetRid)
{
List<string> buildTraits = new();

int archSeparatorPos = targetRid.LastIndexOf('-');
string ridWithoutArch = targetRid.Substring(0, archSeparatorPos != -1 ? archSeparatorPos : 0);
string arch = targetRid.Substring(archSeparatorPos + 1);

// Mono
if (DetermineIsMonoRuntime(dotnetRoot))
{
buildTraits.Add("Mono");
}

// Portable
string[] portableRids = [ "linux", "linux-musl" ];
if (Array.IndexOf(portableRids, ridWithoutArch) != -1)
{
buildTraits.Add("Portable");
}

// CommunityArchitecture
string[] communityArchitectures = [ "s390x", "ppc64le", "loongarch64", "riscv64" ];
if (Array.IndexOf(communityArchitectures, arch) != -1)
{
buildTraits.Add("CommunityArchitecture");
}

return buildTraits;
}

private static bool DetermineIsMonoRuntime(string dotnetRoot)
{
string sharedFrameworkRoot = Path.Combine(dotnetRoot, "shared", "Microsoft.NETCore.App");
if (!Directory.Exists(sharedFrameworkRoot))
{
return false;
}

string? version = Directory.GetDirectories(sharedFrameworkRoot).FirstOrDefault();
if (version is null)
{
return false;
}

string sharedFramework = Path.Combine(sharedFrameworkRoot, version);

// Check the presence of one of the mono header files.
return File.Exists(Path.Combine(sharedFramework, "mono-gc.h"));
}

private static Dictionary<string, List<string>> ParseTraitKeyValuePairs(IList<string> excludedTraits)
{
// Quick hack wo much validation to get args that are passed (notrait, xml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public ScenarioTestFixture()
public string DotNetRoot { get; set; }
public string TestRoot { get; set; }
public string TargetRid { get; set; }
public string TargetArchitecture { get => TargetRid.Split('-').Last(); }
public string PortableRid { get => $"linux-{TargetArchitecture}"; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public enum DotNetSdkActions
Publish = 8,
PublishComplex = 16,
PublishR2R = 32,
Test = 64,
AddClassLibRef = 128,
FullWorkloadTest = 256,
WorkloadInstall = 512,
WorkloadUninstall = 1024,
PublishAot = 64,
Test = 128,
AddClassLibRef = 256,
FullWorkloadTest = 512,
WorkloadInstall = 1024,
WorkloadUninstall = 2048
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal class DotNetSdkHelper
public string? SdkVersion { get; set; }
public string DotNetExecutablePath { get =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Path.Combine(DotNetRoot, "dotnet.exe") : Path.Combine(DotNetRoot, "dotnet"); }

private ITestOutputHelper OutputHelper { get; }

public DotNetSdkHelper(ITestOutputHelper outputHelper, string dotnetRoot, string? sdkVersion)
Expand Down Expand Up @@ -105,7 +104,7 @@ public string ExecuteNew(string projectType, string projectName, string projectD
return projectDirectory;
}

public void ExecutePublish(string projectDirectory, bool? selfContained = null, string? rid = null, bool trimmed = false, bool readyToRun = false, string[]? frameworks = null)
public void ExecutePublish(string projectDirectory, string? rid = null, bool? selfContained = null, bool trimmed = false, bool readyToRun = false, bool? aot = false, string[]? frameworks = null)
{
string options = string.Empty;
string binlogDifferentiator = string.Empty;
Expand Down Expand Up @@ -134,6 +133,15 @@ public void ExecutePublish(string projectDirectory, bool? selfContained = null,
}
}

if (aot.HasValue)
{
options += $" /p:PublishAot={aot.Value.ToString().ToLowerInvariant()}";
if (aot.Value)
{
binlogDifferentiator += "-aot";
}
}

if (frameworks != null)
{
foreach (var item in frameworks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class DotnetWorkloadTest
public DotNetLanguage Language { get; }
public bool NoHttps { get => TargetRid.Contains("osx"); }
public string TargetRid { get; set; }
public string TargetArchitecture { get => TargetRid.Split('-')[1]; }
public string TargetArchitecture { get => TargetRid.Split('-').Last(); }
public string ScenarioName { get; }

public DotnetWorkloadTest(string scenarioName, string targetRid, DotNetSdkActions commands = DotNetSdkActions.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SdkTemplateTest
public DotNetLanguage Language { get; }
public bool NoHttps { get => TargetRid.Contains("osx"); }
public string TargetRid { get; set; }
public string TargetArchitecture { get => TargetRid.Split('-')[1]; }
public string TargetArchitecture { get => TargetRid.Split('-').Last(); }
public string ScenarioName { get; }
public DotNetSdkTemplate Template { get; }

Expand Down Expand Up @@ -86,12 +86,15 @@ internal void Execute(DotNetSdkHelper dotNetHelper, string testRoot, string[]? f
if (Commands.HasFlag(DotNetSdkActions.PublishComplex))
{
dotNetHelper.ExecutePublish(projectDirectory, selfContained: false);
dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, TargetRid);
dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, $"linux-{TargetArchitecture}");
dotNetHelper.ExecutePublish(projectDirectory, TargetRid, selfContained: true);
}
if (Commands.HasFlag(DotNetSdkActions.PublishR2R))
{
dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, $"linux-{TargetArchitecture}", trimmed: true, readyToRun: true);
dotNetHelper.ExecutePublish(projectDirectory, TargetRid, selfContained: true, trimmed: true, readyToRun: true);
}
if (Commands.HasFlag(DotNetSdkActions.PublishAot))
{
dotNetHelper.ExecutePublish(projectDirectory, TargetRid, aot: true);
}
if (Commands.HasFlag(DotNetSdkActions.Test))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ public void VerifyConsoleTemplateComplex(DotNetLanguage language)
{
var newTest = new SdkTemplateTest(
nameof(SdkTemplateTests) + "Complex", language, _scenarioTestInput.TargetRid, DotNetSdkTemplate.Console,
DotNetSdkActions.Build | DotNetSdkActions.Run | DotNetSdkActions.PublishComplex);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Theory]
[MemberData(nameof(GetLanguages))]
[Trait("SkipIfBuild", "CommunityArchitecture")] // Portable assets are not available for community architectures.
public void VerifyConsoleTemplateComplexPortable(DotNetLanguage language)
{
var newTest = new SdkTemplateTest(
nameof(SdkTemplateTests) + "ComplexPortable", language, _scenarioTestInput.PortableRid, DotNetSdkTemplate.Console,
DotNetSdkActions.Build | DotNetSdkActions.Run | DotNetSdkActions.PublishComplex | DotNetSdkActions.PublishR2R);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}
Expand Down Expand Up @@ -208,8 +219,20 @@ public void VerifyRazorTemplate(DotNetLanguage language)
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Fact]
[Trait("SkipIfBuild", "Portable")] // Portable builds don't bundle an AOT compiler.
[Trait("SkipIfBuild", "Mono")] // Mono builds don't bundle an AOT compiler.
public void VerifyWebTemplatePublishBundledAot()
{
var newTest = new SdkTemplateTest(
nameof(SdkTemplateTests) + "Aot", DotNetLanguage.CSharp, _scenarioTestInput.TargetRid, DotNetSdkTemplate.Web,
DotNetSdkActions.PublishAot);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Fact]
[Trait("Category", "Workload")]
[Trait("SkipIfBuild", "CommunityArchitecture")] // SDK has no workloads that support community architectures.
public void VerifyWorkloadCmd()
{
var newTest = new DotnetWorkloadTest(
Expand Down