From patchwork Wed Apr 27 10:04:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8954561 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6A21D9F1D3 for ; Wed, 27 Apr 2016 10:14:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CD1B2022A for ; Wed, 27 Apr 2016 10:14:36 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 164E82021F for ; Wed, 27 Apr 2016 10:14:30 +0000 (UTC) Received: from localhost ([::1]:42297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMUH-0004Mx-8M for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Apr 2016 06:14:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMLf-00055W-EK for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avMLZ-0004Rw-Nh for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38997) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMLZ-0004Rr-H9 for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:29 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D1E081F03 for ; Wed, 27 Apr 2016 10:05:29 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-18.ams2.redhat.com [10.36.6.18]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RA5MRC030816; Wed, 27 Apr 2016 06:05:27 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Wed, 27 Apr 2016 11:04:53 +0100 Message-Id: <1461751518-12128-4-git-send-email-berrange@redhat.com> In-Reply-To: <1461751518-12128-1-git-send-email-berrange@redhat.com> References: <1461751518-12128-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 for-2.7 03/28] migration: remove use of qemu_bufopen from vmstate tests 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 , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some of the test-vmstate.c test cases use a temporary file while others use a memory buffer. To facilitate the future removal of the qemu_bufopen() function, convert all the tests to use a temporary file. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrange Reviewed-by: Juan Quintela --- tests/Makefile | 2 +- tests/test-vmstate.c | 44 +++++++++++++------------------------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 9194f18..797d59e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -434,7 +434,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ hw/core/fw-path-provider.o \ $(test-qapi-obj-y) tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ - migration/vmstate.o migration/qemu-file.o migration/qemu-file-buf.o \ + migration/vmstate.o migration/qemu-file.o \ migration/qemu-file-unix.o qjson.o \ $(test-qom-obj-y) tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o \ diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 713d444..f337cf6 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -44,11 +44,6 @@ void yield_until_fd_readable(int fd) select(fd + 1, &fds, NULL, NULL, NULL); } -/* - * Some tests use 'open_test_file' to work on a real fd, some use - * an in memory file (QEMUSizedBuffer+qemu_bufopen); we could pick one - * but this way we test both. - */ /* Duplicate temp_fd and seek to the beginning of the file */ static QEMUFile *open_test_file(bool write) @@ -61,20 +56,6 @@ static QEMUFile *open_test_file(bool write) return qemu_fdopen(fd, write ? "wb" : "rb"); } -/* - * Check that the contents of the memory-buffered file f match - * the given size/data. - */ -static void check_mem_file(QEMUFile *f, void *data, size_t size) -{ - uint8_t *result = g_malloc(size); - const QEMUSizedBuffer *qsb = qemu_buf_get(f); - g_assert_cmpint(qsb_get_length(qsb), ==, size); - g_assert_cmpint(qsb_get_buffer(qsb, 0, size, result), ==, size); - g_assert_cmpint(memcmp(result, data, size), ==, 0); - g_free(result); -} - #define SUCCESS(val) \ g_assert_cmpint((val), ==, 0) @@ -392,7 +373,7 @@ static const VMStateDescription vmstate_skipping = { static void test_save_noskip(void) { - QEMUFile *fsave = qemu_bufopen("w", NULL); + QEMUFile *fsave = open_test_file(true); TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6, .skip_c_e = false }; vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL); @@ -406,13 +387,14 @@ static void test_save_noskip(void) 0, 0, 0, 5, /* e */ 0, 0, 0, 0, 0, 0, 0, 6, /* f */ }; - check_mem_file(fsave, expected, sizeof(expected)); + qemu_fclose(fsave); + compare_vmstate(expected, sizeof(expected)); } static void test_save_skip(void) { - QEMUFile *fsave = qemu_bufopen("w", NULL); + QEMUFile *fsave = open_test_file(true); TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6, .skip_c_e = true }; vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL); @@ -424,13 +406,14 @@ static void test_save_skip(void) 0, 0, 0, 0, 0, 0, 0, 4, /* d */ 0, 0, 0, 0, 0, 0, 0, 6, /* f */ }; - check_mem_file(fsave, expected, sizeof(expected)); qemu_fclose(fsave); + compare_vmstate(expected, sizeof(expected)); } 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 */ @@ -440,10 +423,10 @@ 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); - QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf)); - g_assert(qsb); - QEMUFile *loading = qemu_bufopen("r", qsb); + QEMUFile *loading = open_test_file(false); TestStruct obj = { .skip_c_e = false }; vmstate_load_state(loading, &vmstate_skipping, &obj, 2); g_assert(!qemu_file_get_error(loading)); @@ -454,11 +437,11 @@ static void test_load_noskip(void) g_assert_cmpint(obj.e, ==, 50); g_assert_cmpint(obj.f, ==, 60); qemu_fclose(loading); - qsb_free(qsb); } 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 */ @@ -466,10 +449,10 @@ 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); - QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf)); - g_assert(qsb); - QEMUFile *loading = qemu_bufopen("r", qsb); + QEMUFile *loading = open_test_file(false); TestStruct obj = { .skip_c_e = true, .c = 300, .e = 500 }; vmstate_load_state(loading, &vmstate_skipping, &obj, 2); g_assert(!qemu_file_get_error(loading)); @@ -480,7 +463,6 @@ static void test_load_skip(void) g_assert_cmpint(obj.e, ==, 500); g_assert_cmpint(obj.f, ==, 60); qemu_fclose(loading); - qsb_free(qsb); } int main(int argc, char **argv)