From nobody Sat May 4 12:06:55 2024 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 1505462676546690.2778008818967; Fri, 15 Sep 2017 01:04:36 -0700 (PDT) Received: from localhost ([::1]:51833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslc3-0000Ui-IP for importer@patchew.org; Fri, 15 Sep 2017 04:04:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslaD-0007ib-KT for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaB-0000Yx-Uc for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50272) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaB-0000Yg-JM for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:39 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93905883CE; Fri, 15 Sep 2017 08:02:38 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E29568B1F; Fri, 15 Sep 2017 08:02:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 93905883CE 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=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:21 +0200 Message-Id: <1505462549-27298-2-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 15 Sep 2017 08:02:38 +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] [PULL 1/9] tests: Introduce generic device hot-plug/hot-unplug functions 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow 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" A lot of tests provide code for adding and removing a device via the device_add and device_del QMP commands. Maintaining this code in so many places is cumbersome and error-prone (some of the code parts check the responses for device deletion in an incorrect way, for example, we've got to deal with both, error code and DEVICE_DEL event here). So let's provide some proper generic functions for adding and removing a device instead. The code for correctly unplugging a device has been taken from a patch from Peter Xu. Reviewed-by: Peter Xu Tested-by: Peter Xu Signed-off-by: Thomas Huth --- tests/libqos/pci.c | 19 ++---------- tests/libqos/usb.c | 30 ++++--------------- tests/libqtest.c | 75 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/libqtest.h | 19 ++++++++++++ tests/usb-hcd-uhci-test.c | 26 ++-------------- tests/usb-hcd-xhci-test.c | 51 +++---------------------------- tests/virtio-scsi-test.c | 24 ++------------- tests/virtio-serial-test.c | 25 ++-------------- 8 files changed, 113 insertions(+), 156 deletions(-) diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 2dcdead..df1f98e 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -394,21 +394,6 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t ad= dr) void qpci_plug_device_test(const char *driver, const char *id, uint8_t slot, const char *opts) { - QDict *response; - char *cmd; - - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': '%s'," - " 'addr': '%d'," - " %s%s" - " 'id': '%s'" - "}}", driver, slot, - opts ? opts : "", opts ? "," : "", - id); - response =3D qmp(cmd); - g_free(cmd); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); + qtest_qmp_device_add(driver, id, "'addr': '%d'%s%s", slot, + opts ? ", " : "", opts ? opts : ""); } diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c index 0cdfaec..2a47604 100644 --- a/tests/libqos/usb.c +++ b/tests/libqos/usb.c @@ -40,34 +40,16 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t = expect) void usb_test_hotplug(const char *hcd_id, const int port, void (*port_check)(void)) { - QDict *response; - char *cmd; + char *id =3D g_strdup_printf("usbdev%d", port); =20 - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': 'usb-tablet'," - " 'port': '%d'," - " 'bus': '%s.0'," - " 'id': 'usbdev%d'" - "}}", port, hcd_id, port); - response =3D qmp(cmd); - g_free(cmd); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); + qtest_qmp_device_add("usb-tablet", id, "'port': '%d', 'bus': '%s.0'", + port, hcd_id); =20 if (port_check) { port_check(); } =20 - cmd =3D g_strdup_printf("{'execute': 'device_del'," - " 'arguments': {" - " 'id': 'usbdev%d'" - "}}", port); - response =3D qmp(cmd); - g_free(cmd); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qtest_qmp_device_del(id); + + g_free(id); } diff --git a/tests/libqtest.c b/tests/libqtest.c index b9a1f18..0c12b38 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -987,3 +987,78 @@ void qtest_cb_for_every_machine(void (*cb)(const char = *machine)) qtest_end(); QDECREF(response); } + +/* + * Generic hot-plugging test via the device_add QMP command. + */ +void qtest_qmp_device_add(const char *driver, const char *id, const char *= fmt, + ...) +{ + QDict *response; + char *cmd, *opts =3D NULL; + va_list va; + + if (fmt) { + va_start(va, fmt); + opts =3D g_strdup_vprintf(fmt, va); + va_end(va); + } + + cmd =3D g_strdup_printf("{'execute': 'device_add'," + " 'arguments': { 'driver': '%s', 'id': '%s'%s%s = }}", + driver, id, opts ? ", " : "", opts ? opts : ""); + g_free(opts); + + response =3D qmp(cmd); + g_free(cmd); + g_assert(response); + g_assert(!qdict_haskey(response, "event")); /* We don't expect any eve= nts */ + g_assert(!qdict_haskey(response, "error")); + QDECREF(response); +} + +/* + * Generic hot-unplugging test via the device_del QMP command. + * Device deletion will get one response and one event. For example: + * + * {'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 - so we've got to detect both. + */ +void qtest_qmp_device_del(const char *id) +{ + QDict *response1, *response2, *event =3D NULL; + char *cmd; + + 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_cmpstr(qdict_get_str(event, "event"), =3D=3D, "DEVICE_DELETED= "); + + QDECREF(response1); + QDECREF(response2); +} diff --git a/tests/libqtest.h b/tests/libqtest.h index 3ae5709..44803d7 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -927,4 +927,23 @@ QDict *qmp_fd(int fd, const char *fmt, ...); */ void qtest_cb_for_every_machine(void (*cb)(const char *machine)); =20 +/** + * qtest_qmp_device_add: + * @driver: Name of the device that should be added + * @id: Identification string + * @fmt: printf-like format string for further options to device_add + * + * Generic hot-plugging test via the device_add QMP command. + */ +void qtest_qmp_device_add(const char *driver, const char *id, const char *= fmt, + ...) GCC_FMT_ATTR(3, 4); + +/** + * qtest_qmp_device_del: + * @id: Identification string + * + * Generic hot-unplugging test via the device_del QMP command. + */ +void qtest_qmp_device_del(const char *id); + #endif diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c index 5b500fe..62e0c78 100644 --- a/tests/usb-hcd-uhci-test.c +++ b/tests/usb-hcd-uhci-test.c @@ -48,31 +48,9 @@ static void test_uhci_hotplug(void) =20 static void test_usb_storage_hotplug(void) { - QDict *response; + qtest_qmp_device_add("usb-storage", "usbdev0", "'drive': 'drive0'"); =20 - response =3D qmp("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': 'usb-storage'," - " 'drive': 'drive0'," - " 'id': 'usbdev0'" - "}}"); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response =3D qmp("{'execute': 'device_del'," - " 'arguments': {" - " 'id': 'usbdev0'" - "}}"); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qtest_qmp_device_del("usbdev0"); } =20 int main(int argc, char **argv) diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c index 031764d..9c14e30 100644 --- a/tests/usb-hcd-xhci-test.c +++ b/tests/usb-hcd-xhci-test.c @@ -23,59 +23,16 @@ static void test_xhci_hotplug(void) =20 static void test_usb_uas_hotplug(void) { - QDict *response; - - response =3D qmp("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': 'usb-uas'," - " 'id': 'uas'" - "}}"); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response =3D qmp("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': 'scsi-hd'," - " 'drive': 'drive0'," - " 'id': 'scsi-hd'" - "}}"); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); + qtest_qmp_device_add("usb-uas", "uas", NULL); + qtest_qmp_device_add("scsi-hd", "scsihd", "'drive': 'drive0'"); =20 /* TODO: UAS HBA driver in libqos, to check that added disk is visible after BUS rescan */ =20 - response =3D qmp("{'execute': 'device_del'," - " 'arguments': {" - " 'id': 'scsi-hd'" - "}}"); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response =3D qmp(""); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); - - - response =3D qmp("{'execute': 'device_del'," - " 'arguments': {" - " 'id': 'uas'" - "}}"); - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qtest_qmp_device_del("scsihd"); + qtest_qmp_device_del("uas"); } =20 int main(int argc, char **argv) diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 87a3b6e..d148512 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -192,32 +192,12 @@ static void pci_nop(void) =20 static void hotplug(void) { - QDict *response; QOSState *qs; =20 qs =3D qvirtio_scsi_start( "-drive id=3Ddrv1,if=3Dnone,file=3Dnull-co://,format=3Draw"); - response =3D qmp("{\"execute\": \"device_add\"," - " \"arguments\": {" - " \"driver\": \"scsi-hd\"," - " \"id\": \"scsi-hd\"," - " \"drive\": \"drv1\"" - "}}"); - - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response =3D qmp("{\"execute\": \"device_del\"," - " \"arguments\": {" - " \"id\": \"scsi-hd\"" - "}}"); - - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qtest_qmp_device_add("scsi-hd", "scsihd", "'drive': 'drv1'"); + qtest_qmp_device_del("scsihd"); qvirtio_scsi_stop(qs); } =20 diff --git a/tests/virtio-serial-test.c b/tests/virtio-serial-test.c index b14d943..7d1517d 100644 --- a/tests/virtio-serial-test.c +++ b/tests/virtio-serial-test.c @@ -17,28 +17,9 @@ static void pci_nop(void) =20 static void hotplug(void) { - QDict *response; - - response =3D qmp("{\"execute\": \"device_add\"," - " \"arguments\": {" - " \"driver\": \"virtserialport\"," - " \"id\": \"hp-port\"" - "}}"); - - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response =3D qmp("{\"execute\": \"device_del\"," - " \"arguments\": {" - " \"id\": \"hp-port\"" - "}}"); - - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qtest_qmp_device_add("virtserialport", "hp-port", NULL); + + qtest_qmp_device_del("hp-port"); } =20 int main(int argc, char **argv) --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 1505462674201914.1457752935559; Fri, 15 Sep 2017 01:04:34 -0700 (PDT) Received: from localhost ([::1]:51832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslc1-0000S2-5B for importer@patchew.org; Fri, 15 Sep 2017 04:04:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslaE-0007ih-V5 for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaE-0000bB-25 for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47888) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaD-0000Zq-SC for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2F665F7B7; Fri, 15 Sep 2017 08:02:40 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE9F268B1F; Fri, 15 Sep 2017 08:02:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D2F665F7B7 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:22 +0200 Message-Id: <1505462549-27298-3-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 15 Sep 2017 08:02:41 +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] [PULL 2/9] tests/test-hmp: Remove puv3 and tricore_testboard from the blacklist 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow 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" The problem with puv3 has been fixed with 0ac241bcf9f9d99a252a352a162f ('unicore32: abort when entering "x 0" on the monitor') and the problem with tricore_testboard has been fixed with b190f477e29c7cd03a8fee49c96d ('qemu-system-tricore: segfault when entering "x 0" on the monitor'). Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Thomas Huth --- tests/test-hmp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test-hmp.c b/tests/test-hmp.c index d124e81..4156d61 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -138,8 +138,7 @@ static void add_machine_test_case(const char *mname) char *path; =20 /* Ignore blacklisted machines that have known problems */ - if (!strcmp("puv3", mname) || !strcmp("tricore_testboard", mname) || - !strcmp("xenfv", mname) || !strcmp("xenpv", mname)) { + if (!strcmp("xenfv", mname) || !strcmp("xenpv", mname)) { return; } =20 --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 150546282909229.322341335103715; Fri, 15 Sep 2017 01:07:09 -0700 (PDT) Received: from localhost ([::1]:51844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsleW-0002ki-9H for importer@patchew.org; Fri, 15 Sep 2017 04:07:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslaH-0007kY-O5 for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaG-0000d3-Ly for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaG-0000cg-Ft for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7ED9581DF3; Fri, 15 Sep 2017 08:02:43 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 376FE68B1F; Fri, 15 Sep 2017 08:02:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7ED9581DF3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:23 +0200 Message-Id: <1505462549-27298-4-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 15 Sep 2017 08:02:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 3/9] tests/libqtest: Use a proper error message if QTEST_QEMU_BINARY is missing 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The user can currently still cause an abort() if running certain tests (like the prom-env-test) without setting the QTEST_QEMU_BINARY first. A similar problem has been fixed with commit 7c933ad61b8f3f51337 already, but forgot to also take care of the qtest_get_arch() function, so let's introduce a proper wrapper around getenv("QTEST_QEMU_BINARY") that can be used in both locations now. Buglink: https://bugs.launchpad.net/qemu/+bug/1713434 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: John Snow Signed-off-by: Thomas Huth --- tests/libqtest.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 0c12b38..3daa0e3 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -150,6 +150,19 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *= data) g_hook_prepend(&abrt_hooks, hook); } =20 +static const char *qtest_qemu_binary(void) +{ + const char *qemu_bin; + + qemu_bin =3D getenv("QTEST_QEMU_BINARY"); + if (!qemu_bin) { + fprintf(stderr, "Environment variable QTEST_QEMU_BINARY required\n= "); + exit(1); + } + + return qemu_bin; +} + QTestState *qtest_init_without_qmp_handshake(const char *extra_args) { QTestState *s; @@ -157,13 +170,7 @@ QTestState *qtest_init_without_qmp_handshake(const cha= r *extra_args) gchar *socket_path; gchar *qmp_socket_path; gchar *command; - const char *qemu_binary; - - qemu_binary =3D getenv("QTEST_QEMU_BINARY"); - if (!qemu_binary) { - fprintf(stderr, "Environment variable QTEST_QEMU_BINARY required\n= "); - exit(1); - } + const char *qemu_binary =3D qtest_qemu_binary(); =20 s =3D g_malloc(sizeof(*s)); =20 @@ -624,8 +631,7 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) =20 const char *qtest_get_arch(void) { - const char *qemu =3D getenv("QTEST_QEMU_BINARY"); - g_assert(qemu !=3D NULL); + const char *qemu =3D qtest_qemu_binary(); const char *end =3D strrchr(qemu, '/'); =20 return end + strlen("/qemu-system-"); --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 15054626834641018.3499253043861; Fri, 15 Sep 2017 01:04:43 -0700 (PDT) Received: from localhost ([::1]:51834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslcA-0000cc-MH for importer@patchew.org; Fri, 15 Sep 2017 04:04:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslaM-0007o3-3C for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaI-0000fX-Ur for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49330) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaI-0000eO-PQ for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDDC785542; Fri, 15 Sep 2017 08:02:45 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id D92106D814; Fri, 15 Sep 2017 08:02:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BDDC785542 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:24 +0200 Message-Id: <1505462549-27298-5-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 15 Sep 2017 08:02:45 +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] [PULL 4/9] tests: Fix broken ivshmem-server-msi/-irq tests 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow 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" Broken with commit b4ba67d9a7025 ("libqos: Change PCI accessors to take opaque BAR handle") a while ago, but nobody noticed since the tests are not run by default: The msix_pba_bar is not correctly initialized anymore if bir_pba has the same value as bir_table. With this fix, "make check SPEED=3Dslow" should work fine again. Fixes: b4ba67d9a702507793c2724e56f98e9b0f7be02b Tested-by: Cornelia Huck Reviewed-by: David Gibson Reviewed-by: Laurent Vivier Signed-off-by: Thomas Huth --- tests/libqos/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index df1f98e..0b73cb2 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -120,6 +120,8 @@ void qpci_msix_enable(QPCIDevice *dev) bir_pba =3D table & PCI_MSIX_FLAGS_BIRMASK; if (bir_pba !=3D bir_table) { dev->msix_pba_bar =3D qpci_iomap(dev, bir_pba, NULL); + } else { + dev->msix_pba_bar =3D dev->msix_table_bar; } dev->msix_pba_off =3D table & ~PCI_MSIX_FLAGS_BIRMASK; =20 @@ -138,8 +140,11 @@ void qpci_msix_disable(QPCIDevice *dev) qpci_config_writew(dev, addr + PCI_MSIX_FLAGS, val & ~PCI_MSIX_FLAGS_ENAB= LE); =20 + if (dev->msix_pba_bar.addr !=3D dev->msix_table_bar.addr) { + qpci_iounmap(dev, dev->msix_pba_bar); + } qpci_iounmap(dev, dev->msix_table_bar); - qpci_iounmap(dev, dev->msix_pba_bar); + dev->msix_enabled =3D 0; dev->msix_table_off =3D 0; dev->msix_pba_off =3D 0; --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 1505462832529545.3625841578204; Fri, 15 Sep 2017 01:07:12 -0700 (PDT) Received: from localhost ([::1]:51845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsleZ-0002nu-Hc for importer@patchew.org; Fri, 15 Sep 2017 04:07:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslaV-0007ve-43 for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaL-0000hA-7a for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaK-0000gM-Vz for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 041814DAFA; Fri, 15 Sep 2017 08:02:48 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22D9A68B1F; Fri, 15 Sep 2017 08:02:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 041814DAFA Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:25 +0200 Message-Id: <1505462549-27298-6-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 15 Sep 2017 08:02:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 5/9] test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Eric Blake Back when the test was introduced, in commit 62c39b307, the test was set up to run qemu-ga directly on the host performing the test, and defaults to limiting itself to safe commands. At the time, it was envisioned that setting QGA_TEST_SIDE_EFFECTING in the environment could cover a few more commands, while noting the potential danger of those side effects running in the host. But this has NEVER been tested: if you enable the environment variable, the test WILL fail. One obvious reason: if you are not running as root, you'll probably get a permission failure when trying to freeze the file systems, or when changing system time. Less obvious: if you run the test as root (wow, you're brave), you could end up hanging if the test tries to log things to a temporarily frozen filesystem. But the cutest reason of all: if you get past the above hurdles, the test uses invalid JSON in test_qga_fstrim() (missing '' around the dictionary key 'minimum'), and will thus fail an assertion in qmp_fd(). Rather than leave this untested time-bomb in place, rip it out. Hopefully, as originally envisioned, we can find an opportunity to test an actual sandboxed guest where the guest-agent has full permissions and will not unduly affect the host running the test - if so, 'git revert' can be used if desired, for salvaging any useful parts of this attempt. Signed-off-by: Eric Blake Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- tests/test-qga.c | 90 ----------------------------------------------------= ---- 1 file changed, 90 deletions(-) diff --git a/tests/test-qga.c b/tests/test-qga.c index 06783e7..fd6bc76 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -642,65 +642,6 @@ static void test_qga_get_time(gconstpointer fix) QDECREF(ret); } =20 -static void test_qga_set_time(gconstpointer fix) -{ - const TestFixture *fixture =3D fix; - QDict *ret; - int64_t current, time; - gchar *cmd; - - /* get current time */ - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - current =3D qdict_get_int(ret, "return"); - g_assert_cmpint(current, >, 0); - QDECREF(ret); - - /* set some old time */ - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-set-time'," - " 'arguments': { 'time': 1000 } }"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); - - /* check old time */ - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - time =3D qdict_get_int(ret, "return"); - g_assert_cmpint(time / 1000, <, G_USEC_PER_SEC * 10); - QDECREF(ret); - - /* set back current time */ - cmd =3D g_strdup_printf("{'execute': 'guest-set-time'," - " 'arguments': { 'time': %" PRId64 " } }", - current + time * 1000); - ret =3D qmp_fd(fixture->fd, cmd); - g_free(cmd); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); -} - -static void test_qga_fstrim(gconstpointer fix) -{ - const TestFixture *fixture =3D fix; - QDict *ret; - QList *list; - const QListEntry *entry; - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fstrim'," - " arguments: { minimum: 4194304 } }"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - list =3D qdict_get_qlist(ret, "return"); - entry =3D qlist_first(list); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "paths")); - - QDECREF(ret); -} - static void test_qga_blacklist(gconstpointer data) { TestFixture fix; @@ -831,30 +772,6 @@ static void test_qga_fsfreeze_status(gconstpointer fix) QDECREF(ret); } =20 -static void test_qga_fsfreeze_and_thaw(gconstpointer fix) -{ - const TestFixture *fixture =3D fix; - QDict *ret; - const gchar *status; - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-freeze'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - status =3D qdict_get_try_str(ret, "return"); - g_assert_cmpstr(status, =3D=3D, "frozen"); - QDECREF(ret); - - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-thaw'}"); - g_assert_nonnull(ret); - qmp_assert_no_error(ret); - QDECREF(ret); -} - static void test_qga_guest_exec(gconstpointer fix) { const TestFixture *fixture =3D fix; @@ -1029,13 +946,6 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/guest-get-osinfo", &fix, test_qga_guest_get_osinfo); =20 - if (g_getenv("QGA_TEST_SIDE_EFFECTING")) { - g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix, - test_qga_fsfreeze_and_thaw); - g_test_add_data_func("/qga/set-time", &fix, test_qga_set_time); - g_test_add_data_func("/qga/fstrim", &fix, test_qga_fstrim); - } - ret =3D g_test_run(); =20 fixture_tear_down(&fix, NULL); --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 1505462837160408.5485355089337; Fri, 15 Sep 2017 01:07:17 -0700 (PDT) Received: from localhost ([::1]:51846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslee-0002rN-Ax for importer@patchew.org; Fri, 15 Sep 2017 04:07:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslaV-0007vf-4M for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaR-0000kx-WB for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaR-0000ko-Ne for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4802882FF; Fri, 15 Sep 2017 08:02:54 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDCBE6DAC1; Fri, 15 Sep 2017 08:02:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B4802882FF Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:26 +0200 Message-Id: <1505462549-27298-7-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 15 Sep 2017 08:02:54 +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] [PULL 6/9] qtest: Don't perform side effects inside assertion 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow 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" From: Eric Blake Assertions should be separate from the side effects, since in theory, g_assert() can be disabled (in practice, we can't really ever do that). Signed-off-by: Eric Blake Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- qtest.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/qtest.c b/qtest.c index 88a09e9..cbbfb71 100644 --- a/qtest.c +++ b/qtest.c @@ -332,10 +332,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) strcmp(words[0], "outl") =3D=3D 0) { unsigned long addr; unsigned long value; + int ret; =20 g_assert(words[1] && words[2]); - g_assert(qemu_strtoul(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtoul(words[2], NULL, 0, &value) =3D=3D 0); + ret =3D qemu_strtoul(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtoul(words[2], NULL, 0, &value); + g_assert(ret =3D=3D 0); g_assert(addr <=3D 0xffff); =20 if (words[0][3] =3D=3D 'b') { @@ -352,9 +355,11 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) strcmp(words[0], "inl") =3D=3D 0) { unsigned long addr; uint32_t value =3D -1U; + int ret; =20 g_assert(words[1]); - g_assert(qemu_strtoul(words[1], NULL, 0, &addr) =3D=3D 0); + ret =3D qemu_strtoul(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); g_assert(addr <=3D 0xffff); =20 if (words[0][2] =3D=3D 'b') { @@ -372,10 +377,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) strcmp(words[0], "writeq") =3D=3D 0) { uint64_t addr; uint64_t value; + int ret; =20 g_assert(words[1] && words[2]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &value) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &value); + g_assert(ret =3D=3D 0); =20 if (words[0][5] =3D=3D 'b') { uint8_t data =3D value; @@ -401,9 +409,11 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) strcmp(words[0], "readq") =3D=3D 0) { uint64_t addr; uint64_t value =3D UINT64_C(-1); + int ret; =20 g_assert(words[1]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); =20 if (words[0][4] =3D=3D 'b') { uint8_t data; @@ -427,10 +437,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len, i; uint8_t *data; char *enc; + int ret; =20 g_assert(words[1] && words[2]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); /* We'd send garbage to libqtest if len is 0 */ g_assert(len); =20 @@ -451,10 +464,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len; uint8_t *data; gchar *b64_data; + int ret; =20 g_assert(words[1] && words[2]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); =20 data =3D g_malloc(len); cpu_physical_memory_read(addr, data, len); @@ -468,10 +484,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len, i; uint8_t *data; size_t data_len; + int ret; =20 g_assert(words[1] && words[2] && words[3]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); =20 data_len =3D strlen(words[3]); if (data_len < 3) { @@ -497,11 +516,15 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint64_t addr, len; uint8_t *data; unsigned long pattern; + int ret; =20 g_assert(words[1] && words[2] && words[3]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); - g_assert(qemu_strtoul(words[3], NULL, 0, &pattern) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtoul(words[3], NULL, 0, &pattern); + g_assert(ret =3D=3D 0); =20 if (len) { data =3D g_malloc(len); @@ -517,10 +540,13 @@ static void qtest_process_command(CharBackend *chr, g= char **words) uint8_t *data; size_t data_len; gsize out_len; + int ret; =20 g_assert(words[1] && words[2] && words[3]); - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) =3D=3D 0); - g_assert(qemu_strtou64(words[2], NULL, 0, &len) =3D=3D 0); + ret =3D qemu_strtou64(words[1], NULL, 0, &addr); + g_assert(ret =3D=3D 0); + ret =3D qemu_strtou64(words[2], NULL, 0, &len); + g_assert(ret =3D=3D 0); =20 data_len =3D strlen(words[3]); if (data_len < 3) { @@ -551,11 +577,16 @@ static void qtest_process_command(CharBackend *chr, g= char **words) } else if (strcmp(words[0], "rtas") =3D=3D 0) { uint64_t res, args, ret; unsigned long nargs, nret; - - g_assert(qemu_strtoul(words[2], NULL, 0, &nargs) =3D=3D 0); - g_assert(qemu_strtou64(words[3], NULL, 0, &args) =3D=3D 0); - g_assert(qemu_strtoul(words[4], NULL, 0, &nret) =3D=3D 0); - g_assert(qemu_strtou64(words[5], NULL, 0, &ret) =3D=3D 0); + int rc; + + rc =3D qemu_strtoul(words[2], NULL, 0, &nargs); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtou64(words[3], NULL, 0, &args); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtoul(words[4], NULL, 0, &nret); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtou64(words[5], NULL, 0, &ret); + g_assert(rc =3D=3D 0); res =3D qtest_rtas_call(words[1], nargs, args, nret, ret); =20 qtest_send_prefix(chr); @@ -565,7 +596,8 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) int64_t ns; =20 if (words[1]) { - g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) =3D=3D 0); + int ret =3D qemu_strtoi64(words[1], NULL, 0, &ns); + g_assert(ret =3D=3D 0); } else { ns =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); } @@ -575,9 +607,11 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); } else if (qtest_enabled() && strcmp(words[0], "clock_set") =3D=3D 0) { int64_t ns; + int ret; =20 g_assert(words[1]); - g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) =3D=3D 0); + ret =3D qemu_strtoi64(words[1], NULL, 0, &ns); + g_assert(ret =3D=3D 0); qtest_clock_warp(ns); qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 1505462840921303.0250781632327; Fri, 15 Sep 2017 01:07:20 -0700 (PDT) Received: from localhost ([::1]:51847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsleh-0002wj-Vc for importer@patchew.org; Fri, 15 Sep 2017 04:07:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslaV-0007vg-4d for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaU-0000lU-2o for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46902) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaT-0000lL-TG for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:02:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1752FF4C; Fri, 15 Sep 2017 08:02:56 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C5EA6D814; Fri, 15 Sep 2017 08:02:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E1752FF4C Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:27 +0200 Message-Id: <1505462549-27298-8-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 15 Sep 2017 08:02:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 7/9] numa-test: Use hmp() 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Eric Blake Don't open-code something that has a convenient helper available. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- tests/numa-test.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/tests/numa-test.c b/tests/numa-test.c index 3f63684..e1b6152 100644 --- a/tests/numa-test.c +++ b/tests/numa-test.c @@ -17,21 +17,6 @@ static char *make_cli(const char *generic_cli, const cha= r *test_cli) return g_strdup_printf("%s %s", generic_cli ? generic_cli : "", test_c= li); } =20 -static char *hmp_info_numa(void) -{ - QDict *resp; - char *s; - - resp =3D qmp("{ 'execute': 'human-monitor-command', 'arguments': " - "{ 'command-line': 'info numa '} }"); - g_assert(resp); - g_assert(qdict_haskey(resp, "return")); - s =3D g_strdup(qdict_get_str(resp, "return")); - g_assert(s); - QDECREF(resp); - return s; -} - static void test_mon_explicit(const void *data) { char *s; @@ -42,7 +27,7 @@ static void test_mon_explicit(const void *data) "-numa node,nodeid=3D1,cpus=3D4-7 "); qtest_start(cli); =20 - s =3D hmp_info_numa(); + s =3D hmp("info numa"); g_assert(strstr(s, "node 0 cpus: 0 1 2 3")); g_assert(strstr(s, "node 1 cpus: 4 5 6 7")); g_free(s); @@ -59,7 +44,7 @@ static void test_mon_default(const void *data) cli =3D make_cli(data, "-smp 8 -numa node -numa node"); qtest_start(cli); =20 - s =3D hmp_info_numa(); + s =3D hmp("info numa"); g_assert(strstr(s, "node 0 cpus: 0 2 4 6")); g_assert(strstr(s, "node 1 cpus: 1 3 5 7")); g_free(s); @@ -78,7 +63,7 @@ static void test_mon_partial(const void *data) "-numa node,nodeid=3D1,cpus=3D4-5 "); qtest_start(cli); =20 - s =3D hmp_info_numa(); + s =3D hmp("info numa"); g_assert(strstr(s, "node 0 cpus: 0 1 2 3 6 7")); g_assert(strstr(s, "node 1 cpus: 4 5")); g_free(s); --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 1505463038026807.0828981089205; Fri, 15 Sep 2017 01:10:38 -0700 (PDT) Received: from localhost ([::1]:51859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslht-0007dd-12 for importer@patchew.org; Fri, 15 Sep 2017 04:10:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslac-00081U-8J for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaW-0000lz-Ap for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaW-0000ls-5J for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B0A9804E3; Fri, 15 Sep 2017 08:02:59 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A70068B1F; Fri, 15 Sep 2017 08:02:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B0A9804E3 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:28 +0200 Message-Id: <1505462549-27298-9-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 15 Sep 2017 08:02:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 8/9] libqtest: Remove dead qtest_instances variable 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Eric Blake Prior to commit 063c23d9, we were tracking a list of parallel qtest objects, in order to safely clean up a SIGABRT handler only after the last connection quits. But when we switched to more of glib's infrastructure, the list became dead code that is never assigned to. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- tests/libqtest.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 3daa0e3..cbd7094 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -42,7 +42,6 @@ struct QTestState }; =20 static GHookList abrt_hooks; -static GList *qtest_instances; static struct sigaction sigact_old; =20 #define g_assert_no_errno(ret) do { \ @@ -247,13 +246,10 @@ QTestState *qtest_init(const char *extra_args) =20 void qtest_quit(QTestState *s) { - qtest_instances =3D g_list_remove(qtest_instances, s); g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s= )); =20 /* Uninstall SIGABRT handler on last instance */ - if (!qtest_instances) { - cleanup_sigabrt_handler(); - } + cleanup_sigabrt_handler(); =20 kill_qemu(s); close(s->fd); --=20 1.8.3.1 From nobody Sat May 4 12:06:55 2024 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 1505462955106819.4404381703339; Fri, 15 Sep 2017 01:09:15 -0700 (PDT) Received: from localhost ([::1]:51850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslgX-0005Rx-WB for importer@patchew.org; Fri, 15 Sep 2017 04:09:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dslae-00083R-IL for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dslaY-0000nk-JH for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dslaY-0000mi-Ak for qemu-devel@nongnu.org; Fri, 15 Sep 2017 04:03:02 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50AEC5D697; Fri, 15 Sep 2017 08:03:01 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87F7568B1F; Fri, 15 Sep 2017 08:02:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 50AEC5D697 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 15 Sep 2017 10:02:29 +0200 Message-Id: <1505462549-27298-10-git-send-email-thuth@redhat.com> In-Reply-To: <1505462549-27298-1-git-send-email-thuth@redhat.com> References: <1505462549-27298-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 15 Sep 2017 08:03:01 +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] [PULL 9/9] qtest: Avoid passing raw strings through hmp() 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: Peter Maydell , "Dr. David Alan Gilbert" , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow 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" From: Eric Blake hmp() passes its string argument through the sprintf() family; with a proper attribute, gcc -Wformat warns us when we do something dangerous like passing a non-constant format string. Fortunately, all our strings were safe, but checking whether the string can contain an unintended % is easy to avoid and therefore worth doing. Signed-off-by: Eric Blake Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- tests/libqtest.h | 8 ++++---- tests/test-hmp.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 44803d7..86b3a3b 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -134,14 +134,14 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const c= har *event); /** * qtest_hmp: * @s: #QTestState instance to operate on. - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, formats arguments like sprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * QMP events are discarded. * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmp(QTestState *s, const char *fmt, ...); +char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); =20 /** * qtest_hmpv: @@ -592,13 +592,13 @@ static inline QDict *qmp_eventwait_ref(const char *ev= ent) =20 /** * hmp: - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, formats arguments like sprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * * Returns: the command's output. The caller should g_free() it. */ -char *hmp(const char *fmt, ...); +char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 /** * get_irq: diff --git a/tests/test-hmp.c b/tests/test-hmp.c index 4156d61..5677fbf 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -81,7 +81,7 @@ static void test_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", hmp_cmds[i]); } - response =3D hmp(hmp_cmds[i]); + response =3D hmp("%s", hmp_cmds[i]); g_free(response); } =20 @@ -104,7 +104,7 @@ static void test_info_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", info); } - resp =3D hmp(info); + resp =3D hmp("%s", info); g_free(resp); /* And move forward to the next line */ info =3D strchr(endp + 1, '\n'); --=20 1.8.3.1