From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsIvx-0003AD-BK for qemu-devel@nongnu.org; Mon, 07 Jan 2013 15:04:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsIvv-0004Iv-Pa for qemu-devel@nongnu.org; Mon, 07 Jan 2013 15:04:33 -0500 Received: from e9.ny.us.ibm.com ([32.97.182.139]:36050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsIvv-0004Iq-Kv for qemu-devel@nongnu.org; Mon, 07 Jan 2013 15:04:31 -0500 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Jan 2013 15:04:30 -0500 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 5E6C56E8043 for ; Mon, 7 Jan 2013 15:04:26 -0500 (EST) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r07K4Qgd24903800 for ; Mon, 7 Jan 2013 15:04:27 -0500 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r07K4IJm032057 for ; Mon, 7 Jan 2013 13:04:18 -0700 From: Anthony Liguori In-Reply-To: <99b3e20143db7c301424b2b8410fdf6b19aa59bf.1356022464.git.jbaron@redhat.com> References: <99b3e20143db7c301424b2b8410fdf6b19aa59bf.1356022464.git.jbaron@redhat.com> Date: Mon, 07 Jan 2013 14:04:02 -0600 Message-ID: <87lic4u5e5.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH v2 2/3] qtest: extend qtest_qmp() to fill in the reply List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Baron , qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, andreas.faerber@web.de, blauwirbel@gmail.com, quintela@redhat.com Jason Baron writes: > From: Jason Baron > > Introduce: > > Add void qtest_qmp_resp(QTestState *s, QString *resp, const char *fmt, > ...) Any reason to not just return a QString? Also, why not do the parsing in this function and just return a QObject of the result? Regards, Anthony Liguori > > 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 > -- > 1.7.1