qemuxml2argvtest: Setup fake driver only once

Move the setup of the fake driver from testCompareXMLToArgv to 'mymain'.
With this we also won't need to reset the fake drivers which was done
only partially.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-12-16 08:48:21 +01:00
parent 59d70e3a41
commit 002daa184d

View File

@ -611,7 +611,6 @@ testCompareXMLToArgv(const void *data)
int ret = -1; int ret = -1;
virDomainObj *vm = NULL; virDomainObj *vm = NULL;
virDomainChrSourceDef monitor_chr = { 0 }; virDomainChrSourceDef monitor_chr = { 0 };
g_autoptr(virConnect) conn = NULL;
virError *err = NULL; virError *err = NULL;
g_autofree char *log = NULL; g_autofree char *log = NULL;
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
@ -646,21 +645,6 @@ testCompareXMLToArgv(const void *data)
testUpdateQEMUCapsHostCPUModel(info->qemuCaps, driver.hostarch); testUpdateQEMUCapsHostCPUModel(info->qemuCaps, driver.hostarch);
} }
if (!(conn = virGetConnect()))
goto cleanup;
conn->secretDriver = &fakeSecretDriver;
conn->storageDriver = &fakeStorageDriver;
conn->nwfilterDriver = &fakeNWFilterDriver;
conn->networkDriver = &fakeNetworkDriver;
virSetConnectInterface(conn);
virSetConnectNetwork(conn);
virSetConnectNWFilter(conn);
virSetConnectNodeDev(conn);
virSetConnectSecret(conn);
virSetConnectStorage(conn);
if (virIdentitySetCurrent(sysident) < 0) if (virIdentitySetCurrent(sysident) < 0)
goto cleanup; goto cleanup;
@ -788,8 +772,6 @@ testCompareXMLToArgv(const void *data)
virDomainChrSourceDefClear(&monitor_chr); virDomainChrSourceDefClear(&monitor_chr);
virObjectUnref(vm); virObjectUnref(vm);
virIdentitySetCurrent(NULL); virIdentitySetCurrent(NULL);
virSetConnectSecret(NULL);
virSetConnectStorage(NULL);
if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64) if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
qemuTestSetHostArch(&driver, VIR_ARCH_NONE); qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
@ -873,6 +855,7 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
g_autoptr(virConnect) conn = NULL;
g_autoptr(GHashTable) duplicateTests = virHashNew(NULL); g_autoptr(GHashTable) duplicateTests = virHashNew(NULL);
g_autoptr(GHashTable) existingTestCases = virHashNew(NULL); g_autoptr(GHashTable) existingTestCases = virHashNew(NULL);
g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps(); g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
@ -924,6 +907,21 @@ mymain(void)
virFileWrapperAddPrefix("/usr/libexec/qemu/vhost-user", virFileWrapperAddPrefix("/usr/libexec/qemu/vhost-user",
abs_srcdir "/qemuvhostuserdata/usr/libexec/qemu/vhost-user"); abs_srcdir "/qemuvhostuserdata/usr/libexec/qemu/vhost-user");
if (!(conn = virGetConnect()))
return EXIT_FAILURE;
conn->secretDriver = &fakeSecretDriver;
conn->storageDriver = &fakeStorageDriver;
conn->nwfilterDriver = &fakeNWFilterDriver;
conn->networkDriver = &fakeNetworkDriver;
virSetConnectInterface(conn);
virSetConnectNetwork(conn);
virSetConnectNWFilter(conn);
virSetConnectNodeDev(conn);
virSetConnectSecret(conn);
virSetConnectStorage(conn);
/** /**
* The following set of macros allows testing of XML -> argv conversion with a * The following set of macros allows testing of XML -> argv conversion with a
* real set of capabilities gathered from a real qemu copy. It is desired to use * real set of capabilities gathered from a real qemu copy. It is desired to use