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 Apr 13, 2022
1 parent 7e26c0e commit 680f42f
Show file tree
Hide file tree
Showing 124 changed files with 21,528 additions and 7,066 deletions.
55 changes: 33 additions & 22 deletions Makefile
@@ -1,4 +1,5 @@
BASE:=base.tar.gz
DEV_BUILD:=0

GO:=go
GO_FLAGS:=-ldflags "-s -w" # strip Go binaries
Expand All @@ -13,11 +14,14 @@ ifeq "$(GOMODVENDOR)" "1"
GO_FLAGS_EXTRA += -mod=vendor
endif
GO_BUILD:=CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(GO_FLAGS) $(GO_FLAGS_EXTRA)
GO_TEST_BUILD:=CGO_ENABLED=$(CGO_ENABLED) $(GO) test $(GO_FLAGS) $(GO_FLAGS_EXTRA) -c

SRCROOT=$(dir $(abspath $(firstword $(MAKEFILE_LIST))))
# additional directories to search for rule prerequisites and targets
VPATH=$(SRCROOT)

DELTA_TARGET=out/delta.tar.gz

ifeq "$(DEV_BUILD)" "1"
DELTA_TARGET=out/delta-dev.tar.gz
endif

# The link aliases for gcstools
GCS_TOOLS=\
Expand All @@ -43,42 +47,47 @@ out/rootfs.vhd: out/rootfs.tar.gz bin/cmd/tar2ext4
gzip -f -d ./out/rootfs.tar.gz
bin/cmd/tar2ext4 -vhd -i ./out/rootfs.tar -o $@

out/rootfs.tar.gz: out/initrd.img
rm -rf rootfs-conv
mkdir rootfs-conv
gunzip -c out/initrd.img | (cd rootfs-conv && cpio -imd)
tar -zcf $@ -C rootfs-conv .
rm -rf rootfs-conv

out/initrd.img: $(BASE) out/delta.tar.gz $(SRCROOT)/hack/catcpio.sh
$(SRCROOT)/hack/catcpio.sh "$(BASE)" out/delta.tar.gz > out/initrd.img.uncompressed
gzip -c out/initrd.img.uncompressed > $@
rm out/initrd.img.uncompressed

out/delta.tar.gz: bin/init bin/vsockexec bin/cmd/gcs bin/cmd/gcstools bin/cmd/hooks/wait-paths Makefile
@mkdir -p out
rm -rf rootfs
mkdir -p rootfs/bin/
mkdir -p rootfs/info/
cp bin/init rootfs/
cp bin/vsockexec rootfs/bin/
cp bin/cmd/gcs rootfs/bin/
cp bin/cmd/gcstools rootfs/bin/
cp bin/cmd/hooks/wait-paths rootfs/bin/
for tool in $(GCS_TOOLS); do ln -s gcstools rootfs/bin/$$tool; done
git -C $(SRCROOT) rev-parse HEAD > rootfs/info/gcs.commit && \
git -C $(SRCROOT) rev-parse --abbrev-ref HEAD > rootfs/info/gcs.branch && \
date --iso-8601=minute --utc > rootfs/info/tar.date
$(if $(realpath $(subst .tar,.testdata.json,$(BASE))), \
jq -r '.IMAGE_NAME' $(subst .tar,.testdata.json,$(BASE)) 2>/dev/null > rootfs/info/image.name && \
jq -r '.DATETIME' $(subst .tar,.testdata.json,$(BASE)) 2>/dev/null > rootfs/info/build.date )
git -C $(SRCROOT) rev-parse HEAD > rootfs/gcs.commit && \
git -C $(SRCROOT) rev-parse --abbrev-ref HEAD > rootfs/gcs.branch
tar -zcf $@ -C rootfs .
rm -rf rootfs

# This target includes utilities which may be useful for testing purposes.
out/delta-dev.tar.gz: out/delta.tar.gz bin/internal/tools/snp-report
rm -rf rootfs-dev
mkdir rootfs-dev
tar -xzf out/delta.tar.gz -C rootfs-dev
cp bin/internal/tools/snp-report rootfs-dev/bin/
tar -zcf $@ -C rootfs-dev .
rm -rf rootfs-dev

out/rootfs.tar.gz: out/initrd.img
rm -rf rootfs-conv
mkdir rootfs-conv
gunzip -c out/initrd.img | (cd rootfs-conv && cpio -imd)
tar -zcf $@ -C rootfs-conv .
rm -rf rootfs-conv

out/initrd.img: $(BASE) $(DELTA_TARGET) $(SRCROOT)/hack/catcpio.sh
$(SRCROOT)/hack/catcpio.sh "$(BASE)" $(DELTA_TARGET) > out/initrd.img.uncompressed
gzip -c out/initrd.img.uncompressed > $@
rm out/initrd.img.uncompressed

-include deps/cmd/gcs.gomake
-include deps/cmd/gcstools.gomake
-include deps/cmd/hooks/wait-paths.gomake
-include deps/cmd/tar2ext4.gomake
-include deps/internal/tools/snp-report.gomake

# Implicit rule for includes that define Go targets.
%.gomake: $(SRCROOT)/Makefile
Expand All @@ -92,6 +101,8 @@ out/delta.tar.gz: bin/init bin/vsockexec bin/cmd/gcs bin/cmd/gcstools bin/cmd/ho
@/bin/echo -e '-include $(@:%.gomake=%.godeps)' >> $@.new
mv $@.new $@

VPATH=$(SRCROOT)

bin/vsockexec: vsockexec/vsockexec.o vsockexec/vsock.o
@mkdir -p bin
$(CC) $(LDFLAGS) -o $@ $^
Expand Down
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

0 comments on commit 680f42f

Please sign in to comment.