@@ -20,6 +20,8 @@ $Script:UnitTestResultsFile = Join-Path $TestDataPath $UnitTestResultsFileName
20
20
$Script :TestSetupLogFile = Join-Path $TestDataPath $TestSetupLogFileName
21
21
$Script :E2ETestDirectory = Join-Path $repositoryRoot.FullName - ChildPath " regress\pesterTests"
22
22
$Script :WindowsInBox = $false
23
+ $Script :EnableAppVerifier = $true
24
+ $Script :PostmortemDebugging = $false
23
25
24
26
<#
25
27
. Synopsis
@@ -32,8 +34,10 @@ function Set-OpenSSHTestEnvironment
32
34
param
33
35
(
34
36
[string ] $OpenSSHBinPath ,
35
- [string ] $TestDataPath = " $env: SystemDrive \OpenSSHTests" ,
36
- [Boolean ] $DebugMode = $false
37
+ [string ] $TestDataPath = " $env: SystemDrive \OpenSSHTests" ,
38
+ [Boolean ] $DebugMode = $false ,
39
+ [Switch ] $NoAppVerifier ,
40
+ [Switch ] $PostmortemDebugging
37
41
)
38
42
39
43
if ($PSBoundParameters.ContainsKey (" Verbose" ))
@@ -51,7 +55,11 @@ function Set-OpenSSHTestEnvironment
51
55
$Script :UnitTestResultsFile = Join-Path $TestDataPath " UnitTestResults.txt"
52
56
$Script :TestSetupLogFile = Join-Path $TestDataPath " TestSetupLog.txt"
53
57
$Script :UnitTestDirectory = Get-UnitTestDirectory
54
-
58
+ $Script :EnableAppVerifier = -not ($NoAppVerifier.IsPresent )
59
+ if ($Script :EnableAppVerifier )
60
+ {
61
+ $Script :PostmortemDebugging = $PostmortemDebugging.IsPresent
62
+ }
55
63
56
64
$Global :OpenSSHTestInfo = @ {
57
65
" Target" = " localhost" ; # test listener name
@@ -67,6 +75,8 @@ function Set-OpenSSHTestEnvironment
67
75
" E2ETestDirectory" = $Script :E2ETestDirectory # the directory of E2E tests
68
76
" UnitTestDirectory" = $Script :UnitTestDirectory # the directory of unit tests
69
77
" DebugMode" = $DebugMode # run openssh E2E in debug mode
78
+ " EnableAppVerifier" = $Script :EnableAppVerifier
79
+ " PostmortemDebugging" = $Script :PostmortemDebugging
70
80
}
71
81
72
82
# if user does not set path, pick it up
@@ -237,6 +247,24 @@ WARNING: Following changes will be made to OpenSSH configuration
237
247
cmd / c " ssh-add -D 2>&1 >> $Script :TestSetupLogFile "
238
248
Repair-UserKeyPermission - FilePath $testPriKeypath - confirm:$false
239
249
cmd / c " ssh-add $testPriKeypath 2>&1 >> $Script :TestSetupLogFile "
250
+
251
+ # Enable AppVerifier
252
+ if ($EnableAppVerifier )
253
+ {
254
+ # clear all applications in application verifier first
255
+ & $env: windir \System32\appverif.exe - disable * - for * | out-null
256
+ Get-ChildItem " $ ( $script :OpenSSHBinPath ) \*.exe" | % {
257
+ & $env: windir \System32\appverif.exe - verify $_.Name | out-null
258
+ }
259
+
260
+ if ($Script :PostmortemDebugging -and (Test-path $Script :WindbgPath ))
261
+ {
262
+ # enable Postmortem debugger
263
+ New-ItemProperty " HKLM:Software\Microsoft\Windows NT\CurrentVersion\AeDebug" - Name Debugger - Type String - Value " `" $Script :WindbgPath `" -p %ld -e %ld -g" - Force - ErrorAction SilentlyContinue | Out-Null
264
+ New-ItemProperty " HKLM:Software\Microsoft\Windows NT\CurrentVersion\AeDebug" - Name Auto - Type String - Value " 1" - Force - ErrorAction SilentlyContinue | Out-Null
265
+ }
266
+ }
267
+
240
268
Backup-OpenSSHTestInfo
241
269
}
242
270
# TODO - this is Windows specific. Need to be in PAL
@@ -294,6 +322,31 @@ function Install-OpenSSHTestDependencies
294
322
Write-Log - Message " Installing Pester..."
295
323
choco install Pester - y -- force -- limitoutput 2>&1 >> $Script :TestSetupLogFile
296
324
}
325
+
326
+ if ($Script :PostmortemDebugging -or (($OpenSSHTestInfo -ne $null ) -and ($OpenSSHTestInfo [" PostmortemDebugging" ])))
327
+ {
328
+ $folderName = " x86"
329
+ $pathroot = $env: ProgramFiles
330
+ if ($env: PROCESSOR_ARCHITECTURE -ieq " AMD64" )
331
+ {
332
+ $folderName = " x64"
333
+ $pathroot = ${env: ProgramFiles(x86)}
334
+ }
335
+ $Script :WindbgPath = " $pathroot \Windows Kits\8.1\Debuggers\$folderName \windbg.exe"
336
+ if (-not (Test-Path $Script :WindbgPath ))
337
+ {
338
+ $Script :WindbgPath = " $pathroot \Windows Kits\10\Debuggers\$folderName \windbg.exe"
339
+ if (-not (Test-Path $Script :WindbgPath ))
340
+ {
341
+ choco install windbg - y -- force -- limitoutput 2>&1 >> $Script :TestSetupLogFile
342
+ }
343
+ }
344
+ }
345
+
346
+ if (($Script :EnableAppVerifier -or (($OpenSSHTestInfo -ne $null ) -and ($OpenSSHTestInfo [" EnableAppVerifier" ]))) -and (-not (Test-path $env: windir \System32\appverif.exe )))
347
+ {
348
+ choco install appverifier - y -- force -- limitoutput 2>&1 >> $Script :TestSetupLogFile
349
+ }
297
350
}
298
351
299
352
function Install-OpenSSHUtilsModule
@@ -313,12 +366,12 @@ function Install-OpenSSHUtilsModule
313
366
}
314
367
315
368
$modulePath = Join-Path - Path $env: ProgramFiles - ChildPath WindowsPowerShell\Modules
316
- if (-not (Test-Path $targetDirectory - PathType Container))
369
+ if (-not (Test-Path " $targetDirectory " - PathType Container))
317
370
{
318
- New-Item - ItemType Directory - Path $targetDirectory - Force - ErrorAction SilentlyContinue | out-null
371
+ New-Item - ItemType Directory - Path " $targetDirectory " - Force - ErrorAction SilentlyContinue | out-null
319
372
}
320
- Copy-item $manifestFile - Destination $targetDirectory - Force - ErrorAction SilentlyContinue | out-null
321
- Copy-item $moduleFile - Destination $targetDirectory - Force - ErrorAction SilentlyContinue | out-null
373
+ Copy-item " $manifestFile " - Destination " $targetDirectory " - Force - ErrorAction SilentlyContinue | out-null
374
+ Copy-item " $moduleFile " - Destination " $targetDirectory " - Force - ErrorAction SilentlyContinue | out-null
322
375
323
376
if ($PSVersionTable.PSVersion.Major -lt 4 )
324
377
{
@@ -396,6 +449,18 @@ function Clear-OpenSSHTestEnvironment
396
449
Get-ChildItem " $sshBinPath \sshtest*hostkey*.pub" | % {
397
450
ssh- add-hostkey.ps1 - Delete_key $_.FullName
398
451
}
452
+
453
+ if ($Global :OpenSSHTestInfo [" EnableAppVerifier" ] -and (Test-path $env: windir \System32\appverif.exe ))
454
+ {
455
+ # clear all applications in application verifier
456
+ & $env: windir \System32\appverif.exe - disable * - for * | out-null
457
+ }
458
+
459
+ if ($Global :OpenSSHTestInfo [" PostmortemDebugging" ])
460
+ {
461
+ Remove-ItemProperty " HKLM:Software\Microsoft\Windows NT\CurrentVersion\AeDebug" - Name Debugger - ErrorAction SilentlyContinue - Force | Out-Null
462
+ Remove-ItemProperty " HKLM:Software\Microsoft\Windows NT\CurrentVersion\AeDebug" - Name Auto - ErrorAction SilentlyContinue - Force | Out-Null
463
+ }
399
464
400
465
Remove-Item $sshBinPath \sshtest* hostkey* - Force - ErrorAction SilentlyContinue
401
466
# Restore sshd_config
@@ -442,7 +507,7 @@ function Clear-OpenSSHTestEnvironment
442
507
{
443
508
Write-Log - Message " Uninstalling Module OpenSSHUtils..."
444
509
Uninstall-OpenSSHUtilsModule
445
- }
510
+ }
446
511
}
447
512
448
513
<#
@@ -506,13 +571,18 @@ function Get-UnitTestDirectory
506
571
Run OpenSSH pester tests.
507
572
#>
508
573
function Invoke-OpenSSHE2ETest
509
- {
574
+ {
575
+ [CmdletBinding ()]
576
+ param
577
+ (
578
+ [ValidateSet (' CI' , ' Scenario' )]
579
+ [string ]$pri = " CI" )
510
580
# Discover all CI tests and run them.
511
581
Import-Module pester - force - global
512
582
Push-Location $Script :E2ETestDirectory
513
583
Write-Log - Message " Running OpenSSH E2E tests..."
514
584
$testFolders = @ (Get-ChildItem * .tests.ps1 - Recurse | ForEach-Object { Split-Path $_.FullName } | Sort-Object - Unique)
515
- Invoke-Pester $testFolders - OutputFormat NUnitXml - OutputFile $Script :E2ETestResultsFile - Tag ' CI '
585
+ Invoke-Pester $testFolders - OutputFormat NUnitXml - OutputFile $Script :E2ETestResultsFile - Tag $pri - PassThru
516
586
Pop-Location
517
587
}
518
588
0 commit comments