c313de
From 8b85c2ad4afbad2998163ac61b376320b4f392b8 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <8b85c2ad4afbad2998163ac61b376320b4f392b8@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:08:01 +0200
c313de
Subject: [PATCH] vircgrouptest: add cgroup v2 tests
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit edf59855cf9b78fc4dc95f4b2833d87188decc71)
c313de
c313de
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
Message-Id: <5354c6c494c94b274e3b366188597ccd0828aefa.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 tests/vircgrouptest.c | 36 ++++++++++++++++++++++++++++++++----
c313de
 1 file changed, 32 insertions(+), 4 deletions(-)
c313de
c313de
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
c313de
index 87f8fa7e67..3b844f0fbf 100644
c313de
--- a/tests/vircgrouptest.c
c313de
+++ b/tests/vircgrouptest.c
c313de
@@ -570,14 +570,35 @@ static int testCgroupNewForSelfAllInOne(const void *args ATTRIBUTE_UNUSED)
c313de
 static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED)
c313de
 {
c313de
     virCgroupPtr cgroup = NULL;
c313de
-    int ret = -1;
c313de
 
c313de
-    if (virCgroupNewSelf(&cgroup) == 0) {
c313de
-        fprintf(stderr, "Expected cgroup creation to fail.\n");
c313de
+    if (virCgroupNewSelf(&cgroup) >= 0) {
c313de
+        fprintf(stderr, "Expected to fail, only systemd cgroup available.\n");
c313de
+        virCgroupFree(&cgroup);
c313de
+        return -1;
c313de
+    }
c313de
+
c313de
+    return 0;
c313de
+}
c313de
+
c313de
+
c313de
+static int testCgroupNewForSelfUnified(const void *args ATTRIBUTE_UNUSED)
c313de
+{
c313de
+    virCgroupPtr cgroup = NULL;
c313de
+    int ret = -1;
c313de
+    const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
c313de
+    unsigned int controllers =
c313de
+        (1 << VIR_CGROUP_CONTROLLER_CPU) |
c313de
+        (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
c313de
+        (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
c313de
+        (1 << VIR_CGROUP_CONTROLLER_BLKIO);
c313de
+
c313de
+    if (virCgroupNewSelf(&cgroup) < 0) {
c313de
+        fprintf(stderr, "Cannot create cgroup for self\n");
c313de
         goto cleanup;
c313de
     }
c313de
 
c313de
-    ret = 0;
c313de
+    ret = validateCgroup(cgroup, "", empty, empty, empty,
c313de
+                         "/not/really/sys/fs/cgroup", "/", controllers);
c313de
  cleanup:
c313de
     virCgroupFree(&cgroup);
c313de
     return ret;
c313de
@@ -994,7 +1015,14 @@ mymain(void)
c313de
         ret = -1;
c313de
     cleanupFakeFS(fakerootdir);
c313de
 
c313de
+    /* cgroup unified */
c313de
 
c313de
+    fakerootdir = initFakeFS("unified", "unified");
c313de
+    if (virTestRun("New cgroup for self (unified)", testCgroupNewForSelfUnified, NULL) < 0)
c313de
+        ret = -1;
c313de
+    if (virTestRun("Cgroup available (unified)", testCgroupAvailable, (void*)0x1) < 0)
c313de
+        ret = -1;
c313de
+    cleanupFakeFS(fakerootdir);
c313de
 
c313de
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
c313de
 }
c313de
-- 
c313de
2.22.0
c313de