diff options
author | Zach Koopmans <zkoopmans@google.com> | 2020-11-10 11:25:17 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-10 11:27:50 -0800 |
commit | 267d18408461350e41d914467608dfc418e61f05 (patch) | |
tree | 93bfb7e11fc20ddcb11b01d005ff65af96fcbe9b /test/benchmarks/base | |
parent | e998b9904f35cca5df468e11a7da7c2d7de5f0e7 (diff) |
Add all base and fs tests to Continuous Tests.
PiperOrigin-RevId: 341660511
Diffstat (limited to 'test/benchmarks/base')
-rw-r--r-- | test/benchmarks/base/BUILD | 40 | ||||
-rw-r--r-- | test/benchmarks/base/base.go | 81 | ||||
-rw-r--r-- | test/benchmarks/base/size_test.go | 92 | ||||
-rw-r--r-- | test/benchmarks/base/startup_test.go | 68 | ||||
-rw-r--r-- | test/benchmarks/base/sysbench_test.go | 5 |
5 files changed, 160 insertions, 126 deletions
diff --git a/test/benchmarks/base/BUILD b/test/benchmarks/base/BUILD index 7dfd4b693..b4b55317b 100644 --- a/test/benchmarks/base/BUILD +++ b/test/benchmarks/base/BUILD @@ -8,23 +8,41 @@ go_library( srcs = [ "base.go", ], - deps = ["//test/benchmarks/harness"], + deps = [ + "//pkg/test/dockerutil", + "//test/benchmarks/harness", + ], ) go_test( - name = "base_test", + name = "startup_test", size = "enormous", - srcs = [ - "size_test.go", - "startup_test.go", - "sysbench_test.go", + srcs = ["startup_test.go"], + visibility = ["//:sandbox"], + deps = [ + "//pkg/test/dockerutil", + "//test/benchmarks/base", + "//test/benchmarks/harness", ], - library = ":base", - tags = [ - # Requires docker and runsc to be configured before test runs. - "manual", - "local", +) + +go_test( + name = "size_test", + size = "enormous", + srcs = ["size_test.go"], + visibility = ["//:sandbox"], + deps = [ + "//pkg/test/dockerutil", + "//test/benchmarks/base", + "//test/benchmarks/harness", + "//test/benchmarks/tools", ], +) + +go_test( + name = "sysbench_test", + size = "enormous", + srcs = ["sysbench_test.go"], visibility = ["//:sandbox"], deps = [ "//pkg/test/dockerutil", diff --git a/test/benchmarks/base/base.go b/test/benchmarks/base/base.go index 7bac52ff1..979564af9 100644 --- a/test/benchmarks/base/base.go +++ b/test/benchmarks/base/base.go @@ -12,20 +12,87 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package base holds base performance benchmarks. +// Package base holds utility methods common to the base tests. package base import ( - "os" + "context" + "net" "testing" + "time" + "gvisor.dev/gvisor/pkg/test/dockerutil" "gvisor.dev/gvisor/test/benchmarks/harness" ) -var testHarness harness.Harness +// ServerArgs wraps args for startServers and runServerWorkload. +type ServerArgs struct { + Machine harness.Machine + Port int + RunOpts dockerutil.RunOpts + Cmd []string +} + +// StartServers starts b.N containers defined by 'runOpts' and 'cmd' and uses +// 'machine' to check that each is up. +func StartServers(ctx context.Context, b *testing.B, args ServerArgs) []*dockerutil.Container { + b.Helper() + servers := make([]*dockerutil.Container, 0, b.N) + + // Create N servers and wait until each of them is serving. + for i := 0; i < b.N; i++ { + server := args.Machine.GetContainer(ctx, b) + servers = append(servers, server) + if err := server.Spawn(ctx, args.RunOpts, args.Cmd...); err != nil { + CleanUpContainers(ctx, servers) + b.Fatalf("failed to spawn node instance: %v", err) + } + + // Get the container IP. + servingIP, err := server.FindIP(ctx, false) + if err != nil { + CleanUpContainers(ctx, servers) + b.Fatalf("failed to get ip from server: %v", err) + } + + // Wait until the server is up. + if err := harness.WaitUntilServing(ctx, args.Machine, servingIP, args.Port); err != nil { + CleanUpContainers(ctx, servers) + b.Fatalf("failed to wait for serving") + } + } + return servers +} + +// CleanUpContainers cleans up a slice of containers. +func CleanUpContainers(ctx context.Context, containers []*dockerutil.Container) { + for _, c := range containers { + if c != nil { + c.CleanUp(ctx) + } + } +} + +// RedisInstance returns a Redis container and its reachable IP. +func RedisInstance(ctx context.Context, b *testing.B, machine harness.Machine) (*dockerutil.Container, net.IP) { + b.Helper() + // Spawn a redis instance for the app to use. + redis := machine.GetNativeContainer(ctx, b) + if err := redis.Spawn(ctx, dockerutil.RunOpts{ + Image: "benchmarks/redis", + }); err != nil { + redis.CleanUp(ctx) + b.Fatalf("failed to spwan redis instance: %v", err) + } -// TestMain is the main method for package network. -func TestMain(m *testing.M) { - testHarness.Init() - os.Exit(m.Run()) + if out, err := redis.WaitForOutput(ctx, "Ready to accept connections", 3*time.Second); err != nil { + redis.CleanUp(ctx) + b.Fatalf("failed to start redis server: %v %s", err, out) + } + redisIP, err := redis.FindIP(ctx, false) + if err != nil { + redis.CleanUp(ctx) + b.Fatalf("failed to get IP from redis instance: %v", err) + } + return redis, redisIP } diff --git a/test/benchmarks/base/size_test.go b/test/benchmarks/base/size_test.go index 7d3877459..acc49cc7c 100644 --- a/test/benchmarks/base/size_test.go +++ b/test/benchmarks/base/size_test.go @@ -12,18 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -package base +package size_test import ( "context" + "os" "testing" "time" "gvisor.dev/gvisor/pkg/test/dockerutil" + "gvisor.dev/gvisor/test/benchmarks/base" "gvisor.dev/gvisor/test/benchmarks/harness" "gvisor.dev/gvisor/test/benchmarks/tools" ) +var testHarness harness.Harness + // BenchmarkSizeEmpty creates N empty containers and reads memory usage from // /proc/meminfo. func BenchmarkSizeEmpty(b *testing.B) { @@ -53,11 +57,11 @@ func BenchmarkSizeEmpty(b *testing.B) { if err := container.Spawn(ctx, dockerutil.RunOpts{ Image: "benchmarks/alpine", }, "sh", "-c", "echo Hello && sleep 1000"); err != nil { - cleanUpContainers(ctx, containers) + base.CleanUpContainers(ctx, containers) b.Fatalf("failed to run container: %v", err) } if _, err := container.WaitForOutputSubmatch(ctx, "Hello", 5*time.Second); err != nil { - cleanUpContainers(ctx, containers) + base.CleanUpContainers(ctx, containers) b.Fatalf("failed to read container output: %v", err) } } @@ -67,7 +71,7 @@ func BenchmarkSizeEmpty(b *testing.B) { // Check available memory after containers are up. after, err := machine.RunCommand(cmd, args...) - cleanUpContainers(ctx, containers) + base.CleanUpContainers(ctx, containers) if err != nil { b.Fatalf("failed to get meminfo: %v", err) } @@ -100,14 +104,14 @@ func BenchmarkSizeNginx(b *testing.B) { Image: "benchmarks/nginx", } const port = 80 - servers := startServers(ctx, b, - serverArgs{ - machine: machine, - port: port, - runOpts: runOpts, - cmd: []string{"nginx", "-c", "/etc/nginx/nginx_gofer.conf"}, + servers := base.StartServers(ctx, b, + base.ServerArgs{ + Machine: machine, + Port: port, + RunOpts: runOpts, + Cmd: []string{"nginx", "-c", "/etc/nginx/nginx_gofer.conf"}, }) - defer cleanUpContainers(ctx, servers) + defer base.CleanUpContainers(ctx, servers) // DropCaches after servers are created. harness.DropCaches(machine) @@ -130,7 +134,7 @@ func BenchmarkSizeNode(b *testing.B) { // Make a redis instance for Node to connect. ctx := context.Background() - redis, redisIP := redisInstance(ctx, b, machine) + redis, redisIP := base.RedisInstance(ctx, b, machine) defer redis.CleanUp(ctx) // DropCaches after redis is created. @@ -152,14 +156,14 @@ func BenchmarkSizeNode(b *testing.B) { } nodeCmd := []string{"node", "index.js", redisIP.String()} const port = 8080 - servers := startServers(ctx, b, - serverArgs{ - machine: machine, - port: port, - runOpts: runOpts, - cmd: nodeCmd, + servers := base.StartServers(ctx, b, + base.ServerArgs{ + Machine: machine, + Port: port, + RunOpts: runOpts, + Cmd: nodeCmd, }) - defer cleanUpContainers(ctx, servers) + defer base.CleanUpContainers(ctx, servers) // DropCaches after servers are created. harness.DropCaches(machine) @@ -172,50 +176,8 @@ func BenchmarkSizeNode(b *testing.B) { meminfo.Report(b, before, after) } -// serverArgs wraps args for startServers and runServerWorkload. -type serverArgs struct { - machine harness.Machine - port int - runOpts dockerutil.RunOpts - cmd []string -} - -// startServers starts b.N containers defined by 'runOpts' and 'cmd' and uses -// 'machine' to check that each is up. -func startServers(ctx context.Context, b *testing.B, args serverArgs) []*dockerutil.Container { - b.Helper() - servers := make([]*dockerutil.Container, 0, b.N) - - // Create N servers and wait until each of them is serving. - for i := 0; i < b.N; i++ { - server := args.machine.GetContainer(ctx, b) - servers = append(servers, server) - if err := server.Spawn(ctx, args.runOpts, args.cmd...); err != nil { - cleanUpContainers(ctx, servers) - b.Fatalf("failed to spawn node instance: %v", err) - } - - // Get the container IP. - servingIP, err := server.FindIP(ctx, false) - if err != nil { - cleanUpContainers(ctx, servers) - b.Fatalf("failed to get ip from server: %v", err) - } - - // Wait until the server is up. - if err := harness.WaitUntilServing(ctx, args.machine, servingIP, args.port); err != nil { - cleanUpContainers(ctx, servers) - b.Fatalf("failed to wait for serving") - } - } - return servers -} - -// cleanUpContainers cleans up a slice of containers. -func cleanUpContainers(ctx context.Context, containers []*dockerutil.Container) { - for _, c := range containers { - if c != nil { - c.CleanUp(ctx) - } - } +// TestMain is the main method for package network. +func TestMain(m *testing.M) { + testHarness.Init() + os.Exit(m.Run()) } diff --git a/test/benchmarks/base/startup_test.go b/test/benchmarks/base/startup_test.go index c36a544db..28731f97a 100644 --- a/test/benchmarks/base/startup_test.go +++ b/test/benchmarks/base/startup_test.go @@ -12,19 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -package base +package startup_test import ( "context" "fmt" - "net" + "os" "testing" - "time" "gvisor.dev/gvisor/pkg/test/dockerutil" + "gvisor.dev/gvisor/test/benchmarks/base" "gvisor.dev/gvisor/test/benchmarks/harness" ) +var testHarness harness.Harness + // BenchmarkStartEmpty times startup time for an empty container. func BenchmarkStartupEmpty(b *testing.B) { machine, err := testHarness.GetMachine() @@ -60,11 +62,11 @@ func BenchmarkStartupNginx(b *testing.B) { Image: "benchmarks/nginx", } runServerWorkload(ctx, b, - serverArgs{ - machine: machine, - runOpts: runOpts, - port: 80, - cmd: []string{"nginx", "-c", "/etc/nginx/nginx_gofer.conf"}, + base.ServerArgs{ + Machine: machine, + RunOpts: runOpts, + Port: 80, + Cmd: []string{"nginx", "-c", "/etc/nginx/nginx_gofer.conf"}, }) } @@ -79,7 +81,7 @@ func BenchmarkStartupNode(b *testing.B) { defer machine.CleanUp() ctx := context.Background() - redis, redisIP := redisInstance(ctx, b, machine) + redis, redisIP := base.RedisInstance(ctx, b, machine) defer redis.CleanUp(ctx) runOpts := dockerutil.RunOpts{ Image: "benchmarks/node", @@ -89,52 +91,28 @@ func BenchmarkStartupNode(b *testing.B) { cmd := []string{"node", "index.js", redisIP.String()} runServerWorkload(ctx, b, - serverArgs{ - machine: machine, - port: 8080, - runOpts: runOpts, - cmd: cmd, + base.ServerArgs{ + Machine: machine, + Port: 8080, + RunOpts: runOpts, + Cmd: cmd, }) } -// redisInstance returns a Redis container and its reachable IP. -func redisInstance(ctx context.Context, b *testing.B, machine harness.Machine) (*dockerutil.Container, net.IP) { - b.Helper() - // Spawn a redis instance for the app to use. - redis := machine.GetNativeContainer(ctx, b) - if err := redis.Spawn(ctx, dockerutil.RunOpts{ - Image: "benchmarks/redis", - }); err != nil { - redis.CleanUp(ctx) - b.Fatalf("failed to spwan redis instance: %v", err) - } - - if out, err := redis.WaitForOutput(ctx, "Ready to accept connections", 3*time.Second); err != nil { - redis.CleanUp(ctx) - b.Fatalf("failed to start redis server: %v %s", err, out) - } - redisIP, err := redis.FindIP(ctx, false) - if err != nil { - redis.CleanUp(ctx) - b.Fatalf("failed to get IP from redis instance: %v", err) - } - return redis, redisIP -} - // runServerWorkload runs a server workload defined by 'runOpts' and 'cmd'. // 'clientMachine' is used to connect to the server on 'serverMachine'. -func runServerWorkload(ctx context.Context, b *testing.B, args serverArgs) { +func runServerWorkload(ctx context.Context, b *testing.B, args base.ServerArgs) { b.ResetTimer() for i := 0; i < b.N; i++ { if err := func() error { - server := args.machine.GetContainer(ctx, b) + server := args.Machine.GetContainer(ctx, b) defer func() { b.StopTimer() // Cleanup servers as we run so that we can go indefinitely. server.CleanUp(ctx) b.StartTimer() }() - if err := server.Spawn(ctx, args.runOpts, args.cmd...); err != nil { + if err := server.Spawn(ctx, args.RunOpts, args.Cmd...); err != nil { return fmt.Errorf("failed to spawn node instance: %v", err) } @@ -144,7 +122,7 @@ func runServerWorkload(ctx context.Context, b *testing.B, args serverArgs) { } // Wait until the Client sees the server as up. - if err := harness.WaitUntilServing(ctx, args.machine, servingIP, args.port); err != nil { + if err := harness.WaitUntilServing(ctx, args.Machine, servingIP, args.Port); err != nil { return fmt.Errorf("failed to wait for serving: %v", err) } return nil @@ -153,3 +131,9 @@ func runServerWorkload(ctx context.Context, b *testing.B, args serverArgs) { } } } + +// TestMain is the main method for package network. +func TestMain(m *testing.M) { + testHarness.Init() + os.Exit(m.Run()) +} diff --git a/test/benchmarks/base/sysbench_test.go b/test/benchmarks/base/sysbench_test.go index 39ced3dab..bbb797e14 100644 --- a/test/benchmarks/base/sysbench_test.go +++ b/test/benchmarks/base/sysbench_test.go @@ -12,16 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package base +package sysbench_test import ( "context" "testing" "gvisor.dev/gvisor/pkg/test/dockerutil" + "gvisor.dev/gvisor/test/benchmarks/harness" "gvisor.dev/gvisor/test/benchmarks/tools" ) +var testHarness harness.Harness + type testCase struct { name string test tools.Sysbench |