diff options
author | Eric Blake <eblake@redhat.com> | 2017-09-11 12:19:57 -0500 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2018-02-14 11:43:41 +0100 |
commit | 05e520f1c7f6ac7a142c616883e00c8924e81331 (patch) | |
tree | 1304e6ac429eaaf25961ab1e9770c5622f820d48 /tests/libqos | |
parent | e5d1730d1e5c1f341d2d692ab2ad0d8d2d7f47e1 (diff) |
libqos: Use explicit QTestState for fw_cfg operations
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 <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
[thuth: Fixed conflict wrt pc_alloc_init() in vhost-user-test.c]
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/libqos')
-rw-r--r-- | tests/libqos/fw_cfg.c | 14 | ||||
-rw-r--r-- | tests/libqos/fw_cfg.h | 10 | ||||
-rw-r--r-- | tests/libqos/libqos.c | 2 | ||||
-rw-r--r-- | tests/libqos/libqos.h | 2 | ||||
-rw-r--r-- | tests/libqos/malloc-pc.c | 8 | ||||
-rw-r--r-- | tests/libqos/malloc-pc.h | 4 | ||||
-rw-r--r-- | tests/libqos/malloc-spapr.c | 4 | ||||
-rw-r--r-- | tests/libqos/malloc-spapr.h | 2 | ||||
-rw-r--r-- | tests/libqos/malloc.h | 1 |
9 files changed, 26 insertions, 21 deletions
diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c index 4d9dc3fd0b..d0889d1e22 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) 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); } 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; for (i = 0; i < len; i++) { - ptr[i] = readb(fw_cfg->base + 2); + ptr[i] = qtest_readb(fw_cfg->qts, fw_cfg->base + 2); } } -QFWCFG *mm_fw_cfg_init(uint64_t base) +QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base) { QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg)); fw_cfg->base = base; + fw_cfg->qts = qts; fw_cfg->select = mm_fw_cfg_select; fw_cfg->read = mm_fw_cfg_read; @@ -82,7 +83,7 @@ QFWCFG *mm_fw_cfg_init(uint64_t base) 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); } 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; for (i = 0; i < len; i++) { - ptr[i] = inb(fw_cfg->base + 1); + ptr[i] = qtest_inb(fw_cfg->qts, fw_cfg->base + 1); } } -QFWCFG *io_fw_cfg_init(uint16_t base) +QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base) { QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg)); fw_cfg->base = base; + fw_cfg->qts = qts; fw_cfg->select = io_fw_cfg_select; fw_cfg->read = io_fw_cfg_read; diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index e8371b2317..0353416af0 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 +#include "libqtest.h" typedef struct QFWCFG QFWCFG; 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); -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); -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); } #endif diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 18f08cf1ba..5729a0618d 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -24,7 +24,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) qs->qts = qtest_start(cmdline); qs->ops = ops; if (ops) { - qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS); + qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS); qs->pcibus = ops->qpci_init(qs->qts, qs->alloc); } diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h index 78e5c044a0..07d4b93d1d 100644 --- a/tests/libqos/libqos.h +++ b/tests/libqos/libqos.h @@ -8,7 +8,7 @@ typedef struct QOSState QOSState; 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 dd2b900c5f..634b9c288a 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); } -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 = pc_fw_cfg_init(); + QFWCFG *fw_cfg = pc_fw_cfg_init(qts); ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE); s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000)); @@ -45,7 +45,7 @@ QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags) return s; } -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 86ab9f0429..10f3da6cf2 100644 --- a/tests/libqos/malloc-pc.h +++ b/tests/libqos/malloc-pc.h @@ -15,8 +15,8 @@ #include "libqos/malloc.h" -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); #endif diff --git a/tests/libqos/malloc-spapr.c b/tests/libqos/malloc-spapr.c index 006404af33..1c359cea6c 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); } -QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags) +QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags) { QGuestAllocator *s; @@ -34,5 +34,5 @@ QGuestAllocator *spapr_alloc_init_flags(QAllocOpts flags) 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 64d0e770d1..52a9346a26 100644 --- a/tests/libqos/malloc-spapr.h +++ b/tests/libqos/malloc-spapr.h @@ -11,7 +11,7 @@ #include "libqos/malloc.h" 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); #endif diff --git a/tests/libqos/malloc.h b/tests/libqos/malloc.h index ae9dac8f61..828fddabdb 100644 --- a/tests/libqos/malloc.h +++ b/tests/libqos/malloc.h @@ -14,6 +14,7 @@ #define LIBQOS_MALLOC_H #include "qemu/queue.h" +#include "libqtest.h" typedef enum { ALLOC_NO_FLAGS = 0x00, |