render / rpms / libvirt

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