From nobody Tue Feb 10 09:24:22 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=1618004008; cv=none; d=zohomail.com; s=zohoarc; b=TsSCxB+WQQs+3MOHRwyEaoC7/rpSBr/vemXl87IgozFsUim4wt91UFRl9DooK0WhC3rc6rHkkq/OxkTgrv/wUXu332c6nD9oWST5UVicHi59KtXVkRQ3EPTqMLpjSivZd8oBjx3mio6UXq/FOzU4vxtx9qX4CqIlrcFAB1WZCwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618004008; 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=xhvS3In7d73FFvKs2yDRRvFZPqrjJnP6lZCK+wWKfpo=; b=kTd2Ee/EEm1YD/U6yJaWQLO9mfRq0e97GhiaosewQCcJdiZIrtK6rwuj2zKKlJWuklqumMmrp/6If2b/DkpCIXdUQQVkptt1c98FO/9sBEw31bG/ye7x4Oa1QQ8Sq2hbQbIxlOhvCkOqft0OTy583q9qToQhtpryo9zDC1i+9BE= 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 1618004008952564.3169806391273; Fri, 9 Apr 2021 14:33:28 -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-282-vKadeBCvMtSnVGMBR3t3Qw-1; Fri, 09 Apr 2021 17:33:23 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E1F7810054F6; Fri, 9 Apr 2021 21:33:18 +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 46DFA5C1A1; Fri, 9 Apr 2021 21:33:18 +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 4E1F818095C9; Fri, 9 Apr 2021 21:33:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 139LXEoV032658 for ; Fri, 9 Apr 2021 17:33:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id B8AAB5D6D3; Fri, 9 Apr 2021 21:33:14 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C4AC5D6A1; Fri, 9 Apr 2021 21:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618004005; 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=xhvS3In7d73FFvKs2yDRRvFZPqrjJnP6lZCK+wWKfpo=; b=daKq5zajrMc20QAb+LF9jI/eIIzpAFpYXgiFoPWSYVfn7Lr+J8HM5s+1pzLDEiAFuzfDdJ +/fQ3wSaUmAV8pcvYIGDh/FXQjG2vUYkO9Mfd7G+JEA51aQyAB6qNUDpUYkcRv+4RmN7Ls 0cRDP+evkkPrjHH0S4Y2nEbGtsZD0S4= X-MC-Unique: vKadeBCvMtSnVGMBR3t3Qw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 09/11] tests: nodedev: Make the mdevctl test function and helper generic Date: Fri, 9 Apr 2021 16:33:04 -0500 Message-Id: <20210409213306.3971286-10-jjongsma@redhat.com> In-Reply-To: <20210409213306.3971286-1-jjongsma@redhat.com> References: <20210409213306.3971286-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.16 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 --- ...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 | 119 +++++------------- 4 files changed, 30 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 c467c798e7..7e192ce118 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; @@ -47,24 +47,24 @@ nodedevCompareToFile(const char *actual, } =20 =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; virNodeDeviceObjPtr 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; =20 @@ -73,12 +73,16 @@ 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(&buf, testCommandDryRunCallback, &stdinbuf); + if (create) + virCommandSetDryRun(&buf, testCommandDryRunCallback, &stdinbuf); + else + virCommandSetDryRun(&buf, NULL, NULL); + if (virCommandRun(cmd, NULL) < 0) goto cleanup; =20 @@ -88,7 +92,7 @@ testMdevctlCreateOrDefine(const char *virt_type, if (nodedevCompareToFile(actualCmdline, cmdfile) < 0) goto cleanup; =20 - if (virTestCompareToFile(stdinbuf, jsonfile) < 0) + if (create && virTestCompareToFile(stdinbuf, jsonfile) < 0) goto cleanup; =20 ret =3D 0; @@ -99,10 +103,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; @@ -115,67 +120,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; - - if (!(def =3D virNodeDeviceDefParseFile(mdevxml, EXISTING_DEVICE, "QEM= U"))) - goto cleanup; - - cmd =3D nodeDeviceGetMdevctlCommand(def, command, NULL, &errmsg); - - if (!cmd) - goto cleanup; - - virCommandSetDryRun(&buf, NULL, NULL); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - if (!(actualCmdline =3D virBufferCurrentContent(&buf))) - goto cleanup; - - if (nodedevCompareToFile(actualCmdline, outfile) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virCommandSetDryRun(NULL, NULL, NULL); - 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) @@ -384,35 +332,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, uuid, command) \ - do { \ - struct UuidCommandTestInfo info =3D { uuid, 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