mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-30 16:35:24 +00:00
qemuxml2xmltest: Split out status XML testing to qemustatusxml2xmltest.c
Separate the test files. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
60129c06ba
commit
89a3115bac
@ -449,6 +449,7 @@ if conf.has('WITH_QEMU')
|
||||
{ 'name': 'qemumigparamstest', 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
|
||||
{ 'name': 'qemumonitorjsontest', 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
|
||||
{ 'name': 'qemusecuritytest', 'sources': [ 'qemusecuritytest.c', 'qemusecuritymock.c' ], 'link_with': [ test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib ] },
|
||||
{ 'name': 'qemustatusxml2xmltest', 'link_with': [ test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_wrapper_lib ] },
|
||||
{ 'name': 'qemuvhostusertest', 'link_with': [ test_qemu_driver_lib ], 'link_whole': [ test_file_wrapper_lib ] },
|
||||
{ 'name': 'qemuxml2argvtest', 'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_wrapper_lib ] },
|
||||
{ 'name': 'qemuxml2xmltest', 'link_with': [ test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_wrapper_lib ] },
|
||||
|
155
tests/qemustatusxml2xmltest.c
Normal file
155
tests/qemustatusxml2xmltest.c
Normal file
@ -0,0 +1,155 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "testutils.h"
|
||||
|
||||
#include "internal.h"
|
||||
#include "testutilsqemu.h"
|
||||
#include "configmake.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
static virQEMUDriver driver;
|
||||
|
||||
static int
|
||||
testCompareStatusXMLToXMLFiles(const void *opaque)
|
||||
{
|
||||
const struct testQemuInfo *data = opaque;
|
||||
virDomainObjPtr obj = NULL;
|
||||
g_autofree char *actual = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(obj = virDomainObjParseFile(data->infile, driver.xmlopt,
|
||||
VIR_DOMAIN_DEF_PARSE_STATUS |
|
||||
VIR_DOMAIN_DEF_PARSE_ACTUAL_NET |
|
||||
VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES |
|
||||
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE |
|
||||
VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL))) {
|
||||
VIR_TEST_DEBUG("\nfailed to parse '%s'", data->infile);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(actual = virDomainObjFormat(obj, driver.xmlopt,
|
||||
VIR_DOMAIN_DEF_FORMAT_SECURE |
|
||||
VIR_DOMAIN_DEF_FORMAT_STATUS |
|
||||
VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET |
|
||||
VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES |
|
||||
VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST))) {
|
||||
VIR_TEST_DEBUG("\nfailed to format back '%s'", data->infile);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virTestCompareToFile(actual, data->outfile) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static const char *statusPath = abs_srcdir "/qemustatusxml2xmldata/";
|
||||
|
||||
static void
|
||||
testInfoSetStatusPaths(struct testQemuInfo *info)
|
||||
{
|
||||
info->infile = g_strdup_printf("%s%s-in.xml", statusPath, info->name);
|
||||
info->outfile = g_strdup_printf("%s%s-out.xml", statusPath, info->name);
|
||||
}
|
||||
|
||||
|
||||
#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
g_autofree char *fakerootdir = NULL;
|
||||
g_autoptr(virQEMUDriverConfig) cfg = NULL;
|
||||
g_autoptr(GHashTable) capslatest = NULL;
|
||||
g_autoptr(virConnect) conn = NULL;
|
||||
|
||||
capslatest = testQemuGetLatestCaps();
|
||||
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 (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
cfg = virQEMUDriverGetConfig(&driver);
|
||||
driver.privileged = true;
|
||||
|
||||
if (!(conn = virGetConnect()))
|
||||
goto cleanup;
|
||||
|
||||
virSetConnectInterface(conn);
|
||||
virSetConnectNetwork(conn);
|
||||
virSetConnectNWFilter(conn);
|
||||
virSetConnectNodeDev(conn);
|
||||
virSetConnectSecret(conn);
|
||||
virSetConnectStorage(conn);
|
||||
|
||||
#define DO_TEST_STATUS(_name) \
|
||||
do { \
|
||||
static struct testQemuInfo info = { \
|
||||
.name = _name, \
|
||||
}; \
|
||||
if (testQemuInfoSetArgs(&info, capslatest, \
|
||||
ARG_QEMU_CAPS, QEMU_CAPS_LAST, \
|
||||
ARG_END) < 0 || \
|
||||
qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
|
||||
VIR_TEST_DEBUG("Failed to generate status test data for '%s'", _name); \
|
||||
return -1; \
|
||||
} \
|
||||
testInfoSetStatusPaths(&info); \
|
||||
\
|
||||
if (virTestRun("QEMU status XML-2-XML " _name, \
|
||||
testCompareStatusXMLToXMLFiles, &info) < 0) \
|
||||
ret = -1; \
|
||||
\
|
||||
testQemuInfoClear(&info); \
|
||||
} while (0)
|
||||
|
||||
|
||||
DO_TEST_STATUS("blockjob-mirror");
|
||||
DO_TEST_STATUS("vcpus-multi");
|
||||
DO_TEST_STATUS("modern");
|
||||
DO_TEST_STATUS("migration-out-nbd");
|
||||
DO_TEST_STATUS("migration-in-params");
|
||||
DO_TEST_STATUS("migration-out-params");
|
||||
DO_TEST_STATUS("migration-out-nbd-tls");
|
||||
DO_TEST_STATUS("upgrade");
|
||||
|
||||
DO_TEST_STATUS("blockjob-blockdev");
|
||||
|
||||
DO_TEST_STATUS("backup-pull");
|
||||
|
||||
cleanup:
|
||||
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
||||
virFileDeleteTree(fakerootdir);
|
||||
|
||||
qemuTestDriverFree(&driver);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
VIR_TEST_MAIN_PRELOAD(mymain,
|
||||
VIR_TEST_MOCK("virpci"),
|
||||
VIR_TEST_MOCK("virrandom"),
|
||||
VIR_TEST_MOCK("domaincaps"),
|
||||
VIR_TEST_MOCK("virdeterministichash"))
|
@ -48,45 +48,6 @@ testXML2XMLInactive(const void *opaque)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testCompareStatusXMLToXMLFiles(const void *opaque)
|
||||
{
|
||||
const struct testQemuInfo *data = opaque;
|
||||
virDomainObjPtr obj = NULL;
|
||||
g_autofree char *actual = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(obj = virDomainObjParseFile(data->infile, driver.xmlopt,
|
||||
VIR_DOMAIN_DEF_PARSE_STATUS |
|
||||
VIR_DOMAIN_DEF_PARSE_ACTUAL_NET |
|
||||
VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES |
|
||||
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE |
|
||||
VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL))) {
|
||||
VIR_TEST_DEBUG("\nfailed to parse '%s'", data->infile);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(actual = virDomainObjFormat(obj, driver.xmlopt,
|
||||
VIR_DOMAIN_DEF_FORMAT_SECURE |
|
||||
VIR_DOMAIN_DEF_FORMAT_STATUS |
|
||||
VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET |
|
||||
VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES |
|
||||
VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST))) {
|
||||
VIR_TEST_DEBUG("\nfailed to format back '%s'", data->infile);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virTestCompareToFile(actual, data->outfile) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testInfoSetPaths(struct testQemuInfo *info,
|
||||
const char *suffix,
|
||||
@ -113,16 +74,6 @@ testInfoSetPaths(struct testQemuInfo *info,
|
||||
}
|
||||
|
||||
|
||||
static const char *statusPath = abs_srcdir "/qemustatusxml2xmldata/";
|
||||
|
||||
static void
|
||||
testInfoSetStatusPaths(struct testQemuInfo *info)
|
||||
{
|
||||
info->infile = g_strdup_printf("%s%s-in.xml", statusPath, info->name);
|
||||
info->outfile = g_strdup_printf("%s%s-out.xml", statusPath, info->name);
|
||||
}
|
||||
|
||||
|
||||
#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||
|
||||
static int
|
||||
@ -1421,41 +1372,6 @@ mymain(void)
|
||||
QEMU_CAPS_VIRTIO_SCSI,
|
||||
QEMU_CAPS_MCH_EXTENDED_TSEG_MBYTES);
|
||||
|
||||
#define DO_TEST_STATUS(_name) \
|
||||
do { \
|
||||
static struct testQemuInfo info = { \
|
||||
.name = _name, \
|
||||
}; \
|
||||
if (testQemuInfoSetArgs(&info, capslatest, \
|
||||
ARG_QEMU_CAPS, QEMU_CAPS_LAST, \
|
||||
ARG_END) < 0 || \
|
||||
qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
|
||||
VIR_TEST_DEBUG("Failed to generate status test data for '%s'", _name); \
|
||||
return -1; \
|
||||
} \
|
||||
testInfoSetStatusPaths(&info); \
|
||||
\
|
||||
if (virTestRun("QEMU status XML-2-XML " _name, \
|
||||
testCompareStatusXMLToXMLFiles, &info) < 0) \
|
||||
ret = -1; \
|
||||
\
|
||||
testQemuInfoClear(&info); \
|
||||
} while (0)
|
||||
|
||||
|
||||
DO_TEST_STATUS("blockjob-mirror");
|
||||
DO_TEST_STATUS("vcpus-multi");
|
||||
DO_TEST_STATUS("modern");
|
||||
DO_TEST_STATUS("migration-out-nbd");
|
||||
DO_TEST_STATUS("migration-in-params");
|
||||
DO_TEST_STATUS("migration-out-params");
|
||||
DO_TEST_STATUS("migration-out-nbd-tls");
|
||||
DO_TEST_STATUS("upgrade");
|
||||
|
||||
DO_TEST_STATUS("blockjob-blockdev");
|
||||
|
||||
DO_TEST_STATUS("backup-pull");
|
||||
|
||||
DO_TEST("vhost-vsock", QEMU_CAPS_DEVICE_VHOST_VSOCK);
|
||||
DO_TEST("vhost-vsock-auto", QEMU_CAPS_DEVICE_VHOST_VSOCK);
|
||||
DO_TEST("vhost-vsock-ccw", QEMU_CAPS_DEVICE_VHOST_VSOCK,
|
||||
|
Loading…
x
Reference in New Issue
Block a user