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

Add NativeAOT publish test #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public enum DotNetSdkActions
PublishR2R = 32,
Test = 64,
AddClassLibRef = 128,
PublishAOT = 256,
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ 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, bool? selfContained = null, string? rid = null, bool trimmed = false, bool readyToRun = false, string[]? frameworks = null, bool aot = false)
{
string options = string.Empty;
string binlogDifferentiator = string.Empty;


if ((trimmed || readyToRun || aot) && (selfContained.HasValue && selfContained.Value != true))
{
throw new ArgumentException("Invalid test parameters: Trimmed and ReadyToRun can only be used with self-contained publish");
}

if (selfContained.HasValue)
{
options += $"--self-contained {selfContained.Value.ToString().ToLowerInvariant()}";
Expand All @@ -130,6 +135,15 @@ public void ExecutePublish(string projectDirectory, bool? selfContained = null,
{
options += " /p:PublishReadyToRun=true";
binlogDifferentiator += "-R2R";
if (aot)
{
throw new ArgumentException("Invalid Test parameters: Publish AOT cannot be used with ReadyToRun publish");
}
}
if (aot)
{
options += " /p:PublishAOT=true";
binlogDifferentiator += "-AOT";
}
}
}
Expand Down Expand Up @@ -168,7 +182,7 @@ public void ExecuteRun(string projectDirectory, string[]? frameworks = null)

public void ExecuteRunWeb(string projectDirectory)
{
//checks what Process.Kill() will return based. Windows this is -1, Mac and Linux this appears
//checks what Process.Kill() will return based. Windows this is -1, Mac and Linux this appears
//to be process based. Currently 137
int exitCode = OperatingSystemFinder.IsWindowsPlatform() ? -1 : 137;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ internal void Execute(DotNetSdkHelper dotNetHelper, string testRoot, string[]? f
}
if (Commands.HasFlag(DotNetSdkActions.PublishComplex))
{
dotNetHelper.ExecutePublish(projectDirectory, selfContained: false);
dotNetHelper.ExecutePublish(projectDirectory, selfContained: false);
dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, TargetRid);
dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, $"linux-{TargetArchitecture}");
}
if (Commands.HasFlag(DotNetSdkActions.PublishR2R))
{
dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, $"linux-{TargetArchitecture}", trimmed: true, readyToRun: true);
}
if (Commands.HasFlag(DotNetSdkActions.PublishAOT))
{
dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, TargetRid, aot: true);
}
if (Commands.HasFlag(DotNetSdkActions.Test))
{
dotNetHelper.ExecuteTest(projectDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SdkTemplateTests(ScenarioTestFixture testInput, ITestOutputHelper outputH
_testOutputHelper = outputHelper;
_sdkHelper = new DotNetSdkHelper(outputHelper, _scenarioTestInput.DotNetRoot, _scenarioTestInput.SdkVersion);
}

[Theory]
[MemberData(nameof(GetLanguages))]
public void VerifyConsoleTemplateComplex(DotNetLanguage language)
Expand All @@ -32,6 +32,16 @@ public void VerifyConsoleTemplateComplex(DotNetLanguage language)
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Theory]
[MemberData(nameof(GetLanguages))]
public void VerifyConsoleTemplateAOT(DotNetLanguage language)
{
var newTest = new SdkTemplateTest(
nameof(SdkTemplateTests) + "AOT", language, _scenarioTestInput.TargetRid, DotNetSdkTemplate.Console,
DotNetSdkActions.Build | DotNetSdkActions.Run | DotNetSdkActions.PublishAOT);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this execute the test as well? We might want to print the value of IsDynamicCodeSupported or similar, just to prove it's Native AOT and it's running correctly.

}

[Theory]
[MemberData(nameof(GetLanguages))]
[Trait("Category", "Offline")]
Expand Down Expand Up @@ -83,7 +93,7 @@ public void VerifyMSTestTemplate(DotNetLanguage language)
DotNetSdkActions.Test);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Theory]
[InlineData(DotNetLanguage.CSharp)]
[InlineData(DotNetLanguage.VB)]
Expand All @@ -97,7 +107,7 @@ public void VerifyWPFTemplate(DotNetLanguage language)
DotNetSdkActions.Test | DotNetSdkActions.Run | DotNetSdkActions.Publish);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Fact]
[Trait("Category", "Offline")]
[Trait("SkipIfPlatform", "LINUX")]
Expand All @@ -109,7 +119,7 @@ public void VerifyWebAppTemplate()
DotNetSdkActions.Test | DotNetSdkActions.Run | DotNetSdkActions.Publish);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Theory]
[InlineData(DotNetLanguage.CSharp)]
[InlineData(DotNetLanguage.VB)]
Expand All @@ -123,7 +133,7 @@ public void VerifyWinformsTemplate(DotNetLanguage language)
DotNetSdkActions.Test | DotNetSdkActions.Run | DotNetSdkActions.Publish);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Theory]
[InlineData(DotNetLanguage.CSharp)]
[InlineData(DotNetLanguage.VB)]
Expand All @@ -141,7 +151,7 @@ public void VerifyReferenceInConsoleTemplate(DotNetLanguage language)
DotNetSdkActions.Run | DotNetSdkActions.Publish);
newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot);
}

[Theory]
[Trait("Category", "MultiTFM")]
[Trait("Category", "Offline")]
Expand Down Expand Up @@ -208,7 +218,7 @@ public void VerifyPreMadeSolution()
}

/*
* v-masche note: Requires ASP.NET runtimes for .NET6 and .NET7. To be enabled if we decide to
* v-masche note: Requires ASP.NET runtimes for .NET6 and .NET7. To be enabled if we decide to
* download that as part of the build like we do the normal .NET runtimes
[Fact]
[Trait("Category", "MultiTFM")]
Expand All @@ -235,7 +245,7 @@ public void VerifyDuplicateReferenceFailuresInConsoleTemplate(DotNetLanguage lan
}*/

private static string[] GetFrameworks = { "net9.0", "net8.0", "net7.0", "net6.0" };

private static IEnumerable<object[]> GetLanguages() => Enum.GetValues<DotNetLanguage>().Select(lang => new object[] { lang });

}