From patchwork Thu Dec 13 22:02:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 206245 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 91A292C00A5 for ; Fri, 14 Dec 2012 09:02:40 +1100 (EST) Received: from localhost ([::1]:51153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjGrW-0003gd-G9 for incoming@patchwork.ozlabs.org; Thu, 13 Dec 2012 17:02:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjGrJ-0003gQ-Fb for qemu-devel@nongnu.org; Thu, 13 Dec 2012 17:02:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TjGrH-0007rJ-FI for qemu-devel@nongnu.org; Thu, 13 Dec 2012 17:02:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:24856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjGrH-0007qW-77 for qemu-devel@nongnu.org; Thu, 13 Dec 2012 17:02:23 -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 qBDM2MTb022668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Dec 2012 17:02:22 -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 qBDM2Mak019846; Thu, 13 Dec 2012 17:02:22 -0500 Date: Thu, 13 Dec 2012 17:02:22 -0500 From: Jason Baron To: qemu-devel@nongnu.org Message-Id: <31c4ba8885438636d2125723b19307ab99dca300.1355435056.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, pbonzini@redhat.com, aliguori@us.ibm.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 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 | 6 +++--- tests/libqtest.c | 17 ++++++++++------- tests/libqtest.h | 4 +++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index b60f0fb..30a101d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -74,10 +74,10 @@ tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi- tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) -tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) +tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) qstring.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o $(trace-obj-y) -tests/fdc-test$(EXESUF): tests/fdc-test.o tests/libqtest.o $(trace-obj-y) -tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/libqtest.o $(trace-obj-y) +tests/fdc-test$(EXESUF): tests/fdc-test.o tests/libqtest.o $(trace-obj-y) qstring.o +tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/libqtest.o $(trace-obj-y) qstring.o # QTest rules diff --git a/tests/libqtest.c b/tests/libqtest.c index f3dd4e4..71c9eb4 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..6441e50 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -18,6 +18,7 @@ #include #include #include +#include "qstring.h" typedef struct QTestState QTestState; @@ -44,7 +45,8 @@ void qtest_quit(QTestState *s); * * 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, ...); +#define qtest_qmp(s, fmt, ...) qtest_qmp_resp(s, NULL, fmt, ## __VA_ARGS__) /** * qtest_get_irq: