From patchwork Fri Aug 15 17:06:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 380356 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 3081A140097 for ; Sat, 16 Aug 2014 03:17:37 +1000 (EST) Received: from localhost ([::1]:60704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIL8B-0006Vm-26 for incoming@patchwork.ozlabs.org; Fri, 15 Aug 2014 13:17:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIKyn-0006AK-BB for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:07:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIKyh-0000Gk-42 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:07:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62995) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIKyg-0000Gd-Qo for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:07:47 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7FH7i3c015484 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Aug 2014 13:07:45 -0400 Received: from localhost (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7FH7hXb021768; Fri, 15 Aug 2014 13:07:44 -0400 From: Stefan Hajnoczi To: Date: Fri, 15 Aug 2014 18:06:26 +0100 Message-Id: <1408122422-13935-20-git-send-email-stefanha@redhat.com> In-Reply-To: <1408122422-13935-1-git-send-email-stefanha@redhat.com> References: <1408122422-13935-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , John Snow , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 19/55] qtest: Adding qtest_memset and qmemset. 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: John Snow Currently, libqtest allows for memread and memwrite, but does not offer a simple way to zero out regions of memory. This patch adds a simple function to do so. Signed-off-by: John Snow Signed-off-by: Stefan Hajnoczi --- tests/libqtest.c | 12 ++++++++++++ tests/libqtest.h | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tests/libqtest.c b/tests/libqtest.c index 4a75cd3..e525e6f 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -659,6 +659,18 @@ void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size) qtest_rsp(s, 0); } +void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size) +{ + size_t i; + + qtest_sendf(s, "write 0x%" PRIx64 " 0x%zx 0x", addr, size); + for (i = 0; i < size; i++) { + qtest_sendf(s, "%02x", pattern); + } + qtest_sendf(s, "\n"); + qtest_rsp(s, 0); +} + QDict *qmp(const char *fmt, ...) { va_list ap; diff --git a/tests/libqtest.h b/tests/libqtest.h index 8f323c7..1be0934 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -283,6 +283,17 @@ void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size); /** + * qtest_memset: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @patt: Byte pattern to fill the guest memory region with. + * @size: Number of bytes to write. + * + * Write a pattern to guest memory. + */ +void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size); + +/** * qtest_clock_step_next: * @s: #QTestState instance to operate on. * @@ -621,6 +632,19 @@ static inline void memwrite(uint64_t addr, const void *data, size_t size) } /** + * qmemset: + * @addr: Guest address to write to. + * @patt: Byte pattern to fill the guest memory region with. + * @size: Number of bytes to write. + * + * Write a pattern to guest memory. + */ +static inline void qmemset(uint64_t addr, uint8_t patt, size_t size) +{ + qtest_memset(global_qtest, addr, patt, size); +} + +/** * clock_step_next: * * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.