qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Amit Shah <amit.shah@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Juan Quintela <quintela@redhat.com>
Subject: [Qemu-devel] [PATCH v3 02/27] migration: remove use of qemu_bufopen from vmstate tests
Date: Fri, 26 Feb 2016 15:10:05 +0000	[thread overview]
Message-ID: <1456499430-8558-3-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1456499430-8558-1-git-send-email-berrange@redhat.com>

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 <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 tests/Makefile       |  2 +-
 tests/test-vmstate.c | 44 +++++++++++++-------------------------------
 2 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index 04e34b5..13f1c84 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -424,7 +424,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)
-- 
2.5.0

  parent reply	other threads:[~2016-02-26 15:10 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-26 15:10 [Qemu-devel] [PATCH v3 00/27] Convert migration to QIOChannel & support TLS Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 01/27] s390: use FILE instead of QEMUFile for creating text file Daniel P. Berrange
2016-02-26 15:10 ` Daniel P. Berrange [this message]
2016-03-03  8:43   ` [Qemu-devel] [PATCH v3 02/27] migration: remove use of qemu_bufopen from vmstate tests Amit Shah
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 03/27] migration: ensure qemu_fflush() always writes full data amount Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 04/27] migration: split migration hooks out of QEMUFileOps Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 05/27] migration: introduce set_blocking function in QEMUFileOps Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 06/27] migration: force QEMUFile to blocking mode for outgoing migration Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 07/27] migration: introduce a new QEMUFile impl based on QIOChannel Daniel P. Berrange
2016-03-10 14:44   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 08/27] migration: add helpers for creating QEMUFile from a QIOChannel Daniel P. Berrange
2016-03-10 14:52   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 09/27] migration: add reporting of errors for outgoing migration Daniel P. Berrange
2016-03-04  9:49   ` Markus Armbruster
2016-03-04 10:49     ` Daniel P. Berrange
2016-03-10 15:13   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 10/27] migration: convert post-copy to use QIOChannelBuffer Daniel P. Berrange
2016-03-10 15:25   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 11/27] migration: convert unix socket protocol to use QIOChannel Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 12/27] migration: rename unix.c to socket.c Daniel P. Berrange
2016-03-10 15:35   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 13/27] migration: convert tcp socket protocol to use QIOChannel Daniel P. Berrange
2016-03-10 15:38   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 14/27] migration: convert fd " Daniel P. Berrange
2016-03-10 15:46   ` Dr. David Alan Gilbert
2016-03-10 15:56     ` Daniel P. Berrange
2016-03-10 17:27       ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 15/27] migration: convert exec " Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 16/27] migration: convert RDMA to use QIOChannel interface Daniel P. Berrange
2016-03-10 17:00   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 17/27] migration: convert savevm to use QIOChannel for writing to files Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 18/27] migration: delete QEMUFile buffer implementation Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 19/27] migration: delete QEMUSizedBuffer struct Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 20/27] migration: delete QEMUFile sockets implementation Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 21/27] migration: delete QEMUFile stdio implementation Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 22/27] migration: move definition of struct QEMUFile back into qemu-file.c Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 23/27] migration: don't use an array for storing migrate parameters Daniel P. Berrange
2016-03-10 17:25   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 24/27] migration: define 'tls-creds' and 'tls-hostname' migration parameters Daniel P. Berrange
2016-03-10 17:42   ` Dr. David Alan Gilbert
2016-03-10 17:50     ` Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 25/27] migration: add support for encrypting data with TLS Daniel P. Berrange
2016-03-10 18:25   ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 26/27] migration: remove support for non-iovec based write handlers Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 27/27] migration: remove qemu_get_fd method from QEMUFile Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456499430-8558-3-git-send-email-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).