]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: add cgroup nested tests
authorPavel Hrdina <phrdina@redhat.com>
Thu, 5 Nov 2020 17:39:10 +0000 (18:39 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 10 Feb 2021 12:37:12 +0000 (13:37 +0100)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/vircgroupdata/systemd-legacy.cgroups [new file with mode: 0644]
tests/vircgroupdata/systemd-legacy.mounts [new file with mode: 0644]
tests/vircgroupdata/systemd-legacy.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/systemd-unified.cgroups [new file with mode: 0644]
tests/vircgroupdata/systemd-unified.mounts [new file with mode: 0644]
tests/vircgroupdata/systemd-unified.self.cgroup [new file with mode: 0644]
tests/vircgrouptest.c

diff --git a/tests/vircgroupdata/systemd-legacy.cgroups b/tests/vircgroupdata/systemd-legacy.cgroups
new file mode 100644 (file)
index 0000000..444354e
--- /dev/null
@@ -0,0 +1,12 @@
+#subsys_name   hierarchy       num_cgroups     enabled
+blkio       1       1       1
+cpu         2       1       1
+cpuacct     3       1       1
+cpuset      4       1       1
+devices     5       1       1
+freezer     6       1       1
+hugetlb     7       1       1
+memory      8       1       1
+net_cls     9       1       1
+perf_event  10      1       1
+pids        11      1       1
diff --git a/tests/vircgroupdata/systemd-legacy.mounts b/tests/vircgroupdata/systemd-legacy.mounts
new file mode 100644 (file)
index 0000000..23462e9
--- /dev/null
@@ -0,0 +1,11 @@
+cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,blkio 0 0
+cgroup /not/really/sys/fs/cgroup/cpu cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpu 0 0
+cgroup /not/really/sys/fs/cgroup/cpuacct cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuacct 0 0
+cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuset 0 0
+cgroup /not/really/sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,noexec,relatime,devices 0 0
+cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,noexec,relatime,freezer 0 0
+cgroup /not/really/sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,noexec,relatime,hugetlb 0 0
+cgroup /not/really/sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,noexec,relatime,memory 0 0
+cgroup /not/really/sys/fs/cgroup/net_cls cgroup rw,seclabel,nosuid,nodev,noexec,relatime,net_cls 0 0
+cgroup /not/really/sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,nodev,noexec,relatime,perf_event 0 0
+cgroup /not/really/sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noexec,relatime,pids 0 0
diff --git a/tests/vircgroupdata/systemd-legacy.self.cgroup b/tests/vircgroupdata/systemd-legacy.self.cgroup
new file mode 100644 (file)
index 0000000..5c133a3
--- /dev/null
@@ -0,0 +1,11 @@
+1:blkio:/libvirt
+2:cpu:/libvirt/emulator
+3:cpuacct:/libvirt/emulator
+4:cpuset:/libvirt/emulator
+5:devices:/libvirt
+6:freezer:/libvirt
+7:hugetlb:/
+8:memory:/libvirt
+9:net_cls:/libvirt
+10:perf_event:/libvirt
+11:pids:/
diff --git a/tests/vircgroupdata/systemd-unified.cgroups b/tests/vircgroupdata/systemd-unified.cgroups
new file mode 100644 (file)
index 0000000..e0d8a35
--- /dev/null
@@ -0,0 +1,13 @@
+#subsys_name   hierarchy       num_cgroups     enabled
+cpuset      0       1       1
+cpu         0       1       1
+cpuacct     0       1       1
+blkio       0       1       1
+memory      0       1       1
+devices     0       1       1
+freezer     0       1       1
+net_cls     0       1       1
+perf_event  0       1       1
+net_prio    0       1       1
+hugetlb     0       1       1
+pids        0       1       1
diff --git a/tests/vircgroupdata/systemd-unified.mounts b/tests/vircgroupdata/systemd-unified.mounts
new file mode 100644 (file)
index 0000000..8225f37
--- /dev/null
@@ -0,0 +1 @@
+cgroup2 /not/really/sys/fs/cgroup cgroup2 rw,seclabel,nosuid,nodev,noexec,relatime,nsdelegate 0 0
diff --git a/tests/vircgroupdata/systemd-unified.self.cgroup b/tests/vircgroupdata/systemd-unified.self.cgroup
new file mode 100644 (file)
index 0000000..6007ce7
--- /dev/null
@@ -0,0 +1 @@
+0::/libvirt/emulator
index 1baa71e61c70adb54a64b680dc2b06a8fc54eabb..85c5a6ebd41cff7db35b97f83909516ac50cdc8c 100644 (file)
@@ -576,6 +576,64 @@ static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
 }
 
 
+static int testCgroupNewForSelfSystemdLegacy(const void *args G_GNUC_UNUSED)
+{
+    g_autoptr(virCgroup) cgroup = NULL;
+    const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
+    const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
+        [VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup/blkio",
+        [VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
+        [VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup/cpuacct",
+        [VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
+        [VIR_CGROUP_CONTROLLER_DEVICES] = "/not/really/sys/fs/cgroup/devices",
+        [VIR_CGROUP_CONTROLLER_FREEZER] = "/not/really/sys/fs/cgroup/freezer",
+        [VIR_CGROUP_CONTROLLER_MEMORY] = "/not/really/sys/fs/cgroup/memory",
+        [VIR_CGROUP_CONTROLLER_NET_CLS] = "/not/really/sys/fs/cgroup/net_cls",
+        [VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/not/really/sys/fs/cgroup/perf_event",
+    };
+    const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
+        [VIR_CGROUP_CONTROLLER_BLKIO] = "",
+        [VIR_CGROUP_CONTROLLER_CPU] = "",
+        [VIR_CGROUP_CONTROLLER_CPUACCT] = "",
+        [VIR_CGROUP_CONTROLLER_CPUSET] = "",
+        [VIR_CGROUP_CONTROLLER_DEVICES] = "",
+        [VIR_CGROUP_CONTROLLER_FREEZER] = "",
+        [VIR_CGROUP_CONTROLLER_MEMORY] = "",
+        [VIR_CGROUP_CONTROLLER_NET_CLS] = "",
+        [VIR_CGROUP_CONTROLLER_PERF_EVENT] = "",
+    };
+
+    if (virCgroupNewSelf(&cgroup) < 0) {
+        fprintf(stderr, "Cannot create cgroup for self\n");
+        return -1;
+    }
+
+    return validateCgroup(cgroup, mounts, empty, placement, NULL, NULL, 0);
+}
+
+
+static int testCgroupNewForSelfSystemdUnified(const void *args G_GNUC_UNUSED)
+{
+    g_autoptr(virCgroup) cgroup = NULL;
+    const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
+    unsigned int controllers =
+        (1 << VIR_CGROUP_CONTROLLER_CPU) |
+        (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
+        (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
+        (1 << VIR_CGROUP_CONTROLLER_DEVICES) |
+        (1 << VIR_CGROUP_CONTROLLER_BLKIO);
+
+    if (virCgroupNewSelf(&cgroup) < 0) {
+        fprintf(stderr, "Cannot create cgroup for self\n");
+        return -1;
+    }
+
+    return validateCgroup(cgroup, empty, empty, empty,
+                          "/not/really/sys/fs/cgroup", "",
+                          controllers);
+}
+
+
 static int testCgroupAvailable(const void *args)
 {
     bool got = virCgroupAvailable();
@@ -1046,6 +1104,20 @@ mymain(void)
         ret = -1;
     cleanupFakeFS(fakerootdir);
 
+    fakerootdir = initFakeFS("legacy", "systemd-legacy");
+    if (virTestRun("New cgroup for self (systemd-legacy)",
+                   testCgroupNewForSelfSystemdLegacy, NULL) < 0) {
+        ret = -1;
+    }
+    cleanupFakeFS(fakerootdir);
+
+    fakerootdir = initFakeFS("unified", "systemd-unified");
+    if (virTestRun("New cgroup for self (systemd-unified)",
+                   testCgroupNewForSelfSystemdUnified, NULL) < 0) {
+        ret = -1;
+    }
+    cleanupFakeFS(fakerootdir);
+
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }