From patchwork Fri Oct 2 12:58:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 525523 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 B69F0140D69 for ; Fri, 2 Oct 2015 23:42:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Je9L+mVO; dkim-atps=neutral Received: from localhost ([::1]:59843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi0b0-0005O7-EK for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 09:41:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhzuw-0001U5-4d for qemu-devel@nongnu.org; Fri, 02 Oct 2015 08:58:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zhzuu-00079J-RF for qemu-devel@nongnu.org; Fri, 02 Oct 2015 08:58:30 -0400 Received: from mail-qg0-x230.google.com ([2607:f8b0:400d:c04::230]:33252) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhzuu-00078w-FT for qemu-devel@nongnu.org; Fri, 02 Oct 2015 08:58:28 -0400 Received: by qgev79 with SMTP id v79so93201117qge.0 for ; Fri, 02 Oct 2015 05:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=RD2VsIltyF2KOK/kW20qE9QX5y3cI+P9Y+mm/b0W1LY=; b=Je9L+mVOz3t9q8e56YX96WtBnZV4x6wgb+3hn056yaOQ4U+F3kfnJKk2ucsd2RE1VN eDzNfr+geuXXZZEsL0lhlVnZdiEeKqd/3Ie5ys56G1DLVP4G+JTNwIWyQW2b4eb5cgbe L7AU0kn1FnsGwbVmaZ0sRHoE2plungo8cRF17c+E3JQAyk44HLyd/jWvC98n0eI8AMej +vdJdZeybdL2DJVZO55Aq0uWLzqbtnP+H13yfU7EIYSlt+coQX4o2mrvX/NoRGBbCt7s 7VKftkf4h7cIH0TYQIupHPATk2mqCqTQ4ie8fQ3BcNpgLt2vzYvui4VOQJlpJpxqXL6s fVnw== X-Received: by 10.140.237.72 with SMTP id i69mr20823006qhc.56.1443790708196; Fri, 02 Oct 2015 05:58:28 -0700 (PDT) Received: from localhost ([2001:450:1e:232:3ea9:f4ff:fe4c:6bac]) by smtp.gmail.com with ESMTPSA id b91sm4587055qge.8.2015.10.02.05.58.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 05:58:27 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 14:58:16 +0200 Message-Id: <1443790698-13327-4-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443790698-13327-1-git-send-email-marcandre.lureau@redhat.com> References: <1443790698-13327-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::230 Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v3 3/5] qtest: add a few fd-level qmp helpers 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: Marc-André Lureau Add a few functions to interact with qmp via a simple fd. Signed-off-by: Marc-André Lureau Reviewed-by: Michael Roth --- tests/libqtest.c | 45 +++++++++++++++++++++++++++++++++++++++++---- tests/libqtest.h | 7 +++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index e5188e0..11e541d 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -357,7 +357,7 @@ static void qmp_response(JSONMessageParser *parser, QList *tokens) qmp->response = (QDict *)obj; } -QDict *qtest_qmp_receive(QTestState *s) +QDict *qmp_fd_receive(int fd) { QMPResponseParser qmp; bool log = getenv("QTEST_LOG") != NULL; @@ -368,7 +368,7 @@ QDict *qtest_qmp_receive(QTestState *s) ssize_t len; char c; - len = read(s->qmp_fd, &c, 1); + len = read(fd, &c, 1); if (len == -1 && errno == EINTR) { continue; } @@ -388,12 +388,17 @@ QDict *qtest_qmp_receive(QTestState *s) return qmp.response; } +QDict *qtest_qmp_receive(QTestState *s) +{ + return qmp_fd_receive(s->qmp_fd); +} + /** * Allow users to send a message without waiting for the reply, * in the case that they choose to discard all replies up until * a particular EVENT is received. */ -void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap) +void qmp_fd_sendv(int fd, const char *fmt, va_list ap) { va_list ap_copy; QObject *qobj; @@ -417,13 +422,25 @@ void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap) fprintf(stderr, "%s", str); } /* Send QMP request */ - socket_send(s->qmp_fd, str, size); + socket_send(fd, str, size); QDECREF(qstr); qobject_decref(qobj); } } +void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap) +{ + qmp_fd_sendv(s->qmp_fd, fmt, ap); +} + +QDict *qmp_fdv(int fd, const char *fmt, va_list ap) +{ + qmp_fd_sendv(fd, fmt, ap); + + return qmp_fd_receive(fd); +} + QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) { qtest_async_qmpv(s, fmt, ap); @@ -432,6 +449,26 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) return qtest_qmp_receive(s); } +QDict *qmp_fd(int fd, const char *fmt, ...) +{ + va_list ap; + QDict *response; + + va_start(ap, fmt); + response = qmp_fdv(fd, fmt, ap); + va_end(ap); + return response; +} + +void qmp_fd_send(int fd, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + qmp_fd_sendv(fd, fmt, ap); + va_end(ap); +} + QDict *qtest_qmp(QTestState *s, const char *fmt, ...) { va_list ap; diff --git a/tests/libqtest.h b/tests/libqtest.h index ec42031..ecd9872 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -818,4 +818,11 @@ static inline int64_t clock_set(int64_t val) */ bool qtest_big_endian(void); + +QDict *qmp_fd_receive(int fd); +void qmp_fd_sendv(int fd, const char *fmt, va_list ap); +void qmp_fd_send(int fd, const char *fmt, ...); +QDict *qmp_fdv(int fd, const char *fmt, va_list ap); +QDict *qmp_fd(int fd, const char *fmt, ...); + #endif