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

test: Add CRI benchmarks for container operations #1569

Merged
merged 2 commits into from
Jan 31, 2023
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
40 changes: 30 additions & 10 deletions scripts/Test-Functional.ps1 → scripts/Run-Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ex: .\scripts\Test-Functional.ps1 -Action Bench -Count 2 -BenchTime "2x"
# ex: .\scripts\Run-Tests.ps1 -vb -TestExe Functional -Count 2 -BenchTime "2x"

[CmdletBinding()]
param (
Expand All @@ -8,12 +8,25 @@ param (
$Action = 'Bench',

[string]
$Note = '',
$Note,

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

[string]
$TestDirectory = '.\bin\test',

[ValidateSet('Functional', 'CRI')]
[string]
$TestExe = 'CRI',
katiewasnothere marked this conversation as resolved.
Show resolved Hide resolved

[string]
$BenchstatPath = 'benchstat.exe',

# test parameters
[switch]
$Shuffle,

[int]
$Count = 1,

Expand All @@ -28,34 +41,41 @@ param (
$TestVerbose,

[string]
$Run = '',
$Run,

[string]
$Feature = ''
[string[]]
$Features
)

$ErrorActionPreference = 'Stop'
Import-Module ( Join-Path $PSScriptRoot Testing.psm1 ) -Force

$exe = Switch ($TestExe) {
'Functional' { 'functional.test.exe'; break }
'CRI' { 'cri-containerd.test.exe'; break }
}
$test = Join-Path $TestDirectory $exe

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

Invoke-TestCommand `
-TestCmd $testcmd `
-OutputFile $out `
-OutputCmd (&{ if ( $Action -eq 'Bench' ) { 'benchstat' } }) `
-OutputCmd (& { if ( $Action -eq 'Bench' ) { $BenchstatPath } }) `
-Preamble `
-Date $Date `
-Note $Note `
Expand Down
37 changes: 20 additions & 17 deletions scripts/Test-LCOW-UVM.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ex: .\scripts\Test-LCOW-UVM.ps1 -vb -Action Bench -BootFilesPath C:\ContainerPlat\LinuxBootFiles\ -MountGCSTest -Count 2 -Benchtime '3s'
#ex: .\scripts\Test-LCOW-UVM.ps1 -vb -Count 2 -Benchtime '3s'
# benchstat via `go install golang.org/x/perf/cmd/benchstat@latest`

[CmdletBinding()]
Expand All @@ -12,6 +12,9 @@ param (
$Note = '',

# test parameters
[switch]
$Shuffle,

[int]
$Count = 1,

Expand All @@ -26,16 +29,16 @@ param (
$TestVerbose,

[string]
$Run = '',

[string]
$CodePath = '.',
$Run,

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

# uvm parameters

[string]
$UVMBootPath = '.\bin\cmd\uvmboot.exe',

[string]
$BootFilesPath = 'C:\ContainerPlat\LinuxBootFiles',

Expand All @@ -61,19 +64,18 @@ param (
$GCSTestPath = '.\bin\test\gcs.test',

[switch]
$MountGCSTest,
$SkipGCSTestMount,

[string]
$Feature = ''
[string[]]
$Features
)

$ErrorActionPreference = 'Stop'
Import-Module ( Join-Path $PSScriptRoot Testing.psm1 ) -Force

$CodePath = Resolve-Path $CodePath
$OutDirectory = Resolve-Path $OutDirectory
$BootFilesPath = Resolve-Path $BootFilesPath
$ContainerRootFSPath = Resolve-Path $ContainerRootFSPath
$GCSTestPath = Resolve-Path $GCSTestPath
$UVMBootPath = Resolve-Path $UVMBootPath

$shell = ( $Action -eq 'Shell' )

Expand All @@ -83,7 +85,7 @@ if ( $shell ) {
$date = Get-Date
$waitfiles = "$ContainerRootFSMount"
$gcspath = 'gcs.test'
if ( $MountGCSTest ) {
if ( -not $SkipGCSTestMount ) {
$waitfiles += ",$GCSTestMount"
$gcspath = "$GCSTestMount/gcs.test"
}
Expand All @@ -104,26 +106,27 @@ if ( $shell ) {
-OutDirectory $OutDirectory `
-Date $date `
-Note $Note `
-Shuffle:$Shuffle `
-TestVerbose:$TestVerbose `
-Count $Count `
-BenchTime $BenchTime `
-Timeout $Timeout `
-Run $Run `
-Feature $Feature `
-Features $Features `
-Verbose:$Verbose

$testcmd += " `'-rootfs-path=$ContainerRootFSMount`' "
$cmd = $pre + $testcmd
}

$boot = '.\bin\tool\uvmboot.exe -gcs lcow ' + `
$boot = "$UVMBootPath -gcs lcow " + `
'-fwd-stdout -fwd-stderr -output-handling stdout ' + `
"-boot-files-path $BootFilesPath " + `
"-root-fs-type $BootFSType " + `
'-kernel-file vmlinux ' + `
"-mount-scsi `"$ContainerRootFSPath,$ContainerRootFSMount`" "

if ( $MountGCSTest ) {
if ( -not $SkipGCSTestMount ) {
$boot += "-share `"$GCSTestPath,$GCSTestMount`" "
}

Expand All @@ -140,8 +143,8 @@ $boot += " -exec `"$cmd`" "
Invoke-TestCommand `
-TestCmd $boot `
-TestCmdPreamble $testcmd `
-OutputFile (&{ if ( $Action -ne 'Shell' ) { $out } }) `
-OutputCmd (&{ if ( $Action -eq 'Bench' ) { 'benchstat' } }) `
-OutputFile (& { if ( $Action -ne 'Shell' ) { $out } }) `
-OutputCmd (& { if ( $Action -eq 'Bench' ) { 'benchstat' } }) `
-Preamble `
-Date $Date `
-Note $Note `
Expand Down
92 changes: 52 additions & 40 deletions scripts/Testing.psm1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function New-TestCommand {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ValidateSet('Test', 'Bench', 'List')]
[alias('a')]
[string]
$Action = 'Bench',
$Action,

[Parameter(Mandatory)]
[string]
Expand All @@ -16,73 +16,82 @@ function New-TestCommand {

[Parameter(Mandatory)]
[string]
$OutDirectory ,
$OutDirectory,

[string]
$OutFile,

[DateTime]
$Date = (Get-Date),

[string]
$Note = '',
$Note,

# test parameters
[alias('tv')]
[switch]
$TestVerbose = $false,
$Shuffle,

[switch]
$TestVerbose,

[int]
$Count = 1,
$Count,

[string]
$BenchTime = '5s',
$BenchTime,

[string]
$Timeout = '10m',
$Timeout,

[string]
$Run = '',
$Run,

[string]
$Feature = ''
[string[]]
$Features
)

$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`' "
$testcmd = "$Path `'-test.timeout=$Timeout`' `'-test.count=$Count`' "

if ( $Shuffle ) {
$testcmd += '''-test.shuffle=on'' '
}

if ( $TestVerbose ) {
$testcmd += ' ''-test.v'' '
$testcmd += '''-test.v'' '
}

switch ( $Action ) {
'List' {
if ( $Run -eq '' ) {
if ( -not $Run ) {
$Run = '.'
}
$testcmd += " `'-test.list=$Run`' "
$testcmd += "`'-test.list=$Run`' "
}
'Test' {
if ( $Run -ne '' ) {
$testcmd += " `'-test.run=$Run`' "
if ( $Run ) {
$testcmd += "`'-test.run=$Run`' "
}
}
'Bench' {
if ( $Run -eq '' ) {
if ( -not $Run ) {
$Run = '.'
}
$testcmd += ' ''-test.run=^#'' ''-test.benchmem'' ' + `
" `'-test.bench=$Run`' `'-test.benchtime=$BenchTime`' "
$testcmd += '''-test.run=^#'' ''-test.benchmem'' ' + `
"`'-test.bench=$Run`' `'-test.benchtime=$BenchTime`' "
}
}

if ( $Feature -ne '' ) {
$testcmd += " `'-feature=$Feature`' "
foreach ( $Feature in $Features ) {
$Feature = $Feature -replace ' ', ''
if ( $Feature ) {
$testcmd += "`'-feature=$Feature`' "
}
}

$f = $Name + '-' + $Action
if ($Note -ne '' ) {
$f = $Name + '-' + ($Action.ToLower())
if ( $Note ) {
$f += '-' + $Note
}
$out = Join-Path $OutDirectory "$f-$(Get-Date -Date $date -Format FileDateTime).txt"
Expand All @@ -101,7 +110,7 @@ function Invoke-TestCommand {
$TestCmdPreamble = $TestCmd,

[string]
$OutputFile = 'nul',
$OutputFile = '',

[string]
$OutputCmd,
Expand All @@ -115,30 +124,33 @@ function Invoke-TestCommand {
[string]
$Note
)
Write-Verbose "Running command: $TestCmd"

if ($OutputFile -eq '' ) {
if ( -not $OutputFile ) {
$OutputFile = 'nul'
} else {
Write-Verbose "Saving output to: $OutputFile"
}

Write-Verbose "Saving output to: $OutputFile"

if ( $Preamble ) {
& {
Write-Output "test.date: $(Get-Date -Date $Date -UFormat '%FT%R%Z' -AsUTC)"
if ( $Note -ne '' ) {
if ( $Note ) {
Write-Output "note: $Note"
}
Write-Output "test.command: $TestCmdPreamble"
Write-Output "pkg.commit: $(git rev-parse HEAD)"
} | Tee-Object -Append -FilePath $OutputFile
if ( Get-Command -ErrorAction Ignore 'git' ) {
Write-Output "pkg.commit: $(git rev-parse HEAD 2>$null)"
}
} | Tee-Object -Encoding utf8 -FilePath $OutputFile
}
Invoke-Expression $TestCmd |
Tee-Object -Encoding utf8 -Append -FilePath $OutputFile

Write-Verbose "Running command: $TestCmd"
Invoke-Expression $TestCmd | Tee-Object -Append -FilePath $OutputFile

if ( $OutputCmd -ne '' -and $OutputFile -ne 'nul' ) {
if ( $OutputCmd -and $OutputFile -ne 'nul' ) {
$oc = "$OutputCmd $OutputFile"
Write-Verbose "Running command: $oc"
Invoke-Expression $oc
}

}
}
Loading