Skip to content

Commit fbfe284

Browse files
authored
parallelize CI tests (#835)
* parallelize CI tests * address copilot feedback
1 parent 78cef95 commit fbfe284

3 files changed

Lines changed: 189 additions & 74 deletions

File tree

.azdo/ci.yml

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ stages:
7474
displayName: Test Win32-OpenSSH
7575
dependsOn: Build
7676
jobs:
77-
- job: TestPkgWin32OpenSSH
77+
- job: TestPkgWin32OpenSSHCore
7878
pool:
7979
vmImage: windows-latest
80-
displayName: Win32-OpenSSH On Windows
80+
displayName: Win32-OpenSSH Core Tests On Windows
8181
variables:
8282
testFilesDrivePath: '**'
8383
steps:
@@ -97,14 +97,6 @@ stages:
9797
artifactName: UnitTests-x64
9898
downloadPath: '$(System.ArtifactsDirectory)'
9999

100-
- task: DownloadBuildArtifacts@0
101-
displayName: 'Download bash test config file artifact'
102-
inputs:
103-
buildType: current
104-
downloadType: single
105-
artifactName: ConfigFile-x64
106-
downloadPath: '$(System.ArtifactsDirectory)'
107-
108100
- pwsh: |
109101
$artifactDir = "$(System.ArtifactsDirectory)"
110102
Write-Verbose -Verbose -Message "Artifacts directory: $artifactDir"
@@ -121,13 +113,6 @@ stages:
121113
Install-UnitTests -SourceDir "$(System.ArtifactsDirectory)/UnitTests-x64/x64/Release" -OpenSSHDir "$env:SystemDrive/OpenSSH" -Verbose
122114
displayName: Install Unit Tests
123115
124-
- pwsh: |
125-
$configFileSrc = "$(System.ArtifactsDirectory)/ConfigFile-x64/config.h"
126-
$configFileDest = "$(Build.SourcesDirectory)"
127-
Write-Verbose -Verbose -Message "Copying config file from: ${configFileSrc} to: ${configFileDest}"
128-
Copy-Item -Path $configFileSrc -Dest $configFileDest -Force
129-
displayName: Copy config file artifact for bash tests
130-
131116
- pwsh: |
132117
$sourceDir = "$(Build.SourcesDirectory)"
133118
Write-Verbose -Verbose -Message "Source repo directory: $sourceDir"
@@ -144,7 +129,7 @@ stages:
144129
# Run OpenSSH tests
145130
Import-Module -Name "$(Build.SourcesDirectory)/contrib/win32/openssh/AzDOBuildTools" -Force
146131
Invoke-OpenSSHTests -OpenSSHBinPath "$env:SystemDrive/OpenSSH"
147-
displayName: Run tests
132+
displayName: Run core tests
148133
149134
- pwsh: |
150135
Write-Host "##vso[task.setvariable variable=testFilesDrivePath;]$env:SystemDrive"
@@ -167,7 +152,86 @@ stages:
167152
# Upload test results artifact
168153
if (Test-Path -Path $ResultsDirectory)
169154
{
170-
$artifactName = 'Win32-OpenSSH-TestResults'
155+
$artifactName = 'Win32-OpenSSH-TestResults-Core'
156+
Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$ResultsDirectory"
157+
}
158+
displayName: Upload test results
159+
condition: always()
160+
161+
- pwsh: |
162+
Import-Module -Name "$(Build.SourcesDirectory)/contrib/win32/openssh/AzDOBuildTools" -Force
163+
Clear-TestEnvironmentSetup
164+
displayName: Clean up OpenSSH test environment
165+
condition: always()
166+
167+
- job: TestPkgWin32OpenSSHBash
168+
pool:
169+
vmImage: windows-latest
170+
displayName: Win32-OpenSSH Bash Tests On Windows
171+
steps:
172+
- task: DownloadBuildArtifacts@0
173+
displayName: 'Download build artifacts'
174+
inputs:
175+
buildType: current
176+
downloadType: single
177+
artifactName: Win32-OpenSSH-x64
178+
downloadPath: '$(System.ArtifactsDirectory)'
179+
180+
- task: DownloadBuildArtifacts@0
181+
displayName: 'Download bash test config file artifact'
182+
inputs:
183+
buildType: current
184+
downloadType: single
185+
artifactName: ConfigFile-x64
186+
downloadPath: '$(System.ArtifactsDirectory)'
187+
188+
- pwsh: |
189+
$artifactDir = "$(System.ArtifactsDirectory)"
190+
Write-Verbose -Verbose -Message "Artifacts directory: $artifactDir"
191+
Get-ChildItem -Path $artifactDir -Recurse
192+
displayName: Capture downloaded artifact directory
193+
194+
- pwsh: |
195+
Import-Module -Name "$(Build.SourcesDirectory)/contrib/win32/openssh/AzDOBuildTools" -Force
196+
Install-OpenSSH -SourceDir "$(System.ArtifactsDirectory)/Win32-OpenSSH-x64/x64/Release" -OpenSSHDir "$env:SystemDrive/OpenSSH" -Verbose
197+
displayName: Install Win32-OpenSSH
198+
199+
- pwsh: |
200+
$configFileSrc = "$(System.ArtifactsDirectory)/ConfigFile-x64/config.h"
201+
$configFileDest = "$(Build.SourcesDirectory)"
202+
Write-Verbose -Verbose -Message "Copying config file from: ${configFileSrc} to: ${configFileDest}"
203+
Copy-Item -Path $configFileSrc -Dest $configFileDest -Force
204+
displayName: Copy config file artifact for bash tests
205+
206+
- pwsh: |
207+
$sourceDir = "$(Build.SourcesDirectory)"
208+
Write-Verbose -Verbose -Message "Source repo directory: $sourceDir"
209+
Get-ChildItem -Path $sourceDir
210+
displayName: Capture source repo directory for test
211+
212+
- pwsh: |
213+
$installedOpenSSHDir = "$env:SystemDrive/OpenSSH"
214+
Write-Verbose -Verbose -Message "Installed OpenSSH directory: $installedOpenSSHDir"
215+
Get-ChildItem -Path $installedOpenSSHDir -Recurse
216+
displayName: Capture installed OpenSSH directory
217+
218+
- pwsh: |
219+
# Run OpenSSH bash tests
220+
Import-Module -Name "$(Build.SourcesDirectory)/contrib/win32/openssh/AzDOBuildTools" -Force
221+
Invoke-OpenSSHBashTestsOnly -OpenSSHBinPath "$env:SystemDrive/OpenSSH"
222+
displayName: Run bash tests
223+
224+
- pwsh: |
225+
Import-Module -Name "$(Build.SourcesDirectory)/contrib/win32/openssh/AzDOBuildTools" -Force
226+
#
227+
# Copy test results to results directory
228+
$ResultsDirectory = "$(Build.SourcesDirectory)/Win32OpenSSHTestResults"
229+
Copy-OpenSSHTestResults -ResultsPath $ResultsDirectory
230+
#
231+
# Upload test results artifact
232+
if (Test-Path -Path $ResultsDirectory)
233+
{
234+
$artifactName = 'Win32-OpenSSH-TestResults-Bash'
171235
Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$ResultsDirectory"
172236
}
173237
displayName: Upload test results

contrib/win32/openssh/AzDOBuildTools/AzDOBuildTools.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ FunctionsToExport = @(
3131
'Invoke-AzDOBuild',
3232
'Install-OpenSSH',
3333
'Invoke-OpenSSHTests',
34+
'Invoke-OpenSSHBashTestsOnly',
3435
'Copy-OpenSSHTestResults',
3536
'Copy-BuildResults',
3637
'Copy-UnitTests',

contrib/win32/openssh/AzDOBuildTools/AzDOBuildTools.psm1

Lines changed: 105 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,42 @@ function Install-CygWin
162162
choco install cygwin -y --force --params "/InstallDir:${InstallLocation} /NoStartMenu"
163163
}
164164

165+
function Ensure-CygWinInstalled
166+
{
167+
[CmdletBinding()]
168+
param (
169+
[string] $InstallLocation = "$env:SystemDrive/cygwin",
170+
[Parameter(Mandatory=$true)]
171+
[string] $FailureMessage
172+
)
173+
174+
if (Test-Path -Path "$InstallLocation/bin/sh.exe")
175+
{
176+
return $true
177+
}
178+
179+
Write-Verbose -Verbose -Message "CygWin not found"
180+
Install-CygWin -InstallLocation $InstallLocation
181+
182+
$expectedCygWinPath = "$InstallLocation/bin/sh.exe"
183+
if (Test-Path -Path $expectedCygWinPath)
184+
{
185+
return $true
186+
}
187+
188+
Write-Verbose -Verbose -Message "CygWin did not install correctly, missing expected path: ${expectedCygWinPath}"
189+
190+
$cygWinDirs = Get-Item -Path "$env:SystemDrive/cygwin*" -ErrorAction SilentlyContinue
191+
if ($cygWinDirs.Count -gt 1)
192+
{
193+
Write-Verbose -Verbose -Message "CygWin install failed with mangled folder locations: ${cygWinDirs}"
194+
Write-Verbose -Verbose -Message 'TODO: Add hack to fix up CygWin folder.'
195+
}
196+
197+
Write-BuildMessage -Message $FailureMessage -Category Error
198+
return $false
199+
}
200+
165201
<#
166202
.Synopsis
167203
Runs the tests for this repo
@@ -229,34 +265,7 @@ function Invoke-OpenSSHTests
229265
Write-Verbose -Verbose -Message "Running E2E Tests..."
230266
Set-OpenSSHTestEnvironment -Confirm:$false
231267

232-
# Ensure CygWin is installed, and install from Chocolatey if needed.
233-
# used for bash tests and default shell pester tests
234-
$cygwinInstalled = $true
235-
$cygwinInstallLocation = "$env:SystemDrive/cygwin"
236-
if (! (Test-Path -Path "$cygwinInstallLocation/bin/sh.exe"))
237-
{
238-
Write-Verbose -Verbose -Message "CygWin not found"
239-
Install-CygWin -InstallLocation $cygwinInstallLocation
240-
241-
# Hack to fix up mangled CygWin directory, if needed.
242-
$expectedCygWinPath = "$env:SystemDrive/cygwin/bin/sh.exe"
243-
if (! (Test-Path -Path $expectedCygWinPath))
244-
{
245-
Write-Verbose -Verbose -Message "CygWin did not install correctly, missing expected path: ${expectedCygWinPath}"
246-
247-
$cygWinDirs = Get-Item -Path "$env:SystemDrive/cygwin*"
248-
if ($cygWinDirs.Count -gt 1)
249-
{
250-
Write-Verbose -Verbose -Message "CygWin install failed with mangled folder locations: ${cygWinDirs}"
251-
Write-Verbose -Verbose -Message 'TODO: Add hack to fix up CygWin folder.'
252-
}
253-
254-
Write-BuildMessage -Message "All bash tests failed because CygWin install failed" -Category Error
255-
$AllTestsPassed = $false
256-
$cygwinInstalled = $false
257-
}
258-
}
259-
268+
$cygwinInstalled = Ensure-CygWinInstalled -FailureMessage "All E2E tests failed because CygWin install failed"
260269
if ($cygwinInstalled)
261270
{
262271
Invoke-OpenSSHE2ETest
@@ -279,33 +288,10 @@ function Invoke-OpenSSHTests
279288
Write-BuildMessage -Message "All E2E tests passed!" -Category Information
280289
}
281290
}
282-
283-
# Bash tests.
284-
Write-Verbose -Verbose -Message "Running Bash Tests..."
285-
286-
# Run UNIX bash tests.
287-
Write-Verbose -Verbose -Message "Starting Bash Tests..."
288-
Invoke-OpenSSHBashTests
289-
if (-not $Global:bash_tests_summary)
290-
{
291-
$errorMessage = "Failed to start OpenSSH bash tests"
292-
Write-BuildMessage -Message $errorMessage -Category Error
293-
$AllTestsPassed = $false
294-
}
295-
else
296-
{
297-
if ($Global:bash_tests_summary["TotalBashTestsFailed"] -ne 0)
298-
{
299-
$total_bash_failed_tests = $Global:bash_tests_summary["TotalBashTestsFailed"]
300-
$total_bash_tests = $Global:bash_tests_summary["TotalBashTests"]
301-
$errorMessage = "At least one of the bash tests failed. [$total_bash_failed_tests of $total_bash_tests]"
302-
Write-BuildMessage -Message $errorMessage -Category Error
303-
$AllTestsPassed = $false
304-
}
305-
306-
$OpenSSHTestInfo["BashTestSummaryFile"] = $Global:bash_tests_summary["BashTestSummaryFile"]
307-
$OpenSSHTestInfo["BashTestLogFile"] = $Global:bash_tests_summary["BashTestLogFile"]
308-
}
291+
}
292+
else
293+
{
294+
$AllTestsPassed = $false
309295
}
310296

311297
# OpenSSH Uninstall Tests
@@ -346,6 +332,70 @@ function Invoke-OpenSSHTests
346332
}
347333
}
348334

335+
<#
336+
.Synopsis
337+
Runs OpenSSH bash tests only.
338+
#>
339+
function Invoke-OpenSSHBashTestsOnly
340+
{
341+
[CmdletBinding()]
342+
param (
343+
[Parameter(Mandatory=$true)]
344+
[string] $OpenSSHBinPath
345+
)
346+
347+
Set-BasicTestInfo -OpenSSHBinPath $OpenSSHBinPath -Confirm:$false
348+
349+
$AllTestsPassed = $true
350+
351+
Write-Verbose -Verbose -Message "Running Bash-only OpenSSH test flow..."
352+
Set-OpenSSHTestEnvironment -Confirm:$false
353+
354+
$cygwinInstalled = Ensure-CygWinInstalled -FailureMessage "All bash tests failed because CygWin install failed"
355+
if (-not $cygwinInstalled)
356+
{
357+
$AllTestsPassed = $false
358+
}
359+
360+
if ($AllTestsPassed)
361+
{
362+
Write-Verbose -Verbose -Message "Starting Bash Tests..."
363+
Invoke-OpenSSHBashTests
364+
if (-not $Global:bash_tests_summary)
365+
{
366+
$errorMessage = "Failed to start OpenSSH bash tests"
367+
Write-BuildMessage -Message $errorMessage -Category Error
368+
$AllTestsPassed = $false
369+
}
370+
else
371+
{
372+
if ($Global:bash_tests_summary["TotalBashTestsFailed"] -ne 0)
373+
{
374+
$total_bash_failed_tests = $Global:bash_tests_summary["TotalBashTestsFailed"]
375+
$total_bash_tests = $Global:bash_tests_summary["TotalBashTests"]
376+
$errorMessage = "At least one of the bash tests failed. [$total_bash_failed_tests of $total_bash_tests]"
377+
Write-BuildMessage -Message $errorMessage -Category Error
378+
$AllTestsPassed = $false
379+
}
380+
381+
$OpenSSHTestInfo["BashTestSummaryFile"] = $Global:bash_tests_summary["BashTestSummaryFile"]
382+
$OpenSSHTestInfo["BashTestLogFile"] = $Global:bash_tests_summary["BashTestLogFile"]
383+
}
384+
}
385+
386+
$OpenSSHTestInfo | Export-Clixml -Path "$repoRoot/OpenSSHTestInfo.xml" -Depth 10
387+
388+
if ($AllTestsPassed)
389+
{
390+
Write-BuildMessage -Message "All OpenSSH bash validation tests have passed!" -Category Information
391+
}
392+
else
393+
{
394+
Write-BuildMessage -Message "Some OpenSSH bash validation tests have failed." -Category Error
395+
throw "OpenSSH bash validation tests failed!"
396+
}
397+
}
398+
349399
<#
350400
.Synopsis
351401
Collect OpenSSH pester test results into one directory

0 commit comments

Comments
 (0)