From nobody Tue Feb 10 04:03:09 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=1618346431; cv=none; d=zohomail.com; s=zohoarc; b=T8tvM9v8s02+bus02hY5UwcB1zQxSCsQJJ2+jyF1vVwQBO/uBvC+eTqAlO2BPGFZTUZtmIaTZQ74yrdpunK0gC12/WQ5fDYdAKJ8PT0qzyKxUYTa5DsDY0SvILQLRxS4PZH/uKvDCxWZUJAXUuR5CY90IQaSHRt+P+TY2Hx+MGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618346431; 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=m58ly33yR7YRz64kYVupqwy4tK8ZJeivDpnezV7tEMs=; b=OJXW7IoCsSzNgjhIOg6TNQSXTE5fn634TEsUxikl3frZhLgbun2uPHZ422ory3354zhtwAxz8yJfrl7Mfj1/91bnKBUcG9miSm3hBQK4LOdGOqdXYgWK7VldzHlF/JsON8OB2Tk/GvRiSXuXA7fmChlpZyaI5GFKkk0S+92U3yU= 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) header.from= 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 1618346431135610.6167321797795; Tue, 13 Apr 2021 13:40:31 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-134-drrrdTLjOeK_xOLa4J-_2g-1; Tue, 13 Apr 2021 16:40:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A4E8B84B9AF; Tue, 13 Apr 2021 20:40:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 878D35B698; Tue, 13 Apr 2021 20:40:20 +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 4EA285534C; Tue, 13 Apr 2021 20:40:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13DKduL2011724 for ; Tue, 13 Apr 2021 16:39:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2FADF1975E; Tue, 13 Apr 2021 20:39:56 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-166.phx2.redhat.com [10.3.113.166]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E57A01972B; Tue, 13 Apr 2021 20:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618346429; 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=m58ly33yR7YRz64kYVupqwy4tK8ZJeivDpnezV7tEMs=; b=CtS6MFuODpDejuUVa9CxG4QWaFZsaD/dYz8mBXSZrNTUjFkCmJh0f/gyLGafMNlg7o0+RQ Mc0SM3QAY+iiHSlR8MmnSedxL8BWYad7l/aBii4cZD0A/MhQ5BVllnTprT/j7wA6FqQY2G /xa+GpepX2UuYd6m2W3UqQf7fSHRHgM= X-MC-Unique: drrrdTLjOeK_xOLa4J-_2g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/12] tests: nodedev: Make the mdevctl test function and helper generic Date: Tue, 13 Apr 2021 15:39:45 -0500 Message-Id: <20210413203948.71864-10-jjongsma@redhat.com> In-Reply-To: <20210413203948.71864-1-jjongsma@redhat.com> References: <20210413203948.71864-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Erik Skultety 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.79 on 10.5.11.15 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) Content-Type: text/plain; charset="utf-8" From: Erik Skultety Now that we have a generic mdevctl command generator, we can unify the test infrastructure as well. Signed-off-by: Erik Skultety Reviewed-by: Laine Stump --- ...19_36ea_4111_8f0a_8c9a70e21366-start.argv} | 0 ...019_36ea_4111_8f0a_8c9a70e21366-stop.argv} | 0 ...36ea_4111_8f0a_8c9a70e21366-undefine.argv} | 0 tests/nodedevmdevctltest.c | 120 +++++------------- 4 files changed, 31 insertions(+), 89 deletions(-) rename tests/nodedevmdevctldata/{mdevctl-start.argv =3D> mdev_d069d019_36e= a_4111_8f0a_8c9a70e21366-start.argv} (100%) rename tests/nodedevmdevctldata/{mdevctl-stop.argv =3D> mdev_d069d019_36ea= _4111_8f0a_8c9a70e21366-stop.argv} (100%) rename tests/nodedevmdevctldata/{mdevctl-undefine.argv =3D> mdev_d069d019_= 36ea_4111_8f0a_8c9a70e21366-undefine.argv} (100%) diff --git a/tests/nodedevmdevctldata/mdevctl-start.argv b/tests/nodedevmde= vctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.argv similarity index 100% rename from tests/nodedevmdevctldata/mdevctl-start.argv rename to tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2136= 6-start.argv diff --git a/tests/nodedevmdevctldata/mdevctl-stop.argv b/tests/nodedevmdev= ctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-stop.argv similarity index 100% rename from tests/nodedevmdevctldata/mdevctl-stop.argv rename to tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2136= 6-stop.argv diff --git a/tests/nodedevmdevctldata/mdevctl-undefine.argv b/tests/nodedev= mdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-undefine.argv similarity index 100% rename from tests/nodedevmdevctldata/mdevctl-undefine.argv rename to tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2136= 6-undefine.argv diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 64ce7fec46..bba521e563 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -10,7 +10,7 @@ =20 #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 -struct startTestInfo { +struct TestInfo { const char *virt_type; int create; const char *filename; @@ -32,24 +32,24 @@ testCommandDryRunCallback(const char *const*args G_GNUC= _UNUSED, *stdinbuf =3D g_strdup(input); } =20 -typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **= ); +typedef virCommand * (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char *= *); =20 =20 static int -testMdevctlCreateOrDefine(const char *virt_type, - int create, - virMdevctlCommand cmd_type, - const char *mdevxml, - const char *cmdfile, - const char *jsonfile) +testMdevctlCmd(const char *virt_type, + int create, + virMdevctlCommand cmd_type, + const char *mdevxml, + const char *cmdfile, + const char *jsonfile) { g_autoptr(virNodeDeviceDef) def =3D NULL; virNodeDeviceObj *obj =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; const char *actualCmdline =3D NULL; int ret =3D -1; - g_autofree char *uuid =3D NULL; - g_autofree char *errmsg =3D NULL; + g_autofree char *outbuf =3D NULL; + g_autofree char *errbuf =3D NULL; g_autofree char *stdinbuf =3D NULL; g_autoptr(virCommand) cmd =3D NULL; g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); @@ -59,12 +59,17 @@ testMdevctlCreateOrDefine(const char *virt_type, =20 /* this function will set a stdin buffer containing the json configura= tion * of the device. The json value is captured in the callback above */ - cmd =3D nodeDeviceGetMdevctlCommand(def, cmd_type, &uuid, &errmsg); + cmd =3D nodeDeviceGetMdevctlCommand(def, cmd_type, &outbuf, &errbuf); =20 if (!cmd) goto cleanup; =20 - virCommandSetDryRun(dryRunToken, &buf, true, true, testCommandDryRunCa= llback, &stdinbuf); + if (create) + virCommandSetDryRun(dryRunToken, &buf, true, true, + testCommandDryRunCallback, &stdinbuf); + else + virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); + if (virCommandRun(cmd, NULL) < 0) goto cleanup; =20 @@ -74,7 +79,7 @@ testMdevctlCreateOrDefine(const char *virt_type, if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < 0) goto cleanup; =20 - if (virTestCompareToFile(stdinbuf, jsonfile) < 0) + if (create && virTestCompareToFile(stdinbuf, jsonfile) < 0) goto cleanup; =20 ret =3D 0; @@ -84,10 +89,11 @@ testMdevctlCreateOrDefine(const char *virt_type, return ret; } =20 + static int -testMdevctlCreateOrDefineHelper(const void *data) +testMdevctlHelper(const void *data) { - const struct startTestInfo *info =3D data; + const struct TestInfo *info =3D data; const char *cmd =3D virMdevctlCommandTypeToString(info->command); g_autofree char *mdevxml =3D NULL; g_autofree char *cmdlinefile =3D NULL; @@ -100,67 +106,10 @@ testMdevctlCreateOrDefineHelper(const void *data) jsonfile =3D g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_s= rcdir, info->filename, cmd); =20 - return testMdevctlCreateOrDefine(info->virt_type, info->create, info->= command, - mdevxml, cmdlinefile, jsonfile); -} - -typedef virCommand* (*GetStopUndefineCmdFunc)(virNodeDeviceDef *def, char = **errbuf); -struct UuidCommandTestInfo { - const char *filename; - virMdevctlCommand command; -}; - -static int -testMdevctlUuidCommand(virMdevctlCommand command, - const char *mdevxml, const char *outfile) -{ - g_autoptr(virNodeDeviceDef) def =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - const char *actualCmdline =3D NULL; - int ret =3D -1; - g_autoptr(virCommand) cmd =3D NULL; - g_autofree char *errmsg =3D NULL; - g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); - - if (!(def =3D virNodeDeviceDefParseFile(mdevxml, EXISTING_DEVICE, "QEM= U"))) - goto cleanup; - - cmd =3D nodeDeviceGetMdevctlCommand(def, command, NULL, &errmsg); - - if (!cmd) - goto cleanup; - - virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - if (!(actualCmdline =3D virBufferCurrentContent(&buf))) - goto cleanup; - - if (virTestCompareToFileFull(actualCmdline, outfile, false) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - return ret; + return testMdevctlCmd(info->virt_type, info->create, info->command, + mdevxml, cmdlinefile, jsonfile); } =20 -static int -testMdevctlUuidCommandHelper(const void *data) -{ - const struct UuidCommandTestInfo *info =3D data; - const char *cmd =3D virMdevctlCommandTypeToString(info->command); - g_autofree char *cmdlinefile =3D NULL; - g_autofree char *mdevxml =3D NULL; - - mdevxml =3D g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir, - info->filename); - cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv= ", - abs_srcdir, cmd); - - return testMdevctlUuidCommand(info->command, mdevxml, cmdlinefile); -} =20 static int testMdevctlListDefined(const void *data G_GNUC_UNUSED) @@ -369,35 +318,28 @@ mymain(void) =20 #define DO_TEST_CMD(desc, virt_type, create, filename, command) \ do { \ - struct startTestInfo info =3D { virt_type, create, filename, comma= nd }; \ - DO_TEST_FULL(desc, testMdevctlCreateOrDefineHelper, &info); \ + struct TestInfo info =3D { virt_type, create, filename, command };= \ + DO_TEST_FULL(desc, testMdevctlHelper, &info); \ } \ while (0) =20 #define DO_TEST_CREATE(filename) \ - DO_TEST_CMD("mdevctl create " filename, "QEMU", CREATE_DEVICE, filenam= e, MDEVCTL_CMD_CREATE) + DO_TEST_CMD("create mdev " filename, "QEMU", CREATE_DEVICE, filename, = MDEVCTL_CMD_CREATE) =20 #define DO_TEST_DEFINE(filename) \ - DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filenam= e, MDEVCTL_CMD_DEFINE) - -#define DO_TEST_UUID_COMMAND_FULL(desc, filename, command) \ - do { \ - struct UuidCommandTestInfo info =3D { filename, command }; \ - DO_TEST_FULL(desc, testMdevctlUuidCommandHelper, &info); \ - } \ - while (0) + DO_TEST_CMD("define mdev " filename, "QEMU", CREATE_DEVICE, filename, = MDEVCTL_CMD_DEFINE) =20 #define DO_TEST_STOP(filename) \ - DO_TEST_UUID_COMMAND_FULL("mdevctl stop " filename, filename, MDEVCTL_= CMD_STOP) + DO_TEST_CMD("stop mdev " filename, "QEMU", EXISTING_DEVICE, filename, = MDEVCTL_CMD_STOP) =20 #define DO_TEST_UNDEFINE(filename) \ - DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " filename, filename, MDEV= CTL_CMD_UNDEFINE) + DO_TEST_CMD("undefine mdev" filename, "QEMU", EXISTING_DEVICE, filenam= e, MDEVCTL_CMD_UNDEFINE) =20 #define DO_TEST_START(filename) \ - DO_TEST_UUID_COMMAND_FULL("mdevctl start " filename, filename, MDEVCTL= _CMD_START) + DO_TEST_CMD("start mdev " filename, "QEMU", EXISTING_DEVICE, filename,= MDEVCTL_CMD_START) =20 #define DO_TEST_LIST_DEFINED() \ - DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) + DO_TEST_FULL("list defined mdevs", testMdevctlListDefined, NULL) =20 #define DO_TEST_PARSE_JSON(filename) \ DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filenam= e) --=20 2.26.3