forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ps1
370 lines (289 loc) · 9.78 KB
/
test.ps1
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<#
.SYNOPSIS
This script runs the MsQuic tests.
.PARAMETER Config
Specifies the build configuration to test.
.PARAMETER Arch
The CPU architecture to test.
.PARAMETER Tls
The TLS library test.
.PARAMETER ExtraArtifactDir
Add an extra classifier to the artifact directory to allow publishing alternate builds of same base library
.PARAMETER Kernel
Runs the Windows kernel mode tests.
.PARAMETER Filter
A filter to include test cases from the list to execute. Multiple filters
are separated by :. Negative filters are prefixed with -.
.PARAMETER ListTestCases
Lists all the test cases.
.PARAMETER IsolationMode
Controls the isolation mode when running each test case.
.PARAMETER KeepOutputOnSuccess
Don't discard console output or logs on success.
.PARAMETER GenerateXmlResults
Generates an xml Test report for the run.
.PARAMETER Debugger
Attaches the debugger to each test case run.
.PARAMETER InitialBreak
Debugger starts broken into the process to allow setting breakpoints, etc.
.PARAMETER BreakOnFailure
Triggers a break point on a test failure.
.PARAMETER LogProfile
The name of the profile to use for log collection.
.PARAMETER CompressOutput
Compresses the output files generated for failed test cases.
.PARAMETER NoProgress
Disables the progress bar.
.Parameter EnableAppVerifier
Enables all basic Application Verifier checks on test binaries.
.Parameter CodeCoverage
Collect code coverage for this test run. Incompatible with -Kernel and -Debugger.
.Parameter AZP
Runs in Azure Pipelines mode.
.Parameter ErrorsAsWarnings
Treats all errors as warnings.
.Parameter DuoNic
Uses DuoNic instead of loopback (DuoNic must already be installed via 'prepare-machine.ps1 -InstallDuoNic').
.EXAMPLE
test.ps1
.EXAMPLE
test.ps1 -ListTestCases
.EXAMPLE
test.ps1 -ListTestCases -Filter ParameterValidation*
.EXAMPLE
test.ps1 -Filter ParameterValidation*
.EXAMPLE
test.ps1 -LogProfile Full.Light
.EXAMPLE
test.ps1 -LogProfile Full.Verbose -Compress
#>
param (
[Parameter(Mandatory = $false)]
[ValidateSet("Debug", "Release")]
[string]$Config = "Debug",
[Parameter(Mandatory = $false)]
[ValidateSet("x86", "x64", "arm", "arm64")]
[string]$Arch = "",
[Parameter(Mandatory = $false)]
[ValidateSet("schannel", "openssl", "openssl3")]
[string]$Tls = "",
[Parameter(Mandatory = $false)]
[switch]$Kernel = $false,
[Parameter(Mandatory = $false)]
[string]$Filter = "",
[Parameter(Mandatory = $false)]
[switch]$ListTestCases = $false,
[Parameter(Mandatory = $false)]
[ValidateSet("Batch", "Isolated")]
[string]$IsolationMode = "Isolated",
[Parameter(Mandatory = $false)]
[switch]$KeepOutputOnSuccess = $false,
[Parameter(Mandatory = $false)]
[switch]$GenerateXmlResults = $false,
[Parameter(Mandatory = $false)]
[switch]$Debugger = $false,
[Parameter(Mandatory = $false)]
[switch]$InitialBreak = $false,
[Parameter(Mandatory = $false)]
[switch]$BreakOnFailure = $false,
[Parameter(Mandatory = $false)]
[ValidateSet("None", "Basic.Light", "Basic.Verbose", "Full.Light", "Full.Verbose")]
[string]$LogProfile = "None",
[Parameter(Mandatory = $false)]
[switch]$CompressOutput = $false,
[Parameter(Mandatory = $false)]
[switch]$NoProgress = $false,
[Parameter(Mandatory = $false)]
[switch]$EnableAppVerifier = $false,
[Parameter(Mandatory = $false)]
[switch]$EnableSystemVerifier = $false,
[Parameter(Mandatory = $false)]
[switch]$CodeCoverage = $false,
[Parameter(Mandatory = $false)]
[string]$ExtraArtifactDir = "",
[Parameter(Mandatory = $false)]
[switch]$AZP = $false,
[Parameter(Mandatory = $false)]
[switch]$GHA = $false,
[Parameter(Mandatory = $false)]
[switch]$SkipUnitTests = $false,
[Parameter(Mandatory = $false)]
[switch]$ErrorsAsWarnings = $false,
[Parameter(Mandatory = $false)]
[switch]$DuoNic = $false,
[Parameter(Mandatory = $false)]
[switch]$UseXdp = $false,
[Parameter(Mandatory = $false)]
[switch]$UseQtip = $false,
[Parameter(Mandatory = $false)]
[string]$OsRunner = ""
)
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
function Test-Administrator
{
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ($IsWindows -and !(Test-Administrator)) {
Write-Warning "We recommend running this test as administrator. Crash dumps will not work"
}
# Validate the the kernel switch.
if ($Kernel -and !$IsWindows) {
Write-Error "-Kernel switch only supported on Windows";
}
# Validate the code coverage switch.
if ($CodeCoverage) {
if (!$IsWindows) {
Write-Error "-CodeCoverage switch only supported on Windows";
}
if ($Kernel) {
Write-Error "-CodeCoverage is not supported for kernel mode tests";
}
if ($Debugger) {
Write-Error "-CodeCoverage switch is not supported with debugging";
}
if (!(Test-Path "C:\Program Files\OpenCppCoverage\OpenCppCoverage.exe")) {
Write-Error "Code coverage tools are not installed";
}
}
if ($UseXdp) {
# Helper for XDP usage
$DuoNic = $true
}
$BuildConfig = & (Join-Path $PSScriptRoot get-buildconfig.ps1) -Tls $Tls -Arch $Arch -ExtraArtifactDir $ExtraArtifactDir -Config $Config
$Tls = $BuildConfig.Tls
$Arch = $BuildConfig.Arch
$RootArtifactDir = $BuildConfig.ArtifactsDir
# Root directory of the project.
$RootDir = Split-Path $PSScriptRoot -Parent
# Coverage destination directory.
$CoverageDir = Join-Path $RootDir "artifacts" "coverage"
if ($CodeCoverage) {
# Clear old coverage data
if (Test-Path $CoverageDir) {
Remove-Item -Path (Join-Path $CoverageDir '*.cov') -Force
}
}
# Path to the run-gtest Powershell script.
$RunTest = Join-Path $RootDir "scripts/run-gtest.ps1"
if ("" -ne $ExtraArtifactDir -and $Kernel) {
Write-Error "Kernel not supported with extra artifact dir"
}
# Path to the msquictest executable.
$MsQuicTest = $null
$MsQuicCoreTest = $null
$MsQuicPlatTest = $null
$KernelPath = $null;
if ($IsWindows) {
$MsQuicTest = Join-Path $RootArtifactDir "msquictest.exe"
$MsQuicCoreTest = Join-Path $RootArtifactDir "msquiccoretest.exe"
$MsQuicPlatTest = Join-Path $RootArtifactDir "msquicplatformtest.exe"
$KernelPath = Join-Path $RootDir "\artifacts\bin\winkernel\$($Arch)_$($Config)_$($Tls)"
} elseif ($IsLinux -or $IsMacOS) {
$MsQuicTest = Join-Path $RootArtifactDir "msquictest"
$MsQuicCoreTest = Join-Path $RootArtifactDir "msquiccoretest"
$MsQuicPlatTest = Join-Path $RootArtifactDir "msquicplatformtest"
} else {
Write-Error "Unsupported platform type!"
}
# Make sure the build is present.
if (!(Test-Path $MsQuicTest)) {
Write-Error "Build does not exist!`n `nRun the following to generate it:`n `n $(Join-Path $RootDir "scripts" "build.ps1") -Config $Config -Arch $Arch -Tls $Tls`n"
}
if ($Kernel) {
if (!(Test-Path (Join-Path $KernelPath "msquictestpriv.sys"))) {
Write-Error "Kernel binaries do not exist!"
}
}
$PfxFile = Join-Path $RootArtifactDir "selfsignedservercert.pfx"
if (!(Test-Path $PfxFile)) {
$MyPath = Split-Path -Path $PSCommandPath -Parent
$ScriptPath = Join-Path $MyPath install-test-certificates.ps1
&$ScriptPath -OutputFile $PfxFile
}
# Build up all the arguments to pass to the Powershell script.
$TestArguments = "-IsolationMode $IsolationMode -PfxPath $PfxFile"
if ($DuoNic) {
$TestArguments += " -DuoNic"
}
if ($Kernel) {
$TestArguments += " -Kernel $KernelPath"
}
if ("" -ne $Filter) {
$TestArguments += " -Filter $Filter"
}
if ($ListTestCases) {
$TestArguments += " -ListTestCases"
}
if ($KeepOutputOnSuccess) {
$TestArguments += " -KeepOutputOnSuccess"
}
if ($GenerateXmlResults) {
$TestArguments += " -GenerateXmlResults"
}
if ($Debugger) {
$TestArguments += " -Debugger"
}
if ($InitialBreak) {
$TestArguments += " -InitialBreak"
}
if ($BreakOnFailure) {
$TestArguments += " -BreakOnFailure"
}
if ("None" -ne $LogProfile) {
$TestArguments += " -LogProfile $LogProfile"
}
if ($CompressOutput) {
$TestArguments += " -CompressOutput"
}
if ($NoProgress) {
$TestArguments += " -NoProgress"
}
if ($EnableAppVerifier) {
$TestArguments += " -EnableAppVerifier"
}
if ($EnableSystemVerifier) {
$TestArguments += " -EnableSystemVerifier"
}
if ($CodeCoverage) {
$TestArguments += " -CodeCoverage"
}
if ($AZP) {
$TestArguments += " -AZP"
}
if ($GHA) {
$TestArguments += " -GHA"
}
if ($ErrorsAsWarnings) {
$TestArguments += " -ErrorsAsWarnings"
}
if ("" -ne $OsRunner) {
$TestArguments += " -OsRunner $OsRunner"
}
if ($UseQtip) {
$TestArguments += " -UseQtip"
}
if (![string]::IsNullOrWhiteSpace($ExtraArtifactDir)) {
$TestArguments += " -ExtraArtifactDir $ExtraArtifactDir"
}
# Run the script.
if (!$Kernel -and !$SkipUnitTests) {
Invoke-Expression ($RunTest + " -Path $MsQuicPlatTest " + $TestArguments)
Invoke-Expression ($RunTest + " -Path $MsQuicCoreTest " + $TestArguments)
}
Invoke-Expression ($RunTest + " -Path $MsQuicTest " + $TestArguments)
if ($CodeCoverage) {
# Merge code coverage results
$CoverageMergeParams = ""
foreach ($file in $(Get-ChildItem -Path $CoverageDir -Filter '*.cov')) {
$CoverageMergeParams += " --input_coverage $(Join-Path $CoverageDir $file.Name)"
}
if ($CoverageMergeParams -ne "") {
$CoverageMergeParams += " --export_type cobertura:$(Join-Path $CoverageDir "msquiccoverage.xml")"
$CoverageExe = 'C:\"Program Files"\OpenCppCoverage\OpenCppCoverage.exe'
Invoke-Expression ($CoverageExe + $CoverageMergeParams) | Out-Null
} else {
Write-Warning "No coverage results to merge!"
}
}