mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
tests: split out common qemu driver initialization
Two utility functions are introduced for proper initialization and cleanup of the driver. Signed-off-by: Pavel Fedin <p.fedin@samsung.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
03cf57a37d
commit
5b7bf20877
@ -152,13 +152,11 @@ mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((driver.caps = testQemuCapsInit()) == NULL)
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver))) {
|
||||
virObjectUnref(driver.caps);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* TODO: test with format probing disabled too */
|
||||
driver.config->allowDiskFormatProbing = true;
|
||||
|
||||
if (VIR_ALLOC(testSnapshotXMLVariableLineRegex) < 0)
|
||||
goto cleanup;
|
||||
@ -227,8 +225,7 @@ mymain(void)
|
||||
if (testSnapshotXMLVariableLineRegex)
|
||||
regfree(testSnapshotXMLVariableLineRegex);
|
||||
VIR_FREE(testSnapshotXMLVariableLineRegex);
|
||||
virObjectUnref(driver.caps);
|
||||
virObjectUnref(driver.xmlopt);
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -908,8 +908,8 @@ testQemuAgentGetInterfaces(const void *data)
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
virQEMUDriver driver;
|
||||
int ret = 0;
|
||||
virDomainXMLOptionPtr xmlopt;
|
||||
|
||||
#if !WITH_YAJL
|
||||
fputs("libvirt not compiled with yajl, skipping this test\n", stderr);
|
||||
@ -917,13 +917,13 @@ mymain(void)
|
||||
#endif
|
||||
|
||||
if (virThreadInitialize() < 0 ||
|
||||
!(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
|
||||
qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
virEventRegisterDefaultImpl();
|
||||
|
||||
#define DO_TEST(name) \
|
||||
if (virtTestRun(# name, testQemuAgent ## name, xmlopt) < 0) \
|
||||
if (virtTestRun(# name, testQemuAgent ## name, driver.xmlopt) < 0) \
|
||||
ret = -1
|
||||
|
||||
DO_TEST(FSFreeze);
|
||||
@ -938,7 +938,7 @@ mymain(void)
|
||||
|
||||
DO_TEST(Timeout); /* Timeout should always be called last */
|
||||
|
||||
virObjectUnref(xmlopt);
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -145,15 +145,9 @@ mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
driver.config = virQEMUDriverConfigNew(false);
|
||||
if (driver.config == NULL)
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if ((driver.caps = testQemuCapsInit()) == NULL)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
# define DO_TEST_FULL(name, flags) \
|
||||
do { \
|
||||
@ -298,9 +292,7 @@ mymain(void)
|
||||
DO_TEST("machine-deakeywrap-off-argv");
|
||||
DO_TEST("machine-keywrap-none-argv");
|
||||
|
||||
virObjectUnref(driver.config);
|
||||
virObjectUnref(driver.caps);
|
||||
virObjectUnref(driver.xmlopt);
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -338,14 +338,11 @@ mymain(void)
|
||||
#endif
|
||||
|
||||
if (virThreadInitialize() < 0 ||
|
||||
!(driver.caps = testQemuCapsInit()) ||
|
||||
!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
|
||||
qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
virEventRegisterDefaultImpl();
|
||||
|
||||
if (!(driver.config = virQEMUDriverConfigNew(false)))
|
||||
return EXIT_FAILURE;
|
||||
VIR_FREE(driver.config->spiceListen);
|
||||
VIR_FREE(driver.config->vncListen);
|
||||
/* some dummy values from 'config file' */
|
||||
@ -486,9 +483,7 @@ mymain(void)
|
||||
"device_del", QMP_DEVICE_DELETED("scsi0-0-0-5") QMP_OK,
|
||||
"human-monitor-command", HMP(""));
|
||||
|
||||
virObjectUnref(driver.caps);
|
||||
virObjectUnref(driver.xmlopt);
|
||||
virObjectUnref(driver.config);
|
||||
qemuTestDriverFree(&driver);
|
||||
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -483,8 +483,7 @@ mymain(void)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
driver.config = virQEMUDriverConfigNew(false);
|
||||
if (driver.config == NULL)
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
driver.privileged = true;
|
||||
@ -499,10 +498,6 @@ mymain(void)
|
||||
if (VIR_STRDUP_QUIET(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if ((driver.caps = testQemuCapsInit()) == NULL)
|
||||
return EXIT_FAILURE;
|
||||
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
|
||||
return EXIT_FAILURE;
|
||||
VIR_FREE(driver.config->stateDir);
|
||||
if (VIR_STRDUP_QUIET(driver.config->stateDir, "/nowhere") < 0)
|
||||
return EXIT_FAILURE;
|
||||
@ -1761,9 +1756,7 @@ mymain(void)
|
||||
QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_DRIVE, QEMU_CAPS_VIRTIO_SCSI,
|
||||
QEMU_CAPS_DEVICE, QEMU_CAPS_VIRTIO_CCW, QEMU_CAPS_VIRTIO_S390);
|
||||
|
||||
virObjectUnref(driver.config);
|
||||
virObjectUnref(driver.caps);
|
||||
virObjectUnref(driver.xmlopt);
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -302,11 +302,11 @@ mymain(void)
|
||||
int ret = 0;
|
||||
struct testInfo info;
|
||||
|
||||
if ((driver.caps = testQemuCapsInit()) == NULL)
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
|
||||
return EXIT_FAILURE;
|
||||
/* TODO: test with format probing disabled too */
|
||||
driver.config->allowDiskFormatProbing = true;
|
||||
|
||||
# define DO_TEST_FULL(name, is_different, when) \
|
||||
do { \
|
||||
@ -631,8 +631,7 @@ mymain(void)
|
||||
DO_TEST("memory-hotplug-dimm");
|
||||
DO_TEST("net-udp");
|
||||
|
||||
virObjectUnref(driver.caps);
|
||||
virObjectUnref(driver.xmlopt);
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -201,15 +201,12 @@ mymain(void)
|
||||
if (!abs_top_srcdir)
|
||||
abs_top_srcdir = abs_srcdir "/..";
|
||||
|
||||
if (!(driver.config = virQEMUDriverConfigNew(false)))
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
VIR_FREE(driver.config->libDir);
|
||||
if (VIR_STRDUP_QUIET(driver.config->libDir, "/tmp") < 0)
|
||||
return EXIT_FAILURE;
|
||||
if ((driver.caps = testQemuCapsInit()) == NULL)
|
||||
return EXIT_FAILURE;
|
||||
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \
|
||||
do { \
|
||||
@ -251,9 +248,7 @@ mymain(void)
|
||||
DO_TEST("qemu-ns-commandline-ns0", false, NONE);
|
||||
DO_TEST("qemu-ns-commandline-ns1", false, NONE);
|
||||
|
||||
virObjectUnref(driver.config);
|
||||
virObjectUnref(driver.caps);
|
||||
virObjectUnref(driver.xmlopt);
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -526,4 +526,32 @@ qemuTestParseCapabilities(const char *capsFile)
|
||||
xmlXPathFreeContext(ctxt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void qemuTestDriverFree(virQEMUDriver *driver)
|
||||
{
|
||||
virObjectUnref(driver->xmlopt);
|
||||
virObjectUnref(driver->caps);
|
||||
virObjectUnref(driver->config);
|
||||
}
|
||||
|
||||
int qemuTestDriverInit(virQEMUDriver *driver)
|
||||
{
|
||||
driver->config = virQEMUDriverConfigNew(false);
|
||||
if (!driver->config)
|
||||
return -1;
|
||||
|
||||
driver->caps = testQemuCapsInit();
|
||||
if (!driver->caps)
|
||||
goto error;
|
||||
|
||||
driver->xmlopt = virQEMUDriverCreateXMLConf(driver);
|
||||
if (!driver->xmlopt)
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
qemuTestDriverFree(driver);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
@ -16,4 +16,6 @@ extern virCPUDefPtr cpuHaswell;
|
||||
void testQemuCapsSetCPU(virCapsPtr caps,
|
||||
virCPUDefPtr hostCPU);
|
||||
|
||||
int qemuTestDriverInit(virQEMUDriver *driver);
|
||||
void qemuTestDriverFree(virQEMUDriver *driver);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user