From d1c2f060ea724b4f430f9e3198676e18bf0656af Mon Sep 17 00:00:00 2001
Message-Id: <d1c2f060ea724b4f430f9e3198676e18bf0656af@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:56 +0200
Subject: [PATCH] vircgrouptest: introduce initFakeFS and cleanupFakeFS helpers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We need to configure multiple env variables for each set of tests so
create helper functions to do that.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 9b9c6528a2f867a3be79022b4f282116d2efd3cd)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <b9c0307500ba7b4e95ed097a457590a54dcd0ddb.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
tests/vircgrouptest.c | 48 ++++++++++++++++++++++++++++++++-----------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index c4bf987ca1..1837383e61 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -831,10 +831,10 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args ATTRIBUTE_UNUSED)
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-static int
-mymain(void)
+static char *
+initFakeFS(const char *mode,
+ const char *filename)
{
- int ret = 0;
char *fakerootdir;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
@@ -849,6 +849,33 @@ mymain(void)
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
+ if (mode)
+ setenv("VIR_CGROUP_MOCK_MODE", mode, 1);
+
+ if (filename)
+ setenv("VIR_CGROUP_MOCK_FILENAME", filename, 1);
+
+ return fakerootdir;
+}
+
+static void
+cleanupFakeFS(char *fakerootdir)
+{
+ if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+ virFileDeleteTree(fakerootdir);
+
+ VIR_FREE(fakerootdir);
+ unsetenv("LIBVIRT_FAKE_ROOT_DIR");
+ unsetenv("VIR_CGROUP_MOCK_MODE");
+ unsetenv("VIR_CGROUP_MOCK_FILENAME");
+}
+
+static int
+mymain(void)
+{
+ int ret = 0;
+ char *fakerootdir;
+
# define DETECT_MOUNTS_FULL(file, fail) \
do { \
struct _detectMountsData data = { file, fail }; \
@@ -872,7 +899,7 @@ mymain(void)
DETECT_MOUNTS_FAIL("no-cgroups");
DETECT_MOUNTS("kubevirt");
- setenv("VIR_CGROUP_MOCK_FILENAME", "systemd", 1);
+ fakerootdir = initFakeFS(NULL, "systemd");
if (virTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0)
ret = -1;
@@ -908,26 +935,23 @@ mymain(void)
if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuStats, NULL) < 0)
ret = -1;
- unsetenv("VIR_CGROUP_MOCK_FILENAME");
+ cleanupFakeFS(fakerootdir);
- setenv("VIR_CGROUP_MOCK_FILENAME", "all-in-one", 1);
+ fakerootdir = initFakeFS(NULL, "all-in-one");
if (virTestRun("New cgroup for self (allinone)", testCgroupNewForSelfAllInOne, NULL) < 0)
ret = -1;
if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x1) < 0)
ret = -1;
- unsetenv("VIR_CGROUP_MOCK_FILENAME");
+ cleanupFakeFS(fakerootdir);
- setenv("VIR_CGROUP_MOCK_FILENAME", "logind", 1);
+ fakerootdir = initFakeFS(NULL, "logind");
if (virTestRun("New cgroup for self (logind)", testCgroupNewForSelfLogind, NULL) < 0)
ret = -1;
if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x0) < 0)
ret = -1;
- unsetenv("VIR_CGROUP_MOCK_FILENAME");
+ cleanupFakeFS(fakerootdir);
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
- VIR_FREE(fakerootdir);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
2.22.0