render / rpms / libvirt

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