-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathdotnet-test-cloud.ps1
More file actions
141 lines (126 loc) · 4.41 KB
/
Copy pathdotnet-test-cloud.ps1
File metadata and controls
141 lines (126 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Runs tests as they are run in cloud test runs.
.PARAMETER Configuration
The configuration within which to run tests
.PARAMETER Agent
The name of the agent. This is used in preparing test run titles.
.PARAMETER PublishResults
A switch to publish results to Azure Pipelines.
.PARAMETER x86
A switch to run the tests in an x86 process.
.PARAMETER dotnet32
The path to a 32-bit dotnet executable to use.
#>
[CmdletBinding()]
Param(
[string]$Configuration='Debug',
[string]$Agent='Local',
[switch]$PublishResults,
[switch]$x86,
[string]$dotnet32
)
$RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path
$ArtifactStagingFolder = & "$PSScriptRoot/Get-ArtifactsStagingDirectory.ps1"
$OnCI = ($env:CI -or $env:TF_BUILD)
$dotnet = 'dotnet'
if ($x86) {
$x86RunTitleSuffix = ", x86"
if ($dotnet32) {
$dotnet = $dotnet32
} else {
$dotnet32Possibilities = "$PSScriptRoot\../obj/tools/x86/.dotnet/dotnet.exe", "$env:AGENT_TOOLSDIRECTORY/x86/dotnet/dotnet.exe", "${env:ProgramFiles(x86)}\dotnet\dotnet.exe"
$dotnet32Matches = $dotnet32Possibilities |? { Test-Path $_ }
if ($dotnet32Matches) {
$dotnet = Resolve-Path @($dotnet32Matches)[0]
Write-Host "Running tests using `"$dotnet`"" -ForegroundColor DarkGray
} else {
Write-Error "Unable to find 32-bit dotnet.exe"
return 1
}
}
}
$testBinLog = Join-Path $ArtifactStagingFolder (Join-Path build_logs test.binlog)
$testLogs = Join-Path $ArtifactStagingFolder test_logs
$extraArgs = @()
if ($IsLinux -or $IsMacOS) {
$extraArgs += '-p:Platform=NonWindows'
}
$globalJson = Get-Content $PSScriptRoot/../global.json | ConvertFrom-Json
$isMTP = $globalJson.test.runner -eq 'Microsoft.Testing.Platform'
$extraArgs = @()
$failedTests = 0
if ($isMTP) {
if ($OnCI) { $extraArgs += '--no-progress' }
$dumpSwitches = @(
,'--hangdump'
,'--hangdump-timeout','120s'
,'--crashdump'
)
$mtpArgs = @(
,'--coverage'
,'--coverage-output-format','cobertura'
,'--diagnostic'
,'--diagnostic-output-directory',$testLogs
,'--diagnostic-verbosity','Information'
,'--results-directory',$testLogs
,'--report-trx'
)
& $dotnet test --solution $RepoRoot `
--no-build `
-c $Configuration `
-bl:"$testBinLog" `
--filter-not-trait 'TestCategory=FailsInCloudTest' `
--coverage-settings "$PSScriptRoot/test.runsettings" `
@mtpArgs `
@dumpSwitches `
@extraArgs
if ($LASTEXITCODE -ne 0) { $failedTests += 1 }
$trxFiles = Get-ChildItem -Recurse -Path $testLogs\*.trx
} else {
$testDiagLog = Join-Path $ArtifactStagingFolder (Join-Path test_logs diag.log)
& $dotnet test $RepoRoot `
--no-build `
-c $Configuration `
--filter "TestCategory!=FailsInCloudTest" `
--collect "Code Coverage;Format=cobertura" `
--settings "$PSScriptRoot/test.runsettings" `
--blame-hang-timeout 60s `
--blame-crash `
-bl:"$testBinLog" `
--diag "$testDiagLog;TraceLevel=info" `
--logger trx `
@extraArgs
if ($LASTEXITCODE -ne 0) { $failedTests += 1 }
$trxFiles = Get-ChildItem -Recurse -Path $RepoRoot\test\*.trx
}
$unknownCounter = 0
$trxFiles |% {
New-Item $testLogs -ItemType Directory -Force | Out-Null
if (!($_.FullName.StartsWith($testLogs, [StringComparison]::OrdinalIgnoreCase))) {
Copy-Item $_ -Destination $testLogs
}
if ($PublishResults) {
$x = [xml](Get-Content -LiteralPath $_)
$runTitle = $null
if ($x.TestRun.TestDefinitions -and $x.TestRun.TestDefinitions.GetElementsByTagName('UnitTest')) {
$storage = $x.TestRun.TestDefinitions.GetElementsByTagName('UnitTest')[0].storage -replace '\\','/'
if ($storage -match '/(?<tfm>net[^/]+)/(?:(?<rid>[^/]+)/)?(?<lib>[^/]+)\.(dll|exe)$') {
if ($matches.rid) {
$runTitle = "$($matches.lib) ($($matches.tfm), $($matches.rid), $Agent)"
} else {
$runTitle = "$($matches.lib) ($($matches.tfm)$x86RunTitleSuffix, $Agent)"
}
}
}
if (!$runTitle) {
$unknownCounter += 1;
$runTitle = "unknown$unknownCounter ($Agent$x86RunTitleSuffix)";
}
Write-Host "##vso[results.publish type=VSTest;runTitle=$runTitle;publishRunAttachments=true;resultFiles=$_;failTaskOnFailedTests=true;testRunSystem=VSTS - PTR;]"
}
}
if ($failedTests -ne 0) {
exit $failedTests
}