All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tests: add /vmstate/simple/array
@ 2018-11-14 13:21 Marc-André Lureau
  2018-11-14 15:33 ` Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marc-André Lureau @ 2018-11-14 13:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: dgilbert, quintela, Marc-André Lureau

A very simple test to show VMSTATE_*_ARRAY usage and result. It could
be systematically extended to other primitives, but I leave that as an
exercise for others :).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/test-vmstate.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 37a7a93784..2a960dedbe 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -284,6 +284,55 @@ static void test_simple_primitive(void)
     FIELD_EQUAL(i64_2);
 }
 
+typedef struct TestSimpleArray {
+    uint16_t u16_1[3];
+} TestSimpleArray;
+
+/* Object instantiation, we are going to use it in more than one test */
+
+TestSimpleArray obj_simple_arr = {
+    .u16_1 = { 0x42, 0x43, 0x44 },
+};
+
+/* Description of the values.  If you add a primitive type
+   you are expected to add a test here */
+
+static const VMStateDescription vmstate_simple_arr = {
+    .name = "simple/array",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT16_ARRAY(u16_1, TestSimpleArray, 3),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+uint8_t wire_simple_arr[] = {
+    /* u16_1 */ 0x00, 0x42,
+    /* u16_1 */ 0x00, 0x43,
+    /* u16_1 */ 0x00, 0x44,
+    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_simple_arr_copy(void *target, void *source)
+{
+    memcpy(target, source, sizeof(TestSimpleArray));
+}
+
+static void test_simple_array(void)
+{
+    TestSimpleArray obj, obj_clone;
+
+    memset(&obj, 0, sizeof(obj));
+    save_vmstate(&vmstate_simple_arr, &obj_simple_arr);
+
+    compare_vmstate(wire_simple_arr, sizeof(wire_simple_arr));
+
+    SUCCESS(load_vmstate(&vmstate_simple_arr, &obj, &obj_clone,
+                         obj_simple_arr_copy, 1, wire_simple_arr,
+                         sizeof(wire_simple_arr)));
+}
+
 typedef struct TestStruct {
     uint32_t a, b, c, e;
     uint64_t d, f;
@@ -863,6 +912,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
     g_test_add_func("/vmstate/simple/primitive", test_simple_primitive);
+    g_test_add_func("/vmstate/simple/array", test_simple_array);
     g_test_add_func("/vmstate/versioned/load/v1", test_load_v1);
     g_test_add_func("/vmstate/versioned/load/v2", test_load_v2);
     g_test_add_func("/vmstate/field_exists/load/noskip", test_load_noskip);
-- 
2.19.1.708.g4ede3d42df

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

* Re: [Qemu-devel] [PATCH] tests: add /vmstate/simple/array
  2018-11-14 13:21 [Qemu-devel] [PATCH] tests: add /vmstate/simple/array Marc-André Lureau
@ 2018-11-14 15:33 ` Philippe Mathieu-Daudé
  2018-11-16 18:59 ` Dr. David Alan Gilbert
  2019-01-23 12:01 ` Dr. David Alan Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 15:33 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel; +Cc: dgilbert, quintela

On 14/11/18 14:21, Marc-André Lureau wrote:
> A very simple test to show VMSTATE_*_ARRAY usage and result. It could
> be systematically extended to other primitives, but I leave that as an
> exercise for others :).

If this patch get accepted, please add this good idea to the 
BiteSizedTasks wiki entry:

https://wiki.qemu.org/Contribute/BiteSizedTasks

> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   tests/test-vmstate.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 50 insertions(+)
> 
> diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
> index 37a7a93784..2a960dedbe 100644
> --- a/tests/test-vmstate.c
> +++ b/tests/test-vmstate.c
> @@ -284,6 +284,55 @@ static void test_simple_primitive(void)
>       FIELD_EQUAL(i64_2);
>   }
>   
> +typedef struct TestSimpleArray {
> +    uint16_t u16_1[3];
> +} TestSimpleArray;
> +
> +/* Object instantiation, we are going to use it in more than one test */
> +
> +TestSimpleArray obj_simple_arr = {
> +    .u16_1 = { 0x42, 0x43, 0x44 },
> +};
> +
> +/* Description of the values.  If you add a primitive type
> +   you are expected to add a test here */
> +
> +static const VMStateDescription vmstate_simple_arr = {
> +    .name = "simple/array",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_UINT16_ARRAY(u16_1, TestSimpleArray, 3),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +uint8_t wire_simple_arr[] = {
> +    /* u16_1 */ 0x00, 0x42,
> +    /* u16_1 */ 0x00, 0x43,
> +    /* u16_1 */ 0x00, 0x44,
> +    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
> +};
> +
> +static void obj_simple_arr_copy(void *target, void *source)
> +{
> +    memcpy(target, source, sizeof(TestSimpleArray));
> +}
> +
> +static void test_simple_array(void)
> +{
> +    TestSimpleArray obj, obj_clone;
> +
> +    memset(&obj, 0, sizeof(obj));
> +    save_vmstate(&vmstate_simple_arr, &obj_simple_arr);
> +
> +    compare_vmstate(wire_simple_arr, sizeof(wire_simple_arr));
> +
> +    SUCCESS(load_vmstate(&vmstate_simple_arr, &obj, &obj_clone,
> +                         obj_simple_arr_copy, 1, wire_simple_arr,
> +                         sizeof(wire_simple_arr)));
> +}
> +
>   typedef struct TestStruct {
>       uint32_t a, b, c, e;
>       uint64_t d, f;
> @@ -863,6 +912,7 @@ int main(int argc, char **argv)
>   
>       g_test_init(&argc, &argv, NULL);
>       g_test_add_func("/vmstate/simple/primitive", test_simple_primitive);
> +    g_test_add_func("/vmstate/simple/array", test_simple_array);
>       g_test_add_func("/vmstate/versioned/load/v1", test_load_v1);
>       g_test_add_func("/vmstate/versioned/load/v2", test_load_v2);
>       g_test_add_func("/vmstate/field_exists/load/noskip", test_load_noskip);
> 

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

* Re: [Qemu-devel] [PATCH] tests: add /vmstate/simple/array
  2018-11-14 13:21 [Qemu-devel] [PATCH] tests: add /vmstate/simple/array Marc-André Lureau
  2018-11-14 15:33 ` Philippe Mathieu-Daudé
@ 2018-11-16 18:59 ` Dr. David Alan Gilbert
  2019-01-23 12:01 ` Dr. David Alan Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: Dr. David Alan Gilbert @ 2018-11-16 18:59 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, quintela

* Marc-André Lureau (marcandre.lureau@redhat.com) wrote:
> A very simple test to show VMSTATE_*_ARRAY usage and result. It could
> be systematically extended to other primitives, but I leave that as an
> exercise for others :).
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Yes, fair enough.  I don't think it's necessary to test every subtype
that can go in the array; but it would be nice to add some of the more
esoteric array macros no one understands.

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

> ---
>  tests/test-vmstate.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
> index 37a7a93784..2a960dedbe 100644
> --- a/tests/test-vmstate.c
> +++ b/tests/test-vmstate.c
> @@ -284,6 +284,55 @@ static void test_simple_primitive(void)
>      FIELD_EQUAL(i64_2);
>  }
>  
> +typedef struct TestSimpleArray {
> +    uint16_t u16_1[3];
> +} TestSimpleArray;
> +
> +/* Object instantiation, we are going to use it in more than one test */
> +
> +TestSimpleArray obj_simple_arr = {
> +    .u16_1 = { 0x42, 0x43, 0x44 },
> +};
> +
> +/* Description of the values.  If you add a primitive type
> +   you are expected to add a test here */
> +
> +static const VMStateDescription vmstate_simple_arr = {
> +    .name = "simple/array",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_UINT16_ARRAY(u16_1, TestSimpleArray, 3),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +uint8_t wire_simple_arr[] = {
> +    /* u16_1 */ 0x00, 0x42,
> +    /* u16_1 */ 0x00, 0x43,
> +    /* u16_1 */ 0x00, 0x44,
> +    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
> +};
> +
> +static void obj_simple_arr_copy(void *target, void *source)
> +{
> +    memcpy(target, source, sizeof(TestSimpleArray));
> +}
> +
> +static void test_simple_array(void)
> +{
> +    TestSimpleArray obj, obj_clone;
> +
> +    memset(&obj, 0, sizeof(obj));
> +    save_vmstate(&vmstate_simple_arr, &obj_simple_arr);
> +
> +    compare_vmstate(wire_simple_arr, sizeof(wire_simple_arr));
> +
> +    SUCCESS(load_vmstate(&vmstate_simple_arr, &obj, &obj_clone,
> +                         obj_simple_arr_copy, 1, wire_simple_arr,
> +                         sizeof(wire_simple_arr)));
> +}
> +
>  typedef struct TestStruct {
>      uint32_t a, b, c, e;
>      uint64_t d, f;
> @@ -863,6 +912,7 @@ int main(int argc, char **argv)
>  
>      g_test_init(&argc, &argv, NULL);
>      g_test_add_func("/vmstate/simple/primitive", test_simple_primitive);
> +    g_test_add_func("/vmstate/simple/array", test_simple_array);
>      g_test_add_func("/vmstate/versioned/load/v1", test_load_v1);
>      g_test_add_func("/vmstate/versioned/load/v2", test_load_v2);
>      g_test_add_func("/vmstate/field_exists/load/noskip", test_load_noskip);
> -- 
> 2.19.1.708.g4ede3d42df
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

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

* Re: [Qemu-devel] [PATCH] tests: add /vmstate/simple/array
  2018-11-14 13:21 [Qemu-devel] [PATCH] tests: add /vmstate/simple/array Marc-André Lureau
  2018-11-14 15:33 ` Philippe Mathieu-Daudé
  2018-11-16 18:59 ` Dr. David Alan Gilbert
@ 2019-01-23 12:01 ` Dr. David Alan Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: Dr. David Alan Gilbert @ 2019-01-23 12:01 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, quintela

* Marc-André Lureau (marcandre.lureau@redhat.com) wrote:
> A very simple test to show VMSTATE_*_ARRAY usage and result. It could
> be systematically extended to other primitives, but I leave that as an
> exercise for others :).
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Queued

> ---
>  tests/test-vmstate.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
> index 37a7a93784..2a960dedbe 100644
> --- a/tests/test-vmstate.c
> +++ b/tests/test-vmstate.c
> @@ -284,6 +284,55 @@ static void test_simple_primitive(void)
>      FIELD_EQUAL(i64_2);
>  }
>  
> +typedef struct TestSimpleArray {
> +    uint16_t u16_1[3];
> +} TestSimpleArray;
> +
> +/* Object instantiation, we are going to use it in more than one test */
> +
> +TestSimpleArray obj_simple_arr = {
> +    .u16_1 = { 0x42, 0x43, 0x44 },
> +};
> +
> +/* Description of the values.  If you add a primitive type
> +   you are expected to add a test here */
> +
> +static const VMStateDescription vmstate_simple_arr = {
> +    .name = "simple/array",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_UINT16_ARRAY(u16_1, TestSimpleArray, 3),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +uint8_t wire_simple_arr[] = {
> +    /* u16_1 */ 0x00, 0x42,
> +    /* u16_1 */ 0x00, 0x43,
> +    /* u16_1 */ 0x00, 0x44,
> +    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
> +};
> +
> +static void obj_simple_arr_copy(void *target, void *source)
> +{
> +    memcpy(target, source, sizeof(TestSimpleArray));
> +}
> +
> +static void test_simple_array(void)
> +{
> +    TestSimpleArray obj, obj_clone;
> +
> +    memset(&obj, 0, sizeof(obj));
> +    save_vmstate(&vmstate_simple_arr, &obj_simple_arr);
> +
> +    compare_vmstate(wire_simple_arr, sizeof(wire_simple_arr));
> +
> +    SUCCESS(load_vmstate(&vmstate_simple_arr, &obj, &obj_clone,
> +                         obj_simple_arr_copy, 1, wire_simple_arr,
> +                         sizeof(wire_simple_arr)));
> +}
> +
>  typedef struct TestStruct {
>      uint32_t a, b, c, e;
>      uint64_t d, f;
> @@ -863,6 +912,7 @@ int main(int argc, char **argv)
>  
>      g_test_init(&argc, &argv, NULL);
>      g_test_add_func("/vmstate/simple/primitive", test_simple_primitive);
> +    g_test_add_func("/vmstate/simple/array", test_simple_array);
>      g_test_add_func("/vmstate/versioned/load/v1", test_load_v1);
>      g_test_add_func("/vmstate/versioned/load/v2", test_load_v2);
>      g_test_add_func("/vmstate/field_exists/load/noskip", test_load_noskip);
> -- 
> 2.19.1.708.g4ede3d42df
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

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

end of thread, other threads:[~2019-01-23 12:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 13:21 [Qemu-devel] [PATCH] tests: add /vmstate/simple/array Marc-André Lureau
2018-11-14 15:33 ` Philippe Mathieu-Daudé
2018-11-16 18:59 ` Dr. David Alan Gilbert
2019-01-23 12:01 ` Dr. David Alan Gilbert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.