From patchwork Thu Dec 20 17:14:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 207689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F245C2C0090 for ; Fri, 21 Dec 2012 04:15:54 +1100 (EST) Received: from localhost ([::1]:58579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tljir-0001KO-0f for incoming@patchwork.ozlabs.org; Thu, 20 Dec 2012 12:15:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tljhz-0007T7-20 for qemu-devel@nongnu.org; Thu, 20 Dec 2012 12:15:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tljhs-00086T-4C for qemu-devel@nongnu.org; Thu, 20 Dec 2012 12:14:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tljhr-00086M-T9 for qemu-devel@nongnu.org; Thu, 20 Dec 2012 12:14:52 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBKHEojg013973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Dec 2012 12:14:50 -0500 Received: from redhat.com (dhcp-185-114.bos.redhat.com [10.16.185.114]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBKHEo7N028681; Thu, 20 Dec 2012 12:14:50 -0500 Date: Thu, 20 Dec 2012 12:14:50 -0500 From: Jason Baron To: qemu-devel@nongnu.org Message-Id: <99b3e20143db7c301424b2b8410fdf6b19aa59bf.1356022464.git.jbaron@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, blauwirbel@gmail.com, andreas.faerber@web.de, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 2/3] qtest: extend qtest_qmp() to fill in the reply 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: Jason Baron Introduce: Add void qtest_qmp_resp(QTestState *s, QString *resp, const char *fmt, ...) which allows a response string to be filled in. Signed-off-by: Jason Baron --- tests/Makefile | 2 +- tests/libqtest.c | 17 ++++++++++------- tests/libqtest.h | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index b60f0fb..1756b47 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -85,7 +85,7 @@ TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS))) QTEST_TARGETS=$(foreach TARGET,$(TARGETS), $(if $(check-qtest-$(TARGET)-y), $(TARGET),)) check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y)) -qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a +qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a $(test-qapi-obj-y) $(qom-obj-y) $(check-qtest-y): $(qtest-obj-y) .PHONY: check-help diff --git a/tests/libqtest.c b/tests/libqtest.c index 57665c9..994cd2f 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -288,7 +288,7 @@ redo: return words; } -void qtest_qmp(QTestState *s, const char *fmt, ...) +void qtest_qmp_resp(QTestState *s, QString *resp, const char *fmt, ...) { va_list ap; bool has_reply = false; @@ -313,16 +313,19 @@ void qtest_qmp(QTestState *s, const char *fmt, ...) fprintf(stderr, "Broken pipe\n"); exit(1); } - - switch (c) { - case '{': + if (c == '{') { nesting++; has_reply = true; - break; - case '}': + } + if (c == '}') { nesting--; - break; } + if (has_reply && resp) { + qstring_append_chr(resp, c); + } + } + if (has_reply && resp) { + qstring_append_chr(resp, '\0'); } } diff --git a/tests/libqtest.h b/tests/libqtest.h index c8ade85..972ba5d 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -18,6 +18,7 @@ #include #include #include +#include "qstring.h" typedef struct QTestState QTestState; @@ -38,13 +39,14 @@ QTestState *qtest_init(const char *extra_args); void qtest_quit(QTestState *s); /** - * qtest_qmp: + * qtest_qmp_resp: * @s: QTestState instance to operate on. + * @resp: Fills in response string if provided * @fmt...: QMP message to send to qemu * * Sends a QMP message to QEMU */ -void qtest_qmp(QTestState *s, const char *fmt, ...); +void qtest_qmp_resp(QTestState *s, QString *resp, const char *fmt, ...); /** * qtest_get_irq: @@ -349,4 +351,13 @@ void qtest_add_func(const char *str, void (*fn)); */ #define clock_set(val) qtest_clock_set(global_qtest, val) +/** + * qtest_qmp: + * @s: QTestState instance to operate on. + * @fmt...: QMP message to send to qemu + * + * Sends a QMP message to QEMU + */ +#define qtest_qmp(s, fmt, ...) qtest_qmp_resp(s, NULL, fmt, ## __VA_ARGS__) + #endif