From nobody Sun Feb 8 15:46:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150529549527320.447997189835974; Wed, 13 Sep 2017 02:38:15 -0700 (PDT) Received: from localhost ([::1]:41205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds47a-0002mQ-Hu for importer@patchew.org; Wed, 13 Sep 2017 05:38:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds45q-000135-Qh for qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ds45p-0007Ur-Qr for qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:36:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ds45p-0007Ue-Iy for qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:36:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3570806A0 for ; Wed, 13 Sep 2017 09:36:24 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08F375C460; Wed, 13 Sep 2017 09:36:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3570806A0 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 13 Sep 2017 17:36:03 +0800 Message-Id: <1505295366-25295-2-git-send-email-peterx@redhat.com> In-Reply-To: <1505295366-25295-1-git-send-email-peterx@redhat.com> References: <1505295366-25295-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 13 Sep 2017 09:36:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/4] libqtest: add qmp_device_del() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Markus Armbruster , peterx@redhat.com, Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Device deletion is tricky since we'll get both a response and an event, while the order of arrival may vary. Provide a helper to handle this complexity. Signed-off-by: Peter Xu --- tests/libqtest.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqtest.h | 8 ++++++++ 2 files changed, 56 insertions(+) diff --git a/tests/libqtest.c b/tests/libqtest.c index b9a1f18..a34d8c4 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -925,6 +925,54 @@ QDict *qmp(const char *fmt, ...) return response; } =20 +void qmp_device_del(const char *id) +{ + QDict *response1, *response2, *event =3D NULL; + char *cmd; + + /* + * device deletion will get one response and one event. E.g.: + * + * {'execute': 'device_del','arguments': { 'id': 'scsi-hd'}} + * + * will get this one: + * + * {"timestamp": {"seconds": 1505289667, "microseconds": 569862}, + * "event": "DEVICE_DELETED", "data": {"device": "scsi-hd", + * "path": "/machine/peripheral/scsi-hd"}} + * + * and this one: + * + * {"return": {}} + * + * But the order of arrival may vary. Detect both. + */ + + cmd =3D g_strdup_printf("{'execute': 'device_del'," + " 'arguments': {" + " 'id': '%s'" + "}}", id); + response1 =3D qmp(cmd); + g_free(cmd); + g_assert(response1); + g_assert(!qdict_haskey(response1, "error")); + + response2 =3D qmp(""); + g_assert(response2); + g_assert(!qdict_haskey(response2, "error")); + + if (qdict_haskey(response1, "event")) { + event =3D response1; + } else if (qdict_haskey(response2, "event")) { + event =3D response2; + } + g_assert(event); + g_assert(!strcmp(qdict_get_str(event, "event"), "DEVICE_DELETED")); + + QDECREF(response1); + QDECREF(response2); +} + void qmp_async(const char *fmt, ...) { va_list ap; diff --git a/tests/libqtest.h b/tests/libqtest.h index 3ae5709..0d48e4b 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -920,6 +920,14 @@ QDict *qmp_fdv(int fd, const char *fmt, va_list ap); QDict *qmp_fd(int fd, const char *fmt, ...); =20 /** + * qmp_device_del: + * @id: The device ID to be deleted + * + * Delete the device with ID @id from QMP interface. + */ +void qmp_device_del(const char *id); + +/** * qtest_cb_for_every_machine: * @cb: Pointer to the callback function * --=20 2.7.4