[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/14] libqos: add pc specific interface
From: |
John Snow |
Subject: |
[Qemu-devel] [PATCH 06/14] libqos: add pc specific interface |
Date: |
Mon, 12 Jan 2015 22:34:31 -0500 |
Create an operations structure so that the libqos interface can be
architecture agnostic, and create a pc-specific interface to functions
like qtest_boot.
Move the libqos object in the Makefile from being ahci-test only to
being linked with all tests that utilize the libqos features.
Signed-off-by: John Snow <address@hidden>
---
tests/Makefile | 6 +++---
tests/ahci-test.c | 4 ++--
tests/libqos/libqos-pc.c | 24 ++++++++++++++++++++++++
tests/libqos/libqos-pc.h | 9 +++++++++
tests/libqos/libqos.c | 16 +++++++++-------
tests/libqos/libqos.h | 10 ++++++++--
6 files changed, 55 insertions(+), 14 deletions(-)
create mode 100644 tests/libqos/libqos-pc.c
create mode 100644 tests/libqos/libqos-pc.h
diff --git a/tests/Makefile b/tests/Makefile
index c5b3b21..f21d63c 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -301,9 +301,9 @@ tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
tests/test-bitops$(EXESUF): tests/test-bitops.o libqemuutil.a
libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
-libqos-obj-y += tests/libqos/i2c.o
+libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
-libqos-pc-obj-y += tests/libqos/malloc-pc.o
+libqos-pc-obj-y += tests/libqos/malloc-pc.o tests/libqos/libqos-pc.o
libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
libqos-usb-obj-y = $(libqos-pc-obj-y) tests/libqos/usb.o
libqos-virtio-obj-y = $(libqos-pc-obj-y) tests/libqos/virtio.o
tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o
tests/libqos/malloc-generic.o
@@ -314,7 +314,7 @@ tests/endianness-test$(EXESUF): tests/endianness-test.o
tests/spapr-phb-test$(EXESUF): tests/spapr-phb-test.o $(libqos-obj-y)
tests/fdc-test$(EXESUF): tests/fdc-test.o
tests/ide-test$(EXESUF): tests/ide-test.o $(libqos-pc-obj-y)
-tests/ahci-test$(EXESUF): tests/ahci-test.o $(libqos-pc-obj-y)
tests/libqos/libqos.o
+tests/ahci-test$(EXESUF): tests/ahci-test.o $(libqos-pc-obj-y)
tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o $(libqos-obj-y)
diff --git a/tests/ahci-test.c b/tests/ahci-test.c
index a498cbb..065d3d3 100644
--- a/tests/ahci-test.c
+++ b/tests/ahci-test.c
@@ -29,7 +29,7 @@
#include <glib.h>
#include "libqtest.h"
-#include "libqos/libqos.h"
+#include "libqos/libqos-pc.h"
#include "libqos/ahci.h"
#include "libqos/pci-pc.h"
#include "libqos/malloc-pc.h"
@@ -151,7 +151,7 @@ static AHCIQState *ahci_boot(void)
" -M q35 "
"-device ide-hd,drive=drive0 "
"-global ide-hd.ver=%s";
- s->parent = qtest_boot(cli, tmp_path, "testdisk", "version");
+ s->parent = qtest_pc_boot(cli, tmp_path, "testdisk", "version");
/* Verify that we have an AHCI device present. */
s->dev = get_ahci_device();
diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c
new file mode 100644
index 0000000..486321e
--- /dev/null
+++ b/tests/libqos/libqos-pc.c
@@ -0,0 +1,24 @@
+#include "libqos/libqos-pc.h"
+#include "libqos/malloc-pc.h"
+
+static QOSOperations qos_ops = {
+ .init_allocator = pc_alloc_init_flags,
+ .uninit_allocator = pc_alloc_uninit
+};
+
+QOSState *qtest_pc_boot(const char *cmdline_fmt, ...)
+{
+ QOSState *qs;
+ va_list ap;
+
+ va_start(ap, cmdline_fmt);
+ qs = qtest_vboot(&qos_ops, cmdline_fmt, ap);
+ va_end(ap);
+
+ return qs;
+}
+
+void qtest_pc_shutdown(QOSState *qs)
+{
+ return qtest_shutdown(qs);
+}
diff --git a/tests/libqos/libqos-pc.h b/tests/libqos/libqos-pc.h
new file mode 100644
index 0000000..316857d
--- /dev/null
+++ b/tests/libqos/libqos-pc.h
@@ -0,0 +1,9 @@
+#ifndef __libqos_pc_h
+#define __libqos_pc_h
+
+#include "libqos/libqos.h"
+
+QOSState *qtest_pc_boot(const char *cmdline_fmt, ...);
+void qtest_pc_shutdown(QOSState *qs);
+
+#endif
diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
index c8b3ef0..d4601cf 100644
--- a/tests/libqos/libqos.c
+++ b/tests/libqos/libqos.c
@@ -8,7 +8,6 @@
#include "libqtest.h"
#include "libqos/libqos.h"
#include "libqos/pci.h"
-#include "libqos/malloc-pc.h"
/*** Test Setup & Teardown ***/
@@ -16,7 +15,7 @@
* Launch QEMU with the given command line,
* and then set up interrupts and our guest malloc interface.
*/
-QOSState *qtest_vboot(const char *cmdline_fmt, va_list ap)
+QOSState *qtest_vboot(QOSOperations *ops, const char *cmdline_fmt, va_list ap)
{
char *cmdline;
@@ -24,8 +23,11 @@ QOSState *qtest_vboot(const char *cmdline_fmt, va_list ap)
cmdline = g_strdup_vprintf(cmdline_fmt, ap);
qs->qts = qtest_start(cmdline);
+ qs->ops = ops;
qtest_irq_intercept_in(global_qtest, "ioapic");
- qs->alloc = pc_alloc_init();
+ if (ops && ops->init_allocator) {
+ qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
+ }
g_free(cmdline);
return qs;
@@ -35,13 +37,13 @@ QOSState *qtest_vboot(const char *cmdline_fmt, va_list ap)
* Launch QEMU with the given command line,
* and then set up interrupts and our guest malloc interface.
*/
-QOSState *qtest_boot(const char *cmdline_fmt, ...)
+QOSState *qtest_boot(QOSOperations *ops, const char *cmdline_fmt, ...)
{
QOSState *qs;
va_list ap;
va_start(ap, cmdline_fmt);
- qs = qtest_vboot(cmdline_fmt, ap);
+ qs = qtest_vboot(ops, cmdline_fmt, ap);
va_end(ap);
return qs;
@@ -52,8 +54,8 @@ QOSState *qtest_boot(const char *cmdline_fmt, ...)
*/
void qtest_shutdown(QOSState *qs)
{
- if (qs->alloc) {
- pc_alloc_uninit(qs->alloc);
+ if (qs->alloc && qs->ops && qs->ops->uninit_allocator) {
+ qs->ops->uninit_allocator(qs->alloc);
qs->alloc = NULL;
}
qtest_quit(qs->qts);
diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h
index 7ae0a8d..871f6c3 100644
--- a/tests/libqos/libqos.h
+++ b/tests/libqos/libqos.h
@@ -5,13 +5,19 @@
#include "libqos/pci.h"
#include "libqos/malloc-pc.h"
+typedef struct QOSOperations {
+ QGuestAllocator *(*init_allocator)(QAllocOpts);
+ void (*uninit_allocator)(QGuestAllocator *);
+} QOSOperations;
+
typedef struct QOSState {
QTestState *qts;
QGuestAllocator *alloc;
+ QOSOperations *ops;
} QOSState;
-QOSState *qtest_vboot(const char *cmdline_fmt, va_list ap);
-QOSState *qtest_boot(const char *cmdline_fmt, ...);
+QOSState *qtest_vboot(QOSOperations *ops, const char *cmdline_fmt, va_list ap);
+QOSState *qtest_boot(QOSOperations *ops, const char *cmdline_fmt, ...);
void qtest_shutdown(QOSState *qs);
static inline uint64_t qmalloc(QOSState *q, size_t bytes)
--
1.9.3
- [Qemu-devel] [PATCH 03/14] libqos: create libqos.c, (continued)
- [Qemu-devel] [PATCH 03/14] libqos: create libqos.c, John Snow, 2015/01/12
- [Qemu-devel] [PATCH 01/14] libqos: Split apart pc_alloc_init, John Snow, 2015/01/12
- [Qemu-devel] [PATCH 10/14] qtest/ahci: remove guest_malloc global, John Snow, 2015/01/12
- [Qemu-devel] [PATCH 07/14] qtest/ahci: Store hba_base in AHCIQState, John Snow, 2015/01/12
- [Qemu-devel] [PATCH 06/14] libqos: add pc specific interface,
John Snow <=
- [Qemu-devel] [PATCH 11/14] libqos/ahci: Functional register helpers, John Snow, 2015/01/12
- [Qemu-devel] [PATCH 08/14] qtest/ahci: finalize AHCIQState consolidation, John Snow, 2015/01/12
- [Qemu-devel] [PATCH 12/14] qtest/ahci: remove getter/setter macros, John Snow, 2015/01/12
- [Qemu-devel] [PATCH 13/14] qtest/ahci: Bookmark FB and CLB pointers, John Snow, 2015/01/12