render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From f186ff31027a18b0568cf8c31da4fbffb7e3ead7 Mon Sep 17 00:00:00 2001
Message-Id: <f186ff31027a18b0568cf8c31da4fbffb7e3ead7@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:08:00 +0200
Subject: [PATCH] vircgrouptest: prepare validateCgroup for cgroupv2
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 2a3df5fac52abb0d414d221a5da3bb957675a094)

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

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

diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index aeb2840823..87f8fa7e67 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -44,7 +44,10 @@ static int validateCgroup(virCgroupPtr cgroup,
                           const char *expectPath,
                           const char **expectMountPoint,
                           const char **expectLinkPoint,
-                          const char **expectPlacement)
+                          const char **expectPlacement,
+                          const char *expectUnifiedMountPoint,
+                          const char *expectUnifiedPlacement,
+                          unsigned int expectUnifiedControllers)
 {
     size_t i;
 
@@ -81,6 +84,38 @@ static int validateCgroup(virCgroupPtr cgroup,
         }
     }
 
+    if (STRNEQ_NULLABLE(expectUnifiedMountPoint,
+                        cgroup->unified.mountPoint)) {
+        fprintf(stderr, "Wrong mount '%s', expected '%s' for 'unified'\n",
+                cgroup->unified.mountPoint,
+                expectUnifiedMountPoint);
+        return -1;
+    }
+    if (STRNEQ_NULLABLE(expectUnifiedPlacement,
+                        cgroup->unified.placement)) {
+        fprintf(stderr, "Wrong placement '%s', expected '%s' for 'unified'\n",
+                cgroup->unified.placement,
+                expectUnifiedPlacement);
+        return -1;
+    }
+    if (expectUnifiedControllers != cgroup->unified.controllers) {
+        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+            int type = 1 << i;
+            if ((expectUnifiedControllers & type) != (cgroup->unified.controllers & type)) {
+                const char *typeStr = virCgroupControllerTypeToString(i);
+                if (expectUnifiedControllers & type) {
+                    fprintf(stderr, "expected controller '%s' for 'unified', "
+                            "but it's missing\n", typeStr);
+                } else {
+                    fprintf(stderr, "existing controller '%s' for 'unified', "
+                            "but it's not expected\n", typeStr);
+                }
+            }
+
+        }
+        return -1;
+    }
+
     return 0;
 }
 
@@ -216,7 +251,7 @@ static int testCgroupNewForSelf(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    ret = validateCgroup(cgroup, "", mountsFull, links, placement);
+    ret = validateCgroup(cgroup, "", mountsFull, links, placement, NULL, NULL, 0);
 
  cleanup:
     virCgroupFree(&cgroup);
@@ -295,14 +330,14 @@ static int testCgroupNewForPartition(const void *args ATTRIBUTE_UNUSED)
         fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
         goto cleanup;
     }
-    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall);
+    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall, NULL, NULL, 0);
     virCgroupFree(&cgroup);
 
     if ((rv = virCgroupNewPartition("/virtualmachines", true, -1, &cgroup)) != 0) {
         fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
         goto cleanup;
     }
-    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull);
+    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull, NULL, NULL, 0);
 
  cleanup:
     virCgroupFree(&cgroup);
@@ -352,7 +387,7 @@ static int testCgroupNewForPartitionNested(const void *args ATTRIBUTE_UNUSED)
     }
 
     ret = validateCgroup(cgroup, "/deployment.partition/production.partition",
-                         mountsFull, links, placementFull);
+                         mountsFull, links, placementFull, NULL, NULL, 0);
 
  cleanup:
     virCgroupFree(&cgroup);
@@ -408,7 +443,7 @@ static int testCgroupNewForPartitionNestedDeep(const void *args ATTRIBUTE_UNUSED
     }
 
     ret = validateCgroup(cgroup, "/user/berrange.user/production.partition",
-                         mountsFull, links, placementFull);
+                         mountsFull, links, placementFull, NULL, NULL, 0);
 
  cleanup:
     virCgroupFree(&cgroup);
@@ -444,7 +479,7 @@ static int testCgroupNewForPartitionDomain(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    ret = validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement);
+    ret = validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
 
  cleanup:
     virCgroupFree(&partitioncgroup);
@@ -495,7 +530,7 @@ static int testCgroupNewForPartitionDomainEscaped(const void *args ATTRIBUTE_UNU
      * since our fake /proc/cgroups pretends this controller
      * isn't compiled into the kernel
      */
-    ret = validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement);
+    ret = validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
 
  cleanup:
     virCgroupFree(&partitioncgroup3);
@@ -524,7 +559,7 @@ static int testCgroupNewForSelfAllInOne(const void *args ATTRIBUTE_UNUSED)
         goto cleanup;
     }
 
-    ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement);
+    ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
 
  cleanup:
     virCgroupFree(&cgroup);
-- 
2.22.0