render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 8b85c2ad4afbad2998163ac61b376320b4f392b8 Mon Sep 17 00:00:00 2001
Message-Id: <8b85c2ad4afbad2998163ac61b376320b4f392b8@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:08:01 +0200
Subject: [PATCH] vircgrouptest: add cgroup v2 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 edf59855cf9b78fc4dc95f4b2833d87188decc71)

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

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

diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 87f8fa7e67..3b844f0fbf 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -570,14 +570,35 @@ static int testCgroupNewForSelfAllInOne(const void *args ATTRIBUTE_UNUSED)
 static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED)
 {
     virCgroupPtr cgroup = NULL;
-    int ret = -1;
 
-    if (virCgroupNewSelf(&cgroup) == 0) {
-        fprintf(stderr, "Expected cgroup creation to fail.\n");
+    if (virCgroupNewSelf(&cgroup) >= 0) {
+        fprintf(stderr, "Expected to fail, only systemd cgroup available.\n");
+        virCgroupFree(&cgroup);
+        return -1;
+    }
+
+    return 0;
+}
+
+
+static int testCgroupNewForSelfUnified(const void *args ATTRIBUTE_UNUSED)
+{
+    virCgroupPtr cgroup = NULL;
+    int ret = -1;
+    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_BLKIO);
+
+    if (virCgroupNewSelf(&cgroup) < 0) {
+        fprintf(stderr, "Cannot create cgroup for self\n");
         goto cleanup;
     }
 
-    ret = 0;
+    ret = validateCgroup(cgroup, "", empty, empty, empty,
+                         "/not/really/sys/fs/cgroup", "/", controllers);
  cleanup:
     virCgroupFree(&cgroup);
     return ret;
@@ -994,7 +1015,14 @@ mymain(void)
         ret = -1;
     cleanupFakeFS(fakerootdir);
 
+    /* cgroup unified */
 
+    fakerootdir = initFakeFS("unified", "unified");
+    if (virTestRun("New cgroup for self (unified)", testCgroupNewForSelfUnified, NULL) < 0)
+        ret = -1;
+    if (virTestRun("Cgroup available (unified)", testCgroupAvailable, (void*)0x1) < 0)
+        ret = -1;
+    cleanupFakeFS(fakerootdir);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
2.22.0