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