-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added testing suite that can built and run directly on the Linux uVM by sharing or adding it to the rootfs. It primarily focuses on container (standalone and CRI) management. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
- Loading branch information
Showing
12 changed files
with
2,023 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#ex: .\scripts\Test-LCOW-UVM.ps1 -vb -Action Bench -BootFilesPath C:\ContainerPlat\LinuxBootFiles\ -MountGCSTest -Count 2 -Benchtime '3s' | ||
# benchstat via `go install golang.org/x/perf/cmd/benchstat@latest` | ||
|
||
[CmdletBinding()] | ||
param ( | ||
[ValidateSet('Test', 'Bench', 'List', 'Shell')] | ||
[alias('a')] | ||
[string] | ||
$Action = 'Bench', | ||
|
||
[string] | ||
$Note = '', | ||
|
||
# test parameters | ||
[int] | ||
$Count = 1, | ||
|
||
[string] | ||
$BenchTime = '5s', | ||
|
||
[string] | ||
$Timeout = '10m', | ||
|
||
[alias('tv')] | ||
[switch] | ||
$TestVerbose, | ||
|
||
[string] | ||
$Run = '', | ||
|
||
[string] | ||
$CodePath = '.', | ||
|
||
[string] | ||
$OutDirectory = '.\test\results', | ||
|
||
# uvm parameters | ||
[string] | ||
$BootFilesPath = 'C:\ContainerPlat\LinuxBootFiles', | ||
|
||
[switch] | ||
$DisableTimeSync, | ||
|
||
[string] | ||
$RootfsMount = '/run/rootfs', | ||
|
||
[string] | ||
$RootfsPath = (Join-Path $BootFilesPath 'rootfs.vhd'), | ||
# $RootfsPath = "C:\ContainerPlatData\root\io.containerd.snapshotter.v1.windows-lcow\snapshots\2\layer.vhd", | ||
|
||
[string] | ||
$GCSTestMount = '/run/bin', | ||
|
||
[string] | ||
$GCSTestPath = '.\bin\test\gcstest', | ||
|
||
[switch] | ||
$MountGCSTest, | ||
|
||
[string] | ||
$Feature = '' | ||
) | ||
|
||
Import-Module ( Join-Path $PSScriptRoot Testing.psm1 ) -Force | ||
|
||
$CodePath = Resolve-Path $CodePath | ||
$OutDirectory = Resolve-Path $OutDirectory | ||
$BootFilesPath = Resolve-Path $BootFilesPath | ||
$RootfsPath = Resolve-Path $RootfsPath | ||
$GCSTestPath = Resolve-Path $GCSTestPath | ||
|
||
$shell = ( $Action -eq 'Shell' ) | ||
|
||
if ( $shell ) { | ||
$cmd = 'ash' | ||
} else { | ||
$date = Get-Date | ||
$waitfiles = "$RootfsMount" | ||
$gcspath = 'gcstest' | ||
if ( $MountGCSTest ) { | ||
$waitfiles += ",$GCSTestMount" | ||
$gcspath = "$GCSTestMount/gcstest" | ||
} | ||
|
||
$pre = "wait-paths -p $waitfiles -t 5 ; " + ` | ||
'echo nproc: `$(nproc) ; ' + ` | ||
'echo kernel: `$(uname -a) ; ' + ` | ||
'echo gcs.commit: `$(cat /info/gcs.commit 2>/dev/null) ; ' + ` | ||
'echo gcs.branch: `$(cat /info/gcs.branch 2>/dev/null) ; ' + ` | ||
'echo tar.date: `$(cat /info/tar.date 2>/dev/null) ; ' + ` | ||
'echo image.name: `$(cat /info/image.name 2>/dev/null) ; ' + ` | ||
'echo build.date: `$(cat /info/build.date 2>/dev/null) ; ' | ||
|
||
$testcmd, $out = New-TestCommand ` | ||
-Action $Action ` | ||
-Path $gcspath ` | ||
-Name gcstest ` | ||
-OutDirectory $OutDirectory ` | ||
-Date $date ` | ||
-Note $Note ` | ||
-TestVerbose:$TestVerbose ` | ||
-Count $Count ` | ||
-BenchTime $BenchTime ` | ||
-Timeout $Timeout ` | ||
-Run $Run ` | ||
-Feature $Feature ` | ||
-Verbose:$Verbose | ||
|
||
$testcmd += " `'-rootfs-path=$RootfsMount`' " | ||
$cmd = $pre + $testcmd | ||
} | ||
|
||
$boot = '.\bin\tools\uvmboot.exe -gcs lcow ' + ` | ||
'-fwd-stdout -fwd-stderr -output-handling stdout ' + ` | ||
"-boot-files-path $BootFilesPath " + ` | ||
'-root-fs-type vhd ' + ` | ||
'-kernel-file vmlinux ' + ` | ||
"-security-policy=`"`" " + ` | ||
"-mount `"$RootfsPath,$RootfsMount`" " | ||
|
||
if ( $MountGCSTest ) { | ||
$boot += "-share `"$GCSTestPath,$GCSTestMount`" " | ||
} | ||
|
||
if ( $DisableTimeSync ) { | ||
$boot += ' -disable-time-sync ' | ||
} | ||
|
||
if ( $shell ) { | ||
$boot += ' -t ' | ||
} | ||
|
||
$boot += " -exec `"$cmd`" " | ||
|
||
Invoke-TestCommand ` | ||
-TestCmd $boot ` | ||
-TestCmdPreamble $testcmd ` | ||
-OutputFile (&{ if ( $Action -ne 'Shell' ) { $out } }) ` | ||
-OutputCmd (&{ if ( $Action -eq 'Bench' ) { 'benchstat' } }) ` | ||
-Preamble ` | ||
-Date $Date ` | ||
-Note $Note ` | ||
-Verbose:$Verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
function New-TestCommand { | ||
[CmdletBinding()] | ||
param ( | ||
[ValidateSet('Test', 'Bench', 'List')] | ||
[alias('a')] | ||
[string] | ||
$Action = 'Bench', | ||
|
||
[Parameter(Mandatory)] | ||
[string] | ||
$Path, | ||
|
||
[Parameter(Mandatory)] | ||
[string] | ||
$Name, | ||
|
||
[Parameter(Mandatory)] | ||
[string] | ||
$OutDirectory , | ||
|
||
[DateTime] | ||
$Date = (Get-Date), | ||
|
||
[string] | ||
$Note = '', | ||
|
||
# test parameters | ||
[alias('tv')] | ||
[switch] | ||
$TestVerbose = $false, | ||
|
||
[int] | ||
$Count = 1, | ||
|
||
[string] | ||
$BenchTime = '5s', | ||
|
||
[string] | ||
$Timeout = '10m', | ||
|
||
[string] | ||
$Run = '', | ||
|
||
[string] | ||
$Feature = '' | ||
) | ||
|
||
$OutDirectory = Resolve-Path $OutDirectory | ||
Write-Verbose "creating $OutDirectory" | ||
|
||
New-Item -ItemType 'directory' -Path $OutDirectory -Force > $null | ||
|
||
$testcmd = "$Path `'-test.timeout=$Timeout`' `'-test.shuffle=on`' `'-test.count=$Count`' " | ||
|
||
if ( $TestVerbose ) { | ||
$testcmd += ' ''-test.v'' ' | ||
} | ||
|
||
switch ( $Action ) { | ||
'List' { | ||
if ( $Run -eq '' ) { | ||
$Run = '.' | ||
} | ||
$testcmd += " `'-test.list=$Run`' " | ||
} | ||
'Test' { | ||
if ( $Run -ne '' ) { | ||
$testcmd += " `'-test.run=$Run`' " | ||
} | ||
} | ||
'Bench' { | ||
if ( $Run -eq '' ) { | ||
$Run = '.' | ||
} | ||
$testcmd += ' ''-test.run=^#'' ''-test.benchmem'' ' + ` | ||
" `'-test.bench=$Run`' `'-test.benchtime=$BenchTime`' " | ||
} | ||
} | ||
|
||
if ( $Feature -ne '' ) { | ||
$testcmd += " `'-feature=$Feature`' " | ||
} | ||
|
||
$f = $Name + '-' + $Action | ||
if ($Note -ne '' ) { | ||
$f += '-' + $Note | ||
} | ||
$out = Join-Path $OutDirectory "$f-$(Get-Date -Date $date -Format FileDateTime).txt" | ||
|
||
return $testcmd, $out | ||
} | ||
|
||
function Invoke-TestCommand { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory)] | ||
[string] | ||
$TestCmd, | ||
|
||
[string] | ||
$TestCmdPreamble = $TestCmd, | ||
|
||
[string] | ||
$OutputFile = 'nul', | ||
|
||
[string] | ||
$OutputCmd, | ||
|
||
[switch] | ||
$Preamble, | ||
|
||
[DateTime] | ||
$Date = (Get-Date), | ||
|
||
[string] | ||
$Note | ||
) | ||
|
||
if ($OutputFile -eq '' ) { | ||
$OutputFile = 'nul' | ||
} | ||
|
||
Write-Verbose "Saving output to: $OutputFile" | ||
if ( $Preamble ) { | ||
& { | ||
Write-Output "test.date: $(Get-Date -Date $Date -UFormat '%FT%R%Z' -AsUTC)" | ||
if ( $Note -ne '' ) { | ||
Write-Output "note: $Note" | ||
} | ||
Write-Output "test.command: $TestCmdPreamble" | ||
Write-Output "pkg.commit: $(git rev-parse HEAD)" | ||
} | Tee-Object -Append -FilePath $OutputFile | ||
} | ||
|
||
Write-Verbose "Running command: $TestCmd" | ||
Invoke-Expression $TestCmd | Tee-Object -Append -FilePath $OutputFile | ||
|
||
if ( $OutputCmd -ne '' -and $OutputFile -ne 'nul' ) { | ||
$oc = "$OutputCmd $OutputFile" | ||
Write-Verbose "Running command: $oc" | ||
Invoke-Expression $oc | ||
} | ||
|
||
} |
Oops, something went wrong.