From nobody Tue Feb 10 03:45:29 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=1689891635; cv=none; d=zohomail.com; s=zohoarc; b=bZ+J8+X7CU/rnByg7DR+/NoCPifovoWbSswandUQxy4H743d0ZxF/6yVUQTCAfMfN6aZ9NySGq2bn4x2D+KfWw5tmozhLo+KLSBkbeIeZAOfQZ3M0N5IJnlrp8mYol1VisxB43Lwycv3lcKhjnZz+5ZVOpDvf51qtrlcN/mcX4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891635; h=Content-Type:Content-Transfer-Encoding:Cc: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=IK4pQ0mzDEzDAvl7dLMR95g+pCPldo3Y2G+xKxC4nAo=; b=RDRYT/lE5ucWTgr11IHfjA1FAqGLcKEM9px7lXBpfxVHbLAVAXIBpfveAcQ13UDt2ACgQut9YgabqlwW2qWgVpcbJDSKTfjXQRiqL9W714D8gBKnKKBze6IaJrErx/8g5o5zkF+NyBz4cqhy6I7I+hRFLosl78lBybu5jaUwKug= 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 1689891635529562.0929510239574; Thu, 20 Jul 2023 15:20:35 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-362-MRGsQzijMFapWHnrxwzifA-1; Thu, 20 Jul 2023 18:20:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B43B28088A4; Thu, 20 Jul 2023 22:20:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4421DC57969; Thu, 20 Jul 2023 22:20:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B53161949754; Thu, 20 Jul 2023 22:20:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9341E1946A45 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8A82740C2005; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F2C140C2004; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891634; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=IK4pQ0mzDEzDAvl7dLMR95g+pCPldo3Y2G+xKxC4nAo=; b=gH2cpUjjh/NmoKGnIVE+6cSpVJohOMosMN49LA5f4NmYXtDkjQJXVBTYMJRbLLaNAqlSVI Af++3zTIrz/05KFhwu6+6VC/n6NJMmJngcYGGedRU8fOsw1LZFBhdMfo78+NGsbs8yAyV7 hp3gRBkBgMas06NXbrdYKf1Ios0ur98= X-MC-Unique: MRGsQzijMFapWHnrxwzifA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 16/36] tests: add ability to test various nbdkit capabilities Date: Thu, 20 Jul 2023 17:19:43 -0500 Message-ID: <20230720222003.411549-17-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1689891636156100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Add new DO_TEST_CAPS_LATEST_NBDKIT macro to test xml2argv for various nbdkit capability scenarios. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 20 +++++++++++++++++--- tests/qemuxml2argvtest.c | 11 +++++++++++ tests/testutilsqemu.c | 26 ++++++++++++++++++++++++++ tests/testutilsqemu.h | 4 ++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 7275d33419..a8988778ac 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -291,10 +291,16 @@ virNbkditCapsCheckModdir(const char *moddir, =20 static bool virNbdkitCapsIsValid(void *data, - void *privData G_GNUC_UNUSED) + void *privData) { qemuNbdkitCaps *nbdkitCaps =3D data; struct stat st; + /* when run under test, we will use privData as a signal to indicate t= hat + * we shouldn't touch the filesystem */ + bool skipValidation =3D (privData !=3D NULL); + + if (skipValidation) + return true; =20 if (!nbdkitCaps->path) return true; @@ -335,9 +341,17 @@ virNbdkitCapsIsValid(void *data, =20 static void* virNbdkitCapsNewData(const char *binary, - void *privData G_GNUC_UNUSED) + void *privData) { - qemuNbdkitCaps *caps =3D qemuNbdkitCapsNew(binary); + /* when run under test, we will use privData as a signal to indicate t= hat + * we shouldn't touch the filesystem */ + bool skipNewData =3D (privData !=3D NULL); + qemuNbdkitCaps *caps =3D NULL; + + if (skipNewData) + return NULL; + + caps =3D qemuNbdkitCapsNew(binary); qemuNbdkitCapsQuery(caps); =20 return caps; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 52d206d00f..d3dafb5bb5 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -613,6 +613,14 @@ testCompareXMLToArgv(const void *data) if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0) goto cleanup; =20 + if (info->nbdkitCaps) { + if (virFileCacheInsertData(driver.nbdkitCapsCache, TEST_NBDKIT_PAT= H, + g_object_ref(info->nbdkitCaps)) < 0) { + g_object_unref(info->nbdkitCaps); + goto cleanup; + } + } + if (info->migrateFrom && !(migrateURI =3D qemuMigrationDstGetURI(info->migrateFrom, info->migrateFd))) @@ -833,6 +841,9 @@ mymain(void) # define DO_TEST_CAPS_ARCH_VER(name, arch, ver) \ DO_TEST_CAPS_ARCH_VER_FULL(name, arch, ver, ARG_END) =20 +# define DO_TEST_CAPS_LATEST_NBDKIT(name, ...) \ + DO_TEST_CAPS_ARCH_LATEST_FULL(name, "x86_64", ARG_NBDKIT_CAPS, __VA_AR= GS__, QEMU_NBDKIT_CAPS_LAST, ARG_END) + # define DO_TEST_CAPS_LATEST(name) \ DO_TEST_CAPS_ARCH_LATEST(name, "x86_64") =20 diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 16b773a768..67923070e1 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -57,6 +57,10 @@ virFindFileInPath(const char *file) return g_strdup_printf("/usr/bin/%s", file); } =20 + if (g_str_equal(file, "nbdkit")) { + return g_strdup(TEST_NBDKIT_PATH); + } + /* Nothing in tests should be relying on real files * in host OS, so we return NULL to try to force * an error in such a case @@ -295,6 +299,7 @@ void qemuTestDriverFree(virQEMUDriver *driver) virObjectUnref(driver->caps); virObjectUnref(driver->config); virObjectUnref(driver->securityManager); + g_clear_object(&driver->nbdkitCapsCache); =20 virCPUDefFree(cpuDefault); virCPUDefFree(cpuHaswell); @@ -494,6 +499,12 @@ int qemuTestDriverInit(virQEMUDriver *driver) if (!driver->qemuCapsCache) goto error; =20 + driver->nbdkitCapsCache =3D qemuNbdkitCapsCacheNew("/dev/null"); + /* the nbdkitCapsCache just interprets the presence of a non-null priv= ate + * data pointer as a signal to skip cache validation. This prevents the + * cache from trying to validate the plugindir mtime, etc during test = */ + virFileCacheSetPriv(driver->nbdkitCapsCache, GUINT_TO_POINTER(1)); + driver->xmlopt =3D virQEMUDriverCreateXMLConf(driver, "none"); if (!driver->xmlopt) goto error; @@ -787,6 +798,14 @@ testQemuInfoSetArgs(struct testQemuInfo *info, ignore_value(virBitmapSetBit(info->args.fakeCapsDel, flag)= ); break; =20 + case ARG_NBDKIT_CAPS: + if (!(info->args.fakeNbdkitCaps)) + info->args.fakeNbdkitCaps =3D virBitmapNew(QEMU_NBDKIT_CAP= S_LAST); + + while ((flag =3D va_arg(argptr, int)) < QEMU_NBDKIT_CAPS_LAST) + ignore_value(virBitmapSetBit(info->args.fakeNbdkitCaps, fl= ag)); + break; + case ARG_GIC: info->args.gic =3D va_arg(argptr, int); break; @@ -1061,6 +1080,11 @@ testQemuInfoInitArgs(struct testQemuInfo *info) for (cap =3D -1; (cap =3D virBitmapNextSetBit(info->args.fakeCapsDel, = cap)) >=3D 0;) virQEMUCapsClear(info->qemuCaps, cap); =20 + info->nbdkitCaps =3D qemuNbdkitCapsNew(TEST_NBDKIT_PATH); + + for (cap =3D -1; (cap =3D virBitmapNextSetBit(info->args.fakeNbdkitCap= s, cap)) >=3D 0;) + qemuNbdkitCapsSet(info->nbdkitCaps, cap); + if (info->args.gic !=3D GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, info->args.gic) < 0) return -1; @@ -1079,6 +1103,8 @@ testQemuInfoClear(struct testQemuInfo *info) g_clear_pointer(&info->args.fakeCapsAdd, virBitmapFree); g_clear_pointer(&info->args.fakeCapsDel, virBitmapFree); g_clear_pointer(&info->args.fds, g_hash_table_unref); + g_clear_object(&info->nbdkitCaps); + g_clear_pointer(&info->args.fakeNbdkitCaps, virBitmapFree); } =20 =20 diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index e0d116336e..d0e0531929 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -28,6 +28,7 @@ # define TEST_TPM_ENV_VAR "VIR_TEST_MOCK_FAKE_TPM_VERSION" # define TPM_VER_1_2 "1.2" # define TPM_VER_2_0 "2.0" +# define TEST_NBDKIT_PATH "/fakebindir/nbdkit" =20 enum { GIC_NONE =3D 0, @@ -49,6 +50,7 @@ typedef enum { ARG_CAPS_VARIANT, ARG_CAPS_HOST_CPU_MODEL, ARG_FD_GROUP, /* name, nfds, fd[0], ... fd[n-1] */ + ARG_NBDKIT_CAPS, ARG_END, } testQemuInfoArgName; =20 @@ -79,6 +81,7 @@ struct testQemuArgs { bool newargs; virBitmap *fakeCapsAdd; virBitmap *fakeCapsDel; + virBitmap *fakeNbdkitCaps; char *capsver; char *capsarch; const char *capsvariant; @@ -94,6 +97,7 @@ struct testQemuInfo { char *outfile; char *errfile; virQEMUCaps *qemuCaps; + qemuNbdkitCaps *nbdkitCaps; const char *migrateFrom; int migrateFd; unsigned int flags; --=20 2.41.0