From patchwork Tue Nov 8 09:55:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Halil Pasic X-Patchwork-Id: 9417025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A0CB760459 for ; Tue, 8 Nov 2016 09:56:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F15328B25 for ; Tue, 8 Nov 2016 09:56:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8398B28B41; Tue, 8 Nov 2016 09:56:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 500A328B3B for ; Tue, 8 Nov 2016 09:56:58 +0000 (UTC) Received: from localhost ([::1]:59695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c439F-00012O-CG for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 Nov 2016 04:56:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c438c-0000ze-4G for qemu-devel@nongnu.org; Tue, 08 Nov 2016 04:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c438Y-0006uY-NF for qemu-devel@nongnu.org; Tue, 08 Nov 2016 04:56:18 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36967) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c438Y-0006tp-FI for qemu-devel@nongnu.org; Tue, 08 Nov 2016 04:56:14 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uA89sCwk093161 for ; Tue, 8 Nov 2016 04:56:13 -0500 Received: from e06smtp08.uk.ibm.com (e06smtp08.uk.ibm.com [195.75.94.104]) by mx0a-001b2d01.pphosted.com with ESMTP id 26kb0bncd6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 08 Nov 2016 04:56:13 -0500 Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 8 Nov 2016 09:56:10 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp08.uk.ibm.com (192.168.101.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 8 Nov 2016 09:56:08 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 231492190023 for ; Tue, 8 Nov 2016 09:55:22 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uA89u7ec28836010 for ; Tue, 8 Nov 2016 09:56:07 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uA89u7Ep029296 for ; Tue, 8 Nov 2016 02:56:07 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uA89u68U029231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Tue, 8 Nov 2016 02:56:07 -0700 From: Halil Pasic To: qemu-devel@nongnu.org Date: Tue, 8 Nov 2016 10:55:58 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20161108095603.72301-1-pasic@linux.vnet.ibm.com> References: <20161108095603.72301-1-pasic@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16110809-0032-0000-0000-00000238EE23 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16110809-0033-0000-0000-00001D9C5128 Message-Id: <20161108095603.72301-4-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-08_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611080183 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [RFC PATCH v2 3/8] tests/test-vmstate.c: add save_buffer util func X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , Halil Pasic , Guenther Hutzl , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Let us deduplicate some code by introducing an utility function for saving a chunk of bytes (used when testing load based on wire). Signed-off-by: Halil Pasic Reviewed-by: Guenther Hutzl Reviewed-by: Juan Quintela --- _No review needed!_ Already included but not in master yet. See: https://lists.gnu.org/archive/html/qemu-devel/2016-11/msg00335.html --- tests/test-vmstate.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 78067b7..9062d6b 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -79,6 +79,13 @@ static void save_vmstate(const VMStateDescription *desc, void *obj) qemu_fclose(f); } +static void save_buffer(const uint8_t *buf, size_t buf_size) +{ + QEMUFile *fsave = open_test_file(true); + qemu_put_buffer(fsave, buf, buf_size); + qemu_fclose(fsave); +} + static void compare_vmstate(uint8_t *wire, size_t size) { QEMUFile *f = open_test_file(false); @@ -305,15 +312,13 @@ static const VMStateDescription vmstate_versioned = { static void test_load_v1(void) { - QEMUFile *fsave = open_test_file(true); uint8_t buf[] = { 0, 0, 0, 10, /* a */ 0, 0, 0, 30, /* c */ 0, 0, 0, 0, 0, 0, 0, 40, /* d */ QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; - qemu_put_buffer(fsave, buf, sizeof(buf)); - qemu_fclose(fsave); + save_buffer(buf, sizeof(buf)); QEMUFile *loading = open_test_file(false); TestStruct obj = { .b = 200, .e = 500, .f = 600 }; @@ -330,7 +335,6 @@ static void test_load_v1(void) static void test_load_v2(void) { - QEMUFile *fsave = open_test_file(true); uint8_t buf[] = { 0, 0, 0, 10, /* a */ 0, 0, 0, 20, /* b */ @@ -340,8 +344,7 @@ static void test_load_v2(void) 0, 0, 0, 0, 0, 0, 0, 60, /* f */ QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; - qemu_put_buffer(fsave, buf, sizeof(buf)); - qemu_fclose(fsave); + save_buffer(buf, sizeof(buf)); QEMUFile *loading = open_test_file(false); TestStruct obj; @@ -419,7 +422,6 @@ static void test_save_skip(void) static void test_load_noskip(void) { - QEMUFile *fsave = open_test_file(true); uint8_t buf[] = { 0, 0, 0, 10, /* a */ 0, 0, 0, 20, /* b */ @@ -429,8 +431,7 @@ static void test_load_noskip(void) 0, 0, 0, 0, 0, 0, 0, 60, /* f */ QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; - qemu_put_buffer(fsave, buf, sizeof(buf)); - qemu_fclose(fsave); + save_buffer(buf, sizeof(buf)); QEMUFile *loading = open_test_file(false); TestStruct obj = { .skip_c_e = false }; @@ -447,7 +448,6 @@ static void test_load_noskip(void) static void test_load_skip(void) { - QEMUFile *fsave = open_test_file(true); uint8_t buf[] = { 0, 0, 0, 10, /* a */ 0, 0, 0, 20, /* b */ @@ -455,8 +455,7 @@ static void test_load_skip(void) 0, 0, 0, 0, 0, 0, 0, 60, /* f */ QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; - qemu_put_buffer(fsave, buf, sizeof(buf)); - qemu_fclose(fsave); + save_buffer(buf, sizeof(buf)); QEMUFile *loading = open_test_file(false); TestStruct obj = { .skip_c_e = true, .c = 300, .e = 500 };