Skip to content

Commit

Permalink
Added LCOW functional tests and benchmarks
Browse files Browse the repository at this point in the history
Split out test utilities from `test/functional` to an internal package.
Updated code to use containerd instead of docker.

Added tests and benchmarks for LCOW uVM containers.
Updated other LCOW tests.
Updated cri-containerd and runhcs tests to use moved code in
`test\internal`

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed May 4, 2022
1 parent 1e01dcc commit b358cef
Show file tree
Hide file tree
Showing 123 changed files with 21,459 additions and 7,016 deletions.
62 changes: 62 additions & 0 deletions scripts/Test-Functional.ps1
@@ -0,0 +1,62 @@
# ex: .\scripts\Test-Functional.ps1 -Count 2 -BenchTime "2x"

[CmdletBinding()]
param (
[ValidateSet('Test', 'Bench', 'List')]
[alias('a')]
[string]
$Action = 'Bench',

[string]
$Note = '',

[string]
$OutDirectory = '.\test\results',

# test parameters
[int]
$Count = 1,

[string]
$BenchTime = '5s',

[string]
$Timeout = '10m',

[alias('tv')]
[switch]
$TestVerbose,

[string]
$Run = '',

[string]
$Feature = ''
)

Import-Module ( Join-Path $PSScriptRoot Testing.psm1 ) -Force

$date = Get-Date
$testcmd, $out = New-TestCommand `
-Action $Action `
-Path .\bin\test\functional.exe `
-Name functional `
-OutDirectory $OutDirectory `
-Date $date `
-Note $Note `
-TestVerbose:$TestVerbose `
-Count $Count `
-BenchTime $BenchTime `
-Timeout $Timeout `
-Run $Run `
-Feature $Feature `
-Verbose:$Verbose

Invoke-TestCommand `
-TestCmd $testcmd `
-OutputFile $out `
-OutputCmd (&{ if ( $Action -eq 'Bench' ) { 'benchstat' } }) `
-Preamble `
-Date $Date `
-Note $Note `
-Verbose:$Verbose
143 changes: 143 additions & 0 deletions scripts/Test-LCOW-UVM.ps1
@@ -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
144 changes: 144 additions & 0 deletions scripts/Testing.psm1
@@ -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
}

}

0 comments on commit b358cef

Please sign in to comment.