diff options
author | Chong Cai <chongc@google.com> | 2021-08-13 14:17:56 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-08-13 14:20:12 -0700 |
commit | 6eb8596f72f3c889de3f826b82319d41ac655829 (patch) | |
tree | 6dcae39e3fbb4bdf078dd5d77e19ef5626712d8d /runsc/container/container_test.go | |
parent | a7b59445db6b76611ea384659cff8f0dfa75cb00 (diff) |
Add Event controls
Add Event controls and implement "stream" commands.
PiperOrigin-RevId: 390691702
Diffstat (limited to 'runsc/container/container_test.go')
-rw-r--r-- | runsc/container/container_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go index 8f612db8f..681f5c1a9 100644 --- a/runsc/container/container_test.go +++ b/runsc/container/container_test.go @@ -2779,3 +2779,53 @@ func TestReduce(t *testing.T) { t.Fatalf("error reduce from container: %v", err) } } + +// TestStream checks that Stream dumps expected events. +func TestStream(t *testing.T) { + spec, conf := sleepSpecConf(t) + conf.Strace = true + conf.StraceEvent = true + conf.StraceSyscalls = "" + + _, bundleDir, cleanup, err := testutil.SetupContainer(spec, conf) + if err != nil { + t.Fatalf("error setting up container: %v", err) + } + defer cleanup() + + args := Args{ + ID: testutil.RandomContainerID(), + Spec: spec, + BundleDir: bundleDir, + } + + cont, err := New(conf, args) + if err != nil { + t.Fatalf("Creating container: %v", err) + } + defer cont.Destroy() + + if err := cont.Start(conf); err != nil { + t.Fatalf("starting container: %v", err) + } + + r, w, err := os.Pipe() + if err != nil { + t.Fatalf("os.Create(): %v", err) + } + + // Spawn a new thread to Stream events as it blocks indefinitely. + go func() { + cont.Stream(nil, w) + }() + + buf := make([]byte, 1024) + if _, err := r.Read(buf); err != nil { + t.Fatalf("Read out: %v", err) + } + + // A syscall strace event includes "Strace". + if got, want := string(buf), "Strace"; !strings.Contains(got, want) { + t.Errorf("out got %s, want include %s", buf, want) + } +} |