qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer
  2014-08-06 17:30 [Qemu-devel] [PATCH 0/2] In memory QEMUFile Dr. David Alan Gilbert (git)
@ 2014-08-06 17:30 ` Dr. David Alan Gilbert (git)
  0 siblings, 0 replies; 6+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2014-08-06 17:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: joel.schopp, stefanb, quintela

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Modify some of tests/test-vmstate.c to use the in memory file based
on QEMUSizedBuffer to provide basic testing of QEMUSizedBuffer and
the associated memory backed QEMUFile type.

Only some of the tests are changed so that the fd backed QEMUFile is
still tested.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 tests/Makefile       |  2 +-
 tests/test-vmstate.c | 73 ++++++++++++++++++++++++++--------------------------
 2 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index 4b2e1bb..f3d32ba 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -253,7 +253,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
 	libqemuutil.a libqemustub.a
 tests/test-vmstate$(EXESUF): tests/test-vmstate.o \
 	vmstate.o qemu-file.o \
-	libqemuutil.a
+	libqemuutil.a libqemustub.a
 
 tests/test-qapi-types.c tests/test-qapi-types.h :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index d72c64c..716d034 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -43,6 +43,12 @@ 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)
 {
@@ -54,6 +60,29 @@ static QEMUFile *open_test_file(bool write)
     return qemu_fdopen(fd, write ? "wb" : "rb");
 }
 
+/* Open a read-only qemu-file from an existing memory block */
+static QEMUFile *open_mem_file_read(const void *data, size_t len)
+{
+    /* The qsb gets freed by qemu_fclose */
+    QEMUSizedBuffer *qsb = qsb_create(data, len);
+
+    return qemu_bufopen("r", qsb);
+}
+
+/*
+ * 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 = NULL; /* qsb_get_buffer allocs a buffer */
+    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)
 
@@ -371,14 +400,12 @@ static const VMStateDescription vmstate_skipping = {
 
 static void test_save_noskip(void)
 {
-    QEMUFile *fsave = open_test_file(true);
+    QEMUFile *fsave = qemu_bufopen("w", NULL);
     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);
     g_assert(!qemu_file_get_error(fsave));
-    qemu_fclose(fsave);
 
-    QEMUFile *loading = open_test_file(false);
     uint8_t expected[] = {
         0, 0, 0, 1,             /* a */
         0, 0, 0, 2,             /* b */
@@ -387,52 +414,31 @@ static void test_save_noskip(void)
         0, 0, 0, 5,             /* e */
         0, 0, 0, 0, 0, 0, 0, 6, /* f */
     };
-    uint8_t result[sizeof(expected)];
-    g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==,
-                    sizeof(result));
-    g_assert(!qemu_file_get_error(loading));
-    g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0);
-
-    /* Must reach EOF */
-    qemu_get_byte(loading);
-    g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO);
-
-    qemu_fclose(loading);
+    check_mem_file(fsave, expected, sizeof(expected));
+    qemu_fclose(fsave);
 }
 
 static void test_save_skip(void)
 {
-    QEMUFile *fsave = open_test_file(true);
+    QEMUFile *fsave = qemu_bufopen("w", NULL);
     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);
     g_assert(!qemu_file_get_error(fsave));
-    qemu_fclose(fsave);
 
-    QEMUFile *loading = open_test_file(false);
     uint8_t expected[] = {
         0, 0, 0, 1,             /* a */
         0, 0, 0, 2,             /* b */
         0, 0, 0, 0, 0, 0, 0, 4, /* d */
         0, 0, 0, 0, 0, 0, 0, 6, /* f */
     };
-    uint8_t result[sizeof(expected)];
-    g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==,
-                    sizeof(result));
-    g_assert(!qemu_file_get_error(loading));
-    g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0);
-
-
-    /* Must reach EOF */
-    qemu_get_byte(loading);
-    g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO);
+    check_mem_file(fsave, expected, sizeof(expected));
 
-    qemu_fclose(loading);
+    qemu_fclose(fsave);
 }
 
 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 */
@@ -442,10 +448,8 @@ 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);
 
-    QEMUFile *loading = open_test_file(false);
+    QEMUFile *loading = open_mem_file_read(buf, sizeof(buf));
     TestStruct obj = { .skip_c_e = false };
     vmstate_load_state(loading, &vmstate_skipping, &obj, 2);
     g_assert(!qemu_file_get_error(loading));
@@ -460,7 +464,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 */
@@ -468,10 +471,8 @@ 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);
 
-    QEMUFile *loading = open_test_file(false);
+    QEMUFile *loading = open_mem_file_read(buf, sizeof(buf));
     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));
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated
@ 2014-12-12  9:53 Yang Hongyang
  2014-12-12  9:53 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Yang Hongyang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yang Hongyang @ 2014-12-12  9:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Yang Hongyang, Dr. David Alan Gilbert, Juan Quintela

Only free qsb that qemu_bufopen allocated, and also allow
qemu_bufopen accept qsb as input for write operation. It
will make the API more logical:
1.If you create the QEMUSizedBuffer yourself, you need to
  free it by using qsb_free() but not depends on other API
  like qemu_fclose.
2.allow qemu_bufopen() accept QEMUSizedBuffer as input for
  write operation, otherwise, it will be a little strange
  for this API won't accept the second parameter.

This brings API change, since there are only 3
users of this API currently, this change only impact the
first one which will be fixed in patch 2 of this patchset,
so I think it is safe to do this change.

1     70  tests/test-vmstate.c <<open_mem_file_read>>
            return qemu_bufopen("r", qsb);
2    404  tests/test-vmstate.c <<test_save_noskip>>
            QEMUFile *fsave = qemu_bufopen("w", NULL);
3    424  tests/test-vmstate.c <<test_save_skip>>
            QEMUFile *fsave = qemu_bufopen("w", NULL);

Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>
---
 qemu-file.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/qemu-file.c b/qemu-file.c
index f938e36..52f8d69 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -904,6 +904,7 @@ QEMUSizedBuffer *qsb_clone(const QEMUSizedBuffer *qsb)
 typedef struct QEMUBuffer {
     QEMUSizedBuffer *qsb;
     QEMUFile *file;
+    bool qsb_allocated;
 } QEMUBuffer;
 
 static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
@@ -933,7 +934,9 @@ static int buf_close(void *opaque)
 {
     QEMUBuffer *s = opaque;
 
-    qsb_free(s->qsb);
+    if (s->qsb_allocated) {
+        qsb_free(s->qsb);
+    }
 
     g_free(s);
 
@@ -972,12 +975,11 @@ QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input)
     }
 
     s = g_malloc0(sizeof(QEMUBuffer));
-    if (mode[0] == 'r') {
-        s->qsb = input;
-    }
+    s->qsb = input;
 
     if (s->qsb == NULL) {
         s->qsb = qsb_create(NULL, 0);
+        s->qsb_allocated = true;
     }
     if (!s->qsb) {
         g_free(s);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer
  2014-12-12  9:53 [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Yang Hongyang
@ 2014-12-12  9:53 ` Yang Hongyang
  2014-12-16 13:37   ` Dr. David Alan Gilbert
  2014-12-16  2:20 ` [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Hongyang Yang
  2014-12-16 13:34 ` Dr. David Alan Gilbert
  2 siblings, 1 reply; 6+ messages in thread
From: Yang Hongyang @ 2014-12-12  9:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Yang Hongyang, Dr. David Alan Gilbert, Juan Quintela

Modify some of tests/test-vmstate.c due to qemu_bufopen() change.
If you create a QEMUSizedBuffer yourself, you have to explicitly
free it.

Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>
---
 tests/test-vmstate.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 5e0fd13..39b7b01 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -60,16 +60,6 @@ static QEMUFile *open_test_file(bool write)
     return qemu_fdopen(fd, write ? "wb" : "rb");
 }
 
-/* Open a read-only qemu-file from an existing memory block */
-static QEMUFile *open_mem_file_read(const void *data, size_t len)
-{
-    /* The qsb gets freed by qemu_fclose */
-    QEMUSizedBuffer *qsb = qsb_create(data, len);
-    g_assert(qsb);
-
-    return qemu_bufopen("r", qsb);
-}
-
 /*
  * Check that the contents of the memory-buffered file f match
  * the given size/data.
@@ -450,7 +440,9 @@ static void test_load_noskip(void)
         QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
     };
 
-    QEMUFile *loading = open_mem_file_read(buf, sizeof(buf));
+    QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf));
+    g_assert(qsb);
+    QEMUFile *loading = qemu_bufopen("r", qsb);
     TestStruct obj = { .skip_c_e = false };
     vmstate_load_state(loading, &vmstate_skipping, &obj, 2);
     g_assert(!qemu_file_get_error(loading));
@@ -461,6 +453,7 @@ 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)
@@ -473,7 +466,9 @@ static void test_load_skip(void)
         QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
     };
 
-    QEMUFile *loading = open_mem_file_read(buf, sizeof(buf));
+    QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf));
+    g_assert(qsb);
+    QEMUFile *loading = qemu_bufopen("r", qsb);
     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));
@@ -484,6 +479,7 @@ 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)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated
  2014-12-12  9:53 [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Yang Hongyang
  2014-12-12  9:53 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Yang Hongyang
@ 2014-12-16  2:20 ` Hongyang Yang
  2014-12-16 13:34 ` Dr. David Alan Gilbert
  2 siblings, 0 replies; 6+ messages in thread
From: Hongyang Yang @ 2014-12-16  2:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Dr. David Alan Gilbert, Juan Quintela

Ping!

在 12/12/2014 05:53 PM, Yang Hongyang 写道:
> Only free qsb that qemu_bufopen allocated, and also allow
> qemu_bufopen accept qsb as input for write operation. It
> will make the API more logical:
> 1.If you create the QEMUSizedBuffer yourself, you need to
>    free it by using qsb_free() but not depends on other API
>    like qemu_fclose.
> 2.allow qemu_bufopen() accept QEMUSizedBuffer as input for
>    write operation, otherwise, it will be a little strange
>    for this API won't accept the second parameter.
>
> This brings API change, since there are only 3
> users of this API currently, this change only impact the
> first one which will be fixed in patch 2 of this patchset,
> so I think it is safe to do this change.
>
> 1     70  tests/test-vmstate.c <<open_mem_file_read>>
>              return qemu_bufopen("r", qsb);
> 2    404  tests/test-vmstate.c <<test_save_noskip>>
>              QEMUFile *fsave = qemu_bufopen("w", NULL);
> 3    424  tests/test-vmstate.c <<test_save_skip>>
>              QEMUFile *fsave = qemu_bufopen("w", NULL);
>
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Cc: Juan Quintela <quintela@redhat.com>
> ---
>   qemu-file.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/qemu-file.c b/qemu-file.c
> index f938e36..52f8d69 100644
> --- a/qemu-file.c
> +++ b/qemu-file.c
> @@ -904,6 +904,7 @@ QEMUSizedBuffer *qsb_clone(const QEMUSizedBuffer *qsb)
>   typedef struct QEMUBuffer {
>       QEMUSizedBuffer *qsb;
>       QEMUFile *file;
> +    bool qsb_allocated;
>   } QEMUBuffer;
>
>   static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
> @@ -933,7 +934,9 @@ static int buf_close(void *opaque)
>   {
>       QEMUBuffer *s = opaque;
>
> -    qsb_free(s->qsb);
> +    if (s->qsb_allocated) {
> +        qsb_free(s->qsb);
> +    }
>
>       g_free(s);
>
> @@ -972,12 +975,11 @@ QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input)
>       }
>
>       s = g_malloc0(sizeof(QEMUBuffer));
> -    if (mode[0] == 'r') {
> -        s->qsb = input;
> -    }
> +    s->qsb = input;
>
>       if (s->qsb == NULL) {
>           s->qsb = qsb_create(NULL, 0);
> +        s->qsb_allocated = true;
>       }
>       if (!s->qsb) {
>           g_free(s);
>

-- 
Thanks,
Yang.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated
  2014-12-12  9:53 [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Yang Hongyang
  2014-12-12  9:53 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Yang Hongyang
  2014-12-16  2:20 ` [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Hongyang Yang
@ 2014-12-16 13:34 ` Dr. David Alan Gilbert
  2 siblings, 0 replies; 6+ messages in thread
From: Dr. David Alan Gilbert @ 2014-12-16 13:34 UTC (permalink / raw)
  To: Yang Hongyang; +Cc: amit.shah, qemu-devel, Juan Quintela

* Yang Hongyang (yanghy@cn.fujitsu.com) wrote:
> Only free qsb that qemu_bufopen allocated, and also allow
> qemu_bufopen accept qsb as input for write operation. It
> will make the API more logical:
> 1.If you create the QEMUSizedBuffer yourself, you need to
>   free it by using qsb_free() but not depends on other API
>   like qemu_fclose.
> 2.allow qemu_bufopen() accept QEMUSizedBuffer as input for
>   write operation, otherwise, it will be a little strange
>   for this API won't accept the second parameter.
> 
> This brings API change, since there are only 3
> users of this API currently, this change only impact the
> first one which will be fixed in patch 2 of this patchset,
> so I think it is safe to do this change.
> 
> 1     70  tests/test-vmstate.c <<open_mem_file_read>>
>             return qemu_bufopen("r", qsb);
> 2    404  tests/test-vmstate.c <<test_save_noskip>>
>             QEMUFile *fsave = qemu_bufopen("w", NULL);
> 3    424  tests/test-vmstate.c <<test_save_skip>>
>             QEMUFile *fsave = qemu_bufopen("w", NULL);
> 
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Cc: Juan Quintela <quintela@redhat.com>

Yes, this feels cleaner to me.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

Dave


> ---
>  qemu-file.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/qemu-file.c b/qemu-file.c
> index f938e36..52f8d69 100644
> --- a/qemu-file.c
> +++ b/qemu-file.c
> @@ -904,6 +904,7 @@ QEMUSizedBuffer *qsb_clone(const QEMUSizedBuffer *qsb)
>  typedef struct QEMUBuffer {
>      QEMUSizedBuffer *qsb;
>      QEMUFile *file;
> +    bool qsb_allocated;
>  } QEMUBuffer;
>  
>  static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
> @@ -933,7 +934,9 @@ static int buf_close(void *opaque)
>  {
>      QEMUBuffer *s = opaque;
>  
> -    qsb_free(s->qsb);
> +    if (s->qsb_allocated) {
> +        qsb_free(s->qsb);
> +    }
>  
>      g_free(s);
>  
> @@ -972,12 +975,11 @@ QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input)
>      }
>  
>      s = g_malloc0(sizeof(QEMUBuffer));
> -    if (mode[0] == 'r') {
> -        s->qsb = input;
> -    }
> +    s->qsb = input;
>  
>      if (s->qsb == NULL) {
>          s->qsb = qsb_create(NULL, 0);
> +        s->qsb_allocated = true;
>      }
>      if (!s->qsb) {
>          g_free(s);
> -- 
> 1.9.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer
  2014-12-12  9:53 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Yang Hongyang
@ 2014-12-16 13:37   ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 6+ messages in thread
From: Dr. David Alan Gilbert @ 2014-12-16 13:37 UTC (permalink / raw)
  To: Yang Hongyang; +Cc: amit.shah, qemu-devel, Juan Quintela

* Yang Hongyang (yanghy@cn.fujitsu.com) wrote:
> Modify some of tests/test-vmstate.c due to qemu_bufopen() change.
> If you create a QEMUSizedBuffer yourself, you have to explicitly
> free it.
> 
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> Cc: Juan Quintela <quintela@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  tests/test-vmstate.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)

> 
> diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
> index 5e0fd13..39b7b01 100644
> --- a/tests/test-vmstate.c
> +++ b/tests/test-vmstate.c
> @@ -60,16 +60,6 @@ static QEMUFile *open_test_file(bool write)
>      return qemu_fdopen(fd, write ? "wb" : "rb");
>  }
>  
> -/* Open a read-only qemu-file from an existing memory block */
> -static QEMUFile *open_mem_file_read(const void *data, size_t len)
> -{
> -    /* The qsb gets freed by qemu_fclose */
> -    QEMUSizedBuffer *qsb = qsb_create(data, len);
> -    g_assert(qsb);
> -
> -    return qemu_bufopen("r", qsb);
> -}
> -
>  /*
>   * Check that the contents of the memory-buffered file f match
>   * the given size/data.
> @@ -450,7 +440,9 @@ static void test_load_noskip(void)
>          QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
>      };
>  
> -    QEMUFile *loading = open_mem_file_read(buf, sizeof(buf));
> +    QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf));
> +    g_assert(qsb);
> +    QEMUFile *loading = qemu_bufopen("r", qsb);
>      TestStruct obj = { .skip_c_e = false };
>      vmstate_load_state(loading, &vmstate_skipping, &obj, 2);
>      g_assert(!qemu_file_get_error(loading));
> @@ -461,6 +453,7 @@ 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)
> @@ -473,7 +466,9 @@ static void test_load_skip(void)
>          QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
>      };
>  
> -    QEMUFile *loading = open_mem_file_read(buf, sizeof(buf));
> +    QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf));
> +    g_assert(qsb);
> +    QEMUFile *loading = qemu_bufopen("r", qsb);
>      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));
> @@ -484,6 +479,7 @@ 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)
> -- 
> 1.9.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-12-16 13:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-12  9:53 [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Yang Hongyang
2014-12-12  9:53 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Yang Hongyang
2014-12-16 13:37   ` Dr. David Alan Gilbert
2014-12-16  2:20 ` [Qemu-devel] [PATCH 1/2] QEMUSizedBuffer: only free qsb that qemu_bufopen allocated Hongyang Yang
2014-12-16 13:34 ` Dr. David Alan Gilbert
  -- strict thread matches above, loose matches on Subject: below --
2014-08-06 17:30 [Qemu-devel] [PATCH 0/2] In memory QEMUFile Dr. David Alan Gilbert (git)
2014-08-06 17:30 ` [Qemu-devel] [PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer Dr. David Alan Gilbert (git)

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).