Now that the parser and formatter are in place we can excercise it on the test files. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- tests/Makefile.am | 1 + .../backup-pull-seclabel.xml | 18 ++++++++ tests/domainbackupxml2xmlout/backup-pull.xml | 10 ++++ .../backup-push-seclabel.xml | 17 +++++++ tests/domainbackupxml2xmlout/backup-push.xml | 10 ++++ tests/domainbackupxml2xmlout/empty.xml | 1 + tests/genericxml2xmltest.c | 46 +++++++++++++++++++ tests/virschematest.c | 3 +- 8 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 tests/domainbackupxml2xmlout/backup-pull-seclabel.xml create mode 100644 tests/domainbackupxml2xmlout/backup-pull.xml create mode 100644 tests/domainbackupxml2xmlout/backup-push-seclabel.xml create mode 100644 tests/domainbackupxml2xmlout/backup-push.xml create mode 100644 tests/domainbackupxml2xmlout/empty.xml diff --git a/tests/Makefile.am b/tests/Makefile.am index ea9e2b2ad0..75eee0006c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -92,6 +92,7 @@ EXTRA_DIST = \ cputestdata \ domaincapsdata \ domainbackupxml2xmlin \ + domainbackupxml2xmlout \ domainconfdata \ domainschemadata \ fchostdata \ diff --git a/tests/domainbackupxml2xmlout/backup-pull-seclabel.xml b/tests/domainbackupxml2xmlout/backup-pull-seclabel.xml new file mode 100644 index 0000000000..c631c9b979 --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-pull-seclabel.xml @@ -0,0 +1,18 @@ +<domainbackup mode='pull'> + <incremental>1525889631</incremental> + <server transport='tcp' name='localhost' port='10809'/> + <disks> + <disk name='vda' backup='yes' type='file'> + <driver type='qcow2'/> + <scratch file='/path/to/file'> + <seclabel model='dac' relabel='no'/> + </scratch> + </disk> + <disk name='vdb' backup='yes' type='block'> + <driver type='qcow2'/> + <scratch dev='/dev/block'> + <seclabel model='dac' relabel='no'/> + </scratch> + </disk> + </disks> +</domainbackup> diff --git a/tests/domainbackupxml2xmlout/backup-pull.xml b/tests/domainbackupxml2xmlout/backup-pull.xml new file mode 100644 index 0000000000..24fce9c0e7 --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-pull.xml @@ -0,0 +1,10 @@ +<domainbackup mode='pull'> + <incremental>1525889631</incremental> + <server transport='tcp' name='localhost' port='10809'/> + <disks> + <disk name='vda' backup='yes' type='file'> + <scratch file='/path/to/file'/> + </disk> + <disk name='hda' backup='no'/> + </disks> +</domainbackup> diff --git a/tests/domainbackupxml2xmlout/backup-push-seclabel.xml b/tests/domainbackupxml2xmlout/backup-push-seclabel.xml new file mode 100644 index 0000000000..9986889ba3 --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-push-seclabel.xml @@ -0,0 +1,17 @@ +<domainbackup mode='push'> + <incremental>1525889631</incremental> + <disks> + <disk name='vda' backup='yes' type='file'> + <driver type='raw'/> + <target file='/path/to/file'> + <seclabel model='dac' relabel='no'/> + </target> + </disk> + <disk name='vdb' backup='yes' type='block'> + <driver type='qcow2'/> + <target dev='/dev/block'> + <seclabel model='dac' relabel='no'/> + </target> + </disk> + </disks> +</domainbackup> diff --git a/tests/domainbackupxml2xmlout/backup-push.xml b/tests/domainbackupxml2xmlout/backup-push.xml new file mode 100644 index 0000000000..1997c814ae --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-push.xml @@ -0,0 +1,10 @@ +<domainbackup mode='push'> + <incremental>1525889631</incremental> + <disks> + <disk name='vda' backup='yes' type='file'> + <driver type='raw'/> + <target file='/path/to/file'/> + </disk> + <disk name='hda' backup='no'/> + </disks> +</domainbackup> diff --git a/tests/domainbackupxml2xmlout/empty.xml b/tests/domainbackupxml2xmlout/empty.xml new file mode 100644 index 0000000000..b1ba4953be --- /dev/null +++ b/tests/domainbackupxml2xmlout/empty.xml @@ -0,0 +1 @@ +<domainbackup mode='push'/> diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 0d04413712..1376221ef8 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -8,6 +8,7 @@ #include "testutils.h" #include "internal.h" #include "virstring.h" +#include "conf/backup_conf.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -44,6 +45,41 @@ testCompareXMLToXMLHelper(const void *data) } +static int +testCompareBackupXML(const void *data) +{ + const char *testname = data; + g_autofree char *xml_in = NULL; + g_autofree char *file_in = NULL; + g_autofree char *file_out = NULL; + g_autoptr(virDomainBackupDef) backup = NULL; + g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; + g_autofree char *actual = NULL; + + file_in = g_strdup_printf("%s/domainbackupxml2xmlin/%s.xml", + abs_srcdir, testname); + file_out = g_strdup_printf("%s/domainbackupxml2xmlout/%s.xml", + abs_srcdir, testname); + + if (virFileReadAll(file_in, 1024 * 64, &xml_in) < 0) + return -1; + + if (!(backup = virDomainBackupDefParseString(xml_in, xmlopt, 0))) { + VIR_TEST_VERBOSE("failed to parse backup def '%s'", file_in); + return -1; + } + + if (virDomainBackupDefFormat(&buf, backup, false) < 0) { + VIR_TEST_VERBOSE("failed to format backup def '%s'", file_in); + return -1; + } + + actual = virBufferContentAndReset(&buf); + + return virTestCompareToFile(actual, file_out); +} + + static int mymain(void) { @@ -149,6 +185,16 @@ mymain(void) DO_TEST_DIFFERENT("cputune"); +#define DO_TEST_BACKUP(name) \ + if (virTestRun("QEMU BACKUP XML-2-XML " name, testCompareBackupXML, name) < 0) \ + ret = -1; + + DO_TEST_BACKUP("empty"); + DO_TEST_BACKUP("backup-pull"); + DO_TEST_BACKUP("backup-pull-seclabel"); + DO_TEST_BACKUP("backup-push"); + DO_TEST_BACKUP("backup-push-seclabel"); + virObjectUnref(caps); virObjectUnref(xmlopt); diff --git a/tests/virschematest.c b/tests/virschematest.c index 5ae2d207d1..e4a440afb0 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -205,7 +205,8 @@ mymain(void) "genericxml2xmloutdata", "xlconfigdata", "libxlxml2domconfigdata", "qemuhotplugtestdomains"); DO_TEST_DIR("domaincaps.rng", "domaincapsdata"); - DO_TEST_DIR("domainbackup.rng", "domainbackupxml2xmlin"); + DO_TEST_DIR("domainbackup.rng", "domainbackupxml2xmlin", + "domainbackupxml2xmlout"); DO_TEST_DIR("domaincheckpoint.rng", "qemudomaincheckpointxml2xmlin", "qemudomaincheckpointxml2xmlout"); DO_TEST_DIR("domainsnapshot.rng", "qemudomainsnapshotxml2xmlin", -- 2.23.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list