render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Pablo Greco 40546a
From 8b85c2ad4afbad2998163ac61b376320b4f392b8 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <8b85c2ad4afbad2998163ac61b376320b4f392b8@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:08:01 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgrouptest: add cgroup v2 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 edf59855cf9b78fc4dc95f4b2833d87188decc71)
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: <5354c6c494c94b274e3b366188597ccd0828aefa.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 | 36 ++++++++++++++++++++++++++++++++----
Pablo Greco 40546a
 1 file changed, 32 insertions(+), 4 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
Pablo Greco 40546a
index 87f8fa7e67..3b844f0fbf 100644
Pablo Greco 40546a
--- a/tests/vircgrouptest.c
Pablo Greco 40546a
+++ b/tests/vircgrouptest.c
Pablo Greco 40546a
@@ -570,14 +570,35 @@ static int testCgroupNewForSelfAllInOne(const void *args ATTRIBUTE_UNUSED)
Pablo Greco 40546a
 static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED)
Pablo Greco 40546a
 {
Pablo Greco 40546a
     virCgroupPtr cgroup = NULL;
Pablo Greco 40546a
-    int ret = -1;
Pablo Greco 40546a
 
Pablo Greco 40546a
-    if (virCgroupNewSelf(&cgroup) == 0) {
Pablo Greco 40546a
-        fprintf(stderr, "Expected cgroup creation to fail.\n");
Pablo Greco 40546a
+    if (virCgroupNewSelf(&cgroup) >= 0) {
Pablo Greco 40546a
+        fprintf(stderr, "Expected to fail, only systemd cgroup available.\n");
Pablo Greco 40546a
+        virCgroupFree(&cgroup);
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return 0;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int testCgroupNewForSelfUnified(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
+    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 = 0;
Pablo Greco 40546a
+    ret = validateCgroup(cgroup, "", empty, empty, empty,
Pablo Greco 40546a
+                         "/not/really/sys/fs/cgroup", "/", controllers);
Pablo Greco 40546a
  cleanup:
Pablo Greco 40546a
     virCgroupFree(&cgroup);
Pablo Greco 40546a
     return ret;
Pablo Greco 40546a
@@ -994,7 +1015,14 @@ mymain(void)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
     cleanupFakeFS(fakerootdir);
Pablo Greco 40546a
 
Pablo Greco 40546a
+    /* cgroup unified */
Pablo Greco 40546a
 
Pablo Greco 40546a
+    fakerootdir = initFakeFS("unified", "unified");
Pablo Greco 40546a
+    if (virTestRun("New cgroup for self (unified)", testCgroupNewForSelfUnified, NULL) < 0)
Pablo Greco 40546a
+        ret = -1;
Pablo Greco 40546a
+    if (virTestRun("Cgroup available (unified)", 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
2.22.0
Pablo Greco 40546a