Now that the QEMU driver natively supports storing all its runtime
data inside an arbitrary directory, we can avoid having multiple
copies of this same logic in the test suite.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
tests/qemuhotplugtest.c | 15 --------------
tests/qemumemlocktest.c | 17 ----------------
tests/qemuxml2argvtest.c | 16 ---------------
tests/qemuxml2xmltest.c | 16 ---------------
tests/testutilsqemu.c | 43 ++++++++++++++--------------------------
5 files changed, 15 insertions(+), 92 deletions(-)
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 9a215ab303..e7443ff4b7 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -594,8 +594,6 @@ testQemuHotplugCpuIndividual(const void *opaque)
return ret;
}
-#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
@@ -604,18 +602,8 @@ mymain(void)
int ret = 0;
struct qemuHotplugTestData data = {0};
struct testQemuHotplugCpuParams cpudata;
- g_autofree char *fakerootdir = NULL;
g_autoptr(virQEMUDriverConfig) cfg = NULL;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
-
if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
@@ -891,9 +879,6 @@ 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);
-
qemuTestDriverFree(&driver);
virObjectUnref(data.vm);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
index 3f18fed1c3..0e254bb3ce 100644
--- a/tests/qemumemlocktest.c
+++ b/tests/qemumemlocktest.c
@@ -51,26 +51,13 @@ testCompareMemLock(const void *data)
return ret;
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
int ret = 0;
- char *fakerootdir;
virQEMUCapsPtr 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 (qemuTestDriverInit(&driver) < 0) {
- VIR_FREE(fakerootdir);
return EXIT_FAILURE;
}
@@ -150,11 +137,7 @@ mymain(void)
cleanup:
virObjectUnref(qemuCaps);
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
-
qemuTestDriverFree(&driver);
- VIR_FREE(fakerootdir);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 04febd1b0c..8bd6102d26 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -609,24 +609,12 @@ testInfoSetPaths(struct testQemuInfo *info,
abs_srcdir, info->name, suffix ? suffix :
"");
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
int ret = 0;
- char *fakerootdir;
virHashTablePtr capslatest = NULL;
- fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
- if (!g_mkdtemp(fakerootdir)) {
- fprintf(stderr, "Cannot create fakerootdir");
- abort();
- }
-
- g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
-
/* Set the timezone because we are mocking the time() function.
* If we don't do that, then localtime() may return unpredictable
* results. In order to detect things that just work by a blind
@@ -3232,12 +3220,8 @@ mymain(void)
DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
-
VIR_FREE(driver.config->nbdTLSx509certdir);
qemuTestDriverFree(&driver);
- VIR_FREE(fakerootdir);
virHashFree(capslatest);
virFileWrapperClearPrefixes();
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 86f3d2c1f3..6a0adab603 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -126,13 +126,10 @@ testInfoSetStatusPaths(struct testQemuInfo *info)
}
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
-
static int
mymain(void)
{
int ret = 0;
- char *fakerootdir;
virQEMUDriverConfigPtr cfg = NULL;
virHashTablePtr capslatest = NULL;
@@ -140,15 +137,6 @@ 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);
-
/* Required for tpm-emulator tests
*/
virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
@@ -1478,12 +1466,8 @@ mymain(void)
DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
- if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
- virFileDeleteTree(fakerootdir);
-
virHashFree(capslatest);
qemuTestDriverFree(&driver);
- VIR_FREE(fakerootdir);
virFileWrapperClearPrefixes();
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 9f9eb4033c..c7983f0014 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -307,11 +307,10 @@ qemuTestParseCapabilitiesArch(virArch arch,
void qemuTestDriverFree(virQEMUDriver *driver)
{
+ if (g_getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+ virFileDeleteTree(driver->embeddedRoot);
+
virMutexDestroy(&driver->lock);
- if (driver->config) {
- virFileDeleteTree(driver->config->stateDir);
- virFileDeleteTree(driver->config->configDir);
- }
virObjectUnref(driver->qemuCapsCache);
virObjectUnref(driver->xmlopt);
virObjectUnref(driver->caps);
@@ -370,14 +369,21 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache,
}
-# define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX"
-# define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX"
+# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
int qemuTestDriverInit(virQEMUDriver *driver)
{
virSecurityManagerPtr mgr = NULL;
- char statedir[] = STATEDIRTEMPLATE;
- char configdir[] = CONFIGDIRTEMPLATE;
+ 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);
memset(driver, 0, sizeof(*driver));
@@ -391,35 +397,16 @@ int qemuTestDriverInit(virQEMUDriver *driver)
return -1;
driver->hostarch = virArchFromHost();
- driver->config = virQEMUDriverConfigNew(false, NULL);
+ driver->config = virQEMUDriverConfigNew(false, fakerootdir);
if (!driver->config)
goto error;
- /* Do this early so that qemuTestDriverFree() doesn't see (unlink) the real
- * dirs. */
- VIR_FREE(driver->config->stateDir);
- VIR_FREE(driver->config->configDir);
-
/* Overwrite some default paths so it's consistent for tests. */
VIR_FREE(driver->config->libDir);
VIR_FREE(driver->config->channelTargetDir);
driver->config->libDir = g_strdup("/tmp/lib");
driver->config->channelTargetDir = g_strdup("/tmp/channel");
- if (!g_mkdtemp(statedir)) {
- fprintf(stderr, "Cannot create fake stateDir");
- goto error;
- }
-
- driver->config->stateDir = g_strdup(statedir);
-
- if (!g_mkdtemp(configdir)) {
- fprintf(stderr, "Cannot create fake configDir");
- goto error;
- }
-
- driver->config->configDir = g_strdup(configdir);
-
driver->caps = testQemuCapsInit();
if (!driver->caps)
goto error;
--
2.25.4