summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Bolognani <abologna@redhat.com>2023-03-01 10:52:14 +0100
committerAndrea Bolognani <abologna@redhat.com>2023-03-03 13:52:37 +0100
commit457a0183d6e0a543232c0cf5d35314449c863cf2 (patch)
treea797bc52b9c99cec988e2b0d08aa3d323416ab7b
parentef3b22e589ebf7419c7f77eee479859e77ff9b64 (diff)
downloadlibvirt-457a0183d6e0a543232c0cf5d35314449c863cf2.tar.gz
tests: Adopt fakerootdir helpers
Most replacements are completely straightforward but vircgrouptest requires slightly different handling because, instead of initializing a single fakerootdir at the start of the test program and cleaning it up at the end, it creates multiple different ones one after the other. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
-rw-r--r--tests/qemuhotplugtest.c14
-rw-r--r--tests/qemumemlocktest.c15
-rw-r--r--tests/qemustatusxml2xmltest.c15
-rw-r--r--tests/qemuxml2argvtest.c15
-rw-r--r--tests/qemuxml2xmltest.c16
-rw-r--r--tests/scsihosttest.c13
-rw-r--r--tests/vircgrouptest.c18
-rw-r--r--tests/virhostdevtest.c17
-rw-r--r--tests/virpcitest.c15
9 files changed, 29 insertions, 109 deletions
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 215837fc8f..429928aa7f 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -656,8 +656,6 @@ testQemuHotplugCpuIndividual(const void *opaque)
return ret;
}
-#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
@@ -669,15 +667,10 @@ mymain(void)
g_autofree char *fakerootdir = NULL;
g_autoptr(virQEMUDriverConfig) cfg = NULL;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
+ if (!(fakerootdir = virTestFakeRootDirInit())) {
+ return EXIT_FAILURE;
}
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
-
if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
@@ -1004,8 +997,7 @@ mymain(void)
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true, true, true);
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true, true, true);
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
qemuTestDriverFree(&driver);
virObjectUnref(data.vm);
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
index b303f70e9d..184d8ede19 100644
--- a/tests/qemumemlocktest.c
+++ b/tests/qemumemlocktest.c
@@ -42,8 +42,6 @@ testCompareMemLock(const void *data)
return virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBytes(def, false));
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
@@ -51,14 +49,8 @@ mymain(void)
g_autofree char *fakerootdir = NULL;
g_autoptr(virQEMUCaps) qemuCaps = NULL;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+ if (!(fakerootdir = virTestFakeRootDirInit()))
+ return EXIT_FAILURE;
if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
@@ -137,8 +129,7 @@ mymain(void)
DO_TEST("pseries-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
cleanup:
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
qemuTestDriverFree(&driver);
diff --git a/tests/qemustatusxml2xmltest.c b/tests/qemustatusxml2xmltest.c
index db82a1a980..a29aa723e6 100644
--- a/tests/qemustatusxml2xmltest.c
+++ b/tests/qemustatusxml2xmltest.c
@@ -70,8 +70,6 @@ testInfoSetStatusPaths(struct testQemuInfo *info)
}
-#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
@@ -87,14 +85,8 @@ mymain(void)
if (!capslatest)
return EXIT_FAILURE;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+ if (!(fakerootdir = virTestFakeRootDirInit()))
+ return EXIT_FAILURE;
if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
@@ -142,8 +134,7 @@ mymain(void)
DO_TEST_STATUS("backup-pull");
cleanup:
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
qemuTestDriverFree(&driver);
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 737eacf530..3f5eda533e 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -796,8 +796,6 @@ testInfoSetPaths(struct testQemuInfo *info,
abs_srcdir, info->name, suffix ? suffix : "");
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
@@ -813,14 +811,8 @@ mymain(void)
if (!capslatest)
return EXIT_FAILURE;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+ if (!(fakerootdir = virTestFakeRootDirInit()))
+ return EXIT_FAILURE;
/* Set the timezone because we are mocking the time() function.
* If we don't do that, then localtime() may return unpredictable
@@ -2995,8 +2987,7 @@ mymain(void)
DO_TEST_CAPS_LATEST("crypto-builtin");
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
VIR_FREE(driver.config->nbdTLSx509certdir);
qemuTestDriverFree(&driver);
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index a3a5fd61e8..2b6006fcc7 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -113,8 +113,6 @@ testInfoSetPaths(struct testQemuInfo *info,
}
-#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
@@ -131,15 +129,8 @@ mymain(void)
if (!capslatest)
return EXIT_FAILURE;
-
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+ if (!(fakerootdir = virTestFakeRootDirInit()))
+ return EXIT_FAILURE;
/* Required for tpm-emulator tests
*/
@@ -1334,8 +1325,7 @@ mymain(void)
DO_TEST_CAPS_LATEST("crypto-builtin");
cleanup:
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
qemuTestDriverFree(&driver);
virFileWrapperClearPrefixes();
diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c
index 28ad59f39d..37d2b86c0a 100644
--- a/tests/scsihosttest.c
+++ b/tests/scsihosttest.c
@@ -227,8 +227,6 @@ testVirFindSCSIHostByPCI(const void *data G_GNUC_UNUSED)
return ret;
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
@@ -236,12 +234,8 @@ mymain(void)
g_autofree char *fakerootdir = NULL;
g_autofree char *fakesysfsdir = NULL;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- goto cleanup;
- }
+ if (!(fakerootdir = virTestFakeRootDirInit()))
+ return EXIT_FAILURE;
fakesysfsdir = g_strdup_printf("%s/sys", fakerootdir);
@@ -268,8 +262,7 @@ mymain(void)
ret = 0;
cleanup:
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
VIR_FREE(scsihost_class_path);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 848a9c7bb0..0e7645af7a 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -956,22 +956,14 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
return 0;
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static char *
initFakeFS(const char *mode,
const char *filename)
{
char *fakerootdir;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
+ if (!(fakerootdir = virTestFakeRootDirInit()))
abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
if (mode)
g_setenv("VIR_CGROUP_MOCK_MODE", mode, TRUE);
@@ -985,13 +977,11 @@ initFakeFS(const char *mode,
static void
cleanupFakeFS(char *fakerootdir)
{
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
-
- VIR_FREE(fakerootdir);
- g_unsetenv("LIBVIRT_FAKE_ROOT_DIR");
g_unsetenv("VIR_CGROUP_MOCK_MODE");
g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
+
+ virTestFakeRootDirCleanup(fakerootdir);
+ VIR_FREE(fakerootdir);
}
static int
diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c
index 1aed0d2b6d..c64940458f 100644
--- a/tests/virhostdevtest.c
+++ b/tests/virhostdevtest.c
@@ -584,22 +584,14 @@ testNVMeDiskRoundtrip(const void *opaque G_GNUC_UNUSED)
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
int ret = 0;
g_autofree char *fakerootdir = NULL;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+ if (!(fakerootdir = virTestFakeRootDirInit()))
+ return EXIT_FAILURE;
# define DO_TEST(fnc) \
do { \
@@ -609,7 +601,7 @@ mymain(void)
if (myInit() < 0) {
fprintf(stderr, "Init data structures failed.");
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
return EXIT_FAILURE;
}
@@ -622,8 +614,7 @@ mymain(void)
myCleanup();
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/virpcitest.c b/tests/virpcitest.c
index 4c0f0b91c3..5ddf4de0bd 100644
--- a/tests/virpcitest.c
+++ b/tests/virpcitest.c
@@ -363,22 +363,14 @@ testVirPCIDeviceGetVPD(const void *opaque)
return 0;
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
int ret = 0;
g_autofree char *fakerootdir = NULL;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- VIR_TEST_DEBUG("Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+ if (!(fakerootdir = virTestFakeRootDirInit()))
+ return EXIT_FAILURE;
# define DO_TEST(fnc) \
do { \
@@ -446,8 +438,7 @@ mymain(void)
DO_TEST_PCI(testVirPCIDeviceGetVPD, 0, 0x03, 0, 0);
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
+ virTestFakeRootDirCleanup(fakerootdir);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}