@@ -20,6 +20,8 @@ $Script:UnitTestResultsFile = Join-Path $TestDataPath $UnitTestResultsFileName
2020$Script :TestSetupLogFile = Join-Path $TestDataPath $TestSetupLogFileName
2121$Script :E2ETestDirectory = Join-Path $repositoryRoot.FullName - ChildPath " regress\pesterTests"
2222$Script :WindowsInBox = $false
23+ $Script :EnableAppVerifier = $true
24+ $Script :PostmortemDebugging = $false
2325
2426<#
2527 . Synopsis
@@ -32,8 +34,10 @@ function Set-OpenSSHTestEnvironment
3234 param
3335 (
3436 [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
3741 )
3842
3943 if ($PSBoundParameters.ContainsKey (" Verbose" ))
@@ -51,7 +55,11 @@ function Set-OpenSSHTestEnvironment
5155 $Script :UnitTestResultsFile = Join-Path $TestDataPath " UnitTestResults.txt"
5256 $Script :TestSetupLogFile = Join-Path $TestDataPath " TestSetupLog.txt"
5357 $Script :UnitTestDirectory = Get-UnitTestDirectory
54-
58+ $Script :EnableAppVerifier = -not ($NoAppVerifier.IsPresent )
59+ if ($Script :EnableAppVerifier )
60+ {
61+ $Script :PostmortemDebugging = $PostmortemDebugging.IsPresent
62+ }
5563
5664 $Global :OpenSSHTestInfo = @ {
5765 " Target" = " localhost" ; # test listener name
@@ -67,6 +75,8 @@ function Set-OpenSSHTestEnvironment
6775 " E2ETestDirectory" = $Script :E2ETestDirectory # the directory of E2E tests
6876 " UnitTestDirectory" = $Script :UnitTestDirectory # the directory of unit tests
6977 " DebugMode" = $DebugMode # run openssh E2E in debug mode
78+ " EnableAppVerifier" = $Script :EnableAppVerifier
79+ " PostmortemDebugging" = $Script :PostmortemDebugging
7080 }
7181
7282 # if user does not set path, pick it up
@@ -237,6 +247,24 @@ WARNING: Following changes will be made to OpenSSH configuration
237247 cmd / c " ssh-add -D 2>&1 >> $Script :TestSetupLogFile "
238248 Repair-UserKeyPermission - FilePath $testPriKeypath - confirm:$false
239249 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+
240268 Backup-OpenSSHTestInfo
241269}
242270# TODO - this is Windows specific. Need to be in PAL
@@ -294,6 +322,31 @@ function Install-OpenSSHTestDependencies
294322 Write-Log - Message " Installing Pester..."
295323 choco install Pester - y -- force -- limitoutput 2>&1 >> $Script :TestSetupLogFile
296324 }
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+ }
297350}
298351
299352function Install-OpenSSHUtilsModule
@@ -313,12 +366,12 @@ function Install-OpenSSHUtilsModule
313366 }
314367
315368 $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))
317370 {
318- New-Item - ItemType Directory - Path $targetDirectory - Force - ErrorAction SilentlyContinue | out-null
371+ New-Item - ItemType Directory - Path " $targetDirectory " - Force - ErrorAction SilentlyContinue | out-null
319372 }
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
322375
323376 if ($PSVersionTable.PSVersion.Major -lt 4 )
324377 {
@@ -396,6 +449,18 @@ function Clear-OpenSSHTestEnvironment
396449 Get-ChildItem " $sshBinPath \sshtest*hostkey*.pub" | % {
397450 ssh- add-hostkey.ps1 - Delete_key $_.FullName
398451 }
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+ }
399464
400465 Remove-Item $sshBinPath \sshtest* hostkey* - Force - ErrorAction SilentlyContinue
401466 # Restore sshd_config
@@ -442,7 +507,7 @@ function Clear-OpenSSHTestEnvironment
442507 {
443508 Write-Log - Message " Uninstalling Module OpenSSHUtils..."
444509 Uninstall-OpenSSHUtilsModule
445- }
510+ }
446511}
447512
448513<#
@@ -506,13 +571,18 @@ function Get-UnitTestDirectory
506571 Run OpenSSH pester tests.
507572#>
508573function Invoke-OpenSSHE2ETest
509- {
574+ {
575+ [CmdletBinding ()]
576+ param
577+ (
578+ [ValidateSet (' CI' , ' Scenario' )]
579+ [string ]$pri = " CI" )
510580 # Discover all CI tests and run them.
511581 Import-Module pester - force - global
512582 Push-Location $Script :E2ETestDirectory
513583 Write-Log - Message " Running OpenSSH E2E tests..."
514584 $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
516586 Pop-Location
517587}
518588
0 commit comments