render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From d1c2f060ea724b4f430f9e3198676e18bf0656af Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <d1c2f060ea724b4f430f9e3198676e18bf0656af@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:07:56 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgrouptest: introduce initFakeFS and cleanupFakeFS helpers
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
We need to configure multiple env variables for each set of tests so
Pablo Greco 40546a
create helper functions to do that.
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 9b9c6528a2f867a3be79022b4f282116d2efd3cd)
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: <b9c0307500ba7b4e95ed097a457590a54dcd0ddb.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 | 48 ++++++++++++++++++++++++++++++++-----------
Pablo Greco 40546a
 1 file changed, 36 insertions(+), 12 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
Pablo Greco 40546a
index c4bf987ca1..1837383e61 100644
Pablo Greco 40546a
--- a/tests/vircgrouptest.c
Pablo Greco 40546a
+++ b/tests/vircgrouptest.c
Pablo Greco 40546a
@@ -831,10 +831,10 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args ATTRIBUTE_UNUSED)
Pablo Greco 40546a
 
Pablo Greco 40546a
 # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
Pablo Greco 40546a
 
Pablo Greco 40546a
-static int
Pablo Greco 40546a
-mymain(void)
Pablo Greco 40546a
+static char *
Pablo Greco 40546a
+initFakeFS(const char *mode,
Pablo Greco 40546a
+           const char *filename)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    int ret = 0;
Pablo Greco 40546a
     char *fakerootdir;
Pablo Greco 40546a
 
Pablo Greco 40546a
     if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
Pablo Greco 40546a
@@ -849,6 +849,33 @@ mymain(void)
Pablo Greco 40546a
 
Pablo Greco 40546a
     setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
Pablo Greco 40546a
 
Pablo Greco 40546a
+    if (mode)
Pablo Greco 40546a
+        setenv("VIR_CGROUP_MOCK_MODE", mode, 1);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (filename)
Pablo Greco 40546a
+        setenv("VIR_CGROUP_MOCK_FILENAME", filename, 1);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return fakerootdir;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+static void
Pablo Greco 40546a
+cleanupFakeFS(char *fakerootdir)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
Pablo Greco 40546a
+        virFileDeleteTree(fakerootdir);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    VIR_FREE(fakerootdir);
Pablo Greco 40546a
+    unsetenv("LIBVIRT_FAKE_ROOT_DIR");
Pablo Greco 40546a
+    unsetenv("VIR_CGROUP_MOCK_MODE");
Pablo Greco 40546a
+    unsetenv("VIR_CGROUP_MOCK_FILENAME");
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+mymain(void)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    int ret = 0;
Pablo Greco 40546a
+    char *fakerootdir;
Pablo Greco 40546a
+
Pablo Greco 40546a
 # define DETECT_MOUNTS_FULL(file, fail) \
Pablo Greco 40546a
     do { \
Pablo Greco 40546a
         struct _detectMountsData data = { file, fail }; \
Pablo Greco 40546a
@@ -872,7 +899,7 @@ mymain(void)
Pablo Greco 40546a
     DETECT_MOUNTS_FAIL("no-cgroups");
Pablo Greco 40546a
     DETECT_MOUNTS("kubevirt");
Pablo Greco 40546a
 
Pablo Greco 40546a
-    setenv("VIR_CGROUP_MOCK_FILENAME", "systemd", 1);
Pablo Greco 40546a
+    fakerootdir = initFakeFS(NULL, "systemd");
Pablo Greco 40546a
     if (virTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -908,26 +935,23 @@ mymain(void)
Pablo Greco 40546a
 
Pablo Greco 40546a
     if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuStats, NULL) < 0)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
-    unsetenv("VIR_CGROUP_MOCK_FILENAME");
Pablo Greco 40546a
+    cleanupFakeFS(fakerootdir);
Pablo Greco 40546a
 
Pablo Greco 40546a
-    setenv("VIR_CGROUP_MOCK_FILENAME", "all-in-one", 1);
Pablo Greco 40546a
+    fakerootdir = initFakeFS(NULL, "all-in-one");
Pablo Greco 40546a
     if (virTestRun("New cgroup for self (allinone)", testCgroupNewForSelfAllInOne, NULL) < 0)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
     if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x1) < 0)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
-    unsetenv("VIR_CGROUP_MOCK_FILENAME");
Pablo Greco 40546a
+    cleanupFakeFS(fakerootdir);
Pablo Greco 40546a
 
Pablo Greco 40546a
-    setenv("VIR_CGROUP_MOCK_FILENAME", "logind", 1);
Pablo Greco 40546a
+    fakerootdir = initFakeFS(NULL, "logind");
Pablo Greco 40546a
     if (virTestRun("New cgroup for self (logind)", testCgroupNewForSelfLogind, NULL) < 0)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
     if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x0) < 0)
Pablo Greco 40546a
         ret = -1;
Pablo Greco 40546a
-    unsetenv("VIR_CGROUP_MOCK_FILENAME");
Pablo Greco 40546a
+    cleanupFakeFS(fakerootdir);
Pablo Greco 40546a
 
Pablo Greco 40546a
-    if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
Pablo Greco 40546a
-        virFileDeleteTree(fakerootdir);
Pablo Greco 40546a
 
Pablo Greco 40546a
-    VIR_FREE(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