From dd0029c0f44d5121c64a02d3aa0440283fb72fcd Mon Sep 17 00:00:00 2001 From: John Snow Date: Mon, 19 Jan 2015 15:15:51 -0500 Subject: libqos: create libqos.c The intent of this file is to serve as a misc. utilities file to be shared amongst tests that are utilizing libqos facilities. In a later patch, migration test helpers will be added to libqos.c that will allow simplified testing of migration cases where libqos is "Just Enough OS" for migrations testing. The addition of the AHCIQState structure will also allow us to eliminate global variables inside of qtests to manage allocators and test instances in a better, more functional way. libqos.c: - Add qtest_boot - Add qtest_shutdown libqos.h: - Create QOSState structure for allocator and QTestState. ahci-test.c: - Move qtest_boot and qtest_shutdown to libqos.c/h - Create AHCIQState to interface with new qtest_boot/shutdown prototypes - Modify tests slightly to use new types. For now, the new object file is only linked to ahci-test, because it still relies on pc architecture specific code in libqos. The next two patches will reorganize the code to be more general. Signed-off-by: John Snow Reviewed-by: Paolo Bonzini Message-id: 1421698563-6977-4-git-send-email-jsnow@redhat.com Signed-off-by: Stefan Hajnoczi --- tests/libqos/libqos.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/libqos/libqos.c (limited to 'tests/libqos/libqos.c') diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c new file mode 100644 index 0000000000..c478bc958c --- /dev/null +++ b/tests/libqos/libqos.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include + +#include "libqtest.h" +#include "libqos/libqos.h" +#include "libqos/pci.h" +#include "libqos/malloc-pc.h" + +/*** Test Setup & Teardown ***/ + +/** + * 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 *qs = g_malloc(sizeof(QOSState)); + char *cmdline; + va_list ap; + + va_start(ap, cmdline_fmt); + cmdline = g_strdup_vprintf(cmdline_fmt, ap); + va_end(ap); + + qs->qts = qtest_start(cmdline); + qtest_irq_intercept_in(global_qtest, "ioapic"); + qs->alloc = pc_alloc_init(); + + g_free(cmdline); + return qs; +} + +/** + * Tear down the QEMU instance. + */ +void qtest_shutdown(QOSState *qs) +{ + if (qs->alloc) { + pc_alloc_uninit(qs->alloc); + qs->alloc = NULL; + } + qtest_quit(qs->qts); + g_free(qs); +} -- cgit v1.2.3 From f1518d1192a1a9387f881919897fbb0101ad3426 Mon Sep 17 00:00:00 2001 From: John Snow Date: Mon, 19 Jan 2015 15:15:52 -0500 Subject: libqos: add qtest_vboot Add a va_list variant of the qtest_boot function. Signed-off-by: John Snow Reviewed-by: Paolo Bonzini Message-id: 1421698563-6977-5-git-send-email-jsnow@redhat.com Signed-off-by: Stefan Hajnoczi --- tests/libqos/libqos.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tests/libqos/libqos.c') diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index c478bc958c..c8b3ef044b 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -16,16 +16,13 @@ * 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_vboot(const char *cmdline_fmt, va_list ap) { - QOSState *qs = g_malloc(sizeof(QOSState)); char *cmdline; - va_list ap; - va_start(ap, cmdline_fmt); - cmdline = g_strdup_vprintf(cmdline_fmt, ap); - va_end(ap); + struct QOSState *qs = g_malloc(sizeof(QOSState)); + cmdline = g_strdup_vprintf(cmdline_fmt, ap); qs->qts = qtest_start(cmdline); qtest_irq_intercept_in(global_qtest, "ioapic"); qs->alloc = pc_alloc_init(); @@ -34,6 +31,22 @@ QOSState *qtest_boot(const char *cmdline_fmt, ...) return qs; } +/** + * 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 *qs; + va_list ap; + + va_start(ap, cmdline_fmt); + qs = qtest_vboot(cmdline_fmt, ap); + va_end(ap); + + return qs; +} + /** * Tear down the QEMU instance. */ -- cgit v1.2.3 From 90e5add6f2fa0b0bd9a4c1d5a4de2304b5f3e466 Mon Sep 17 00:00:00 2001 From: John Snow Date: Mon, 19 Jan 2015 15:15:55 -0500 Subject: 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 Reviewed-by: Paolo Bonzini Message-id: 1421698563-6977-8-git-send-email-jsnow@redhat.com Signed-off-by: Stefan Hajnoczi --- tests/libqos/libqos.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'tests/libqos/libqos.c') 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); -- cgit v1.2.3