/
lcow_bench_test.go
106 lines (84 loc) · 2.29 KB
/
lcow_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//go:build windows && functional
// +build windows,functional
package functional
import (
"context"
"testing"
"github.com/Microsoft/hcsshim/osversion"
"github.com/Microsoft/hcsshim/test/internal/util"
"github.com/Microsoft/hcsshim/test/pkg/require"
testuvm "github.com/Microsoft/hcsshim/test/pkg/uvm"
)
func BenchmarkLCOW_UVM(b *testing.B) {
requireFeatures(b, featureLCOW, featureUVM)
require.Build(b, osversion.RS5)
pCtx := util.Context(context.Background(), b)
b.Run("Create", func(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ctx, cancel := context.WithTimeout(pCtx, benchmarkIterationTimeout)
opts := defaultLCOWOptions(ctx, b)
opts.ID += util.RandNameSuffix(i)
b.StartTimer()
_, cleanup := testuvm.CreateLCOW(ctx, b, opts)
b.StopTimer()
cleanup(ctx)
cancel()
}
})
b.Run("Start", func(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ctx, cancel := context.WithTimeout(pCtx, benchmarkIterationTimeout)
opts := defaultLCOWOptions(ctx, b)
opts.ID += util.RandNameSuffix(i)
vm, cleanup := testuvm.CreateLCOW(ctx, b, opts)
b.StartTimer()
if err := vm.Start(ctx); err != nil {
b.Fatalf("could not start UVM: %v", err)
}
b.StopTimer()
cleanup(ctx)
cancel()
}
})
b.Run("Kill", func(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ctx, cancel := context.WithTimeout(pCtx, benchmarkIterationTimeout)
opts := defaultLCOWOptions(ctx, b)
opts.ID += util.RandNameSuffix(i)
vm, cleanup := testuvm.CreateLCOW(ctx, b, opts)
testuvm.Start(ctx, b, vm)
b.StartTimer()
testuvm.Kill(ctx, b, vm)
if err := vm.WaitCtx(ctx); err != nil {
b.Fatalf("could not kill uvm %q: %v", vm.ID(), err)
}
b.StopTimer()
cleanup(ctx)
cancel()
}
})
b.Run("Close", func(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ctx, cancel := context.WithTimeout(pCtx, benchmarkIterationTimeout)
opts := defaultLCOWOptions(ctx, b)
opts.ID += util.RandNameSuffix(i)
vm, cleanup := testuvm.CreateLCOW(ctx, b, opts)
testuvm.Start(ctx, b, vm)
b.StartTimer()
if err := vm.CloseCtx(ctx); err != nil {
b.Fatalf("could not kill uvm %q: %v", vm.ID(), err)
}
b.StopTimer()
cleanup(ctx)
cancel()
}
})
}