Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Appverifier tests #191

Merged
merged 5 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions contrib/win32/openssh/OpenSSHTestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $Script:UnitTestResultsFile = Join-Path $TestDataPath $UnitTestResultsFileName
$Script:TestSetupLogFile = Join-Path $TestDataPath $TestSetupLogFileName
$Script:E2ETestDirectory = Join-Path $repositoryRoot.FullName -ChildPath "regress\pesterTests"
$Script:WindowsInBox = $false
$Script:EnableAppVerifier = $true

<#
.Synopsis
Expand All @@ -32,8 +33,9 @@ function Set-OpenSSHTestEnvironment
param
(
[string] $OpenSSHBinPath,
[string] $TestDataPath = "$env:SystemDrive\OpenSSHTests",
[Boolean] $DebugMode = $false
[string] $TestDataPath = "$env:SystemDrive\OpenSSHTests",
[Boolean] $DebugMode = $false,
[Switch] $NoAppVerifier
)

if($PSBoundParameters.ContainsKey("Verbose"))
Expand All @@ -51,7 +53,7 @@ function Set-OpenSSHTestEnvironment
$Script:UnitTestResultsFile = Join-Path $TestDataPath "UnitTestResults.txt"
$Script:TestSetupLogFile = Join-Path $TestDataPath "TestSetupLog.txt"
$Script:UnitTestDirectory = Get-UnitTestDirectory

$Script:EnableAppVerifier = -not ($NoAppVerifier.IsPresent)

$Global:OpenSSHTestInfo = @{
"Target"= "localhost"; # test listener name
Expand All @@ -67,6 +69,7 @@ function Set-OpenSSHTestEnvironment
"E2ETestDirectory" = $Script:E2ETestDirectory # the directory of E2E tests
"UnitTestDirectory" = $Script:UnitTestDirectory # the directory of unit tests
"DebugMode" = $DebugMode # run openssh E2E in debug mode
"EnableAppVerifier" = $Script:EnableAppVerifier
}

#if user does not set path, pick it up
Expand Down Expand Up @@ -237,6 +240,22 @@ WARNING: Following changes will be made to OpenSSH configuration
cmd /c "ssh-add -D 2>&1 >> $Script:TestSetupLogFile"
Repair-UserKeyPermission -FilePath $testPriKeypath -confirm:$false
cmd /c "ssh-add $testPriKeypath 2>&1 >> $Script:TestSetupLogFile"

#Enable AppVerifier
if($EnableAppVerifier)
{
<#$folderName = "x86"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete this before you push your changes upstream

Copy link
Author

@bingbing8 bingbing8 Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to keep them to save time in case people want to set Postmortem Debugging when things got broken or even want to enable it in the future. :)

if($env:PROCESSOR_ARCHITECTURE -ieq "AMD64")
{
$folderName = "x64"
}#>
& $env:windir\System32\appverif.exe -disable * -for *
Get-ChildItem "$($script:OpenSSHBinPath)\*.exe" -Exclude sftp.exe | % {
& $env:windir\System32\appverif.exe -verify $_.Name | out-null
#reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug" /v "Debugger" /t REG_SZ /d "`"${env:ProgramFiles(x86)}\Windows Kits\8.1\Debuggers\$folderName\Debuggers\windbg.exe`" -p %ld -e %ld -g" /f
}
}

Backup-OpenSSHTestInfo
}
#TODO - this is Windows specific. Need to be in PAL
Expand Down Expand Up @@ -294,6 +313,11 @@ function Install-OpenSSHTestDependencies
Write-Log -Message "Installing Pester..."
choco install Pester -y --force --limitoutput 2>&1 >> $Script:TestSetupLogFile
}

if(($Script:EnableAppVerifier -or (($OpenSSHTestInfo -ne $null) -and ($OpenSSHTestInfo["EnableAppVerifier"]))) -and (-not (Test-path $env:windir\System32\appverif.exe)))
{
choco install appverifier -y --force --limitoutput 2>&1 >> $Script:TestSetupLogFile
}
}

function Install-OpenSSHUtilsModule
Expand Down Expand Up @@ -396,6 +420,11 @@ function Clear-OpenSSHTestEnvironment
Get-ChildItem "$sshBinPath\sshtest*hostkey*.pub"| % {
ssh-add-hostkey.ps1 -Delete_key $_.FullName
}

if($Global:OpenSSHTestInfo["EnableAppVerifier"] -and (Test-path $env:windir\System32\appverif.exe))
{
& $env:windir\System32\appverif.exe -disable * -for *

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do ? can you put in some comments please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just clean up the applications in application verifier.

}

Remove-Item $sshBinPath\sshtest*hostkey* -Force -ErrorAction SilentlyContinue
#Restore sshd_config
Expand Down Expand Up @@ -442,7 +471,7 @@ function Clear-OpenSSHTestEnvironment
{
Write-Log -Message "Uninstalling Module OpenSSHUtils..."
Uninstall-OpenSSHUtilsModule
}
}
}

<#
Expand Down
2 changes: 2 additions & 0 deletions contrib/win32/win32compat/termio.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ ReadThread(_In_ LPVOID lpParameter)
pio->read_details.buf_size, &read_status.transferred, NULL)) {
read_status.error = GetLastError();
debug("ReadThread - ReadFile failed %d, io:%p", GetLastError(), pio);
return -1;
}

char *p = NULL;
Expand All @@ -128,6 +129,7 @@ ReadThread(_In_ LPVOID lpParameter)
pio->read_details.buf_size, &read_status.transferred, NULL)) {
read_status.error = GetLastError();
debug("ReadThread - ReadFile failed %d, io:%p", GetLastError(), pio);
return -1;
}
}
if (0 == QueueUserAPC(ReadAPCProc, main_thread, (ULONG_PTR)pio)) {
Expand Down