Files
libvirt/tests/networkxml2xmltest.c
T

167 lines
5.1 KiB
C
Raw Normal View History

2009-10-09 08:47:43 -04:00
#include <config.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include "internal.h"
#include "testutils.h"
#include "network_conf.h"
2019-07-14 18:25:12 -04:00
#include "network/bridge_driver.h"
2009-10-09 08:47:43 -04:00
2013-06-07 17:10:28 +02:00
#define VIR_FROM_THIS VIR_FROM_NONE
typedef enum {
TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS,
TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE,
TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT,
TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE,
} testCompareNetXML2XMLResult;
2011-04-25 00:25:10 +02:00
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
unsigned int flags,
testCompareNetXML2XMLResult expectResult)
2011-04-25 00:25:10 +02:00
{
2021-09-04 22:35:15 +02:00
g_autofree char *actual = NULL;
int ret;
2016-04-20 14:36:37 +02:00
testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS;
g_autoptr(virNetworkDef) dev = NULL;
g_autoptr(virNetworkXMLOption) xmlopt = NULL;
2009-10-09 08:47:43 -04:00
2019-07-14 18:25:12 -04:00
if (!(xmlopt = networkDnsmasqCreateXMLConf()))
goto cleanup;
if (!(dev = virNetworkDefParse(NULL, inxml, xmlopt, false))) {
result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE;
goto cleanup;
}
if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE)
goto cleanup;
2009-10-09 08:47:43 -04:00
2019-07-14 18:25:12 -04:00
if (!(actual = virNetworkDefFormat(dev, xmlopt, flags))) {
result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT;
goto cleanup;
}
if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT)
goto cleanup;
2009-10-09 08:47:43 -04:00
if (virTestCompareToFile(actual, outxml) < 0) {
result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE;
goto cleanup;
}
if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE)
goto cleanup;
2009-10-09 08:47:43 -04:00
cleanup:
if (result == expectResult) {
ret = 0;
if (expectResult != TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) {
VIR_TEST_DEBUG("Got expected failure code=%d msg=%s",
result, virGetLastErrorMessage());
}
} else {
ret = -1;
VIR_TEST_DEBUG("Expected result code=%d but received code=%d",
expectResult, result);
}
virResetLastError();
2009-10-09 08:47:43 -04:00
return ret;
}
struct testInfo {
const char *name;
unsigned int flags;
testCompareNetXML2XMLResult expectResult;
};
2011-04-25 00:25:10 +02:00
static int
testCompareXMLToXMLHelper(const void *data)
{
const struct testInfo *info = data;
2011-04-25 00:25:10 +02:00
int result = -1;
2021-09-04 22:35:15 +02:00
g_autofree char *inxml = NULL;
g_autofree char *outxml = NULL;
2011-04-25 00:25:10 +02:00
inxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcdir, info->name);
outxml = g_strdup_printf("%s/networkxml2xmlout/%s.xml", abs_srcdir, info->name);
2011-04-25 00:25:10 +02:00
result = testCompareXMLToXMLFiles(inxml, outxml, info->flags,
info->expectResult);
2009-10-09 08:47:43 -04:00
2011-04-25 00:25:10 +02:00
return result;
}
2009-10-09 08:47:43 -04:00
static int
2011-04-29 10:21:20 -06:00
mymain(void)
2009-10-09 08:47:43 -04:00
{
int ret = 0;
2017-11-03 13:09:47 +01:00
#define DO_TEST_FULL(name, flags, expectResult) \
do { \
const struct testInfo info = {name, flags, expectResult}; \
if (virTestRun("Network XML-2-XML " name, \
testCompareXMLToXMLHelper, &info) < 0) \
ret = -1; \
} while (0)
#define DO_TEST(name) \
DO_TEST_FULL(name, 0, TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS)
#define DO_TEST_FLAGS(name, flags) \
DO_TEST_FULL(name, flags, TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS)
#define DO_TEST_PARSE_ERROR(name) \
DO_TEST_FULL(name, 0, TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE)
2009-10-09 08:47:43 -04:00
2013-02-15 14:02:26 -05:00
DO_TEST("dhcp6host-routed-network");
DO_TEST("empty-allow-ipv6");
2009-10-09 08:47:43 -04:00
DO_TEST("isolated-network");
DO_TEST("routed-network");
DO_TEST("routed-network-no-dns");
DO_TEST_PARSE_ERROR("routed-network-no-dns-extra-elements");
2016-08-10 19:09:55 -04:00
DO_TEST("open-network");
DO_TEST_PARSE_ERROR("open-network-with-forward-dev");
2009-10-09 08:47:43 -04:00
DO_TEST("nat-network");
DO_TEST("netboot-network");
DO_TEST("netboot-proxy-network");
DO_TEST("netboot-tftp");
DO_TEST("nat-network-dns-txt-record");
DO_TEST("nat-network-dns-srv-record");
2013-07-29 17:17:47 +02:00
DO_TEST("nat-network-dns-srv-records");
DO_TEST("nat-network-dns-srv-record-minimal");
DO_TEST("nat-network-dns-hosts");
DO_TEST("nat-network-dns-forward-plain");
2013-09-13 13:31:07 -03:00
DO_TEST("nat-network-dns-forwarders");
DO_TEST("nat-network-dns-forwarder-no-resolv");
DO_TEST("nat-network-forward-nat-ipv6");
DO_TEST("nat-network-forward-nat-address");
DO_TEST("nat-network-forward-nat-no-address");
DO_TEST("nat-network-mtu");
DO_TEST("8021Qbh-net");
DO_TEST("direct-net");
DO_TEST("host-bridge-net");
DO_TEST("vepa-net");
2011-07-22 16:07:28 +02:00
DO_TEST("bandwidth-network");
DO_TEST("openvswitch-net");
DO_TEST_FLAGS("passthrough-pf", VIR_NETWORK_XML_INACTIVE);
DO_TEST("hostdev");
DO_TEST_FLAGS("hostdev-pf", VIR_NETWORK_XML_INACTIVE);
DO_TEST("passthrough-address-crash");
DO_TEST("nat-network-explicit-flood");
DO_TEST("host-bridge-no-flood");
DO_TEST_PARSE_ERROR("hostdev-duplicate");
DO_TEST_PARSE_ERROR("passthrough-duplicate");
DO_TEST("metadata");
DO_TEST("set-mtu");
2019-07-14 18:25:12 -04:00
DO_TEST("dnsmasq-options");
DO_TEST("leasetime-seconds");
DO_TEST("leasetime-minutes");
DO_TEST("leasetime-hours");
DO_TEST("leasetime-infinite");
DO_TEST("isolated-ports");
2009-10-09 08:47:43 -04:00
2014-03-17 10:38:38 +01:00
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
2009-10-09 08:47:43 -04:00
}
VIR_TEST_MAIN(mymain)