Skip to content

Commit ff7989d

Browse files
authored
Run acceptance tests against the locally built sources (#2340)
* Use current version of TP in acceptance tests
1 parent fd0fe3d commit ff7989d

File tree

42 files changed

+682
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+682
-454
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ msbuild*.err
3131
build*.log
3232
build*.wrn
3333
build*.err
34+
*.binlog
3435

3536
# MSTest test Results
3637
[Tt]est[Rr]esult*/

TestPlatform.sln

+14-169
Large diffs are not rendered by default.

samples/UnitTestProject/UnitTestProject.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<ItemGroup>
1818
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestFrameworkVersion)" />
1919
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestAdapterVersion)" />
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(NETTestSdkPreviousVersion)" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(NETTestSdkVersion)" />
2121
</ItemGroup>
2222
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
2323
<Reference Include="System.Runtime" />

scripts/build.ps1

+75-18
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ $env:TP_OUT_DIR = Join-Path $env:TP_ROOT_DIR "artifacts"
6262
$env:TP_TESTARTIFACTS = Join-Path $env:TP_OUT_DIR "testArtifacts"
6363
$env:TP_PACKAGE_PROJ_DIR = Join-Path $env:TP_ROOT_DIR "src\package"
6464

65-
# Set Version from scripts/build/TestPlatform.Settings.targets
65+
# Set Version from scripts/build/TestPlatform.Settings.targets, when we are running locally and not providing the version as the parameter
66+
# or when the build is done directly in VS
6667
if([string]::IsNullOrWhiteSpace($Version))
6768
{
68-
$Version = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Settings.targets)).Project.PropertyGroup.TPVersionPrefix |
69-
Where-Object { $_ } |
69+
$Version = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Settings.targets)).Project.PropertyGroup[0].TPVersionPrefix |
7070
ForEach-Object { $_.Trim() } |
7171
Select-Object -First 1
7272

73-
Write-Verbose "Version was not provided using version '$Version' from TestPlatform.Settings.targets"
73+
Write-Verbose "Version was not provided using version '$Version' from TestPlatform.Settings.targets"
7474
}
7575

7676
#
@@ -102,7 +102,7 @@ $TPB_TargetRuntime = $TargetRuntime
102102
$TPB_X64_Runtime = "win7-x64"
103103
$TPB_X86_Runtime = "win7-x86"
104104

105-
# Version suffix is empty for RTM releases
105+
# Version suffix is empty for RTM release
106106
$TPB_Version = if ($VersionSuffix -ne '') { $Version + "-" + $VersionSuffix } else { $Version }
107107
$TPB_CIBuild = $CIBuild
108108
$TPB_PublishTests = $PublishTestArtifacts
@@ -116,6 +116,14 @@ $Script:ScriptFailed = $false
116116

117117
Import-Module "$($CurrentScriptDir.FullName)\verify-nupkgs.ps1"
118118

119+
# 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
120+
# 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
121+
# the version in multiple places
122+
$dependenciesPath = "$env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props"
123+
$dependencies = Get-Content -Raw -Encoding UTF8 $dependenciesPath
124+
$updatedDependencies = $dependencies -replace "<NETTestSdkVersion>.*?</NETTestSdkVersion>", "<NETTestSdkVersion>$TPB_Version</NETTestSdkVersion>"
125+
$updatedDependencies | Set-Content -Encoding UTF8 $dependenciesPath
126+
119127
function Write-Log ([string] $message)
120128
{
121129
$currentColor = $Host.UI.RawUI.ForegroundColor
@@ -163,22 +171,42 @@ function Install-DotNetCli
163171
Write-Log "Install-DotNetCli: Get the latest dotnet cli toolset..."
164172
$dotnetInstallPath = Join-Path $env:TP_TOOLS_DIR "dotnet"
165173
New-Item -ItemType directory -Path $dotnetInstallPath -Force | Out-Null
166-
& $dotnetInstallScript -Channel "master" -InstallDir $dotnetInstallPath -NoPath -Version $env:DOTNET_CLI_VERSION
174+
& $dotnetInstallScript -Channel "master" -InstallDir $dotnetInstallPath -Version $env:DOTNET_CLI_VERSION
167175

168176
# Pull in additional shared frameworks.
169177
# Get netcoreapp2.1 shared components.
170-
if (!(Test-Path "$dotnetInstallPath\shared\Microsoft.NETCore.App\2.1.0")) {
171-
& $dotnetInstallScript -InstallDir $dotnetInstallPath -SharedRuntime -Version '2.1.0' -Channel 'release/2.1.0'
172-
}
178+
179+
& $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Version '2.1.0' -Channel 'release/2.1.0' -Architecture x64 -NoPath
180+
$env:DOTNET_ROOT= $dotnetInstallPath
181+
182+
& $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Version '2.1.0' -Channel 'release/2.1.0' -Architecture x86 -NoPath
183+
${env:DOTNET_ROOT(x86)} = "${dotnetInstallPath}_x86"
184+
185+
$env:DOTNET_MULTILEVEL_LOOKUP=0
186+
187+
"---- dotnet environment variables"
188+
Get-ChildItem "Env:\dotnet_*"
189+
190+
"`n`n---- x64 dotnet"
191+
& "$env:DOTNET_ROOT\dotnet.exe" --info
192+
193+
"`n`n---- x86 dotnet"
194+
& "${env:DOTNET_ROOT(x86)}\dotnet.exe" --info
173195

174-
# Get shared components which is compatible with dotnet cli version $env:DOTNET_CLI_VERSION
175-
#if (!(Test-Path "$dotnetInstallPath\shared\Microsoft.NETCore.App\$env:DOTNET_RUNTIME_VERSION")) {
176-
#& $dotnetInstallScript -InstallDir $dotnetInstallPath -SharedRuntime -Version $env:DOTNET_RUNTIME_VERSION -Channel 'master'
177-
#}
178196

179197
Write-Log "Install-DotNetCli: Complete. {$(Get-ElapsedTime($timer))}"
180198
}
181199

200+
function Clear-Package {
201+
# find all microsoft packages that have the same version as we specified
202+
# this is cache-busting the nuget packages, so we don't reuse them from cache
203+
# after we built new ones
204+
if (Test-Path $env:TP_PACKAGES_DIR) {
205+
$devPackages = Get-ChildItem $env:TP_PACKAGES_DIR/microsoft.*/$TPB_Version | Select-Object -ExpandProperty FullName
206+
$devPackages | Remove-Item -Force -Recurse -Confirm:$false
207+
}
208+
}
209+
182210
function Restore-Package
183211
{
184212
$timer = Start-Timer
@@ -202,26 +230,51 @@ function Invoke-Build
202230

203231
Write-Log ".. .. Build: Source: $TPB_Solution"
204232
Write-Verbose "$dotnetExe build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild"
205-
& $dotnetExe build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild
233+
& $dotnetExe build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:TestPlatform.binlog
206234
Write-Log ".. .. Build: Complete."
207235

208236
Set-ScriptFailedOnError
209237

238+
Write-Log "Invoke-Build: Complete. {$(Get-ElapsedTime($timer))}"
239+
}
240+
241+
function Invoke-TestAssetsBuild
242+
{
243+
$timer = Start-Timer
244+
Write-Log "Invoke-TestAssetsBuild: Start test assets build."
245+
$dotnetExe = Get-DotNetPath
246+
247+
210248
Write-Log ".. .. Build: Source: $TPB_TestAssets_Solution"
211249
Write-Verbose "$dotnetExe build $TPB_TestAssets_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild"
212-
& $dotnetExe build $TPB_TestAssets_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild
250+
& $dotnetExe build $TPB_TestAssets_Solution --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:"$($env:TP_ROOT_DIR)\TestAssets.binlog"
213251
Write-Log ".. .. Build: Complete."
214252

215253
Set-ScriptFailedOnError
216254

217-
Write-Log "Invoke-Build: Complete. {$(Get-ElapsedTime($timer))}"
255+
Write-Log "Invoke-TestAssetsBuild: Complete. {$(Get-ElapsedTime($timer))}"
256+
}
257+
258+
function Copy-PackageIntoStaticDirectory {
259+
# packages are published into folder based on configuration, but
260+
# nuget does not understand that, and does not support wildcards in paths
261+
# in order to be able to use the produced packages for acceptance tests we
262+
# need to put them in folder that is not changing it's name based on config
263+
$tpPackagesPath = "$env:TP_OUT_DIR\$TPB_Configuration\packages\"
264+
$tpPackagesDestination = "$env:TP_TESTARTIFACTS"
265+
Copy-Item $tpPackagesPath $tpPackagesDestination -Force -Filter *.nupkg -Verbose -Recurse
218266
}
219267

220268
function Publish-PatchedDotnet {
221269
Write-Log "Publish-PatchedDotnet: Copy local dotnet installation to testArtifacts"
222270
$dotnetPath = "$env:TP_TOOLS_DIR\dotnet\"
223-
271+
224272
$dotnetTestArtifactsPath = "$env:TP_TESTARTIFACTS\dotnet\"
273+
274+
if (Test-Path $dotnetTestArtifactsPath) {
275+
Remove-Item -Force -Recurse $dotnetTestArtifactsPath
276+
}
277+
225278
$dotnetTestArtifactsSdkPath = "$env:TP_TESTARTIFACTS\dotnet\sdk\$env:DOTNET_CLI_VERSION\"
226279
Copy-Item $dotnetPath $dotnetTestArtifactsPath -Force -Recurse
227280

@@ -922,15 +975,19 @@ Get-ChildItem env: | Where-Object -FilterScript { $_.Name.StartsWith("TP_") } |
922975
Write-Log "Test platform build variables: "
923976
Get-Variable | Where-Object -FilterScript { $_.Name.StartsWith("TPB_") } | Format-Table
924977
Install-DotNetCli
978+
Clear-Package
925979
Restore-Package
926980
Update-LocalizedResources
927981
Invoke-Build
928982
Publish-Package
929-
Publish-PatchedDotnet
930983
Publish-Tests
931984
Create-VsixPackage
932985
Create-NugetPackages
933986
Generate-Manifest
987+
Publish-PatchedDotnet
988+
Copy-PackageIntoStaticDirectory
989+
Invoke-TestAssetsBuild
990+
934991
Write-Log "Build complete. {$(Get-ElapsedTime($timer))}"
935992
if ($Script:ScriptFailed) { Exit 1 } else { Exit 0 }
936993

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ VERSION=$(test -z $VERSION && grep TPVersionPrefix $TP_ROOT_DIR/scripts/build/Te
111111
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
112112
# Dotnet build doesnt support --packages yet. See https://github.com./dotnet/cli/issues/2712
113113
export NUGET_PACKAGES=$TP_PACKAGES_DIR
114-
DOTNET_CLI_VERSION="3.1.100-preview2-014569"
114+
DOTNET_CLI_VERSION="3.1.100"
115115
#DOTNET_RUNTIME_VERSION="LATEST"
116116

117117
#

scripts/build/TestPlatform.Dependencies.props

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<VSSdkBuildToolsVersion>15.8.3247</VSSdkBuildToolsVersion>
55

66
<!-- Name of the elements must be in sync with test\Microsoft.TestPlatform.TestUtilities\IntegrationTestBase.cs -->
7-
<NETTestSdkPreviousVersion>15.5.0</NETTestSdkPreviousVersion>
87

9-
<MSTestFrameworkVersion>1.4.0</MSTestFrameworkVersion>
10-
<MSTestAdapterVersion>1.4.0</MSTestAdapterVersion>
8+
<!-- this version needs to be the same as in TestPlatform.Settings.targets, we might want to unify this into
9+
a single .props file, but the other version is used by multiple build scripts, so I just query it and validate that
10+
they are both the same during build -->
11+
<!-- this version also needs to be "statically" readable because the test fixture will inspect this file for the version
12+
and because during the test `dotnet test` will run and re-build some of the test projects and at that time the version
13+
from a build parameter would not be available, so I am writing this version from the build.ps1 script to keep it in sync -->
14+
<NETTestSdkVersion>16.6.0-dev</NETTestSdkVersion>
15+
16+
<MSTestFrameworkVersion>2.1.0</MSTestFrameworkVersion>
17+
<MSTestAdapterVersion>2.1.0</MSTestAdapterVersion>
1118
<MSTestAssertExtensionVersion>1.0.3-preview</MSTestAssertExtensionVersion>
1219

1320
<XUnitFrameworkVersion>2.3.1</XUnitFrameworkVersion>

scripts/build/TestPlatform.Settings.targets

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">$(MSBuildThisFileDirectory)../../</TestPlatformRoot>
5-
<TPVersionPrefix>16.5.0</TPVersionPrefix>
5+
<!-- This version is read by vsts-prebuild.ps1 and is a base for the current version, this should be updated
6+
at the start of new iteration to the goal number. This is also used to version the local packages. This version needs to be statically
7+
readable when we read the file as xml, don't move it to a .props file, unless you change the build server process -->
8+
<TPVersionPrefix>16.6.0</TPVersionPrefix>
69
</PropertyGroup>
710
<PropertyGroup>
811
<!-- Versioning is defined from the build script. Use a default dev build if it's not defined.

scripts/test.ps1

+21-4
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,32 @@ $env:TP_ROOT_DIR = (Get-Item (Split-Path $MyInvocation.MyCommand.Path)).Parent.F
5959
$env:TP_TOOLS_DIR = Join-Path $env:TP_ROOT_DIR "tools"
6060
$env:TP_PACKAGES_DIR = Join-Path $env:TP_ROOT_DIR "packages"
6161
$env:TP_OUT_DIR = Join-Path $env:TP_ROOT_DIR "artifacts"
62+
63+
Write-Verbose "Setup dotnet configuration."
6264
# Add latest dotnet.exe directory to environment variable PATH to tests run on latest dotnet.
6365
$env:PATH = "$(Split-Path $(Get-DotNetPath));$env:PATH"
6466

65-
#
66-
# Dotnet configuration
67-
#
67+
# set the roots to use only the versions of dotnet that we installed
68+
$env:DOTNET_ROOT = Join-Path $env:TP_TOOLS_DIR "dotnet"
69+
# set the root for x86 runtimes as well
70+
${env:DOTNET_ROOT(x86)} = "${env:DOTNET_ROOT}_x86"
71+
# disable looking up other dotnets in programfiles
72+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
73+
6874
# Disable first run since we want to control all package sources
69-
Write-Verbose "Setup dotnet configuration."
7075
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
76+
77+
# list what we have set and what is available
78+
"---- dotnet environment variables"
79+
Get-ChildItem "Env:\dotnet_*"
80+
81+
"`n`n---- x64 dotnet"
82+
& "$env:DOTNET_ROOT\dotnet.exe" --info
83+
84+
"`n`n---- x86 dotnet"
85+
& "${env:DOTNET_ROOT(x86)}\dotnet.exe" --info
86+
87+
7188
# Dotnet build doesn't support --packages yet. See https://github.com./dotnet/cli/issues/2712
7289
$env:NUGET_PACKAGES = $env:TP_PACKAGES_DIR
7390

src/Microsoft.TestPlatform.CoreUtilities/Helpers/CommandLineArgumentsHelper.cs

+24-3
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,33 @@ public static IDictionary<string, string> GetArgumentsDictionary(string[] args)
5252
/// <exception cref="ArgumentException">Thrown if value of an argument is not an integer.</exception>
5353
public static int GetIntArgFromDict(IDictionary<string, string> argsDictionary, string fullname)
5454
{
55-
string optionValue;
56-
return argsDictionary.TryGetValue(fullname, out optionValue) ? int.Parse(optionValue) : 0;
55+
var found = TryGetIntArgFromDict(argsDictionary, fullname, out var value);
56+
return found ? value : 0;
5757
}
5858

5959
/// <summary>
60-
/// Parse the value of an argument as an integer.
60+
/// Try get the argument and parse the value of an argument as an integer.
61+
/// </summary>
62+
/// <param name="argsDictionary">Dictionary of all arguments Ex: <c>{ "--port":"12312", "--parentprocessid":"2312" }</c></param>
63+
/// <param name="fullname">The full name for required argument. Ex: "--port"</param>
64+
/// <returns>Value of the argument.</returns>
65+
/// <exception cref="ArgumentException">Thrown if value of an argument is not an integer.</exception>
66+
public static bool TryGetIntArgFromDict(IDictionary<string, string> argsDictionary, string fullname, out int value)
67+
{
68+
var found = argsDictionary.TryGetValue(fullname, out var optionValue);
69+
if (!found)
70+
{
71+
value = default;
72+
return false;
73+
}
74+
75+
value = int.Parse(optionValue);
76+
return true;
77+
}
78+
79+
80+
/// <summary>
81+
/// Parse the value of an argument as a string.
6182
/// </summary>
6283
/// <param name="argsDictionary">Dictionary of all arguments Ex: <c>{ "--port":"12312", "--parentprocessid":"2312" }</c></param>
6384
/// <param name="fullname">The full name for required argument. Ex: "--port"</param>

src/Microsoft.TestPlatform.ObjectModel/Navigation/PortableSymbolReader.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ private void PopulateCacheForTypeAndMethodSymbols(string binaryPath)
9494
// At this point, the assembly should be already loaded into the load context. We query for a reference to
9595
// find the types and cache the symbol information. Let the loader follow default lookup order instead of
9696
// forcing load from a specific path.
97-
var asm = Assembly.Load(new PlatformAssemblyLoadContext().GetAssemblyNameFromPath(binaryPath));
97+
Assembly asm;
98+
try
99+
{
100+
asm = Assembly.Load(new PlatformAssemblyLoadContext().GetAssemblyNameFromPath(binaryPath));
101+
}
102+
catch (FileNotFoundException)
103+
{
104+
// fallback when the assembly is not loaded
105+
asm = Assembly.LoadFile(binaryPath);
106+
}
98107

99108
foreach (var type in asm.GetTypes())
100109
{

test/DataCollectors/TraceDataCollector.UnitTests/VanguardTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void StartShouldStartVanguardProcessWithCollectCommand()
109109
this.vanguard.Start(this.outputFileName, this.dataCollectionContext);
110110
cts.Cancel();
111111

112-
var numOfProcessCreated = numOfProcessCreatedTask.Result;
112+
var numOfProcessCreated = numOfProcessCreatedTask.Result.Count;
113113

114114
// TODO find the reason why additional process launched when collecting code coverage.
115115
Assert.IsTrue(numOfProcessCreated == 1 || numOfProcessCreated == 2, $"Number of process created:{numOfProcessCreated} expected is 1 or 2.");
@@ -172,7 +172,7 @@ public void StopShouldLaunchVarguardWithShutdownCommand()
172172
this.vanguard.Stop();
173173
cts.Cancel();
174174

175-
var numOfProcessCreated = numOfProcessCreatedTask.Result;
175+
var numOfProcessCreated = numOfProcessCreatedTask.Result.Count;
176176

177177
// TODO find the reason why additional process launched when collecting code coverage.
178178
Assert.IsTrue(numOfProcessCreated == 2 || numOfProcessCreated == 4, $"Number of process created:{numOfProcessCreated} expected is 2 or 4.");

0 commit comments

Comments
 (0)