From nobody Sat Feb 7 08:53:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1641977341; cv=none; d=zohomail.com; s=zohoarc; b=bbE/3fUG6vPERpcU9fDHnRnyN+MabNIaX1cRyDC+o5ozQ5nM3Z6juf4RLMjkxLOwG1tb3jzDlYTCQ+1EpD/dL1I2H5YKc6LPWa4KBqy9P9WSg3sjXLaaDzh6M/FOnho02+YSHD7+zvBwEYl6sRmhj20DQ4mCwlT0dwBr9JnrMvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641977341; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s8AUUpHEgrDvhdThlL2NpDw6i0ZnXjIpuVFubL3Ie5w=; b=ddmjp5f7F2qlv414eRyGNIV69taVnhlRnuh2gAAmkILifBGgxc4Se2SS7346WiqGj8NsrdP/2wyv3R2BbG7RnbFMhFih6/fdxqRgae2wK0fnp9LcpkFORT/KNbxRS+Uckf8D9RmfhgnKgl0KNKO48dWSnDo6rpJ7OdXcYpUwwQ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 164197734104077.23301833650135; Wed, 12 Jan 2022 00:49:01 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-Vs2X8v3yOJicpYcxxh8iMg-1; Wed, 12 Jan 2022 03:48:58 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 51B871006AA5; Wed, 12 Jan 2022 08:48:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3399110589CF; Wed, 12 Jan 2022 08:48:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 031B41806D1C; Wed, 12 Jan 2022 08:48:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20C8mqmh017615 for ; Wed, 12 Jan 2022 03:48:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1BDFA60C44; Wed, 12 Jan 2022 08:48:52 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99C18752AA for ; Wed, 12 Jan 2022 08:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641977340; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=s8AUUpHEgrDvhdThlL2NpDw6i0ZnXjIpuVFubL3Ie5w=; b=XfCR4x1aqfJp+QHAgMJ66OttkdcS9K5MeiX3xzzEYeCzL20vqFFQFetEmW/0lej3/S1q8X XBjYxjbzAKMPoobE3TRXo4GS44zT81vBp421A+s4RxXx1i10+2u0ui1v5ipsjDvLvpF6xH nPuglz+4QKKyOXhfiy11+vvEbK57+20= X-MC-Unique: Vs2X8v3yOJicpYcxxh8iMg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 5/7] networkxml2conftest: Use dnsmasqCapsNewFromBinary() to construct caps Date: Wed, 12 Jan 2022 09:47:56 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1641977342781100001 Content-Type: text/plain; charset="utf-8" DISCLAIMER: dnsmasq capabilities are empty as of v8.0.0-rc1~145. In a real environment the dnsmasq capabilities are constructed using dnsmasqCapsNewFromBinary(). We also have dnsmasqCapsNewFromBuffer() to bypass checks that real code is doing and just get capabilities object. The latter is used from test suite. However, with a little bit of mocking we can test the real life code. All that's needed is to simulate dnsmasq's output for --version and --help and mock a stat() that's done in dnsmasqCapsRefreshInternal(). Signed-off-by: Michal Privoznik --- tests/networkmock.c | 16 ++++++++++++++++ tests/networkxml2conftest.c | 38 ++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/networkmock.c b/tests/networkmock.c index a9c13311a6..25014de8b8 100644 --- a/tests/networkmock.c +++ b/tests/networkmock.c @@ -28,3 +28,19 @@ virFindFileInPath(const char *file) /* We should not need any other binaries so return NULL. */ return NULL; } + +static int +virMockStatRedirect(const char *path G_GNUC_UNUSED, + char **newpath G_GNUC_UNUSED) +{ + /* We don't need to redirect stat. Do nothing. */ + return 0; +} + +#define VIR_MOCK_STAT_HOOK \ + if (strstr(path, "dnsmasq")) { \ + memset(sb, 0, sizeof(*sb)); \ + return 0; \ + } + +#include "virmockstathelpers.c" diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 8a6657654a..68dd3023e1 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -12,6 +12,8 @@ #include "viralloc.h" #include "network/bridge_driver.h" #include "virstring.h" +#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW +#include "vircommandpriv.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -108,13 +110,47 @@ testCompareXMLToConfHelper(const void *data) return result; } =20 +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[1], "--version")) { + *output =3D g_strdup("Dnsmasq version 2.67\n"); + *status =3D EXIT_SUCCESS; + } else if (STREQ(args[1], "--help")) { + *output =3D g_strdup("--bind-dynamic\n--ra-param"); + *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 int mymain(void) { int ret =3D 0; g_autoptr(dnsmasqCaps) full =3D NULL; =20 - full =3D dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynami= c\n--ra-param"); + full =3D buildCaps(); =20 #define DO_TEST(xname, xcaps) \ do { \ --=20 2.34.1