libvirt/tests/interfacexml2xmltest.c

102 lines
2.1 KiB
C
Raw Normal View History

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include "internal.h"
#include "testutils.h"
#include "interface_conf.h"
#include "testutilsqemu.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE
static int
testCompareXMLToXMLFiles(const char *xml)
{
char *xmlData = NULL;
char *actual = NULL;
int ret = -1;
virInterfaceDefPtr dev = NULL;
if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (!(dev = virInterfaceDefParseString(xmlData)))
goto fail;
if (!(actual = virInterfaceDefFormat(dev)))
goto fail;
if (STRNEQ(xmlData, actual)) {
virtTestDifference(stderr, xmlData, actual);
goto fail;
}
ret = 0;
fail:
VIR_FREE(xmlData);
VIR_FREE(actual);
virInterfaceDefFree(dev);
return ret;
}
static int
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
char *xml = NULL;
if (virAsprintf(&xml, "%s/interfaceschemadata/%s.xml",
abs_srcdir, (const char*)data) < 0)
return -1;
result = testCompareXMLToXMLFiles(xml);
VIR_FREE(xml);
return result;
}
static int
tests: simplify common setup A few of the tests were missing basic sanity checks, while most of them were doing copy-and-paste initialization (in fact, some of them pasted the argc > 1 check more than once!). It's much nicer to do things in one common place, and minimizes the size of the next patch that fixes getcwd usage. * tests/testutils.h (EXIT_AM_HARDFAIL): New define. (progname, abs_srcdir): Define for all tests. (VIRT_TEST_MAIN): Change callback signature. * tests/testutils.c (virtTestMain): Do more common init. * tests/commandtest.c (mymain): Simplify. * tests/cputest.c (mymain): Likewise. * tests/esxutilstest.c (mymain): Likewise. * tests/eventtest.c (mymain): Likewise. * tests/hashtest.c (mymain): Likewise. * tests/networkxml2xmltest.c (mymain): Likewise. * tests/nodedevxml2xmltest.c (myname): Likewise. * tests/nodeinfotest.c (mymain): Likewise. * tests/nwfilterxml2xmltest.c (mymain): Likewise. * tests/qemuargv2xmltest.c (mymain): Likewise. * tests/qemuhelptest.c (mymain): Likewise. * tests/qemuxml2argvtest.c (mymain): Likewise. * tests/qemuxml2xmltest.c (mymain): Likewise. * tests/qparamtest.c (mymain): Likewise. * tests/sexpr2xmltest.c (mymain): Likewise. * tests/sockettest.c (mymain): Likewise. * tests/statstest.c (mymain): Likewise. * tests/storagepoolxml2xmltest.c (mymain): Likewise. * tests/storagevolxml2xmltest.c (mymain): Likewise. * tests/virbuftest.c (mymain): Likewise. * tests/virshtest.c (mymain): Likewise. * tests/vmx2xmltest.c (mymain): Likewise. * tests/xencapstest.c (mymain): Likewise. * tests/xmconfigtest.c (mymain): Likewise. * tests/xml2sexprtest.c (mymain): Likewise. * tests/xml2vmxtest.c (mymain): Likewise.
2011-04-29 16:21:20 +00:00
mymain(void)
{
int ret = 0;
#define DO_TEST(name) \
if (virtTestRun("Interface XML-2-XML " name, \
testCompareXMLToXMLHelper, (name)) < 0) \
ret = -1
DO_TEST("ethernet-dhcp");
DO_TEST("ethernet-dhcp-and-multi-static");
DO_TEST("ethernet-static");
DO_TEST("ethernet-static-no-prefix");
DO_TEST("bridge");
DO_TEST("bridge42");
DO_TEST("bridge-bond");
DO_TEST("bridge-empty");
DO_TEST("bridge-no-address");
DO_TEST("bridge-vlan");
DO_TEST("bridge-no-address");
DO_TEST("vlan");
DO_TEST("bond");
DO_TEST("bond-arp");
DO_TEST("ipv6-autoconf-dhcp");
DO_TEST("ipv6-autoconf");
DO_TEST("ipv6-dhcp");
DO_TEST("ipv6-local");
DO_TEST("ipv6-static-multi");
DO_TEST("ipv6-static");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
VIRT_TEST_MAIN(mymain)