Blob Blame History Raw
From 0628a57a5b4a28d644970a2ad82cfadc14a3cd9f Mon Sep 17 00:00:00 2001
Message-Id: <0628a57a5b4a28d644970a2ad82cfadc14a3cd9f@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:08:02 +0200
Subject: [PATCH] vircgrouptest: add hybrid tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit a26de856f98119bf651ed9928c64b6f96f78f185)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <434692bd0df2a6f28c93e3cc071187144820d836.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 tests/vircgrouptest.c | 48 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 3b844f0fbf..7fde50b463 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -605,6 +605,45 @@ static int testCgroupNewForSelfUnified(const void *args ATTRIBUTE_UNUSED)
 }
 
 
+static int testCgroupNewForSelfHybrid(const void *args ATTRIBUTE_UNUSED)
+{
+    virCgroupPtr cgroup = NULL;
+    int ret = -1;
+    const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
+    const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
+        [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_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_CPUSET] = "/",
+        [VIR_CGROUP_CONTROLLER_DEVICES] = "/",
+        [VIR_CGROUP_CONTROLLER_FREEZER] = "/",
+        [VIR_CGROUP_CONTROLLER_NET_CLS] = "/",
+        [VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/",
+    };
+    unsigned int controllers =
+        (1 << VIR_CGROUP_CONTROLLER_CPU) |
+        (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
+        (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
+        (1 << VIR_CGROUP_CONTROLLER_BLKIO);
+
+    if (virCgroupNewSelf(&cgroup) < 0) {
+        fprintf(stderr, "Cannot create cgroup for self\n");
+        goto cleanup;
+    }
+
+    ret = validateCgroup(cgroup, "", mounts, empty, placement,
+                         "/not/really/sys/fs/cgroup/unified", "/", controllers);
+
+ cleanup:
+    virCgroupFree(&cgroup);
+    return ret;
+}
+
+
 static int testCgroupAvailable(const void *args)
 {
     bool got = virCgroupAvailable();
@@ -1024,6 +1063,15 @@ mymain(void)
         ret = -1;
     cleanupFakeFS(fakerootdir);
 
+    /* cgroup hybrid */
+
+    fakerootdir = initFakeFS("hybrid", "hybrid");
+    if (virTestRun("New cgroup for self (hybrid)", testCgroupNewForSelfHybrid, NULL) < 0)
+        ret = -1;
+    if (virTestRun("Cgroup available (hybrid)", testCgroupAvailable, (void*)0x1) < 0)
+        ret = -1;
+    cleanupFakeFS(fakerootdir);
+
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-- 
2.22.0