remote: add sysusers file to create 'libvirt' group
[libvirt.git] / tests / networkxml2xmltest.c
blob0783d84915a95fa7bcae38ecac9017931344ae89
1 #include <config.h>
3 #include <unistd.h>
5 #include <sys/types.h>
6 #include <fcntl.h>
8 #include "internal.h"
9 #include "testutils.h"
10 #include "network_conf.h"
11 #include "network/bridge_driver.h"
13 #define VIR_FROM_THIS VIR_FROM_NONE
15 typedef enum {
16 TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS,
17 TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE,
18 TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT,
19 TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE,
20 } testCompareNetXML2XMLResult;
22 static int
23 testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
24 unsigned int flags,
25 testCompareNetXML2XMLResult expectResult)
27 g_autofree char *actual = NULL;
28 int ret;
29 testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS;
30 g_autoptr(virNetworkDef) dev = NULL;
31 g_autoptr(virNetworkXMLOption) xmlopt = NULL;
33 if (!(xmlopt = networkDnsmasqCreateXMLConf()))
34 goto cleanup;
36 if (!(dev = virNetworkDefParse(NULL, inxml, xmlopt, false))) {
37 result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE;
38 goto cleanup;
40 if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE)
41 goto cleanup;
43 if (!(actual = virNetworkDefFormat(dev, xmlopt, flags))) {
44 result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT;
45 goto cleanup;
47 if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT)
48 goto cleanup;
50 if (virTestCompareToFile(actual, outxml) < 0) {
51 result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE;
52 goto cleanup;
54 if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE)
55 goto cleanup;
57 cleanup:
58 if (result == expectResult) {
59 ret = 0;
60 if (expectResult != TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) {
61 VIR_TEST_DEBUG("Got expected failure code=%d msg=%s",
62 result, virGetLastErrorMessage());
64 } else {
65 ret = -1;
66 VIR_TEST_DEBUG("Expected result code=%d but received code=%d",
67 expectResult, result);
69 virResetLastError();
71 return ret;
74 struct testInfo {
75 const char *name;
76 unsigned int flags;
77 testCompareNetXML2XMLResult expectResult;
80 static int
81 testCompareXMLToXMLHelper(const void *data)
83 const struct testInfo *info = data;
84 int result = -1;
85 g_autofree char *inxml = NULL;
86 g_autofree char *outxml = NULL;
88 inxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcdir, info->name);
89 outxml = g_strdup_printf("%s/networkxml2xmlout/%s.xml", abs_srcdir, info->name);
91 result = testCompareXMLToXMLFiles(inxml, outxml, info->flags,
92 info->expectResult);
94 return result;
97 static int
98 mymain(void)
100 int ret = 0;
102 #define DO_TEST_FULL(name, flags, expectResult) \
103 do { \
104 const struct testInfo info = {name, flags, expectResult}; \
105 if (virTestRun("Network XML-2-XML " name, \
106 testCompareXMLToXMLHelper, &info) < 0) \
107 ret = -1; \
108 } while (0)
109 #define DO_TEST(name) \
110 DO_TEST_FULL(name, 0, TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS)
111 #define DO_TEST_FLAGS(name, flags) \
112 DO_TEST_FULL(name, flags, TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS)
113 #define DO_TEST_PARSE_ERROR(name) \
114 DO_TEST_FULL(name, 0, TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE)
116 DO_TEST("dhcp6host-routed-network");
117 DO_TEST("empty-allow-ipv6");
118 DO_TEST("isolated-network");
119 DO_TEST("routed-network");
120 DO_TEST("routed-network-no-dns");
121 DO_TEST_PARSE_ERROR("routed-network-no-dns-extra-elements");
122 DO_TEST("open-network");
123 DO_TEST_PARSE_ERROR("open-network-with-forward-dev");
124 DO_TEST("nat-network");
125 DO_TEST("netboot-network");
126 DO_TEST("netboot-proxy-network");
127 DO_TEST("netboot-tftp");
128 DO_TEST("nat-network-dns-txt-record");
129 DO_TEST("nat-network-dns-srv-record");
130 DO_TEST("nat-network-dns-srv-records");
131 DO_TEST("nat-network-dns-srv-record-minimal");
132 DO_TEST("nat-network-dns-hosts");
133 DO_TEST("nat-network-dns-forward-plain");
134 DO_TEST("nat-network-dns-forwarders");
135 DO_TEST("nat-network-dns-forwarder-no-resolv");
136 DO_TEST("nat-network-forward-nat-ipv6");
137 DO_TEST("nat-network-forward-nat-address");
138 DO_TEST("nat-network-forward-nat-no-address");
139 DO_TEST("nat-network-mtu");
140 DO_TEST("8021Qbh-net");
141 DO_TEST("direct-net");
142 DO_TEST("host-bridge-net");
143 DO_TEST("vepa-net");
144 DO_TEST("bandwidth-network");
145 DO_TEST("openvswitch-net");
146 DO_TEST_FLAGS("passthrough-pf", VIR_NETWORK_XML_INACTIVE);
147 DO_TEST("hostdev");
148 DO_TEST_FLAGS("hostdev-pf", VIR_NETWORK_XML_INACTIVE);
149 DO_TEST_FLAGS("hostdev-pf-driver-model", VIR_NETWORK_XML_INACTIVE);
151 DO_TEST("passthrough-address-crash");
152 DO_TEST("nat-network-explicit-flood");
153 DO_TEST("host-bridge-no-flood");
154 DO_TEST_PARSE_ERROR("hostdev-duplicate");
155 DO_TEST_PARSE_ERROR("passthrough-duplicate");
156 DO_TEST("metadata");
157 DO_TEST("set-mtu");
158 DO_TEST("dnsmasq-options");
159 DO_TEST("leasetime-seconds");
160 DO_TEST("leasetime-minutes");
161 DO_TEST("leasetime-hours");
162 DO_TEST("leasetime-infinite");
163 DO_TEST("isolated-ports");
165 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
168 VIR_TEST_MAIN(mymain)