From patchwork Fri Feb 4 13:49:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 81890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by ozlabs.org (Postfix) with ESMTP id A3BBBB7125 for ; Sat, 5 Feb 2011 00:58:45 +1100 (EST) Received: from localhost ([127.0.0.1]:34207 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlM5z-0002co-5r for incoming@patchwork.ozlabs.org; Fri, 04 Feb 2011 08:53:07 -0500 Received: from [140.186.70.92] (port=39791 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlM3F-0001BJ-Vo for qemu-devel@nongnu.org; Fri, 04 Feb 2011 08:50:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PlM37-0008So-5G for qemu-devel@nongnu.org; Fri, 04 Feb 2011 08:50:17 -0500 Received: from e38.co.us.ibm.com ([32.97.110.159]:54813) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PlM36-0008SI-UD for qemu-devel@nongnu.org; Fri, 04 Feb 2011 08:50:09 -0500 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e38.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p14DZp0W005906 for ; Fri, 4 Feb 2011 06:35:51 -0700 Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p14Do7g6123972 for ; Fri, 4 Feb 2011 06:50:07 -0700 Received: from d03av05.boulder.ibm.com (loopback [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p14Do6Cx007932 for ; Fri, 4 Feb 2011 06:50:07 -0700 Received: from localhost.localdomain (sig-9-76-204-19.mts.ibm.com [9.76.204.19]) by d03av05.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p14Do4t3007812; Fri, 4 Feb 2011 06:50:06 -0700 From: Michael Roth To: qemu-devel@nongnu.org Date: Fri, 4 Feb 2011 07:49:50 -0600 Message-Id: <1296827392-1291-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1296827392-1291-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1296827392-1291-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.110.159 Cc: aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [RFC][PATCH v1 2/4] qtest: basic test infrastructure and vl.c hooks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Michael Roth --- qtest/qtest.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qtest/qtest.h | 37 ++++++++++++++++++++++++++++++++ vl.c | 24 +++++++++++++++++++++ 3 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 qtest/qtest.c create mode 100644 qtest/qtest.h diff --git a/qtest/qtest.c b/qtest/qtest.c new file mode 100644 index 0000000..fa30bdc --- /dev/null +++ b/qtest/qtest.c @@ -0,0 +1,65 @@ +#include "qtest.h" +#include "qemu-thread.h" + +static QTAILQ_HEAD(, QTestModule) qtest_module_list = +QTAILQ_HEAD_INITIALIZER(qtest_module_list); + +static const QTestModule *qtest_module_by_name(const char *test_name) +{ + const QTestModule *module; + QTAILQ_FOREACH(module, &qtest_module_list, next) { + if (strcmp(module->name, test_name) == 0) { + return module; + } + } + + return NULL; +} + +void qtest_list_modules(void) +{ + const QTestModule *module; + printf("Available test modules:\n"); + QTAILQ_FOREACH(module, &qtest_module_list, next) { + printf("%s\n", module->name); + } +} + +void qtest_register(QTestModule *module) +{ + QTAILQ_INSERT_TAIL(&qtest_module_list, module, next); +} + +void qtest_init(const char *test_name) +{ + const QTestModule *module = qtest_module_by_name(test_name); + + if (!module) { + fprintf(stderr, "unknown qtest module: %s\n", test_name); + exit(1); + } + module->init(); +} + +void qtest_cleanup(const char *test_name) +{ + const QTestModule *module = qtest_module_by_name(test_name); + + if (!module) { + fprintf(stderr, "unknown qtest module: %s\n", test_name); + exit(1); + } + module->cleanup(); +} + +void qtest_start(const char *test_name, void *thread_args) +{ + const QTestModule *module = qtest_module_by_name(test_name); + QemuThread thread; + + if (!module) { + fprintf(stderr, "unknown qtest module: %s\n", test_name); + exit(1); + } + qemu_thread_create(&thread, module->start, thread_args); +} diff --git a/qtest/qtest.h b/qtest/qtest.h new file mode 100644 index 0000000..7e3daed --- /dev/null +++ b/qtest/qtest.h @@ -0,0 +1,37 @@ +/* + * qtest - general interface definitions + * + * Copyright IBM Corp. 2011 + * + * Authors: + * Michael Roth + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ +#ifndef QTEST_H +#define QTEST_H + +#include "qemu-common.h" +#include "qemu-queue.h" + +typedef void *(QTestStartFunc)(void *thread_args); +typedef void (QTestCleanupFunc)(void); +typedef void (QTestInitFunc)(void); + +typedef struct QTestModule { + const char *name; + QTestInitFunc *init; + QTestCleanupFunc *cleanup; + QTestStartFunc *start; + QTAILQ_ENTRY(QTestModule) next; +} QTestModule; + +void qtest_register(QTestModule *module); +void qtest_init(const char *test_name); +void qtest_cleanup(const char *test_name); +void qtest_start(const char *test_name, void *thread_args); +void qtest_list_modules(void); + +#endif diff --git a/vl.c b/vl.c index 655617f..0b5b613 100644 --- a/vl.c +++ b/vl.c @@ -164,6 +164,9 @@ int main(int argc, char **argv) #include "arch_init.h" #include "ui/qemu-spice.h" +#ifdef CONFIG_QTEST +#include "qtest/qtest.h" +#endif //#define DEBUG_NET //#define DEBUG_SLIRP @@ -1930,6 +1933,9 @@ int main(int argc, char **argv, char **envp) int show_vnc_port = 0; int defconfig = 1; +#ifdef CONFIG_QTEST + const char *qtest_module = NULL; +#endif #ifdef CONFIG_SIMPLE_TRACE const char *trace_file = NULL; #endif @@ -1943,6 +1949,9 @@ int main(int argc, char **argv, char **envp) QLIST_INIT (&vm_change_state_head); os_setup_early_signal_handling(); +#ifdef CONFIG_QTEST + module_call_init(MODULE_INIT_QTEST_REGISTRY); +#endif module_call_init(MODULE_INIT_MACHINE); machine = find_default_machine(); cpu_model = NULL; @@ -2859,7 +2868,11 @@ int main(int argc, char **argv, char **envp) exit(1); } +#ifdef CONFIG_QTEST + if (!qtest_module && kvm_allowed) { +#else if (kvm_allowed) { +#endif int ret = kvm_init(); if (ret < 0) { if (!kvm_available()) { @@ -2986,6 +2999,14 @@ int main(int argc, char **argv, char **envp) exit(1); module_call_init(MODULE_INIT_DEVICE); +#ifdef CONFIG_QTEST + if (qtest_module) { + module_call_init(MODULE_INIT_QTEST_REGISTRY); + qtest_init(qtest_module); + qtest_start(qtest_module, NULL); + goto out_machine_creation; + } +#endif if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0) exit(0); @@ -3101,6 +3122,9 @@ int main(int argc, char **argv, char **envp) exit(1); } +#ifdef CONFIG_QTEST +out_machine_creation: +#endif qdev_machine_creation_done(); if (rom_load_all() != 0) {