summaryrefslogtreecommitdiffhomepage
path: root/runsc/test/root/cgroup_test.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-12-28 13:47:19 -0800
committerShentubot <shentubot@google.com>2018-12-28 13:48:24 -0800
commita891afad6d7e3b09bafdccb4cc4b9fc4e577620e (patch)
tree5dc0a3be78d6e06f24ddc22b9a4df7de094d09bf /runsc/test/root/cgroup_test.go
parent652d068119052b0b3bc4a0808a4400a22380a30b (diff)
Simplify synchronization between runsc and sandbox process
Make 'runsc create' join cgroup before creating sandbox process. This removes the need to synchronize platform creation and ensure that sandbox process is charged to the right cgroup from the start. PiperOrigin-RevId: 227166451 Change-Id: Ieb4b18e6ca0daf7b331dc897699ca419bc5ee3a2
Diffstat (limited to 'runsc/test/root/cgroup_test.go')
-rw-r--r--runsc/test/root/cgroup_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/runsc/test/root/cgroup_test.go b/runsc/test/root/cgroup_test.go
index fdb94ff64..0eabf9561 100644
--- a/runsc/test/root/cgroup_test.go
+++ b/runsc/test/root/cgroup_test.go
@@ -18,6 +18,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "strconv"
"strings"
"testing"
@@ -123,6 +124,8 @@ func TestCgroup(t *testing.T) {
t.Fatalf("Docker.ID() failed: %v", err)
}
t.Logf("cgroup ID: %s", gid)
+
+ // Check list of attributes defined above.
for _, attr := range attrs {
path := filepath.Join("/sys/fs/cgroup", attr.ctrl, "docker", gid, attr.file)
out, err := ioutil.ReadFile(path)
@@ -137,4 +140,33 @@ func TestCgroup(t *testing.T) {
t.Errorf("arg: %q, cgroup attribute %s/%s, got: %q, want: %q", attr.arg, attr.ctrl, attr.file, got, attr.want)
}
}
+
+ // Check that sandbox is inside cgroup.
+ controllers := []string{
+ "blkio",
+ "cpu",
+ "cpuset",
+ "memory",
+ "net_cls",
+ "net_prio",
+ "devices",
+ "freezer",
+ "perf_event",
+ "pids",
+ "systemd",
+ }
+ pid, err := d.SandboxPid()
+ if err != nil {
+ t.Fatalf("SandboxPid: %v", err)
+ }
+ for _, ctrl := range controllers {
+ path := filepath.Join("/sys/fs/cgroup", ctrl, "docker", gid, "cgroup.procs")
+ out, err := ioutil.ReadFile(path)
+ if err != nil {
+ t.Fatalf("failed to read %q: %v", path, err)
+ }
+ if got := string(out); !strings.Contains(got, strconv.Itoa(pid)) {
+ t.Errorf("cgroup control %s processes, got: %q, want: %q", ctrl, got, pid)
+ }
+ }
}