render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From 0628a57a5b4a28d644970a2ad82cfadc14a3cd9f Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <0628a57a5b4a28d644970a2ad82cfadc14a3cd9f@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:08:02 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgrouptest: add hybrid tests
Pablo Greco 40546a
MIME-Version: 1.0
Pablo Greco 40546a
Content-Type: text/plain; charset=UTF-8
Pablo Greco 40546a
Content-Transfer-Encoding: 8bit
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
(cherry picked from commit a26de856f98119bf651ed9928c64b6f96f78f185)
Pablo Greco 40546a
Pablo Greco 40546a
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Message-Id: <434692bd0df2a6f28c93e3cc071187144820d836.1561993100.git.phrdina@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 tests/vircgrouptest.c | 48 +++++++++++++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 1 file changed, 48 insertions(+)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
Pablo Greco 40546a
index 3b844f0fbf..7fde50b463 100644
Pablo Greco 40546a
--- a/tests/vircgrouptest.c
Pablo Greco 40546a
+++ b/tests/vircgrouptest.c
Pablo Greco 40546a
@@ -605,6 +605,45 @@ static int testCgroupNewForSelfUnified(const void *args ATTRIBUTE_UNUSED)
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int testCgroupNewForSelfHybrid(const void *args ATTRIBUTE_UNUSED)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    virCgroupPtr cgroup = NULL;
Pablo Greco 40546a
+    int ret = -1;
Pablo Greco 40546a
+    const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
Pablo Greco 40546a
+    const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_DEVICES] = "/not/really/sys/fs/cgroup/devices",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_FREEZER] = "/not/really/sys/fs/cgroup/freezer",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_NET_CLS] = "/not/really/sys/fs/cgroup/net_cls",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/not/really/sys/fs/cgroup/perf_event",
Pablo Greco 40546a
+    };
Pablo Greco 40546a
+    const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_CPUSET] = "/",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_DEVICES] = "/",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_FREEZER] = "/",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_NET_CLS] = "/",
Pablo Greco 40546a
+        [VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/",
Pablo Greco 40546a
+    };
Pablo Greco 40546a
+    unsigned int controllers =
Pablo Greco 40546a
+        (1 << VIR_CGROUP_CONTROLLER_CPU) |
Pablo Greco 40546a
+        (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
Pablo Greco 40546a
+        (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
Pablo Greco 40546a
+        (1 << VIR_CGROUP_CONTROLLER_BLKIO);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virCgroupNewSelf(&cgroup) < 0) {
Pablo Greco 40546a
+        fprintf(stderr, "Cannot create cgroup for self\n");
Pablo Greco 40546a
+        goto cleanup;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    ret = validateCgroup(cgroup, "", mounts, empty, placement,
Pablo Greco 40546a
+                         "/not/really/sys/fs/cgroup/unified", "/", controllers);
Pablo Greco 40546a
+
Pablo Greco 40546a
+ cleanup:
Pablo Greco 40546a
+    virCgroupFree(&cgroup);
Pablo Greco 40546a
+    return ret;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 static int testCgroupAvailable(const void *args)
Pablo Greco 40546a
 {
Pablo Greco 40546a
     bool got = virCgroupAvailable();
Pablo Greco 40546a
@@ -1024,6 +1063,15 @@ mymain(void)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
     cleanupFakeFS(fakerootdir);
Pablo Greco 40546a
 
Pablo Greco 40546a
+    /* cgroup hybrid */
Pablo Greco 40546a
+
Pablo Greco 40546a
+    fakerootdir = initFakeFS("hybrid", "hybrid");
Pablo Greco 40546a
+    if (virTestRun("New cgroup for self (hybrid)", testCgroupNewForSelfHybrid, NULL) < 0)
Pablo Greco 40546a
+        ret = -1;
Pablo Greco 40546a
+    if (virTestRun("Cgroup available (hybrid)", testCgroupAvailable, (void*)0x1) < 0)
Pablo Greco 40546a
+        ret = -1;
Pablo Greco 40546a
+    cleanupFakeFS(fakerootdir);
Pablo Greco 40546a
+
Pablo Greco 40546a
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a