From nobody Sat Oct 25 08:28:23 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518607390271274.42193000894304; Wed, 14 Feb 2018 03:23:10 -0800 (PST) Received: from localhost ([::1]:37530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elv9X-0007oN-57 for importer@patchew.org; Wed, 14 Feb 2018 06:23:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elv7K-0006Ij-HT for qemu-devel@nongnu.org; Wed, 14 Feb 2018 06:20:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elv7H-00078z-Ci for qemu-devel@nongnu.org; Wed, 14 Feb 2018 06:20:50 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34520 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elv7H-00078N-6B for qemu-devel@nongnu.org; Wed, 14 Feb 2018 06:20:47 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEFBA4040852; Wed, 14 Feb 2018 11:20:46 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id A299A2024CA4; Wed, 14 Feb 2018 11:20:45 +0000 (UTC) From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Date: Wed, 14 Feb 2018 12:20:20 +0100 Message-Id: <1518607234-17739-5-git-send-email-thuth@redhat.com> In-Reply-To: <1518607234-17739-1-git-send-email-thuth@redhat.com> References: <1518607234-17739-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 14 Feb 2018 11:20:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 14 Feb 2018 11:20:46 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 04/18] libqos: Use explicit QTestState for fw_cfg operations 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: , 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 Drop one more client of global_qtest by teaching all fw_cfg test functionality (invoked through alloc-pc) to pass in an explicit QTestState, adjusting all callers. In particular, fw_cfg-test had to reorder things to create the test state prior to creating the fw_cfg (and drop a pointless strdup in the meantime), but that test now no longer depends on global_qtest. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Thomas Huth [thuth: Fixed conflict wrt pc_alloc_init() in vhost-user-test.c] Signed-off-by: Thomas Huth --- tests/boot-order-test.c | 6 +++--- tests/e1000e-test.c | 2 +- tests/fw_cfg-test.c | 13 ++++--------- tests/ide-test.c | 2 +- tests/libqos/fw_cfg.c | 14 ++++++++------ tests/libqos/fw_cfg.h | 10 ++++++---- tests/libqos/libqos.c | 2 +- tests/libqos/libqos.h | 2 +- tests/libqos/malloc-pc.c | 8 ++++---- tests/libqos/malloc-pc.h | 4 ++-- tests/libqos/malloc-spapr.c | 4 ++-- tests/libqos/malloc-spapr.h | 2 +- tests/libqos/malloc.h | 1 + tests/vhost-user-test.c | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/boot-order-test.c b/tests/boot-order-test.c index 508469a..e70f5de 100644 --- a/tests/boot-order-test.c +++ b/tests/boot-order-test.c @@ -132,7 +132,7 @@ static void test_prep_boot_order(void) =20 static uint64_t read_boot_order_pmac(void) { - QFWCFG *fw_cfg =3D mm_fw_cfg_init(0xf0000510); + QFWCFG *fw_cfg =3D mm_fw_cfg_init(global_qtest, 0xf0000510); =20 return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); } @@ -157,7 +157,7 @@ static void test_pmac_newworld_boot_order(void) =20 static uint64_t read_boot_order_sun4m(void) { - QFWCFG *fw_cfg =3D mm_fw_cfg_init(0xd00000510ULL); + QFWCFG *fw_cfg =3D mm_fw_cfg_init(global_qtest, 0xd00000510ULL); =20 return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); } @@ -169,7 +169,7 @@ static void test_sun4m_boot_order(void) =20 static uint64_t read_boot_order_sun4u(void) { - QFWCFG *fw_cfg =3D io_fw_cfg_init(0x510); + QFWCFG *fw_cfg =3D io_fw_cfg_init(global_qtest, 0x510); =20 return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); } diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c index d8085d9..32aa738 100644 --- a/tests/e1000e-test.c +++ b/tests/e1000e-test.c @@ -392,7 +392,7 @@ static void data_test_init(e1000e_device *d) qtest_start(cmdline); g_free(cmdline); =20 - test_alloc =3D pc_alloc_init(); + test_alloc =3D pc_alloc_init(global_qtest); g_assert_nonnull(test_alloc); =20 test_bus =3D qpci_init_pc(global_qtest, test_alloc); diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c index 81f45bd..1548bf1 100644 --- a/tests/fw_cfg-test.c +++ b/tests/fw_cfg-test.c @@ -102,12 +102,13 @@ static void test_fw_cfg_boot_menu(void) int main(int argc, char **argv) { QTestState *s; - char *cmdline; int ret; =20 g_test_init(&argc, &argv, NULL); =20 - fw_cfg =3D pc_fw_cfg_init(); + s =3D qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8"); + + fw_cfg =3D pc_fw_cfg_init(s); =20 qtest_add_func("fw_cfg/signature", test_fw_cfg_signature); qtest_add_func("fw_cfg/id", test_fw_cfg_id); @@ -125,15 +126,9 @@ int main(int argc, char **argv) qtest_add_func("fw_cfg/numa", test_fw_cfg_numa); qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu); =20 - cmdline =3D g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d= 8 "); - s =3D qtest_start(cmdline); - g_free(cmdline); - ret =3D g_test_run(); =20 - if (s) { - qtest_quit(s); - } + qtest_quit(s); =20 return ret; } diff --git a/tests/ide-test.c b/tests/ide-test.c index ed71db0..2384c2c 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -132,7 +132,7 @@ static void ide_test_start(const char *cmdline_fmt, ...) va_end(ap); =20 qtest_start(cmdline); - guest_malloc =3D pc_alloc_init(); + guest_malloc =3D pc_alloc_init(global_qtest); =20 g_free(cmdline); } diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c index 4d9dc3f..d0889d1 100644 --- a/tests/libqos/fw_cfg.c +++ b/tests/libqos/fw_cfg.c @@ -56,7 +56,7 @@ uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key) =20 static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) { - writew(fw_cfg->base, key); + qtest_writew(fw_cfg->qts, fw_cfg->base, key); } =20 static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len) @@ -65,15 +65,16 @@ static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, = size_t len) int i; =20 for (i =3D 0; i < len; i++) { - ptr[i] =3D readb(fw_cfg->base + 2); + ptr[i] =3D qtest_readb(fw_cfg->qts, fw_cfg->base + 2); } } =20 -QFWCFG *mm_fw_cfg_init(uint64_t base) +QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base) { QFWCFG *fw_cfg =3D g_malloc0(sizeof(*fw_cfg)); =20 fw_cfg->base =3D base; + fw_cfg->qts =3D qts; fw_cfg->select =3D mm_fw_cfg_select; fw_cfg->read =3D mm_fw_cfg_read; =20 @@ -82,7 +83,7 @@ QFWCFG *mm_fw_cfg_init(uint64_t base) =20 static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) { - outw(fw_cfg->base, key); + qtest_outw(fw_cfg->qts, fw_cfg->base, key); } =20 static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len) @@ -91,15 +92,16 @@ static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, = size_t len) int i; =20 for (i =3D 0; i < len; i++) { - ptr[i] =3D inb(fw_cfg->base + 1); + ptr[i] =3D qtest_inb(fw_cfg->qts, fw_cfg->base + 1); } } =20 -QFWCFG *io_fw_cfg_init(uint16_t base) +QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base) { QFWCFG *fw_cfg =3D g_malloc0(sizeof(*fw_cfg)); =20 fw_cfg->base =3D base; + fw_cfg->qts =3D qts; fw_cfg->select =3D io_fw_cfg_select; fw_cfg->read =3D io_fw_cfg_read; =20 diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index e8371b2..0353416 100644 --- a/tests/libqos/fw_cfg.h +++ b/tests/libqos/fw_cfg.h @@ -13,12 +13,14 @@ #ifndef LIBQOS_FW_CFG_H #define LIBQOS_FW_CFG_H =20 +#include "libqtest.h" =20 typedef struct QFWCFG QFWCFG; =20 struct QFWCFG { uint64_t base; + QTestState *qts; void (*select)(QFWCFG *fw_cfg, uint16_t key); void (*read)(QFWCFG *fw_cfg, void *data, size_t len); }; @@ -30,12 +32,12 @@ uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key); uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key); uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key); =20 -QFWCFG *mm_fw_cfg_init(uint64_t base); -QFWCFG *io_fw_cfg_init(uint16_t base); +QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base); +QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base); =20 -static inline QFWCFG *pc_fw_cfg_init(void) +static inline QFWCFG *pc_fw_cfg_init(QTestState *qts) { - return io_fw_cfg_init(0x510); + return io_fw_cfg_init(qts, 0x510); } =20 #endif diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 18f08cf..5729a06 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -24,7 +24,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fm= t, va_list ap) qs->qts =3D qtest_start(cmdline); qs->ops =3D ops; if (ops) { - qs->alloc =3D ops->init_allocator(ALLOC_NO_FLAGS); + qs->alloc =3D ops->init_allocator(qs->qts, ALLOC_NO_FLAGS); qs->pcibus =3D ops->qpci_init(qs->qts, qs->alloc); } =20 diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h index 78e5c04..07d4b93 100644 --- a/tests/libqos/libqos.h +++ b/tests/libqos/libqos.h @@ -8,7 +8,7 @@ typedef struct QOSState QOSState; =20 typedef struct QOSOps { - QGuestAllocator *(*init_allocator)(QAllocOpts); + QGuestAllocator *(*init_allocator)(QTestState *qts, QAllocOpts); void (*uninit_allocator)(QGuestAllocator *); QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc); void (*qpci_free)(QPCIBus *bus); diff --git a/tests/libqos/malloc-pc.c b/tests/libqos/malloc-pc.c index dd2b900..634b9c2 100644 --- a/tests/libqos/malloc-pc.c +++ b/tests/libqos/malloc-pc.c @@ -29,11 +29,11 @@ void pc_alloc_uninit(QGuestAllocator *allocator) alloc_uninit(allocator); } =20 -QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags) +QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags) { QGuestAllocator *s; uint64_t ram_size; - QFWCFG *fw_cfg =3D pc_fw_cfg_init(); + QFWCFG *fw_cfg =3D pc_fw_cfg_init(qts); =20 ram_size =3D qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE); s =3D alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000)); @@ -45,7 +45,7 @@ QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags) return s; } =20 -inline QGuestAllocator *pc_alloc_init(void) +inline QGuestAllocator *pc_alloc_init(QTestState *qts) { - return pc_alloc_init_flags(ALLOC_NO_FLAGS); + return pc_alloc_init_flags(qts, ALLOC_NO_FLAGS); } diff --git a/tests/libqos/malloc-pc.h b/tests/libqos/malloc-pc.h index 86ab9f0..10f3da6 100644 --- a/tests/libqos/malloc-pc.h +++ b/tests/libqos/malloc-pc.h @@ -15,8 +15,8 @@ =20 #include "libqos/malloc.h" =20 -QGuestAllocator *pc_alloc_init(void); -QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags); +QGuestAllocator *pc_alloc_init(QTestState *qts); +QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags); void pc_alloc_uninit(QGuestAllocator *allocator); =20 #endif diff --git a/tests/libqos/malloc-spapr.c b/tests/libqos/malloc-spapr.c index 006404a..1c359ce 100644 --- a/tests/libqos/malloc-spapr.c +++ b/tests/libqos/malloc-spapr.c @@ -22,7 +22,7 @@ void spapr_alloc_uninit(QGuestAllocator *allocator) alloc_uninit(allocator); } =20 -QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags) +QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags) { QGuestAllocator *s; =20 @@ -34,5 +34,5 @@ QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags) =20 QGuestAllocator *spapr_alloc_init(void) { - return spapr_alloc_init_flags(ALLOC_NO_FLAGS); + return spapr_alloc_init_flags(NULL, ALLOC_NO_FLAGS); } diff --git a/tests/libqos/malloc-spapr.h b/tests/libqos/malloc-spapr.h index 64d0e77..52a9346 100644 --- a/tests/libqos/malloc-spapr.h +++ b/tests/libqos/malloc-spapr.h @@ -11,7 +11,7 @@ #include "libqos/malloc.h" =20 QGuestAllocator *spapr_alloc_init(void); -QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags); +QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags); void spapr_alloc_uninit(QGuestAllocator *allocator); =20 #endif diff --git a/tests/libqos/malloc.h b/tests/libqos/malloc.h index ae9dac8..828fdda 100644 --- a/tests/libqos/malloc.h +++ b/tests/libqos/malloc.h @@ -14,6 +14,7 @@ #define LIBQOS_MALLOC_H =20 #include "qemu/queue.h" +#include "libqtest.h" =20 typedef enum { ALLOC_NO_FLAGS =3D 0x00, diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 3f74511..22e9202 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -191,7 +191,7 @@ static void init_virtio_dev(TestServer *s, uint32_t fea= tures_mask) qvirtio_set_acknowledge(&s->dev->vdev); qvirtio_set_driver(&s->dev->vdev); =20 - s->alloc =3D pc_alloc_init(); + s->alloc =3D pc_alloc_init(global_qtest); =20 for (i =3D 0; i < s->queues * 2; i++) { s->vq[i] =3D qvirtqueue_setup(&s->dev->vdev, s->alloc, i); --=20 1.8.3.1