-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for building a test exe as single file (#42972)
* Add option for building a test exe as single file * Remove left over test * Add target to exclude references from single-file * First attempt at adding a CI job * Opt-in specific libraries for single-file testing support Start with System.Collections as all tests pass. * Config testing using single-file in build.cmd * Change yml suffix name to SingleFile * Windows_NT_x64 -> windows_x64 * Fix for helix queueing * Respond to host rename * Change TargetOS to check for windows * chmod test exe on linux * Direct singlefilehost to the locally built copy * Adjust singlefilehost copy+call * Add .exe suffix on Windows * Move libraries after hosts build to allow for libs.test to depend on hosts build * Split up host and libs packaging and tests * Move host packaging * Move pretest up * Move packages up as well * Reorder libs pretest and libs.packages * Add isSingleFile build parameter to limit Linux Helix jobs * Typo * Change conditional check * Fix yml * Fix yml * Fix neq * Fix subsets * Typo * Fix * Adjust assert * Include code from Michal to skip failing test * Remove empty ItemGroup * Update src/libraries/Common/tests/SingleFileTestRunner/SingleFileTestRunner.cs Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com> * Update eng/testing/tests.singlefile.targets Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com> * Use ProjectExclusions * Update eng/testing/tests.singlefile.targets Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com> * Revert changes * Remove host build from tests Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
- Loading branch information
1 parent
4581290
commit 7677f7d
Showing
9 changed files
with
188 additions
and
16 deletions.
There are no files selected for viewing
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
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,62 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
|
||
<BundleDir>$([MSBuild]::NormalizeDirectory('$(OutDir)', 'publish'))</BundleDir> | ||
<RunScriptOutputPath>$([MSBuild]::NormalizePath('$(BundleDir)', '$(RunScriptOutputName)'))</RunScriptOutputPath> | ||
<RuntimeIdentifier>$(PackageRID)</RuntimeIdentifier> | ||
|
||
<RunScriptCommand Condition="'$(TargetOS)' == 'windows'">$(AssemblyName).exe</RunScriptCommand> | ||
<RunScriptCommand Condition="'$(TargetOS)' != 'windows'">chmod +rwx $(AssemblyName) && ./$(AssemblyName)</RunScriptCommand> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PublishSingleFile>true</PublishSingleFile> | ||
<UseAppHost>true</UseAppHost> | ||
<SelfContained>true</SelfContained> | ||
<SingleFileHostSourcePath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(Configuration)', 'corehost'))/singlefilehost</SingleFileHostSourcePath> | ||
<SingleFileHostSourcePath Condition="'$(TargetOS)' == 'windows'">$(SingleFileHostSourcePath).exe</SingleFileHostSourcePath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="$(CommonTestPath)SingleFileTestRunner\SingleFileTestRunner.cs" | ||
Link="Common\SingleFileTestRunner\SingleFileTestRunner.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="xunit.runner.utility" Version="$(XUnitVersion)" /> | ||
</ItemGroup> | ||
|
||
<Target Name="__ExcludeAssembliesFromSingleFile" | ||
Inputs="%(ResolvedFileToPublish.Identity)" | ||
Outputs="__NewResolvedFiles" | ||
BeforeTargets="_ComputeFilesToBundle"> | ||
<PropertyGroup> | ||
<__Identity>%(ResolvedFileToPublish.Identity)</__Identity> | ||
<__FileName>%(ResolvedFileToPublish.Filename)%(ResolvedFileToPublish.Extension)</__FileName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<__NewResolvedFiles Include="@(ResolvedFileToPublish)"> | ||
<ExcludeFromSingleFile Condition="'%(__ExcludeFromBundle.Identity)' == '$(__FileName)'">true</ExcludeFromSingleFile> | ||
</__NewResolvedFiles> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="__UpdateExcludedAssembliesFromSingleFile" | ||
Inputs="ExcludeFromSingleFile" | ||
Outputs="ResolvedFileToPublish" | ||
DependsOnTargets="ComputeResolvedFilesToPublishList" | ||
BeforeTargets="_ComputeFilesToBundle"> | ||
<ItemGroup> | ||
<ResolvedFileToPublish Remove="@(ResolvedFileToPublish)" /> | ||
<ResolvedFileToPublish Include="@(__NewResolvedFiles)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="PublishTestAsSingleFile" | ||
Condition="'$(IsCrossTargetingBuild)' != 'true'" | ||
AfterTargets="Build" | ||
DependsOnTargets="Publish;ArchiveTests" /> | ||
|
||
</Project> |
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
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
77 changes: 77 additions & 0 deletions
77
src/libraries/Common/tests/SingleFileTestRunner/SingleFileTestRunner.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,77 @@ | ||
// 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; | ||
|
||
public class SingleFileTestRunner : XunitTestFramework | ||
{ | ||
private SingleFileTestRunner(IMessageSink messageSink) | ||
: base(messageSink) { } | ||
|
||
public static int Main(string[] args) | ||
{ | ||
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 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()); | ||
discoverySink.Finished.WaitOne(); | ||
XunitFilters filters = new XunitFilters(); | ||
filters.ExcludedTraits.Add("category", new List<string> { "failing" }); | ||
var filteredTestCases = discoverySink.TestCases.Where(filters.Filter).ToList(); | ||
var executor = xunitTestFx.CreateExecutor(asmName); | ||
executor.RunTests(filteredTestCases, resultsSink, TestFrameworkOptions.ForExecution()); | ||
|
||
resultsSink.Finished.WaitOne(); | ||
|
||
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; | ||
} | ||
} |
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