From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 From: Halil Pasic Date: Tue, 8 Nov 2016 10:55:58 +0100 In-Reply-To: <20161108095603.72301-1-pasic@linux.vnet.ibm.com> References: <20161108095603.72301-1-pasic@linux.vnet.ibm.com> Message-Id: <20161108095603.72301-4-pasic@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC PATCH v2 3/8] tests/test-vmstate.c: add save_buffer util func List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Amit Shah , Juan Quintela , Guenther Hutzl , "Dr. David Alan Gilbert" , Halil Pasic 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 }; -- 2.8.4