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

CPP runner under .NET (Core) #3003

Merged
merged 21 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add core cpp runner
  • Loading branch information
nohwnd committed Sep 13, 2021
commit ca533b3d4f113f79f8076e79c49884bb62bc5de6
48 changes: 16 additions & 32 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ $TPB_Configuration = $Configuration
$TPB_TargetRuntime = $TargetRuntime
$TPB_X64_Runtime = "win7-x64"
$TPB_X86_Runtime = "win7-x86"
$TPB_ARM64_Runtime = "win10-arm64"

# Version suffix is empty for RTM release
$TPB_Version = if ($VersionSuffix -ne '') { $Version + "-" + $VersionSuffix } else { $Version }
Expand All @@ -103,7 +102,7 @@ $language = @("cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt-BR", "ru", "tr
# Capture error state in any step globally to modify return code
$Script:ScriptFailed = $false

. "$($CurrentScriptDir.FullName)\verify-nupkgs.ps1"
Import-Module -Name "$($CurrentScriptDir.FullName)\verify-nupkgs.ps1" -Scope Local

# Update the version in the dependencies props to be the TPB_version version, this is not ideal but because changing how this is resolved would
# mean that we need to change the whole build process this is a solution with the least amount of impact, that does not require us to keep track of
Expand Down Expand Up @@ -197,24 +196,19 @@ function Publish-Package
$packageProject = Join-Path $env:TP_PACKAGE_PROJ_DIR "package\package.csproj"
$testHostProject = Join-Path $env:TP_ROOT_DIR "src\testhost\testhost.csproj"
$testHostx86Project = Join-Path $env:TP_ROOT_DIR "src\testhost.x86\testhost.x86.csproj"
$testHostarm64Project = Join-Path $env:TP_ROOT_DIR "src\testhost.arm64\testhost.arm64.csproj"

$testhostFullPackageDir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFramework451\$TPB_TargetRuntime")
$testhostCore20PackageDir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20")
$testhostCore20PackageX64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20\$TPB_X64_Runtime")
$testhostCore20PackageX86Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20\$TPB_X86_Runtime")
$testhostCore20PackageARM64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20\$TPB_ARM64_Runtime")
$testhostCore20PackageTempX64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\publishTemp\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20\$TPB_X64_Runtime")
$testhostCore20PackageTempX86Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\publishTemp\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20\$TPB_X86_Runtime")
$testhostCore20PackageTempARM64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\publishTemp\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20\$TPB_ARM64_Runtime")

$testhostCore10PackageDir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore10")
$testhostCore10PackageX64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore10\$TPB_X64_Runtime")
$testhostCore10PackageX86Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore10\$TPB_X86_Runtime")
$testhostCore10PackageARM64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore10\$TPB_ARM64_Runtime")
$testhostCore10PackageTempX64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\publishTemp\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore10\$TPB_X64_Runtime")
$testhostCore10PackageTempX86Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\publishTemp\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore10\$TPB_X86_Runtime")
$testhostCore10PackageTempARM64Dir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\publishTemp\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore10\$TPB_ARM64_Runtime")

$testhostUapPackageDir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkUap100")
$vstestConsoleProject = Join-Path $env:TP_ROOT_DIR "src\vstest.console\vstest.console.csproj"
Expand Down Expand Up @@ -254,11 +248,6 @@ function Publish-Package
Publish-PackageWithRuntimeInternal $testHostx86Project $TPB_TargetFrameworkCore20 $TPB_X86_Runtime false $testhostCore20PackageTempX86Dir
Publish-PackageWithRuntimeInternal $testHostx86Project $TPB_TargetFrameworkCore10 $TPB_X86_Runtime true $testhostCore10PackageTempX86Dir

Write-Log "Package: Publish testhost.arm64\testhost.arm64.csproj"
Publish-PackageInternal $testHostarm64Project $TPB_TargetFramework451 $testhostFullPackageDir
Publish-PackageWithRuntimeInternal $testHostarm64Project $TPB_TargetFrameworkCore20 $TPB_ARM64_Runtime false $testhostCore20PackageTempARM64Dir
Publish-PackageWithRuntimeInternal $testHostarm64Project $TPB_TargetFrameworkCore10 $TPB_ARM64_Runtime true $testhostCore10PackageTempARM64Dir

# Copy the .NET multitarget testhost exes to destination folder (except for net451 which is the default)
foreach ($tfm in "net452;net46;net461;net462;net47;net471;net472;net48" -split ";") {
Copy-Item "$(Split-Path $testHostProject)\bin\$TPB_Configuration\$tfm\$TPB_X64_Runtime\testhost.$tfm.exe" $testhostFullPackageDir\testhost.$tfm.exe -Force
Expand All @@ -273,25 +262,14 @@ function Publish-Package
Copy-Item "$(Split-Path $testHostx86Project)\bin\$TPB_Configuration\$tfm\$TPB_X86_Runtime\testhost.$tfm.x86.exe.config" $testhostFullPackageDir\testhost.$tfm.x86.exe.config -Force
}

# Copy the .NET multitarget testhost.arm64 exes to destination folder (except for net451 which is the default)
foreach ($tfm in "net452;net46;net461;net462;net47;net471;net472;net48" -split ";") {
Copy-Item "$(Split-Path $testHostarm64Project)\bin\$TPB_Configuration\$tfm\$TPB_ARM64_Runtime\testhost.$tfm.arm64.exe" $testhostFullPackageDir\testhost.$tfm.arm64.exe -Force
Copy-Item "$(Split-Path $testHostarm64Project)\bin\$TPB_Configuration\$tfm\$TPB_ARM64_Runtime\testhost.$tfm.arm64.pdb" $testhostFullPackageDir\testhost.$tfm.arm64.pdb -Force
Copy-Item "$(Split-Path $testHostarm64Project)\bin\$TPB_Configuration\$tfm\$TPB_ARM64_Runtime\testhost.$tfm.arm64.exe.config" $testhostFullPackageDir\testhost.$tfm.arm64.exe.config -Force
}

# Copy the .NET core x86, x64 and arm64 testhost exes from tempPublish to required folder
# Copy the .NET core x86 and x64 testhost exes from tempPublish to required folder
New-Item -ItemType directory -Path $testhostCore20PackageX64Dir -Force | Out-Null
Copy-Item $testhostCore20PackageTempX64Dir\testhost* $testhostCore20PackageX64Dir -Force -Recurse
Copy-Item $testhostCore20PackageTempX64Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore20PackageX64Dir -Force

New-Item -ItemType directory -Path $testhostCore20PackageX86Dir -Force | Out-Null
Copy-Item $testhostCore20PackageTempX86Dir\testhost.x86* $testhostCore20PackageX86Dir -Force -Recurse
Copy-Item $testhostCore20PackageTempX86Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore20PackageX86Dir -Force

New-Item -ItemType directory -Path $testhostCore20PackageARM64Dir -Force | Out-Null
Copy-Item $testhostCore20PackageTempARM64Dir\testhost.arm64* $testhostCore20PackageARM64Dir -Force -Recurse
Copy-Item $testhostCore20PackageTempARM64Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore20PackageARM64Dir -Force

New-Item -ItemType directory -Path $testhostCore10PackageX64Dir -Force | Out-Null
Copy-Item $testhostCore10PackageTempX64Dir\testhost* $testhostCore10PackageX64Dir -Force -Recurse
Expand All @@ -300,10 +278,6 @@ function Publish-Package
New-Item -ItemType directory -Path $testhostCore10PackageX86Dir -Force | Out-Null
Copy-Item $testhostCore10PackageTempX86Dir\testhost.x86* $testhostCore10PackageX86Dir -Force -Recurse
Copy-Item $testhostCore10PackageTempX86Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore10PackageX86Dir -Force

New-Item -ItemType directory -Path $testhostCore10PackageARM64Dir -Force | Out-Null
Copy-Item $testhostCore10PackageTempARM64Dir\testhost.arm64* $testhostCore10PackageARM64Dir -Force -Recurse
Copy-Item $testhostCore10PackageTempARM64Dir\Microsoft.TestPlatform.PlatformAbstractions.dll $testhostCore10PackageARM64Dir -Force

# Copy over the Full CLR built testhost package assemblies to the Core CLR and Full CLR package folder.
$coreCLRFull_Dir = "TestHost"
Expand Down Expand Up @@ -493,6 +467,16 @@ function Publish-Package
Move-Loc-Files $coreCLR20PackageDir $coreCLRExtensionsDir "Microsoft.TestPlatform.TestHostRuntimeProvider.resources.dll"
}

# Add .NET Standard CPP Test adapter
$cppNetStandardRunner = Join-Path $env:TP_ROOT_DIR "temp\cpp\*"
Copy-Item $cppNetStandardRunner $coreCLRExtensionsDir -Force

# Add standalone testhost
$standaloneTesthost = Join-Path $env:TP_ROOT_DIR "temp\testhost\*"
Copy-Item $standaloneTesthost $coreCLR20PackageDir -Force
Copy-Item $testhostCore20PackageDir\testhost.dll $coreCLR20PackageDir -Force
Copy-Item $testhostCore20PackageDir\testhost.pdb $coreCLR20PackageDir -Force

# Copy dependency of Microsoft.TestPlatform.TestHostRuntimeProvider
$newtonsoft = Join-Path $env:TP_PACKAGES_DIR "newtonsoft.json\9.0.1\lib\net45\Newtonsoft.Json.dll"
Write-Verbose "Copy-Item $newtonsoft $fullCLRPackage451Dir -Force"
Expand Down Expand Up @@ -1109,17 +1093,17 @@ if ($Force -or $Steps -contains "Restore") {
Restore-Package
}

# if ($Force -or $Steps -contains "UpdateLocalization") {
# Update-LocalizedResources
# }
if ($Force -or $Steps -contains "UpdateLocalization") {
Update-LocalizedResources
}

if ($Force -or $Steps -contains "Build") {
Invoke-Build
}

if ($Force -or $Steps -contains "Publish") {
Publish-Package
# Create-VsixPackage
Create-VsixPackage
Create-NugetPackages
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting
[FriendlyName(DefaultTestHostFriendlyName)]
public class DefaultTestHostManager : ITestRuntimeProvider2
{
private const string X64TestHostProcessName = "testhost{0}.exe";
private const string X86TestHostProcessName = "testhost{0}.x86.exe";

private const string DefaultTestHostUri = "HostProvider://DefaultTestHost";
private const string DefaultTestHostFriendlyName = "DefaultTestHost";
private const string TestAdapterEndsWithPattern = @"TestAdapter.dll";
Expand Down Expand Up @@ -133,7 +136,24 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
IDictionary<string, string> environmentVariables,
TestRunnerConnectionInfo connectionInfo)
{
string testHostProcessName = this.GetTesthostName(this.architecture, this.targetFramework);
string testHostProcessName;
if (this.targetFramework.Name.StartsWith(".NETFramework,Version=v"))
{
var targetFrameworkMoniker = "net" + this.targetFramework.Name.Replace(".NETFramework,Version=v", string.Empty).Replace(".", string.Empty);

// Net451 or older will use the default testhost.exe that is compiled against net451.
var isSupportedNetTarget = new[] { "net452", "net46", "net461", "net462", "net47", "net471", "net472", "net48" }.Contains(targetFrameworkMoniker);
var targetFrameworkSuffix = isSupportedNetTarget ? $".{targetFrameworkMoniker}" : string.Empty;

// Default test host manager supports shared test sources
testHostProcessName = string.Format(this.architecture == Architecture.X86 ? X86TestHostProcessName : X64TestHostProcessName, targetFrameworkSuffix);
}
else
{
// This path is probably happening only in our tests, because otherwise we are first running CanExecuteCurrentRunConfiguration
// which would disqualify anything that is not netframework.
testHostProcessName = string.Format(this.architecture == Architecture.X86 ? X86TestHostProcessName : X64TestHostProcessName, string.Empty);
}

var currentWorkingDirectory = Path.Combine(Path.GetDirectoryName(typeof(DefaultTestHostManager).GetTypeInfo().Assembly.Location), "..//");
var argumentsString = " " + connectionInfo.ToCommandLineOptions();
Expand All @@ -143,7 +163,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(

if (!File.Exists(testhostProcessPath))
{
// "TestHost" is the name of the folder which contain Full CLR built testhost package assemblies, in dotnet SDK.
// "TestHost" is the name of the folder which contain Full CLR built testhost package assemblies.
testHostProcessName = Path.Combine("TestHost", testHostProcessName);
testhostProcessPath = Path.Combine(currentWorkingDirectory, testHostProcessName);
}
Expand Down Expand Up @@ -421,37 +441,5 @@ private string GetUwpSources(string uwpSource)

return AppxManifestFile.GetApplicationExecutableName(appxManifestPath);
}

private string GetTesthostName(Architecture architecture, Framework targetFramework)
{
string testHostProcessName = "testhost";

if (targetFramework.Name.StartsWith(".NETFramework,Version=v"))
{
var targetFrameworkMoniker = "net" + targetFramework.Name.Replace(".NETFramework,Version=v", string.Empty).Replace(".", string.Empty);

// Net451 or older will use the default testhost.exe that is compiled against net451.
var isSupportedNetTarget = new[] { "net452", "net46", "net461", "net462", "net47", "net471", "net472", "net48" }.Contains(targetFrameworkMoniker);
var targetFrameworkSuffix = isSupportedNetTarget ? $".{targetFrameworkMoniker}" : string.Empty;

// Default test host manager supports shared test sources
testHostProcessName += targetFrameworkSuffix;
}

if (architecture == Architecture.Default || architecture == Architecture.AnyCPU || architecture == Architecture.X64)
{
// testhost.exe (and testhost.net###.exe) is a 64-bit executable, and should be used when there is no preference (Default),
// the assembly is AnyCPU, or when explicitly requested.
}
else
{
// append .<architecture> to the name, such as .x86. It is possible that we are not shipping the
// executable for the architecture with VS, and that should fail later with file not found exception.
testHostProcessName += $".{architecture.ToString().ToLowerInvariant()}";
}

testHostProcessName += ".exe";
return testHostProcessName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(

if (string.IsNullOrEmpty(testHostPath))
{
// We still did not find testhost.dll. Try finding it next to the currently executing assembly, in folder testhost-core.
var testHostNextToRunner = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "testhost-core", "testhost.dll");
// We still did not find testhost.dll. Try finding it next to vstest.console, which is in .., b
var testHostNextToRunner = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "testhost.dll");
if (System.IO.File.Exists(testHostNextToRunner))
{
EqtTrace.Verbose("DotnetTestHostManager: Found testhost.dll next to runner executable: {0}.", testHostNextToRunner);
Expand Down
Loading