From patchwork Mon Feb 16 15:45:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 440218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CB65914009B for ; Tue, 17 Feb 2015 02:54:01 +1100 (AEDT) Received: from localhost ([::1]:40379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNNzk-0002Xc-1K for incoming@patchwork.ozlabs.org; Mon, 16 Feb 2015 10:54:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNNsw-0006Ls-3J for qemu-devel@nongnu.org; Mon, 16 Feb 2015 10:46:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNNsu-0005sp-R9 for qemu-devel@nongnu.org; Mon, 16 Feb 2015 10:46:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42431) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNNsu-0005sb-K2 for qemu-devel@nongnu.org; Mon, 16 Feb 2015 10:46:56 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1GFksbl021090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 16 Feb 2015 10:46:54 -0500 Received: from localhost (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1GFkrhQ000624; Mon, 16 Feb 2015 10:46:54 -0500 From: Stefan Hajnoczi To: Date: Mon, 16 Feb 2015 15:45:35 +0000 Message-Id: <1424101590-7627-11-git-send-email-stefanha@redhat.com> In-Reply-To: <1424101590-7627-1-git-send-email-stefanha@redhat.com> References: <1424101590-7627-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , John Snow , Stefan Hajnoczi Subject: [Qemu-devel] [PULL v2 10/65] libqos: add pc specific interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: John Snow 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/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 0469bbd..415498c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -307,9 +307,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-virtio-obj-y = $(libqos-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o libqos-usb-obj-y = $(libqos-pc-obj-y) tests/libqos/usb.o @@ -320,7 +320,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 15542b9..3bc9772 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -29,7 +29,7 @@ #include #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..bbace89 --- /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 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..bc8beb2 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 7ae0a8d..612d41e 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)