From: Michal Privoznik Date: Tue, 27 Jan 2026 21:08:18 +0000 (+0100) Subject: test: wire up networkValidateTests() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecb2e06bdf85ea174c32f89a996aad9a344dd3ad;p=thirdparty%2Flibvirt.git test: wire up networkValidateTests() Our network driver calls networkValidate() right after a network XML is parsed. This is similar to domain validation step when parsing domain XML. But it's not that convoluted in network driver. Regardless, any network related test should mimic real life scenario as close as possible and thus networkValidateTests() should be called right after domain XML is parsed. Now, networkValidate() might query sysfs wrt to PCI devices and thus tests must start using virpcimock. The function will also generate random MAC addresses, if needed, hence virrandommock. With this change, passthrough-pf and passthrough-address-crash test cases of networkxml2xmltest started failing but looking at corresponding XMLs those test cases were designed to test just XML parsing. They were never designed to showcase a "real" network XML. So mark them as expected fail. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/tests/networkxml2confdata/leasetime-hours.xml b/tests/networkxml2confdata/leasetime-hours.xml index 5c8bec8328..3824d42368 100644 --- a/tests/networkxml2confdata/leasetime-hours.xml +++ b/tests/networkxml2confdata/leasetime-hours.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2confdata/leasetime-infinite.xml b/tests/networkxml2confdata/leasetime-infinite.xml index a5a9e6c5ed..24df80d5e3 100644 --- a/tests/networkxml2confdata/leasetime-infinite.xml +++ b/tests/networkxml2confdata/leasetime-infinite.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2confdata/leasetime-minutes.xml b/tests/networkxml2confdata/leasetime-minutes.xml index 1cbc285685..99956edc51 100644 --- a/tests/networkxml2confdata/leasetime-minutes.xml +++ b/tests/networkxml2confdata/leasetime-minutes.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2confdata/leasetime-seconds.xml b/tests/networkxml2confdata/leasetime-seconds.xml index 9d8efc2608..76bd7909b8 100644 --- a/tests/networkxml2confdata/leasetime-seconds.xml +++ b/tests/networkxml2confdata/leasetime-seconds.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2confdata/netboot-tftp.xml b/tests/networkxml2confdata/netboot-tftp.xml index 297f5a7ba1..9d5d57bae4 100644 --- a/tests/networkxml2confdata/netboot-tftp.xml +++ b/tests/networkxml2confdata/netboot-tftp.xml @@ -3,6 +3,7 @@ eb486e5c-4df5-42ee-ae4a-ad8557998d00 + diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 59ab3a402b..67856f2e8c 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -36,6 +36,9 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, if (!(def = virNetworkDefParse(NULL, inxml, xmlopt, false))) goto fail; + if (networkValidateTests(def) < 0) + goto fail; + if (!(obj = virNetworkObjNew())) goto fail; @@ -203,4 +206,6 @@ mymain(void) } VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("virpci"), + VIR_TEST_MOCK("virrandom"), VIR_TEST_MOCK("virdnsmasq")) diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c index e32f1b281e..0febae9ebc 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -27,6 +27,8 @@ # include +# define LIBVIRT_BRIDGE_DRIVER_PRIV_H_ALLOW +# include "bridge_driver_priv.h" # include "bridge_driver_platform.h" # include "virbuffer.h" # include "virmock.h" @@ -106,6 +108,9 @@ static int testCompareXMLToArgvFiles(const char *xml, if (!(def = virNetworkDefParse(NULL, xml, NULL, false))) return -1; + if (networkValidateTests(def) < 0) + return -1; + if (networkAddFirewallRules(def, backend, NULL) < 0) return -1; @@ -213,7 +218,10 @@ mymain(void) * virGDBusIsServiceRegistered(). */ -VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virgdbus"), +VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("virpci"), + VIR_TEST_MOCK("virrandom"), + VIR_TEST_MOCK("virgdbus"), VIR_TEST_MOCK("virfirewall")) #else /* ! defined (__linux__) */ diff --git a/tests/networkxml2xmlout/dnsmasq-options.xml b/tests/networkxml2xmlout/dnsmasq-options.xml index 856a018f25..97911eb65e 100644 --- a/tests/networkxml2xmlout/dnsmasq-options.xml +++ b/tests/networkxml2xmlout/dnsmasq-options.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-dns-forward-plain.xml b/tests/networkxml2xmlout/nat-network-dns-forward-plain.xml index 7522f6ae1c..76e0f926a9 100644 --- a/tests/networkxml2xmlout/nat-network-dns-forward-plain.xml +++ b/tests/networkxml2xmlout/nat-network-dns-forward-plain.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-dns-forwarder-no-resolv.xml b/tests/networkxml2xmlout/nat-network-dns-forwarder-no-resolv.xml index 9661ce561e..ab2800331c 100644 --- a/tests/networkxml2xmlout/nat-network-dns-forwarder-no-resolv.xml +++ b/tests/networkxml2xmlout/nat-network-dns-forwarder-no-resolv.xml @@ -3,6 +3,7 @@ 81ff0d90-c91e-6742-64da-4a736edb9a9c + diff --git a/tests/networkxml2xmlout/nat-network-dns-forwarders.xml b/tests/networkxml2xmlout/nat-network-dns-forwarders.xml index e03912750c..170b043d09 100644 --- a/tests/networkxml2xmlout/nat-network-dns-forwarders.xml +++ b/tests/networkxml2xmlout/nat-network-dns-forwarders.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-dns-hosts.xml b/tests/networkxml2xmlout/nat-network-dns-hosts.xml index 86832af518..548282e514 100644 --- a/tests/networkxml2xmlout/nat-network-dns-hosts.xml +++ b/tests/networkxml2xmlout/nat-network-dns-hosts.xml @@ -5,6 +5,7 @@ + pudding diff --git a/tests/networkxml2xmlout/nat-network-dns-srv-record-minimal.xml b/tests/networkxml2xmlout/nat-network-dns-srv-record-minimal.xml index a18afae2fd..50e968be9d 100644 --- a/tests/networkxml2xmlout/nat-network-dns-srv-record-minimal.xml +++ b/tests/networkxml2xmlout/nat-network-dns-srv-record-minimal.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-dns-srv-record.xml b/tests/networkxml2xmlout/nat-network-dns-srv-record.xml index 3dd19e6698..1486fc3224 100644 --- a/tests/networkxml2xmlout/nat-network-dns-srv-record.xml +++ b/tests/networkxml2xmlout/nat-network-dns-srv-record.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-dns-srv-records.xml b/tests/networkxml2xmlout/nat-network-dns-srv-records.xml index eda9e20333..26b802e1eb 100644 --- a/tests/networkxml2xmlout/nat-network-dns-srv-records.xml +++ b/tests/networkxml2xmlout/nat-network-dns-srv-records.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-dns-txt-record.xml b/tests/networkxml2xmlout/nat-network-dns-txt-record.xml index a4590119ef..cba7e9d1f8 100644 --- a/tests/networkxml2xmlout/nat-network-dns-txt-record.xml +++ b/tests/networkxml2xmlout/nat-network-dns-txt-record.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-explicit-flood.xml b/tests/networkxml2xmlout/nat-network-explicit-flood.xml index 305c3b7d98..c039955543 100644 --- a/tests/networkxml2xmlout/nat-network-explicit-flood.xml +++ b/tests/networkxml2xmlout/nat-network-explicit-flood.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-forward-nat-address.xml b/tests/networkxml2xmlout/nat-network-forward-nat-address.xml index faeba24706..e3276ac338 100644 --- a/tests/networkxml2xmlout/nat-network-forward-nat-address.xml +++ b/tests/networkxml2xmlout/nat-network-forward-nat-address.xml @@ -9,6 +9,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-forward-nat-ipv6.xml b/tests/networkxml2xmlout/nat-network-forward-nat-ipv6.xml index cfec391ee2..642929cc8d 100644 --- a/tests/networkxml2xmlout/nat-network-forward-nat-ipv6.xml +++ b/tests/networkxml2xmlout/nat-network-forward-nat-ipv6.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml b/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml index f19e34deec..77fc0b5324 100644 --- a/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml +++ b/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml @@ -8,6 +8,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network-mtu.xml b/tests/networkxml2xmlout/nat-network-mtu.xml index 715bc1b505..97044c70ec 100644 --- a/tests/networkxml2xmlout/nat-network-mtu.xml +++ b/tests/networkxml2xmlout/nat-network-mtu.xml @@ -6,6 +6,7 @@ + diff --git a/tests/networkxml2xmlout/nat-network.xml b/tests/networkxml2xmlout/nat-network.xml index 93bc7db51d..9d3757f0e0 100644 --- a/tests/networkxml2xmlout/nat-network.xml +++ b/tests/networkxml2xmlout/nat-network.xml @@ -5,6 +5,7 @@ + diff --git a/tests/networkxml2xmlout/netboot-network.xml b/tests/networkxml2xmlout/netboot-network.xml index 8d5ad31a00..723c6c7a72 100644 --- a/tests/networkxml2xmlout/netboot-network.xml +++ b/tests/networkxml2xmlout/netboot-network.xml @@ -3,6 +3,7 @@ 81ff0d90-c91e-6742-64da-4a736edb9a9b + diff --git a/tests/networkxml2xmlout/netboot-proxy-network.xml b/tests/networkxml2xmlout/netboot-proxy-network.xml index a5b7c1e4e6..8c9fae874c 100644 --- a/tests/networkxml2xmlout/netboot-proxy-network.xml +++ b/tests/networkxml2xmlout/netboot-proxy-network.xml @@ -3,6 +3,7 @@ 81ff0d90-c91e-6742-64da-4a736edb9a9b + diff --git a/tests/networkxml2xmlout/passthrough-address-crash.xml b/tests/networkxml2xmlout/passthrough-address-crash.xml deleted file mode 100644 index a05dbbf837..0000000000 --- a/tests/networkxml2xmlout/passthrough-address-crash.xml +++ /dev/null @@ -1,7 +0,0 @@ - - passthrough_001 - 50e92386-8dd1-4a95-8a4b-9a888274eb66 - -
- - diff --git a/tests/networkxml2xmlout/passthrough-pf.xml b/tests/networkxml2xmlout/passthrough-pf.xml deleted file mode 100644 index 1a7e71ea88..0000000000 --- a/tests/networkxml2xmlout/passthrough-pf.xml +++ /dev/null @@ -1,9 +0,0 @@ - - local - 81ff0d90-c91e-6742-64da-4a736edb9a9b - - - - - - diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 840bcaa83f..10eed8173e 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -17,6 +17,7 @@ typedef enum { TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS, TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE, + TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE, TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT, TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE, } testCompareNetXML2XMLResult; @@ -42,6 +43,13 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE) goto cleanup; + if (networkValidateTests(dev) < 0) { + result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE; + goto cleanup; + } + if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE) + goto cleanup; + if (!(actual = virNetworkDefFormat(dev, xmlopt, flags))) { result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT; goto cleanup; @@ -114,6 +122,8 @@ mymain(void) 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) +#define DO_TEST_VALIDATE_ERROR(name) \ + DO_TEST_FULL(name, 0, TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE) DO_TEST("dhcp6host-routed-network"); DO_TEST("empty-allow-ipv6"); @@ -145,12 +155,12 @@ mymain(void) DO_TEST("vepa-net"); DO_TEST("bandwidth-network"); DO_TEST("openvswitch-net"); - DO_TEST_FLAGS("passthrough-pf", VIR_NETWORK_XML_INACTIVE); + DO_TEST_VALIDATE_ERROR("passthrough-pf"); DO_TEST("hostdev"); DO_TEST_FLAGS("hostdev-pf", VIR_NETWORK_XML_INACTIVE); DO_TEST_FLAGS("hostdev-pf-driver-model", VIR_NETWORK_XML_INACTIVE); - DO_TEST("passthrough-address-crash"); + DO_TEST_VALIDATE_ERROR("passthrough-address-crash"); DO_TEST("nat-network-explicit-flood"); DO_TEST("host-bridge-no-flood"); DO_TEST_PARSE_ERROR("hostdev-duplicate"); @@ -167,4 +177,6 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("virpci"), + VIR_TEST_MOCK("virrandom"))