backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / networkxml2conftest.c
blobdcb99aad6e7515060e409328a874aadfd0a8e39f
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 "vircommand.h"
12 #include "viralloc.h"
13 #include "network/bridge_driver.h"
14 #include "virstring.h"
16 #define VIR_FROM_THIS VIR_FROM_NONE
18 static int
19 testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps)
21 char *actual = NULL;
22 int ret = -1;
23 virNetworkDefPtr def = NULL;
24 virNetworkObjPtr obj = NULL;
25 virCommandPtr cmd = NULL;
26 char *pidfile = NULL;
27 dnsmasqContext *dctx = NULL;
28 virNetworkXMLOptionPtr xmlopt = NULL;
30 if (!(xmlopt = networkDnsmasqCreateXMLConf()))
31 goto fail;
33 if (!(def = virNetworkDefParseFile(inxml, xmlopt)))
34 goto fail;
36 if (!(obj = virNetworkObjNew()))
37 goto fail;
39 virNetworkObjSetDef(obj, def);
41 dctx = dnsmasqContextNew(def->name, "/var/lib/libvirt/dnsmasq");
43 if (dctx == NULL)
44 goto fail;
46 if (networkDnsmasqConfContents(obj, pidfile, &actual, dctx, caps) < 0)
47 goto fail;
49 /* Any changes to this function ^^ should be reflected here too. */
50 #ifndef __linux__
51 char * tmp;
53 if (!(tmp = virStringReplace(actual,
54 "except-interface=lo0\n",
55 "except-interface=lo\n")))
56 goto fail;
57 VIR_FREE(actual);
58 VIR_STEAL_PTR(actual, tmp);
59 #endif
61 if (virTestCompareToFile(actual, outconf) < 0)
62 goto fail;
64 ret = 0;
66 fail:
67 VIR_FREE(actual);
68 VIR_FREE(pidfile);
69 virCommandFree(cmd);
70 virObjectUnref(xmlopt);
71 virNetworkObjEndAPI(&obj);
72 dnsmasqContextFree(dctx);
73 return ret;
76 typedef struct {
77 const char *name;
78 dnsmasqCapsPtr caps;
79 } testInfo;
81 static int
82 testCompareXMLToConfHelper(const void *data)
84 int result = -1;
85 const testInfo *info = data;
86 char *inxml = NULL;
87 char *outconf = NULL;
89 if (virAsprintf(&inxml, "%s/networkxml2confdata/%s.xml",
90 abs_srcdir, info->name) < 0 ||
91 virAsprintf(&outconf, "%s/networkxml2confdata/%s.conf",
92 abs_srcdir, info->name) < 0) {
93 goto cleanup;
96 result = testCompareXMLToConfFiles(inxml, outconf, info->caps);
98 cleanup:
99 VIR_FREE(inxml);
100 VIR_FREE(outconf);
102 return result;
105 static int
106 mymain(void)
108 int ret = 0;
109 dnsmasqCapsPtr restricted
110 = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.48", DNSMASQ);
111 dnsmasqCapsPtr full
112 = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.63\n--bind-dynamic", DNSMASQ);
113 dnsmasqCapsPtr dhcpv6
114 = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.64\n--bind-dynamic", DNSMASQ);
116 #define DO_TEST(xname, xcaps) \
117 do { \
118 static testInfo info; \
120 info.name = xname; \
121 info.caps = xcaps; \
122 if (virTestRun("Network XML-2-Conf " xname, \
123 testCompareXMLToConfHelper, &info) < 0) { \
124 ret = -1; \
126 } while (0)
128 DO_TEST("isolated-network", restricted);
129 DO_TEST("netboot-network", restricted);
130 DO_TEST("netboot-proxy-network", restricted);
131 DO_TEST("nat-network-dns-srv-record-minimal", restricted);
132 DO_TEST("nat-network-name-with-quotes", restricted);
133 DO_TEST("routed-network", full);
134 DO_TEST("routed-network-no-dns", full);
135 DO_TEST("open-network", full);
136 DO_TEST("nat-network", dhcpv6);
137 DO_TEST("nat-network-dns-txt-record", full);
138 DO_TEST("nat-network-dns-srv-record", full);
139 DO_TEST("nat-network-dns-hosts", full);
140 DO_TEST("nat-network-dns-forward-plain", full);
141 DO_TEST("nat-network-dns-forwarders", full);
142 DO_TEST("nat-network-dns-forwarder-no-resolv", full);
143 DO_TEST("nat-network-dns-local-domain", full);
144 DO_TEST("nat-network-mtu", dhcpv6);
145 DO_TEST("dhcp6-network", dhcpv6);
146 DO_TEST("dhcp6-nat-network", dhcpv6);
147 DO_TEST("dhcp6host-routed-network", dhcpv6);
148 DO_TEST("ptr-domains-auto", dhcpv6);
149 DO_TEST("dnsmasq-options", dhcpv6);
151 virObjectUnref(dhcpv6);
152 virObjectUnref(full);
153 virObjectUnref(restricted);
155 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
158 VIR_TEST_MAIN(mymain)