-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RemoteExecutor: support single file and NativeAOT
- Loading branch information
1 parent
80b6be4
commit 149e5f0
Showing
7 changed files
with
333 additions
and
29 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
src/Microsoft.DotNet.RemoteExecutor/SingleFileTests/Program.cs
This file contains 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,122 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
using System.Threading.Tasks; | ||
using System.Xml.Linq; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
// @TODO medium-to-longer term, we should try to get rid of the special-unicorn-single-file runner in favor of making the real runner work for single file. | ||
// https://github.com/dotnet/runtime/issues/70432 | ||
public class SingleFileTestRunner : XunitTestFramework | ||
{ | ||
private SingleFileTestRunner(IMessageSink messageSink) | ||
: base(messageSink) { } | ||
|
||
public static int Main(string[] args) | ||
{ | ||
int? maybeExitCode = Microsoft.DotNet.RemoteExecutor.Program.TryExecute(args); | ||
if (maybeExitCode.HasValue) | ||
{ | ||
return maybeExitCode.Value; | ||
} | ||
|
||
var asm = typeof(SingleFileTestRunner).Assembly; | ||
Console.WriteLine("Running assembly:" + asm.FullName); | ||
|
||
var diagnosticSink = new ConsoleDiagnosticMessageSink(); | ||
var testsFinished = new TaskCompletionSource(); | ||
var testSink = new TestMessageSink(); | ||
var summarySink = new DelegatingExecutionSummarySink(testSink, | ||
() => false, | ||
(completed, summary) => Console.WriteLine($"Tests run: {summary.Total}, Errors: {summary.Errors}, Failures: {summary.Failed}, Skipped: {summary.Skipped}. Time: {TimeSpan.FromSeconds((double)summary.Time).TotalSeconds}s")); | ||
var resultsXmlAssembly = new XElement("assembly"); | ||
var resultsSink = new DelegatingXmlCreationSink(summarySink, resultsXmlAssembly); | ||
|
||
testSink.Execution.TestSkippedEvent += args => { Console.WriteLine($"[SKIP] {args.Message.Test.DisplayName}"); }; | ||
testSink.Execution.TestFailedEvent += args => { Console.WriteLine($"[FAIL] {args.Message.Test.DisplayName}{Environment.NewLine}{Xunit.ExceptionUtility.CombineMessages(args.Message)}{Environment.NewLine}{Xunit.ExceptionUtility.CombineStackTraces(args.Message)}"); }; | ||
|
||
testSink.Execution.TestAssemblyFinishedEvent += args => | ||
{ | ||
Console.WriteLine($"Finished {args.Message.TestAssembly.Assembly}{Environment.NewLine}"); | ||
testsFinished.SetResult(); | ||
}; | ||
|
||
var assemblyConfig = new TestAssemblyConfiguration() | ||
{ | ||
// Turn off pre-enumeration of theories, since there is no theory selection UI in this runner | ||
PreEnumerateTheories = false, | ||
}; | ||
|
||
var xunitTestFx = new SingleFileTestRunner(diagnosticSink); | ||
var asmInfo = Reflector.Wrap(asm); | ||
var asmName = asm.GetName(); | ||
|
||
var discoverySink = new TestDiscoverySink(); | ||
var discoverer = xunitTestFx.CreateDiscoverer(asmInfo); | ||
discoverer.Find(false, discoverySink, TestFrameworkOptions.ForDiscovery(assemblyConfig)); | ||
discoverySink.Finished.WaitOne(); | ||
|
||
string xmlResultFileName = null; | ||
XunitFilters filters = new XunitFilters(); | ||
// Quick hack wo much validation to get args that are passed (notrait, xml) | ||
Dictionary<string, List<string>> noTraits = new Dictionary<string, List<string>>(); | ||
for (int i = 0; i < args.Length; i++) | ||
{ | ||
if (args[i].Equals("-notrait", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var traitKeyValue=args[i + 1].Split("=", StringSplitOptions.TrimEntries); | ||
if (!noTraits.TryGetValue(traitKeyValue[0], out List<string> values)) | ||
{ | ||
noTraits.Add(traitKeyValue[0], values = new List<string>()); | ||
} | ||
values.Add(traitKeyValue[1]); | ||
} | ||
if (args[i].Equals("-xml", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
xmlResultFileName=args[i + 1].Trim(); | ||
} | ||
} | ||
|
||
foreach (KeyValuePair<string, List<string>> kvp in noTraits) | ||
{ | ||
filters.ExcludedTraits.Add(kvp.Key, kvp.Value); | ||
} | ||
|
||
var filteredTestCases = discoverySink.TestCases.Where(filters.Filter).ToList(); | ||
var executor = xunitTestFx.CreateExecutor(asmName); | ||
executor.RunTests(filteredTestCases, resultsSink, TestFrameworkOptions.ForExecution(assemblyConfig)); | ||
|
||
resultsSink.Finished.WaitOne(); | ||
|
||
// Helix need to see results file in the drive to detect if the test has failed or not | ||
if(xmlResultFileName != null) | ||
{ | ||
resultsXmlAssembly.Save(xmlResultFileName); | ||
} | ||
|
||
var failed = resultsSink.ExecutionSummary.Failed > 0 || resultsSink.ExecutionSummary.Errors > 0; | ||
return failed ? 1 : 0; | ||
} | ||
} | ||
|
||
internal class ConsoleDiagnosticMessageSink : IMessageSink | ||
{ | ||
public bool OnMessage(IMessageSinkMessage message) | ||
{ | ||
if (message is IDiagnosticMessage diagnosticMessage) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/Microsoft.DotNet.RemoteExecutor/SingleFileTests/SingleFileTests.csproj
This file contains 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,45 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\Microsoft.DotNet.RemoteExecutor.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\tests\RemoteExecutorTests.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="xunit" Version="2.4.2" ExcludeAssets="build" /> | ||
<PackageReference Include="xunit.analyzers" Version="1.0.0" ExcludeAssets="build" /> | ||
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="8.0.0-beta.22524.5" /> | ||
<PackageReference Include="xunit.runner.utility" Version="2.4.2" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(PublishSingleFile)' == 'true'"> | ||
<UseAppHost>true</UseAppHost> | ||
<SelfContained>true</SelfContained> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(PublishAot)' == 'true'"> | ||
<RdXmlFile Include="rd.xml" /> | ||
<IlcArg Include="--nometadatablocking" /> | ||
<IlcArg Include="--feature:System.Reflection.IsTypeConstructionEagerlyValidated=false" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(PublishAot)' == 'true'"> | ||
<NoWarn>$(NoWarn);IL1005;IL3002</NoWarn> | ||
<TrimMode>partial</TrimMode> | ||
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings> | ||
<SuppressAotAnalysisWarnings>true</SuppressAotAnalysisWarnings> | ||
|
||
<!-- Forced by ILLink targets; we should fix the SDK --> | ||
<SelfContained>true</SelfContained> | ||
</PropertyGroup> | ||
|
||
</Project> |
82 changes: 82 additions & 0 deletions
82
src/Microsoft.DotNet.RemoteExecutor/SingleFileTests/rd.xml
This file contains 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,82 @@ | ||
<Directives> | ||
<Application> | ||
<!-- xunit will reflect on these to process certain InlineDataAttributes --> | ||
<Assembly Name="System.Linq"> | ||
<Type Name="System.Linq.Enumerable"> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Char, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Char, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Boolean, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Boolean, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Byte, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Byte, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.SByte, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.SByte, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Int16, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Int16, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.UInt16, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.UInt16, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Int32, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Int32, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.UInt32, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.UInt32, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Int64, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Int64, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.UInt64, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.UInt64, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Single, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Single, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="Cast"> | ||
<GenericArgument Name="System.Double, System.Private.CoreLib" /> | ||
</Method> | ||
<Method Name="ToArray"> | ||
<GenericArgument Name="System.Double, System.Private.CoreLib" /> | ||
</Method> | ||
</Type> | ||
</Assembly> | ||
</Application> | ||
</Directives> | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.