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 project to create helix work items for host tests #108529

Merged
merged 2 commits into from
Oct 11, 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
2 changes: 2 additions & 0 deletions src/installer/tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<ProjectReferenceExclusion Include="@(NetCoreAppLibrary)" />
</ItemGroup>

<Target Name="GetTargetDir" Returns="$([System.IO.Path]::GetFullPath('$(TargetDir)'))" />

<Target Name="SetupTestContextVariables"
Condition="'$(IsTestProject)' == 'true'"
DependsOnTargets="
Expand Down
24 changes: 17 additions & 7 deletions src/installer/tests/TestUtils/RepoDirectoriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@ public sealed class RepoDirectoriesProvider
{
public static readonly RepoDirectoriesProvider Default = new RepoDirectoriesProvider();

// Paths computed by looking for the repo root
// Paths computed by looking for the repo root or helix correlation payload
public string BaseArtifactsFolder { get; }
public string HostArtifacts { get; }
public string HostTestArtifacts { get; }

private RepoDirectoriesProvider()
{
string repoRoot = GetRepoRootDirectory();
BaseArtifactsFolder = Path.Combine(repoRoot, "artifacts");
string helixPayload = Environment.GetEnvironmentVariable("HELIX_CORRELATION_PAYLOAD");
if (helixPayload != null)
{
// See src/installer/tests/helixpublish.proj
HostArtifacts = Path.Combine(helixPayload, "host_bin");
HostTestArtifacts = Path.Combine(helixPayload, "host_test_bin");
}
else
{
string repoRoot = GetRepoRootDirectory();
BaseArtifactsFolder = Path.Combine(repoRoot, "artifacts");

string osPlatformConfig = $"{TestContext.BuildRID}.{TestContext.Configuration}";
string artifacts = Path.Combine(BaseArtifactsFolder, "bin", osPlatformConfig);
HostArtifacts = Path.Combine(artifacts, "corehost");
HostTestArtifacts = Path.Combine(artifacts, "corehost_test");
string osPlatformConfig = $"{TestContext.BuildRID}.{TestContext.Configuration}";
string artifacts = Path.Combine(BaseArtifactsFolder, "bin", osPlatformConfig);
HostArtifacts = Path.Combine(artifacts, "corehost");
HostTestArtifacts = Path.Combine(artifacts, "corehost_test");
}
}

private static string GetRepoRootDirectory()
Expand Down
65 changes: 65 additions & 0 deletions src/installer/tests/helixpublish.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<Project Sdk="Microsoft.DotNet.Helix.Sdk">

<PropertyGroup>
<HelixArchitecture>$(TargetArchitecture)</HelixArchitecture>
<HelixBuild Condition="'$(HelixBuild)' == ''">$(BUILD_BUILDNUMBER)</HelixBuild>
<HelixBuild Condition="'$(HelixBuild)' == ''">default</HelixBuild>
<HelixConfiguration>$(Configuration)</HelixConfiguration>
<HelixType>test/host</HelixType>

<IncludeDotNetCli>true</IncludeDotNetCli>
<DotNetCliPackageType>sdk</DotNetCliPackageType>
</PropertyGroup>

<ItemGroup>
<HostTestProject Include="$(InstallerProjectRoot)tests\AppHost.Bundle.Tests\AppHost.Bundle.Tests.csproj" />
<HostTestProject Include="$(InstallerProjectRoot)tests\HostActivation.Tests\HostActivation.Tests.csproj" />
<HostTestProject Include="$(InstallerProjectRoot)tests\Microsoft.NET.HostModel.Tests\Microsoft.NET.HostModel.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<!-- Pre-built test projects and constructed .NET install layout -->
<HelixCorrelationPayload Include="$(TestArtifactsOutputRoot)" Destination="test_assets" />
<!-- Native host binaries -->
<HelixCorrelationPayload Include="$(DotNetHostBinDir)" Destination="host_bin" />
<!-- Native host test/mock binaries -->
<HelixCorrelationPayload Include="$([MSBuild]::NormalizePath('$(DotNetHostBinDir)', '..', 'corehost_test'))" Destination="host_test_bin" />
</ItemGroup>

<!-- Environment variables used by host tests to find test assets. See src/installer/tests/TestUtils/TestContext.cs -->
<ItemGroup Condition="'$(TargetOS)' == 'windows'">
<_HelixPreCommands Include="set TEST_ASSETS_OUTPUT=%HELIX_CORRELATION_PAYLOAD%\test_assets" />
<_HelixPreCommands Include="set TEST_ARTIFACTS=%HELIX_WORKITEM_ROOT%\test_artifacts" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' != 'windows'">
<_HelixPreCommands Include="export TEST_ASSETS_OUTPUT=$HELIX_CORRELATION_PAYLOAD/test_assets" />
<_HelixPreCommands Include="export TEST_ARTIFACTS=$HELIX_WORKITEM_ROOT/test_artifacts" />
</ItemGroup>

<!-- Get the command and payload directory corresponding to each test -->
<Target Name="ComputePayloadPaths" Outputs="%(HostTestProject.Identity)">
<MSBuild Projects="%(HostTestProject.Identity)" Targets="GetTargetDir">
<Output TaskParameter="TargetOutputs" PropertyName="_PayloadDirectory" />
</MSBuild>
<MSBuild Projects="%(HostTestProject.Identity)" Targets="GetTargetPath">
<Output TaskParameter="TargetOutputs" PropertyName="_TargetPath" />
</MSBuild>
<ItemGroup>
<HostTestProject>
<Command>dotnet test $([System.IO.Path]::GetFileName($(_TargetPath))) $(TestRunnerAdditionalArguments)</Command>
<PayloadDirectory>$(_PayloadDirectory)</PayloadDirectory>
</HostTestProject>
</ItemGroup>
</Target>

<Target Name="CreateHelixWorkItems" DependsOnTargets="ComputePayloadPaths" BeforeTargets="CoreTest">
<ItemGroup>
<HelixWorkItem Include="$([System.IO.Path]::GetFileNameWithoutExtension(%(HostTestProject.Identity)))">
<PayloadDirectory>%(HostTestProject.PayloadDirectory)</PayloadDirectory>
<Command>%(HostTestProject.Command)</Command>
<PreCommands>@(_HelixPreCommands)</PreCommands>
</HelixWorkItem>
</ItemGroup>
</Target>

</Project>