提交 d98cc196 编写于 作者: A Andrea Bolognani

tests: Use qemu:///embed to simplify fakerootdir management

Now that the QEMU driver natively supports storing all its runtime
data inside an arbitrary directory, we can avoid having multiple
copies of the same logic in the test suite.
Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 f28fbb05
...@@ -594,8 +594,6 @@ testQemuHotplugCpuIndividual(const void *opaque) ...@@ -594,8 +594,6 @@ testQemuHotplugCpuIndividual(const void *opaque)
return ret; return ret;
} }
#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
static int static int
mymain(void) mymain(void)
...@@ -604,18 +602,8 @@ mymain(void) ...@@ -604,18 +602,8 @@ mymain(void)
int ret = 0; int ret = 0;
struct qemuHotplugTestData data = {0}; struct qemuHotplugTestData data = {0};
struct testQemuHotplugCpuParams cpudata; struct testQemuHotplugCpuParams cpudata;
g_autofree char *fakerootdir = NULL;
g_autoptr(virQEMUDriverConfig) cfg = 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) if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -891,9 +879,6 @@ mymain(void) ...@@ -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", "16-22", true, true, true);
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true, true, true); DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true, true, true);
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);
qemuTestDriverFree(&driver); qemuTestDriverFree(&driver);
virObjectUnref(data.vm); virObjectUnref(data.vm);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
......
...@@ -51,28 +51,14 @@ testCompareMemLock(const void *data) ...@@ -51,28 +51,14 @@ testCompareMemLock(const void *data)
return ret; return ret;
} }
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
static int static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char *fakerootdir;
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); if (qemuTestDriverInit(&driver) < 0)
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; return EXIT_FAILURE;
}
driver.privileged = true; driver.privileged = true;
...@@ -150,11 +136,7 @@ mymain(void) ...@@ -150,11 +136,7 @@ mymain(void)
cleanup: cleanup:
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);
qemuTestDriverFree(&driver); qemuTestDriverFree(&driver);
VIR_FREE(fakerootdir);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }
......
...@@ -609,24 +609,12 @@ testInfoSetPaths(struct testQemuInfo *info, ...@@ -609,24 +609,12 @@ testInfoSetPaths(struct testQemuInfo *info,
abs_srcdir, info->name, suffix ? suffix : ""); abs_srcdir, info->name, suffix ? suffix : "");
} }
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
static int static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char *fakerootdir;
virHashTablePtr capslatest = NULL; 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. /* Set the timezone because we are mocking the time() function.
* If we don't do that, then localtime() may return unpredictable * If we don't do that, then localtime() may return unpredictable
* results. In order to detect things that just work by a blind * results. In order to detect things that just work by a blind
...@@ -3232,12 +3220,8 @@ mymain(void) ...@@ -3232,12 +3220,8 @@ mymain(void)
DO_TEST_CAPS_LATEST("virtio-9p-multidevs"); DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);
VIR_FREE(driver.config->nbdTLSx509certdir); VIR_FREE(driver.config->nbdTLSx509certdir);
qemuTestDriverFree(&driver); qemuTestDriverFree(&driver);
VIR_FREE(fakerootdir);
virHashFree(capslatest); virHashFree(capslatest);
virFileWrapperClearPrefixes(); virFileWrapperClearPrefixes();
......
...@@ -126,13 +126,10 @@ testInfoSetStatusPaths(struct testQemuInfo *info) ...@@ -126,13 +126,10 @@ testInfoSetStatusPaths(struct testQemuInfo *info)
} }
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
static int static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char *fakerootdir;
virQEMUDriverConfigPtr cfg = NULL; virQEMUDriverConfigPtr cfg = NULL;
virHashTablePtr capslatest = NULL; virHashTablePtr capslatest = NULL;
...@@ -140,15 +137,6 @@ mymain(void) ...@@ -140,15 +137,6 @@ mymain(void)
if (!capslatest) if (!capslatest)
return EXIT_FAILURE; 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 /* Required for tpm-emulator tests
*/ */
virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware", virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
...@@ -1478,12 +1466,8 @@ mymain(void) ...@@ -1478,12 +1466,8 @@ mymain(void)
DO_TEST_CAPS_LATEST("virtio-9p-multidevs"); DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);
virHashFree(capslatest); virHashFree(capslatest);
qemuTestDriverFree(&driver); qemuTestDriverFree(&driver);
VIR_FREE(fakerootdir);
virFileWrapperClearPrefixes(); virFileWrapperClearPrefixes();
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
......
...@@ -307,11 +307,10 @@ qemuTestParseCapabilitiesArch(virArch arch, ...@@ -307,11 +307,10 @@ qemuTestParseCapabilitiesArch(virArch arch,
void qemuTestDriverFree(virQEMUDriver *driver) void qemuTestDriverFree(virQEMUDriver *driver)
{ {
if (g_getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(driver->embeddedRoot);
virMutexDestroy(&driver->lock); virMutexDestroy(&driver->lock);
if (driver->config) {
virFileDeleteTree(driver->config->stateDir);
virFileDeleteTree(driver->config->configDir);
}
virObjectUnref(driver->qemuCapsCache); virObjectUnref(driver->qemuCapsCache);
virObjectUnref(driver->xmlopt); virObjectUnref(driver->xmlopt);
virObjectUnref(driver->caps); virObjectUnref(driver->caps);
...@@ -370,14 +369,21 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache, ...@@ -370,14 +369,21 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache,
} }
# define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX" # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
# define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX"
int qemuTestDriverInit(virQEMUDriver *driver) int qemuTestDriverInit(virQEMUDriver *driver)
{ {
virSecurityManagerPtr mgr = NULL; virSecurityManagerPtr mgr = NULL;
char statedir[] = STATEDIRTEMPLATE; g_autofree char *fakerootdir = NULL;
char configdir[] = CONFIGDIRTEMPLATE;
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)); memset(driver, 0, sizeof(*driver));
...@@ -391,35 +397,16 @@ int qemuTestDriverInit(virQEMUDriver *driver) ...@@ -391,35 +397,16 @@ int qemuTestDriverInit(virQEMUDriver *driver)
return -1; return -1;
driver->hostarch = virArchFromHost(); driver->hostarch = virArchFromHost();
driver->config = virQEMUDriverConfigNew(false, NULL); driver->config = virQEMUDriverConfigNew(false, fakerootdir);
if (!driver->config) if (!driver->config)
goto error; 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. */ /* Overwrite some default paths so it's consistent for tests. */
VIR_FREE(driver->config->libDir); VIR_FREE(driver->config->libDir);
VIR_FREE(driver->config->channelTargetDir); VIR_FREE(driver->config->channelTargetDir);
driver->config->libDir = g_strdup("/tmp/lib"); driver->config->libDir = g_strdup("/tmp/lib");
driver->config->channelTargetDir = g_strdup("/tmp/channel"); 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(); driver->caps = testQemuCapsInit();
if (!driver->caps) if (!driver->caps)
goto error; goto error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册