Skip to content

Commit

Permalink
Added GCS tests and benchmarks
Browse files Browse the repository at this point in the history
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
helsaawy committed Apr 27, 2022
1 parent 13ceffd commit 99379fb
Show file tree
Hide file tree
Showing 12 changed files with 2,026 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.vscode/
.idea/

test/results/
# Test binary, build with `go test -c`
*.test

Expand All @@ -24,17 +25,18 @@ service/pkg/
*.img
*.vhd
*.tar.gz
*.tar

# Make stuff
.rootfs-done
bin/*
rootfs/*
rootfs-conv/*
*.o
/build/

deps/*
out/*
bin/
build/
deps/
out/
protobuf/
rootfs/
rootfs-conv/

go.work
go.work.sum
go.work.sum
143 changes: 143 additions & 0 deletions scripts/Test-LCOW-UVM.ps1
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
144 changes: 144 additions & 0 deletions scripts/Testing.psm1
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
}

}
Loading

0 comments on commit 99379fb

Please sign in to comment.