snapshot: test domainsnapshot indentation

Add a test for the simple parts of my indentation changes, and
fix the fallout.

* tests/domainsnapshotxml2xmltest.c: New test.
* tests/Makefile.am (domainsnapshotxml2xmltest_SOURCES): Build it.
* src/conf/domain_conf.c (virDomainSnapshotDefFormat): Avoid NULL
deref, match documented order.
* src/conf/domain_conf.h (virDomainSnapshotDefFormat): Add const.
* tests/domainsnapshotxml2xmlout/all_parameters.xml: Tweak output.
* tests/domainsnapshotxml2xmlout/disk_snapshot.xml: Likewise.
* tests/domainsnapshotxml2xmlout/full_domain.xml: Likewise.
* .gitignore: Exempt new binary.
This commit is contained in:
Eric Blake 2011-09-22 14:29:00 -06:00
parent 9cba392768
commit 27b3b303d9
8 changed files with 225 additions and 88 deletions

1
.gitignore vendored
View File

@ -69,6 +69,7 @@
/src/util/virkeymaps.h /src/util/virkeymaps.h
/tests/*.log /tests/*.log
/tests/cputest /tests/cputest
/tests/domainsnapshotxml2xmltest
/tests/hashtest /tests/hashtest
/tests/jsontest /tests/jsontest
/tests/networkxml2argvtest /tests/networkxml2argvtest

View File

@ -12020,7 +12020,7 @@ cleanup:
return ret; return ret;
} }
char *virDomainSnapshotDefFormat(char *domain_uuid, char *virDomainSnapshotDefFormat(const char *domain_uuid,
virDomainSnapshotDefPtr def, virDomainSnapshotDefPtr def,
unsigned int flags, unsigned int flags,
int internal) int internal)
@ -12061,12 +12061,12 @@ char *virDomainSnapshotDefFormat(char *domain_uuid,
virDomainDiskSnapshotTypeToString(disk->snapshot)); virDomainDiskSnapshotTypeToString(disk->snapshot));
if (disk->file || disk->driverType) { if (disk->file || disk->driverType) {
virBufferAddLit(&buf, ">\n"); virBufferAddLit(&buf, ">\n");
if (disk->file)
virBufferEscapeString(&buf, " <source file='%s'/>\n",
disk->file);
if (disk->driverType) if (disk->driverType)
virBufferEscapeString(&buf, " <driver type='%s'/>\n", virBufferEscapeString(&buf, " <driver type='%s'/>\n",
disk->driverType); disk->driverType);
if (disk->file)
virBufferEscapeString(&buf, " <source file='%s'/>\n",
disk->file);
virBufferAddLit(&buf, " </disk>\n"); virBufferAddLit(&buf, " </disk>\n");
} else { } else {
virBufferAddLit(&buf, "/>\n"); virBufferAddLit(&buf, "/>\n");
@ -12081,7 +12081,7 @@ char *virDomainSnapshotDefFormat(char *domain_uuid,
return NULL; return NULL;
} }
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
} else { } else if (domain_uuid) {
virBufferAddLit(&buf, " <domain>\n"); virBufferAddLit(&buf, " <domain>\n");
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", domain_uuid); virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", domain_uuid);
virBufferAddLit(&buf, " </domain>\n"); virBufferAddLit(&buf, " </domain>\n");

View File

@ -1498,7 +1498,7 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
unsigned int expectedVirtTypes, unsigned int expectedVirtTypes,
unsigned int flags); unsigned int flags);
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def); void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
char *virDomainSnapshotDefFormat(char *domain_uuid, char *virDomainSnapshotDefFormat(const char *domain_uuid,
virDomainSnapshotDefPtr def, virDomainSnapshotDefPtr def,
unsigned int flags, unsigned int flags,
int internal); int internal);

View File

@ -109,7 +109,8 @@ check_PROGRAMS += xml2sexprtest sexpr2xmltest \
xmconfigtest xencapstest statstest reconnect xmconfigtest xencapstest statstest reconnect
endif endif
if WITH_QEMU if WITH_QEMU
check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest qemuargv2xmltest qemuhelptest check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest
endif endif
if WITH_OPENVZ if WITH_OPENVZ
@ -234,8 +235,8 @@ TESTS += xml2sexprtest \
endif endif
if WITH_QEMU if WITH_QEMU
TESTS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest qemuargv2xmltest qemuhelptest TESTS += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest qemuargv2xmltest \
TESTS += nwfilterxml2xmltest qemuhelptest domainsnapshotxml2xmltest nwfilterxml2xmltest
endif endif
if WITH_OPENVZ if WITH_OPENVZ
@ -362,8 +363,15 @@ qemuargv2xmltest_LDADD = $(qemu_LDADDS) $(LDADDS)
qemuhelptest_SOURCES = qemuhelptest.c testutils.c testutils.h qemuhelptest_SOURCES = qemuhelptest.c testutils.c testutils.h
qemuhelptest_LDADD = $(qemu_LDADDS) $(LDADDS) qemuhelptest_LDADD = $(qemu_LDADDS) $(LDADDS)
domainsnapshotxml2xmltest_SOURCES = \
domainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \
testutils.c testutils.h
domainsnapshotxml2xmltest_LDADD = $(qemu_LDADDS) $(LDADDS)
else else
EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuxmlnstest.c qemuargv2xmltest.c qemuhelptest.c testutilsqemu.c testutilsqemu.h EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
qemuxmlnstest.c qemuhelptest.c domainsnapshotxml2xmltest.c \
testutilsqemu.c testutilsqemu.h
endif endif
if WITH_OPENVZ if WITH_OPENVZ

View File

@ -1,10 +1,10 @@
<domainsnapshot> <domainsnapshot>
<name>my snap name</name> <name>my snap name</name>
<description>!@#$%^</description> <description>!@#$%^</description>
<state>running</state>
<parent> <parent>
<name>earlier_snap</name> <name>earlier_snap</name>
</parent> </parent>
<state>running</state>
<creationTime>1272917631</creationTime> <creationTime>1272917631</creationTime>
<domain> <domain>
<uuid>9d37b878-a7cc-9f9a-b78f-49b3abad25a8</uuid> <uuid>9d37b878-a7cc-9f9a-b78f-49b3abad25a8</uuid>

View File

@ -1,10 +1,10 @@
<domainsnapshot> <domainsnapshot>
<name>my snap name</name> <name>my snap name</name>
<description>!@#$%^</description> <description>!@#$%^</description>
<state>disk-snapshot</state>
<parent> <parent>
<name>earlier_snap</name> <name>earlier_snap</name>
</parent> </parent>
<state>disk-snapshot</state>
<creationTime>1272917631</creationTime> <creationTime>1272917631</creationTime>
<disks> <disks>
<disk name='hda' snapshot='no'/> <disk name='hda' snapshot='no'/>
@ -23,55 +23,55 @@
<source file='/path/to/generated5'/> <source file='/path/to/generated5'/>
</disk> </disk>
</disks> </disks>
<domain type='qemu'> <domain type='qemu'>
<name>QEMUGuest1</name> <name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory>219100</memory> <memory>219100</memory>
<currentMemory>219100</currentMemory> <currentMemory>219100</currentMemory>
<vcpu cpuset='1-4,8-20,525'>1</vcpu> <vcpu cpuset='1-4,8-20,525'>1</vcpu>
<os> <os>
<type arch='i686' machine='pc'>hvm</type> <type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/> <boot dev='hd'/>
</os> </os>
<clock offset='utc'/> <clock offset='utc'/>
<on_poweroff>destroy</on_poweroff> <on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/bin/qemu</emulator> <emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'> <disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/> <source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/> <target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/> <address type='drive' controller='0' bus='0' unit='0'/>
</disk> </disk>
<disk type='block' device='disk'> <disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest2'/> <source dev='/dev/HostVG/QEMUGuest2'/>
<target dev='hdb' bus='ide'/> <target dev='hdb' bus='ide'/>
<address type='drive' controller='0' bus='1' unit='0'/> <address type='drive' controller='0' bus='1' unit='0'/>
</disk> </disk>
<disk type='block' device='disk'> <disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest3'/> <source dev='/dev/HostVG/QEMUGuest3'/>
<target dev='hdc' bus='ide'/> <target dev='hdc' bus='ide'/>
<address type='drive' controller='0' bus='2' unit='0'/> <address type='drive' controller='0' bus='2' unit='0'/>
</disk> </disk>
<disk type='block' device='disk'> <disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest4'/> <source dev='/dev/HostVG/QEMUGuest4'/>
<target dev='hdd' bus='ide'/> <target dev='hdd' bus='ide'/>
<address type='drive' controller='0' bus='3' unit='0'/> <address type='drive' controller='0' bus='3' unit='0'/>
</disk> </disk>
<disk type='block' device='disk'> <disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest5'/> <source dev='/dev/HostVG/QEMUGuest5'/>
<target dev='hde' bus='ide'/> <target dev='hde' bus='ide'/>
<address type='drive' controller='0' bus='4' unit='0'/> <address type='drive' controller='0' bus='4' unit='0'/>
</disk> </disk>
<disk type='block' device='disk'> <disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest6'/> <source dev='/dev/HostVG/QEMUGuest6'/>
<target dev='hdf' bus='ide'/> <target dev='hdf' bus='ide'/>
<address type='drive' controller='0' bus='5' unit='0'/> <address type='drive' controller='0' bus='5' unit='0'/>
</disk> </disk>
<controller type='ide' index='0'/> <controller type='ide' index='0'/>
<memballoon model='virtio'/> <memballoon model='virtio'/>
</devices> </devices>
</domain> </domain>
<active>1</active> <active>1</active>
</domainsnapshot> </domainsnapshot>

View File

@ -1,35 +1,35 @@
<domainsnapshot> <domainsnapshot>
<name>my snap name</name> <name>my snap name</name>
<description>!@#$%^</description> <description>!@#$%^</description>
<state>running</state>
<parent> <parent>
<name>earlier_snap</name> <name>earlier_snap</name>
</parent> </parent>
<state>running</state>
<creationTime>1272917631</creationTime> <creationTime>1272917631</creationTime>
<domain type='qemu'> <domain type='qemu'>
<name>QEMUGuest1</name> <name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory>219100</memory> <memory>219100</memory>
<currentMemory>219100</currentMemory> <currentMemory>219100</currentMemory>
<vcpu cpuset='1-4,8-20,525'>1</vcpu> <vcpu cpuset='1-4,8-20,525'>1</vcpu>
<os> <os>
<type arch='i686' machine='pc'>hvm</type> <type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/> <boot dev='hd'/>
</os> </os>
<clock offset='utc'/> <clock offset='utc'/>
<on_poweroff>destroy</on_poweroff> <on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/bin/qemu</emulator> <emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'> <disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/> <source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/> <target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/> <address type='drive' controller='0' bus='0' unit='0'/>
</disk> </disk>
<controller type='ide' index='0'/> <controller type='ide' index='0'/>
<memballoon model='virtio'/> <memballoon model='virtio'/>
</devices> </devices>
</domain> </domain>
<active>1</active> <active>1</active>
</domainsnapshot> </domainsnapshot>

View File

@ -0,0 +1,128 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#ifdef WITH_QEMU
# include "internal.h"
# include "testutils.h"
# include "qemu/qemu_conf.h"
# include "qemu/qemu_domain.h"
# include "testutilsqemu.h"
static struct qemud_driver driver;
static int
testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
{
char *inXmlData = NULL;
char *actual = NULL;
int ret = -1;
virDomainSnapshotDefPtr def = NULL;
unsigned int flags = (VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE |
VIR_DOMAIN_SNAPSHOT_PARSE_DISKS);
if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
if (internal)
flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.caps,
QEMU_EXPECTED_VIRT_TYPES,
flags)))
goto fail;
if (!(actual = virDomainSnapshotDefFormat(uuid, def,
VIR_DOMAIN_XML_SECURE,
internal)))
goto fail;
if (STRNEQ(inXmlData, actual)) {
virtTestDifference(stderr, inXmlData, actual);
goto fail;
}
ret = 0;
fail:
free(inXmlData);
free(actual);
virDomainSnapshotDefFree(def);
return ret;
}
struct testInfo {
const char *name;
const char *uuid;
int internal;
};
static int
testCompareXMLToXMLHelper(const void *data)
{
const struct testInfo *info = data;
char *xml_in = NULL;
int ret = -1;
if (virAsprintf(&xml_in, "%s/domainsnapshotxml2xmlout/%s.xml",
abs_srcdir, info->name) < 0)
goto cleanup;
ret = testCompareXMLToXMLFiles(xml_in, info->uuid, info->internal);
cleanup:
free(xml_in);
return ret;
}
static int
mymain(void)
{
int ret = 0;
if ((driver.caps = testQemuCapsInit()) == NULL)
return (EXIT_FAILURE);
# define DO_TEST(name, uuid, internal) \
do { \
const struct testInfo info = {name, uuid, internal}; \
if (virtTestRun("SNAPSHOT XML-2-XML " name, \
1, testCompareXMLToXMLHelper, &info) < 0) \
ret = -1; \
} while (0)
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
* values for these envvars */
setenv("PATH", "/bin", 1);
DO_TEST("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 1);
DO_TEST("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
DO_TEST("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
DO_TEST("noparent_nodescription_noactive", NULL, 0);
DO_TEST("noparent_nodescription", NULL, 1);
DO_TEST("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
virCapabilitiesFree(driver.caps);
return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
VIRT_TEST_MAIN(mymain)
#else
int
main(void)
{
return EXIT_AM_SKIP;
}
#endif /* WITH_QEMU */