10 #include "network_conf.h"
11 #include "network/bridge_driver.h"
13 #define VIR_FROM_THIS VIR_FROM_NONE
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
;
23 testCompareXMLToXMLFiles(const char *inxml
, const char *outxml
,
25 testCompareNetXML2XMLResult expectResult
)
27 g_autofree
char *actual
= NULL
;
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()))
36 if (!(dev
= virNetworkDefParse(NULL
, inxml
, xmlopt
, false))) {
37 result
= TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE
;
40 if (expectResult
== TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE
)
43 if (!(actual
= virNetworkDefFormat(dev
, xmlopt
, flags
))) {
44 result
= TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT
;
47 if (expectResult
== TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT
)
50 if (virTestCompareToFile(actual
, outxml
) < 0) {
51 result
= TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE
;
54 if (expectResult
== TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE
)
58 if (result
== expectResult
) {
60 if (expectResult
!= TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS
) {
61 VIR_TEST_DEBUG("Got expected failure code=%d msg=%s",
62 result
, virGetLastErrorMessage());
66 VIR_TEST_DEBUG("Expected result code=%d but received code=%d",
67 expectResult
, result
);
77 testCompareNetXML2XMLResult expectResult
;
81 testCompareXMLToXMLHelper(const void *data
)
83 const struct testInfo
*info
= data
;
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
,
102 #define DO_TEST_FULL(name, flags, expectResult) \
104 const struct testInfo info = {name, flags, expectResult}; \
105 if (virTestRun("Network XML-2-XML " name, \
106 testCompareXMLToXMLHelper, &info) < 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");
144 DO_TEST("bandwidth-network");
145 DO_TEST("openvswitch-net");
146 DO_TEST_FLAGS("passthrough-pf", VIR_NETWORK_XML_INACTIVE
);
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");
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
)