-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add integration tests for MonoAOTLLVMToolchain #2965
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
Open
AndyBodnar
wants to merge
3
commits into
dotnet:master
Choose a base branch
from
AndyBodnar:add-monoaotllvm-integration-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−3
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
172 changes: 172 additions & 0 deletions
172
tests/BenchmarkDotNet.IntegrationTests/MonoAotLlvmTests.cs
This file contains hidden or 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,172 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Configs; | ||
| using BenchmarkDotNet.Detectors; | ||
| using BenchmarkDotNet.Environments; | ||
| using BenchmarkDotNet.IntegrationTests.Diagnosers; | ||
| using BenchmarkDotNet.IntegrationTests.Xunit; | ||
| using BenchmarkDotNet.Jobs; | ||
| using BenchmarkDotNet.Portability; | ||
| using BenchmarkDotNet.Tests.Loggers; | ||
| using BenchmarkDotNet.Tests.XUnit; | ||
| using BenchmarkDotNet.Toolchains.DotNetCli; | ||
| using BenchmarkDotNet.Toolchains.MonoAotLLVM; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace BenchmarkDotNet.IntegrationTests | ||
| { | ||
| /// <summary> | ||
| /// In order to run MonoAotLlvmTests locally, the following prerequisites are required: | ||
| /// * Have MonoAOT workload installed | ||
| /// * Have the Mono AOT compiler available at the path specified by MONOAOTLLVM_COMPILER_PATH environment variable | ||
| /// </summary> | ||
| public class MonoAotLlvmTests(ITestOutputHelper output) : BenchmarkTestExecutor(output) | ||
| { | ||
| private const string AotCompilerPathEnvVar = "MONOAOTLLVM_COMPILER_PATH"; | ||
|
|
||
| private static string GetAotCompilerPath() | ||
| => Environment.GetEnvironmentVariable(AotCompilerPathEnvVar); | ||
|
|
||
| private static bool IsAotCompilerAvailable() | ||
| => !string.IsNullOrEmpty(GetAotCompilerPath()) && System.IO.File.Exists(GetAotCompilerPath()); | ||
|
|
||
| private ManualConfig GetConfig(MonoAotCompilerMode mode = MonoAotCompilerMode.llvm) | ||
| { | ||
| var aotCompilerPath = GetAotCompilerPath(); | ||
| var logger = new OutputLogger(Output); | ||
| var netCoreAppSettings = new NetCoreAppSettings( | ||
| "net8.0", | ||
| null, | ||
| "MonoAOTLLVM", | ||
| aotCompilerPath: aotCompilerPath, | ||
| aotCompilerMode: mode); | ||
|
|
||
| return ManualConfig.CreateEmpty() | ||
| .AddLogger(logger) | ||
| .AddJob(Job.Dry | ||
| .WithRuntime(new MonoAotLLVMRuntime( | ||
| new System.IO.FileInfo(aotCompilerPath), | ||
| mode, | ||
| "net8.0")) | ||
| .WithToolchain(MonoAotLLVMToolChain.From(netCoreAppSettings))) | ||
| .WithBuildTimeout(TimeSpan.FromMinutes(5)) | ||
| .WithOption(ConfigOptions.GenerateMSBuildBinLog, true); | ||
| } | ||
|
|
||
| private static bool GetShouldRunTest() | ||
| { | ||
| // MonoAOTLLVM is only supported on non-Windows platforms with a 64-bit architecture | ||
| if (!RuntimeInformation.Is64BitPlatform()) | ||
AndyBodnar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return false; | ||
|
|
||
| if (OsDetector.IsWindows()) | ||
| return false; | ||
|
|
||
| if (!IsAotCompilerAvailable()) | ||
| return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| [FactEnvSpecific("MonoAOTLLVM is only supported on Unix", EnvRequirement.NonWindows)] | ||
| public void MonoAotLlvmIsSupported() | ||
| { | ||
| if (!GetShouldRunTest()) | ||
| { | ||
| Output.WriteLine($"Skipping test: AOT compiler not available at {AotCompilerPathEnvVar}"); | ||
| return; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| CanExecute<MonoAotLlvmBenchmark>(GetConfig()); | ||
| } | ||
| catch (MisconfiguredEnvironmentException e) | ||
| { | ||
| if (ContinuousIntegration.IsLocalRun()) | ||
| Output.WriteLine(e.SkipMessage); | ||
| else | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| [FactEnvSpecific("MonoAOTLLVM is only supported on Unix", EnvRequirement.NonWindows)] | ||
| public void MonoAotLlvmSupportsInProcessDiagnosers() | ||
| { | ||
| if (!GetShouldRunTest()) | ||
| { | ||
| Output.WriteLine($"Skipping test: AOT compiler not available at {AotCompilerPathEnvVar}"); | ||
| return; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var diagnoser = new MockInProcessDiagnoser1(BenchmarkDotNet.Diagnosers.RunMode.NoOverhead); | ||
| var config = GetConfig().AddDiagnoser(diagnoser); | ||
|
|
||
| try | ||
| { | ||
| CanExecute<MonoAotLlvmBenchmark>(config); | ||
| } | ||
| catch (MisconfiguredEnvironmentException e) | ||
| { | ||
| if (ContinuousIntegration.IsLocalRun()) | ||
| { | ||
| Output.WriteLine(e.SkipMessage); | ||
| return; | ||
| } | ||
| throw; | ||
| } | ||
|
|
||
| Assert.Equal([diagnoser.ExpectedResult], diagnoser.Results.Values); | ||
| Assert.Equal([diagnoser.ExpectedResult], BaseMockInProcessDiagnoser.s_completedResults.Select(t => t.result)); | ||
| } | ||
| finally | ||
| { | ||
| BaseMockInProcessDiagnoser.s_completedResults.Clear(); | ||
| } | ||
| } | ||
|
|
||
| [FactEnvSpecific("MonoAOTLLVM is only supported on Unix", EnvRequirement.NonWindows)] | ||
| public void MonoAotLlvmMiniModeIsSupported() | ||
AndyBodnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (!GetShouldRunTest()) | ||
| { | ||
| Output.WriteLine($"Skipping test: AOT compiler not available at {AotCompilerPathEnvVar}"); | ||
| return; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| CanExecute<MonoAotLlvmBenchmark>(GetConfig(MonoAotCompilerMode.mini)); | ||
| } | ||
| catch (MisconfiguredEnvironmentException e) | ||
| { | ||
| if (ContinuousIntegration.IsLocalRun()) | ||
| Output.WriteLine(e.SkipMessage); | ||
| else | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| public class MonoAotLlvmBenchmark | ||
| { | ||
| [Benchmark] | ||
| public void Check() | ||
| { | ||
| // Verify we're running on Mono AOT | ||
| if (!RuntimeInformation.IsMono) | ||
| { | ||
| throw new Exception("This is not Mono runtime"); | ||
| } | ||
|
|
||
| if (!RuntimeInformation.IsAot) | ||
| { | ||
| throw new Exception("This is not running in AOT mode"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.