mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-21 21:25:25 +00:00
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>
This commit is contained in:
parent
ef3b22e589
commit
457a0183d6
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user