qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 111/124] vmstate: Test for VMSTATE_VARRAY_UINT16_UNS


From: Juan Quintela
Subject: [Qemu-devel] [PATCH 111/124] vmstate: Test for VMSTATE_VARRAY_UINT16_UNSAFE
Date: Mon, 21 Apr 2014 16:41:31 +0200

I have to refactor object creation to allow for zero arrays at the end
of the struct.

Signed-off-by: Juan Quintela <address@hidden>
---
 tests/test-vmstate.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 8a6ca48..edceaee 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1213,6 +1213,8 @@ typedef struct TestVarray {
     uint8_t  *u8_2p;
     int32_t size;
     uint32_t *u32_1p;
+    uint16_t size2;
+    uint16_t u16_1[0];
 } TestVArray;

 static const VMStateDescription vmstate_varray_simple = {
@@ -1226,6 +1228,9 @@ static const VMStateDescription vmstate_varray_simple = {
         VMSTATE_INT32(size, TestVArray),
         VMSTATE_VARRAY_INT32(u32_1p, TestVArray, size,
                              vmstate_info_uint32, uint32_t),
+        VMSTATE_UINT16_EQUAL(size2, TestVArray),
+        VMSTATE_VARRAY_UINT16_UNSAFE(u16_1, TestVArray, size2,
+                                     vmstate_info_uint16, uint16_t),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -1236,6 +1241,9 @@ uint8_t wire_varray_simple[] = {
     /* u32_1p */        0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16,
                         0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18,
                         0x00, 0x00, 0x00, 0x19,
+    /* size2 */         0x00, 0x05,
+    /* u16_1 */         0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d,
+                        0x00, 0x0e, 0x00, 0x0f,
     QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -1246,19 +1254,23 @@ static void obj_varray_copy(void *arg1, void *arg2)
     int i;

     target->size = source->size;
+    target->size2 = source->size2;
     for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
         target->u8_1p[i] = source->u8_1p[i];
         target->u8_2p[i] = source->u8_2p[i];
         target->u32_1p[i] = source->u32_1p[i];
+        target->u16_1[i] = source->u16_1[i];
     }
 }

 static TestVArray *create_varray(void)
 {
-    TestVArray *obj = g_malloc0(sizeof(*obj));
+    TestVArray *obj = g_malloc0(sizeof(TestVArray) +
+                                VMSTATE_ARRAY_SIZE * sizeof(uint16_t));
+    obj->size = VMSTATE_ARRAY_SIZE;
+    obj->size2 = VMSTATE_ARRAY_SIZE;
     obj->u8_1p = g_malloc0(VMSTATE_ARRAY_SIZE);
     obj->u8_2p = g_malloc0(VMSTATE_ARRAY_SIZE);
-    obj->size =  VMSTATE_ARRAY_SIZE;
     obj->u32_1p = g_malloc0(VMSTATE_ARRAY_SIZE * sizeof(uint32_t));

     return obj;
@@ -1273,6 +1285,7 @@ static TestVArray *create_varray_init(void)
         obj->u8_1p[i] = i + 1;
         obj->u8_2p[i] = i + 11;
         obj->u32_1p[i] = i + 21;
+        obj->u16_1[i] = i + 11;
     }
     return obj;
 }
@@ -1302,6 +1315,7 @@ static void test_varray_simple(void)
         ELEM_EQUAL(u8_1p, i);
         ELEM_NOT_EQUAL(u8_2p, i);
         ELEM_EQUAL(u32_1p, i);
+        ELEM_EQUAL(u16_1, i);
     }
 }
 static const VMStateDescription vmstate_varray_test = {
-- 
1.9.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]