From nobody Mon Feb 2 07:31:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1769612069; cv=none; d=zohomail.com; s=zohoarc; b=H+xwqxowHb2SreVR4TgYY3I07dyg9aIk2ABijK9YEiEVr04jCQPfAwC5YRJ60Hz8knzdXwMUpvuT2bxYelqof/Hruq4Pmo9C/2BIwOUBFelWjOWVkCH58vK93U8Y1F8jKpe6VqB5+2dw9fMQza0SG9/KoU5Rh9JfJnceBzYJk98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769612069; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=GffwCIrcCkVoBk3VaTNyfxer2Vix1Kt4PLvB6ftPrEA=; b=OQv39ztVAi2s83r7rLofDq2Ik/YA3Ehc3eAQamaBcsTrF1NiIL9/61srehgZTHnfIzAHL0E8+J5/dENjMOA/d4ZsREQ2VgB++EE1r2di8xsNftrLHKnYe7qD89CK7l2zTdmgTEkhPUm+dYIsA6F2Ei1UmRWn+eystnjRBjHuc9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1769612069983625.6879750496386; Wed, 28 Jan 2026 06:54:29 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 2477541AEE; Wed, 28 Jan 2026 09:54:29 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 93D0E441C8; Wed, 28 Jan 2026 09:38:56 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 7C6F943EF0; Wed, 28 Jan 2026 09:38:50 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 22CAE43E5A for ; Wed, 28 Jan 2026 09:31:09 -0500 (EST) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-zVOe5O06O0G-FNUffwct7A-1; Wed, 28 Jan 2026 09:31:06 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30EA01956096 for ; Wed, 28 Jan 2026 14:31:05 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 757E11956095 for ; Wed, 28 Jan 2026 14:31:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769610668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GffwCIrcCkVoBk3VaTNyfxer2Vix1Kt4PLvB6ftPrEA=; b=bHCSj6SaPrVI2gpUoVR1urltF+nkg9HcNn21RRQS3QhuqD9RdmhXYbroCRHI5V1AgUrsXu FcgPTD6gj8ZD7NW3xE3a1NNYE+ricDyqp4qlNgNGWfr9AZDZHZs/3tiKi2qawj3McVN6eB nmZFiBtwxNqJwMNFEM4yT+UnyvnWWTE= X-MC-Unique: zVOe5O06O0G-FNUffwct7A-1 X-Mimecast-MFC-AGG-ID: zVOe5O06O0G-FNUffwct7A_1769610665 To: devel@lists.libvirt.org Subject: [PATCH 18/20] networkxml2xmltest: Do conf test Date: Wed, 28 Jan 2026 15:30:39 +0100 Message-ID: <53502d2416e8d537933427d96b7277b68de128b8.1769610369.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -207zJLo0AOf6GLiYlPK9CeCRmMUMN3ucviuiS_RMlo_1769610665 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: F4PIOK5S3KJHII42HOF4CCRWBSRMARGI X-Message-ID-Hash: F4PIOK5S3KJHII42HOF4CCRWBSRMARGI X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1769612070533158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Signed-off-by: Michal Privoznik --- src/network/bridge_driver.c | 2 +- .../bandwidth-network.conf | 16 +++ .../nat-network-dns-srv-records.conf | 20 +++ .../nat-network-dns-srv-records.hostsfile | 2 + .../nat-network-explicit-flood.conf | 18 +++ .../nat-network-explicit-flood.hostsfile | 2 + .../nat-network-forward-nat-address.conf | 18 +++ .../nat-network-forward-nat-address.hostsfile | 2 + .../nat-network-forward-nat-ipv6.conf | 12 ++ .../nat-network-forward-nat-no-address.conf | 18 +++ ...t-network-forward-nat-no-address.hostsfile | 2 + tests/networkxml2confdata/passthrough-pf.conf | 11 ++ tests/networkxml2confdata/set-mtu.conf | 20 +++ tests/networkxml2xmltest.c | 136 +++++++++++++++++- 14 files changed, 277 insertions(+), 2 deletions(-) create mode 100644 tests/networkxml2confdata/bandwidth-network.conf create mode 100644 tests/networkxml2confdata/nat-network-dns-srv-records.c= onf create mode 100644 tests/networkxml2confdata/nat-network-dns-srv-records.h= ostsfile create mode 100644 tests/networkxml2confdata/nat-network-explicit-flood.co= nf create mode 100644 tests/networkxml2confdata/nat-network-explicit-flood.ho= stsfile create mode 100644 tests/networkxml2confdata/nat-network-forward-nat-addre= ss.conf create mode 100644 tests/networkxml2confdata/nat-network-forward-nat-addre= ss.hostsfile create mode 100644 tests/networkxml2confdata/nat-network-forward-nat-ipv6.= conf create mode 100644 tests/networkxml2confdata/nat-network-forward-nat-no-ad= dress.conf create mode 100644 tests/networkxml2confdata/nat-network-forward-nat-no-ad= dress.hostsfile create mode 100644 tests/networkxml2confdata/passthrough-pf.conf create mode 100644 tests/networkxml2confdata/set-mtu.conf diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 9636984390..104c298683 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1178,7 +1178,7 @@ networkDnsmasqConfContents(virNetworkObj *obj, =20 /* create dnsmasq config file appropriate for this network */ =20 - /* Don't forget to update networkxml2conftest :-) */ + /* Don't forget to update networkxml2conftest and networkxml2xmltest := -) */ virBufferAsprintf(&configbuf, "##WARNING: THIS IS AN AUTO-GENERATED FILE. " "CHANGES TO IT ARE LIKELY TO BE\n" diff --git a/tests/networkxml2confdata/bandwidth-network.conf b/tests/netwo= rkxml2confdata/bandwidth-network.conf new file mode 100644 index 0000000000..d45b23ad7a --- /dev/null +++ b/tests/networkxml2confdata/bandwidth-network.conf @@ -0,0 +1,16 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit test-net +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3Dvirbr1 +dhcp-range=3D192.168.120.2,192.168.120.254,255.255.255.0 +dhcp-no-override +dhcp-authoritative +dhcp-lease-max=3D253 +dhcp-hostsfile=3D/var/lib/libvirt/dnsmasq/test-net.hostsfile +addn-hosts=3D/var/lib/libvirt/dnsmasq/test-net.addnhosts diff --git a/tests/networkxml2confdata/nat-network-dns-srv-records.conf b/t= ests/networkxml2confdata/nat-network-dns-srv-records.conf new file mode 100644 index 0000000000..b85eb85af3 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-dns-srv-records.conf @@ -0,0 +1,20 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit default +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3Dvirbr0 +srv-host=3D_name._tcp.test-domain-name +srv-host=3D_name._tcp.donkey +dhcp-range=3D192.168.122.2,192.168.122.254,255.255.255.0 +dhcp-no-override +dhcp-authoritative +dhcp-lease-max=3D253 +dhcp-hostsfile=3D/var/lib/libvirt/dnsmasq/default.hostsfile +addn-hosts=3D/var/lib/libvirt/dnsmasq/default.addnhosts +dhcp-range=3D2001:db8:ac10:fe01::1,ra-only +dhcp-range=3D2001:db8:ac10:fd01::1,ra-only diff --git a/tests/networkxml2confdata/nat-network-dns-srv-records.hostsfil= e b/tests/networkxml2confdata/nat-network-dns-srv-records.hostsfile new file mode 100644 index 0000000000..deb3f00ac1 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-dns-srv-records.hostsfile @@ -0,0 +1,2 @@ +00:16:3e:77:e2:ed,192.168.122.10,a.example.com +00:16:3e:3e:a9:1a,192.168.122.11,b.example.com diff --git a/tests/networkxml2confdata/nat-network-explicit-flood.conf b/te= sts/networkxml2confdata/nat-network-explicit-flood.conf new file mode 100644 index 0000000000..873a360acc --- /dev/null +++ b/tests/networkxml2confdata/nat-network-explicit-flood.conf @@ -0,0 +1,18 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit default +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3Dvirbr0 +dhcp-range=3D192.168.122.2,192.168.122.254,255.255.255.0 +dhcp-no-override +dhcp-authoritative +dhcp-lease-max=3D253 +dhcp-hostsfile=3D/var/lib/libvirt/dnsmasq/default.hostsfile +addn-hosts=3D/var/lib/libvirt/dnsmasq/default.addnhosts +dhcp-range=3D2001:db8:ac10:fe01::1,ra-only +dhcp-range=3D2001:db8:ac10:fd01::1,ra-only diff --git a/tests/networkxml2confdata/nat-network-explicit-flood.hostsfile= b/tests/networkxml2confdata/nat-network-explicit-flood.hostsfile new file mode 100644 index 0000000000..deb3f00ac1 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-explicit-flood.hostsfile @@ -0,0 +1,2 @@ +00:16:3e:77:e2:ed,192.168.122.10,a.example.com +00:16:3e:3e:a9:1a,192.168.122.11,b.example.com diff --git a/tests/networkxml2confdata/nat-network-forward-nat-address.conf= b/tests/networkxml2confdata/nat-network-forward-nat-address.conf new file mode 100644 index 0000000000..873a360acc --- /dev/null +++ b/tests/networkxml2confdata/nat-network-forward-nat-address.conf @@ -0,0 +1,18 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit default +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3Dvirbr0 +dhcp-range=3D192.168.122.2,192.168.122.254,255.255.255.0 +dhcp-no-override +dhcp-authoritative +dhcp-lease-max=3D253 +dhcp-hostsfile=3D/var/lib/libvirt/dnsmasq/default.hostsfile +addn-hosts=3D/var/lib/libvirt/dnsmasq/default.addnhosts +dhcp-range=3D2001:db8:ac10:fe01::1,ra-only +dhcp-range=3D2001:db8:ac10:fd01::1,ra-only diff --git a/tests/networkxml2confdata/nat-network-forward-nat-address.host= sfile b/tests/networkxml2confdata/nat-network-forward-nat-address.hostsfile new file mode 100644 index 0000000000..deb3f00ac1 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-forward-nat-address.hostsfile @@ -0,0 +1,2 @@ +00:16:3e:77:e2:ed,192.168.122.10,a.example.com +00:16:3e:3e:a9:1a,192.168.122.11,b.example.com diff --git a/tests/networkxml2confdata/nat-network-forward-nat-ipv6.conf b/= tests/networkxml2confdata/nat-network-forward-nat-ipv6.conf new file mode 100644 index 0000000000..3627bbaf1d --- /dev/null +++ b/tests/networkxml2confdata/nat-network-forward-nat-ipv6.conf @@ -0,0 +1,12 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit default +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3Dvirbr0 +addn-hosts=3D/var/lib/libvirt/dnsmasq/default.addnhosts +dhcp-range=3D2001:db8:ac10:fe01::1,ra-only diff --git a/tests/networkxml2confdata/nat-network-forward-nat-no-address.c= onf b/tests/networkxml2confdata/nat-network-forward-nat-no-address.conf new file mode 100644 index 0000000000..873a360acc --- /dev/null +++ b/tests/networkxml2confdata/nat-network-forward-nat-no-address.conf @@ -0,0 +1,18 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit default +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3Dvirbr0 +dhcp-range=3D192.168.122.2,192.168.122.254,255.255.255.0 +dhcp-no-override +dhcp-authoritative +dhcp-lease-max=3D253 +dhcp-hostsfile=3D/var/lib/libvirt/dnsmasq/default.hostsfile +addn-hosts=3D/var/lib/libvirt/dnsmasq/default.addnhosts +dhcp-range=3D2001:db8:ac10:fe01::1,ra-only +dhcp-range=3D2001:db8:ac10:fd01::1,ra-only diff --git a/tests/networkxml2confdata/nat-network-forward-nat-no-address.h= ostsfile b/tests/networkxml2confdata/nat-network-forward-nat-no-address.hos= tsfile new file mode 100644 index 0000000000..deb3f00ac1 --- /dev/null +++ b/tests/networkxml2confdata/nat-network-forward-nat-no-address.hostsfile @@ -0,0 +1,2 @@ +00:16:3e:77:e2:ed,192.168.122.10,a.example.com +00:16:3e:3e:a9:1a,192.168.122.11,b.example.com diff --git a/tests/networkxml2confdata/passthrough-pf.conf b/tests/networkx= ml2confdata/passthrough-pf.conf new file mode 100644 index 0000000000..1957dc8011 --- /dev/null +++ b/tests/networkxml2confdata/passthrough-pf.conf @@ -0,0 +1,11 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit local +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3D(null) +addn-hosts=3D/var/lib/libvirt/dnsmasq/local.addnhosts diff --git a/tests/networkxml2confdata/set-mtu.conf b/tests/networkxml2conf= data/set-mtu.conf new file mode 100644 index 0000000000..011a288a5b --- /dev/null +++ b/tests/networkxml2confdata/set-mtu.conf @@ -0,0 +1,20 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made usin= g: +## virsh net-edit private +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=3Dlo +bind-dynamic +interface=3Dvirbr2 +dhcp-option=3D3 +no-resolv +ra-param=3D*,0,0 +dhcp-range=3D192.168.152.2,192.168.152.254,255.255.255.0 +dhcp-no-override +dhcp-authoritative +dhcp-lease-max=3D253 +dhcp-hostsfile=3D/var/lib/libvirt/dnsmasq/private.hostsfile +addn-hosts=3D/var/lib/libvirt/dnsmasq/private.addnhosts +dhcp-option=3Doption:mtu,9000 diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index a8dacfe0f3..1d897c1fe4 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -11,6 +11,8 @@ #include "bridge_driver.h" #define LIBVIRT_BRIDGE_DRIVER_PRIV_H_ALLOW #include "bridge_driver_priv.h" +#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW +#include "vircommandpriv.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -27,9 +29,12 @@ struct _testInfo { unsigned int flags; testCompareNetXML2XMLResult expectResult; virNetworkXMLOption *xmlopt; /* borrowed, immutable */ + dnsmasqCaps *caps; virNetworkDef *def; char *inxml; char *outxml; + char *outconf; + char *outhostsfile; }; =20 typedef struct _testInfo testInfo; @@ -44,6 +49,8 @@ void testInfoFree(testInfo *info) virNetworkDefFree(info->def); VIR_FREE(info->inxml); VIR_FREE(info->outxml); + VIR_FREE(info->outconf); + VIR_FREE(info->outhostsfile); VIR_FREE(info); } =20 @@ -104,37 +111,163 @@ testCompareXMLToXMLFiles(const void *data) } =20 =20 +static int +testCompareXMLToConfFiles(const void *data) +{ + testInfo *info =3D (void *) data; + char *confactual =3D NULL; + g_autofree char *hostsfileactual =3D NULL; + int ret =3D -1; + virNetworkDef *def =3D NULL; + virNetworkObj *obj =3D NULL; + g_autofree char *pidfile =3D NULL; + g_autoptr(dnsmasqContext) dctx =3D NULL; + bool compareFailed =3D false; + + if (!(obj =3D virNetworkObjNew())) + goto fail; + + if (!(def =3D g_steal_pointer(&info->def))) { + /* Previous test wasn't executed. */ + if (!(def =3D virNetworkDefParse(NULL, info->inxml, info->xmlopt, = false))) + goto fail; + + if (networkValidateTests(def) < 0) { + virNetworkDefFree(def); + goto fail; + } + } + + virNetworkObjSetDef(obj, def); + + if (!networkNeedsDnsmasq(def)) + return EXIT_AM_SKIP; + + dctx =3D dnsmasqContextNew(def->name, "/var/lib/libvirt/dnsmasq"); + + if (dctx =3D=3D NULL) + goto fail; + + if (networkDnsmasqConfContents(obj, pidfile, &confactual, + &hostsfileactual, dctx, info->caps) < 0) + goto fail; + + /* Any changes to this function ^^ should be reflected here too. */ +#ifndef __linux__ + { + char * tmp; + + if (!(tmp =3D virStringReplace(confactual, + "except-interface=3Dlo0\n", + "except-interface=3Dlo\n"))) + goto fail; + VIR_FREE(confactual); + confactual =3D g_steal_pointer(&tmp); + } +#endif + + if (virTestCompareToFile(confactual, info->outconf) < 0) + compareFailed =3D true; + + if (hostsfileactual) { + if (virTestCompareToFile(hostsfileactual, info->outhostsfile) < 0)= { + compareFailed =3D true; + } + } else { + if (virFileExists(info->outhostsfile)) { + VIR_TEST_DEBUG("%s: hostsfile exists but the configuration did= not specify any host", + info->outhostsfile); + compareFailed =3D true; + } + } + + if (compareFailed) + goto fail; + + ret =3D 0; + + fail: + VIR_FREE(confactual); + virNetworkObjEndAPI(&obj); + return ret; +} + +static void +buildCapsCallback(const char *const*args, + const char *const*env G_GNUC_UNUSED, + const char *input G_GNUC_UNUSED, + char **output, + char **error G_GNUC_UNUSED, + int *status, + void *opaque G_GNUC_UNUSED) +{ + if (STREQ(args[0], "/usr/sbin/dnsmasq") && STREQ(args[1], "--version")= ) { + *output =3D g_strdup("Dnsmasq version 2.67\n"); + *status =3D EXIT_SUCCESS; + } else { + *status =3D EXIT_FAILURE; + } +} + + +static dnsmasqCaps * +buildCaps(void) +{ + g_autoptr(dnsmasqCaps) caps =3D NULL; + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + + virCommandSetDryRun(dryRunToken, NULL, true, true, buildCapsCallback, = NULL); + + caps =3D dnsmasqCapsNewFromBinary(); + + return g_steal_pointer(&caps); +} + + static void testRun(const char *name, int *ret, virNetworkXMLOption *xmlopt, + dnsmasqCaps *caps, testCompareNetXML2XMLResult expectResult, unsigned int flags) { g_autofree char *name_xml2xml =3D g_strdup_printf("Network XML-2-XML %= s", name); + g_autofree char *name_xml2conf =3D g_strdup_printf("Network XML-2-Conf= %s", name); g_autoptr(testInfo) info =3D g_new0(testInfo, 1); =20 info->name =3D name; info->flags =3D flags; info->expectResult =3D expectResult; info->xmlopt =3D xmlopt; + info->caps =3D caps; info->inxml =3D g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcd= ir, name); info->outxml =3D g_strdup_printf("%s/networkxml2xmlout/%s.xml", abs_sr= cdir, name); + /* Temporarily use conf files from networkxml2confdata/ */ + info->outconf =3D g_strdup_printf("%s/networkxml2confdata/%s.conf", ab= s_srcdir, name); + info->outhostsfile =3D g_strdup_printf("%s/networkxml2confdata/%s.host= sfile", abs_srcdir, name); =20 virTestRunLog(ret, name_xml2xml, testCompareXMLToXMLFiles, info); + + if (expectResult =3D=3D TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) + virTestRunLog(ret, name_xml2conf, testCompareXMLToConfFiles, info); } =20 static int mymain(void) { g_autoptr(virNetworkXMLOption) xmlopt =3D NULL; + g_autoptr(dnsmasqCaps) caps =3D NULL; int ret =3D 0; =20 if (!(xmlopt =3D networkDnsmasqCreateXMLConf())) return -1; =20 + if (!(caps =3D buildCaps())) + return -1; + #define DO_TEST_FULL(name, flags, expectResult) \ - testRun(name, &ret, xmlopt, expectResult, flags) + testRun(name, &ret, xmlopt, caps, expectResult, flags) #define DO_TEST(name) \ DO_TEST_FULL(name, 0, TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) #define DO_TEST_FLAGS(name, flags) \ @@ -202,4 +335,5 @@ mymain(void) =20 VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virpci"), + VIR_TEST_MOCK("virdnsmasq"), VIR_TEST_MOCK("virrandom")) --=20 2.52.0