aboutsummaryrefslogtreecommitdiff
path: root/tests/libqos
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2015-01-19 15:15:55 -0500
committerStefan Hajnoczi <stefanha@redhat.com>2015-02-16 14:40:55 +0000
commit90e5add6f2fa0b0bd9a4c1d5a4de2304b5f3e466 (patch)
treed88630f9c1149ea6e5d774d45c12fcd6cb0165e9 /tests/libqos
parentf6f363c1f4f962aee9f69c67ab2f3ff58c30f8c1 (diff)
libqos: add pc specific interface
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 <jsnow@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1421698563-6977-8-git-send-email-jsnow@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests/libqos')
-rw-r--r--tests/libqos/libqos-pc.c24
-rw-r--r--tests/libqos/libqos-pc.h9
-rw-r--r--tests/libqos/libqos.c16
-rw-r--r--tests/libqos/libqos.h10
4 files changed, 50 insertions, 9 deletions
diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c
new file mode 100644
index 0000000000..bbace893fb
--- /dev/null
+++ b/tests/libqos/libqos-pc.c
@@ -0,0 +1,24 @@
+#include "libqos/libqos-pc.h"
+#include "libqos/malloc-pc.h"
+
+static QOSOps 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 0000000000..316857d32f
--- /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 c8b3ef044b..bc8beb281f 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(QOSOps *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(QOSOps *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 7ae0a8d600..612d41e5e9 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 QOSOps {
+ QGuestAllocator *(*init_allocator)(QAllocOpts);
+ void (*uninit_allocator)(QGuestAllocator *);
+} QOSOps;
+
typedef struct QOSState {
QTestState *qts;
QGuestAllocator *alloc;
+ QOSOps *ops;
} QOSState;
-QOSState *qtest_vboot(const char *cmdline_fmt, va_list ap);
-QOSState *qtest_boot(const char *cmdline_fmt, ...);
+QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap);
+QOSState *qtest_boot(QOSOps *ops, const char *cmdline_fmt, ...);
void qtest_shutdown(QOSState *qs);
static inline uint64_t qmalloc(QOSState *q, size_t bytes)