render / rpms / libvirt

Forked from rpms/libvirt 4 months ago
Clone
c313de
From f186ff31027a18b0568cf8c31da4fbffb7e3ead7 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <f186ff31027a18b0568cf8c31da4fbffb7e3ead7@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:08:00 +0200
c313de
Subject: [PATCH] vircgrouptest: prepare validateCgroup for cgroupv2
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 2a3df5fac52abb0d414d221a5da3bb957675a094)
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: <b5ae08efdc04ae116b8af6041a751672e090506b.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 tests/vircgrouptest.c | 53 +++++++++++++++++++++++++++++++++++--------
c313de
 1 file changed, 44 insertions(+), 9 deletions(-)
c313de
c313de
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
c313de
index aeb2840823..87f8fa7e67 100644
c313de
--- a/tests/vircgrouptest.c
c313de
+++ b/tests/vircgrouptest.c
c313de
@@ -44,7 +44,10 @@ static int validateCgroup(virCgroupPtr cgroup,
c313de
                           const char *expectPath,
c313de
                           const char **expectMountPoint,
c313de
                           const char **expectLinkPoint,
c313de
-                          const char **expectPlacement)
c313de
+                          const char **expectPlacement,
c313de
+                          const char *expectUnifiedMountPoint,
c313de
+                          const char *expectUnifiedPlacement,
c313de
+                          unsigned int expectUnifiedControllers)
c313de
 {
c313de
     size_t i;
c313de
 
c313de
@@ -81,6 +84,38 @@ static int validateCgroup(virCgroupPtr cgroup,
c313de
         }
c313de
     }
c313de
 
c313de
+    if (STRNEQ_NULLABLE(expectUnifiedMountPoint,
c313de
+                        cgroup->unified.mountPoint)) {
c313de
+        fprintf(stderr, "Wrong mount '%s', expected '%s' for 'unified'\n",
c313de
+                cgroup->unified.mountPoint,
c313de
+                expectUnifiedMountPoint);
c313de
+        return -1;
c313de
+    }
c313de
+    if (STRNEQ_NULLABLE(expectUnifiedPlacement,
c313de
+                        cgroup->unified.placement)) {
c313de
+        fprintf(stderr, "Wrong placement '%s', expected '%s' for 'unified'\n",
c313de
+                cgroup->unified.placement,
c313de
+                expectUnifiedPlacement);
c313de
+        return -1;
c313de
+    }
c313de
+    if (expectUnifiedControllers != cgroup->unified.controllers) {
c313de
+        for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c313de
+            int type = 1 << i;
c313de
+            if ((expectUnifiedControllers & type) != (cgroup->unified.controllers & type)) {
c313de
+                const char *typeStr = virCgroupControllerTypeToString(i);
c313de
+                if (expectUnifiedControllers & type) {
c313de
+                    fprintf(stderr, "expected controller '%s' for 'unified', "
c313de
+                            "but it's missing\n", typeStr);
c313de
+                } else {
c313de
+                    fprintf(stderr, "existing controller '%s' for 'unified', "
c313de
+                            "but it's not expected\n", typeStr);
c313de
+                }
c313de
+            }
c313de
+
c313de
+        }
c313de
+        return -1;
c313de
+    }
c313de
+
c313de
     return 0;
c313de
 }
c313de
 
c313de
@@ -216,7 +251,7 @@ static int testCgroupNewForSelf(const void *args ATTRIBUTE_UNUSED)
c313de
         goto cleanup;
c313de
     }
c313de
 
c313de
-    ret = validateCgroup(cgroup, "", mountsFull, links, placement);
c313de
+    ret = validateCgroup(cgroup, "", mountsFull, links, placement, NULL, NULL, 0);
c313de
 
c313de
  cleanup:
c313de
     virCgroupFree(&cgroup);
c313de
@@ -295,14 +330,14 @@ static int testCgroupNewForPartition(const void *args ATTRIBUTE_UNUSED)
c313de
         fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
c313de
         goto cleanup;
c313de
     }
c313de
-    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall);
c313de
+    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall, NULL, NULL, 0);
c313de
     virCgroupFree(&cgroup);
c313de
 
c313de
     if ((rv = virCgroupNewPartition("/virtualmachines", true, -1, &cgroup)) != 0) {
c313de
         fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
c313de
         goto cleanup;
c313de
     }
c313de
-    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull);
c313de
+    ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull, NULL, NULL, 0);
c313de
 
c313de
  cleanup:
c313de
     virCgroupFree(&cgroup);
c313de
@@ -352,7 +387,7 @@ static int testCgroupNewForPartitionNested(const void *args ATTRIBUTE_UNUSED)
c313de
     }
c313de
 
c313de
     ret = validateCgroup(cgroup, "/deployment.partition/production.partition",
c313de
-                         mountsFull, links, placementFull);
c313de
+                         mountsFull, links, placementFull, NULL, NULL, 0);
c313de
 
c313de
  cleanup:
c313de
     virCgroupFree(&cgroup);
c313de
@@ -408,7 +443,7 @@ static int testCgroupNewForPartitionNestedDeep(const void *args ATTRIBUTE_UNUSED
c313de
     }
c313de
 
c313de
     ret = validateCgroup(cgroup, "/user/berrange.user/production.partition",
c313de
-                         mountsFull, links, placementFull);
c313de
+                         mountsFull, links, placementFull, NULL, NULL, 0);
c313de
 
c313de
  cleanup:
c313de
     virCgroupFree(&cgroup);
c313de
@@ -444,7 +479,7 @@ static int testCgroupNewForPartitionDomain(const void *args ATTRIBUTE_UNUSED)
c313de
         goto cleanup;
c313de
     }
c313de
 
c313de
-    ret = validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement);
c313de
+    ret = validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
c313de
 
c313de
  cleanup:
c313de
     virCgroupFree(&partitioncgroup);
c313de
@@ -495,7 +530,7 @@ static int testCgroupNewForPartitionDomainEscaped(const void *args ATTRIBUTE_UNU
c313de
      * since our fake /proc/cgroups pretends this controller
c313de
      * isn't compiled into the kernel
c313de
      */
c313de
-    ret = validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement);
c313de
+    ret = validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
c313de
 
c313de
  cleanup:
c313de
     virCgroupFree(&partitioncgroup3);
c313de
@@ -524,7 +559,7 @@ static int testCgroupNewForSelfAllInOne(const void *args ATTRIBUTE_UNUSED)
c313de
         goto cleanup;
c313de
     }
c313de
 
c313de
-    ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement);
c313de
+    ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
c313de
 
c313de
  cleanup:
c313de
     virCgroupFree(&cgroup);
c313de
-- 
c313de
2.22.0
c313de