From patchwork Tue Feb 24 00:45:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 442714 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 AF72E140111 for ; Tue, 24 Feb 2015 11:49:31 +1100 (AEDT) Received: from localhost ([::1]:46256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQ3gn-0002Bj-LQ for incoming@patchwork.ozlabs.org; Mon, 23 Feb 2015 19:49:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQ3dB-0003zl-V3 for qemu-devel@nongnu.org; Mon, 23 Feb 2015 19:45:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQ3d3-00017K-PR for qemu-devel@nongnu.org; Mon, 23 Feb 2015 19:45:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQ3d3-000174-Gt for qemu-devel@nongnu.org; Mon, 23 Feb 2015 19:45:37 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1O0jZVW006945 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 23 Feb 2015 19:45:35 -0500 Received: from scv.usersys.redhat.com (dhcp-17-161.bos.redhat.com [10.18.17.161]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1O0jVgn006646; Mon, 23 Feb 2015 19:45:34 -0500 From: John Snow To: qemu-devel@nongnu.org Date: Mon, 23 Feb 2015 19:45:26 -0500 Message-Id: <1424738729-17082-4-git-send-email-jsnow@redhat.com> In-Reply-To: <1424738729-17082-1-git-send-email-jsnow@redhat.com> References: <1424738729-17082-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, marc.mari.barcelo@gmail.com, stefanha@redhat.com, pbonzini@redhat.com, John Snow , afaerber@suse.de Subject: [Qemu-devel] [PATCH 3/6] libqtest: add qmp_eventwait 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 Allow the user to poll until a desired interrupt occurs. Signed-off-by: John Snow --- tests/ide-test.c | 11 +---------- tests/libqtest.c | 16 ++++++++++++++++ tests/libqtest.h | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tests/ide-test.c b/tests/ide-test.c index b28a302..1dae84f 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -520,7 +520,6 @@ static void test_retry_flush(const char *machine) { uint8_t data; const char *s; - QDict *response; prepare_blkdebug_script(debug_path, "flush_to_disk"); @@ -539,15 +538,7 @@ static void test_retry_flush(const char *machine) assert_bit_set(data, BSY | DRDY); assert_bit_clear(data, DF | ERR | DRQ); - for (;; response = NULL) { - response = qmp_receive(); - if ((qdict_haskey(response, "event")) && - (strcmp(qdict_get_str(response, "event"), "STOP") == 0)) { - QDECREF(response); - break; - } - QDECREF(response); - } + qmp_eventwait("STOP"); /* Complete the command */ s = "{'execute':'cont' }"; diff --git a/tests/libqtest.c b/tests/libqtest.c index 9a92aa7..a3ee8ae 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -450,6 +450,22 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...) QDECREF(response); } +void qtest_qmp_eventwait(QTestState *s, const char *event) +{ + QDict *response; + + for (;;) { + response = qtest_qmp_receive(s); + if ((qdict_haskey(response, "event")) && + (strcmp(qdict_get_str(response, "event"), event) == 0)) { + QDECREF(response); + break; + } + QDECREF(response); + } +} + + const char *qtest_get_arch(void) { const char *qemu = getenv("QTEST_QEMU_BINARY"); diff --git a/tests/libqtest.h b/tests/libqtest.h index e7413d5..2aa2e6f 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -92,6 +92,15 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap); QDict *qtest_qmp_receive(QTestState *s); /** + * qtest_qmp_eventwait: + * @s: #QTestState instance to operate on. + * @s: #event event to wait for. + * + * Continuosly polls for QMP responses until it receives the desired event. + */ +void qtest_qmp_eventwait(QTestState *s, const char *event); + +/** * qtest_get_irq: * @s: #QTestState instance to operate on. * @num: Interrupt to observe. @@ -397,6 +406,17 @@ static inline QDict *qmp_receive(void) } /** + * qmp_eventwait: + * @s: #event event to wait for. + * + * Continuosly polls for QMP responses until it receives the desired event. + */ +static inline void qmp_eventwait(const char *event) +{ + return qtest_qmp_eventwait(global_qtest, event); +} + +/** * get_irq: * @num: Interrupt to observe. *