Skip to content

Commit

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

Added new functional tests and benchmarks for LCOW uVM containers, and
updated other LCOW tests as well. Not all (LCOW) functional tests were
updated, and most others are now explicitly skipped.

Updated `k8s.io/cri-api` to v0.22 to include `WindowsPodSandboxConfig`
struct

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed May 11, 2022
1 parent 25b6734 commit 2f2328e
Show file tree
Hide file tree
Showing 60 changed files with 2,427 additions and 296 deletions.
62 changes: 62 additions & 0 deletions scripts/Test-Functional.ps1
@@ -0,0 +1,62 @@
# ex: .\scripts\Test-Functional.ps1 -Action Bench -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
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
}

}
101 changes: 101 additions & 0 deletions test/functional/lcow_bench_test.go
@@ -0,0 +1,101 @@
//go:build windows && functional
// +build windows,functional

package functional

import (
"context"
"testing"

"github.com/Microsoft/hcsshim/osversion"

"github.com/Microsoft/hcsshim/test/internal/require"
"github.com/Microsoft/hcsshim/test/internal/uvm"
)

func BenchmarkLCOW_UVM_Create(b *testing.B) {
requireFeatures(b, featureLCOW)
require.Build(b, osversion.RS5)

ctx := context.Background()

b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
opts := defaultLCOWOptions(b, b.Name())

b.StartTimer()
vm := uvm.CreateLCOW(ctx, b, opts)
b.StopTimer()

// vm.Close() hangs unless the vm was started
cleanup := uvm.Start(ctx, b, vm)
cleanup()
}
}

func BenchmarkLCOW_UVM_Start(b *testing.B) {
requireFeatures(b, featureLCOW)
require.Build(b, osversion.RS5)

ctx := context.Background()

b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b, b.Name()))

b.StartTimer()
if err := vm.Start(ctx); err != nil {
b.Fatalf("could not start UVM: %v", err)
}
b.StopTimer()

vm.Close()
}
}

func BenchmarkLCOW_UVM_Kill(b *testing.B) {
requireFeatures(b, featureLCOW)
require.Build(b, osversion.RS5)

ctx := context.Background()

b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b, b.Name()))
cleanup := uvm.Start(ctx, b, vm)

b.StartTimer()
uvm.Kill(ctx, b, vm)
if err := vm.Wait(); err != nil {
b.Fatalf("could not kill uvm %q: %v", vm.ID(), err)
}
b.StopTimer()

cleanup()
}
}

func BenchmarkLCOW_UVM_Close(b *testing.B) {
requireFeatures(b, featureLCOW)
require.Build(b, osversion.RS5)

ctx := context.Background()

b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b, b.Name()))
cleanup := uvm.Start(ctx, b, vm)

b.StartTimer()
if err := vm.Close(); err != nil {
b.Fatalf("could not kill uvm %q: %v", vm.ID(), err)
}
b.StopTimer()

cleanup()
}
}

0 comments on commit 2f2328e

Please sign in to comment.