[libvirt PATCH 9/9] tests: add cgroup nested tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 tests/vircgroupdata/systemd-legacy.cgroups    | 12 ++++
 tests/vircgroupdata/systemd-legacy.mounts     | 11 +++
 .../vircgroupdata/systemd-legacy.self.cgroup  | 11 +++
 tests/vircgroupdata/systemd-unified.cgroups   | 13 ++++
 tests/vircgroupdata/systemd-unified.mounts    |  1 +
 .../vircgroupdata/systemd-unified.self.cgroup |  1 +
 tests/vircgrouptest.c                         | 72 +++++++++++++++++++
 7 files changed, 121 insertions(+)
 create mode 100644 tests/vircgroupdata/systemd-legacy.cgroups
 create mode 100644 tests/vircgroupdata/systemd-legacy.mounts
 create mode 100644 tests/vircgroupdata/systemd-legacy.self.cgroup
 create mode 100644 tests/vircgroupdata/systemd-unified.cgroups
 create mode 100644 tests/vircgroupdata/systemd-unified.mounts
 create mode 100644 tests/vircgroupdata/systemd-unified.self.cgroup

diff --git a/tests/vircgroupdata/systemd-legacy.cgroups b/tests/vircgroupdata/systemd-legacy.cgroups
new file mode 100644
index 0000000000..444354e3c8
--- /dev/null
+++ b/tests/vircgroupdata/systemd-legacy.cgroups
@@ -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
index 0000000000..23462e9e68
--- /dev/null
+++ b/tests/vircgroupdata/systemd-legacy.mounts
@@ -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
index 0000000000..5c133a3c08
--- /dev/null
+++ b/tests/vircgroupdata/systemd-legacy.self.cgroup
@@ -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
index 0000000000..e0d8a3561c
--- /dev/null
+++ b/tests/vircgroupdata/systemd-unified.cgroups
@@ -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
index 0000000000..8225f37f45
--- /dev/null
+++ b/tests/vircgroupdata/systemd-unified.mounts
@@ -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
index 0000000000..6007ce7e18
--- /dev/null
+++ b/tests/vircgroupdata/systemd-unified.self.cgroup
@@ -0,0 +1 @@
+0::/libvirt/emulator
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 1baa71e61c..85c5a6ebd4 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -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;
 }
 
-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux