qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 118/124] vmstate: Test for VMSTATE_STRUCT_VARRAY_UIN


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

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

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index f4ff93d..25e162f 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1653,6 +1653,8 @@ static void test_struct_test(void)
 typedef struct TestStruct2 {
     uint8_t size;
     SubStruct a[3];
+    uint32_t size2;
+    SubStruct b[3];
 } TestStruct2;

 /*
@@ -1668,6 +1670,9 @@ static const VMStateDescription vmstate_struct_varray = {
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
         VMSTATE_UINT8_EQUAL(size, TestStruct2),
+        VMSTATE_UINT32_EQUAL(size2, TestStruct2),
+        VMSTATE_STRUCT_VARRAY_UINT32(b, TestStruct2, size2,
+                                     vmstate_sub_struct, SubStruct),
         VMSTATE_STRUCT_VARRAY_UINT8(a, TestStruct2, size,
                                     vmstate_sub_struct, SubStruct),
         VMSTATE_END_OF_LIST()
@@ -1678,6 +1683,22 @@ static const VMStateDescription vmstate_struct_varray = {
 /* We need to change the first byte for load to work */
 uint8_t wire_struct_varray[] = {
     /* size */      0x03,
+    /* size2 */     0x00, 0x00, 0x00, 0x03,
+    /* b[0] */
+    /* i32 */       0x00, 0x00, 0x00, 0x29,
+    /* i64 */       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33,
+    /* buffer */    0x62, 0x79, 0x65, 0x33, 0x20, 0x20, 0x77, 0x6f,
+                    0x72, 0x6c, 0x64, 0x21, 0x00,
+    /* b[1] */
+    /* i32 */       0x00, 0x00, 0x00, 0x2a,
+    /* i64 */       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34,
+    /* buffer */    0x62, 0x79, 0x65, 0x34, 0x20, 0x20, 0x77, 0x6f,
+                    0x72, 0x6c, 0x64, 0x21, 0x00,
+    /* b[2] */
+    /* i32 */       0x00, 0x00, 0x00, 0x2b,
+    /* i64 */       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35,
+    /* buffer */    0x62, 0x79, 0x65, 0x35, 0x20, 0x20, 0x77, 0x6f,
+                    0x72, 0x6c, 0x64, 0x21, 0x00,
     /* a[0] */
     /* i32 */       0x00, 0x00, 0x00, 0x15,
     /* i64 */       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
@@ -1703,10 +1724,14 @@ static void obj_struct2_copy(void *arg1, void *arg2)
     int i;

     target->size = source->size;
+    target->size2 = source->size2;
     for (i = 0; i < 3; i++) {
         target->a[i].i32 = source->a[i].i32;
         target->a[i].i64 = source->a[i].i64;
         memcpy(target->a[i].buffer, source->a[i].buffer, 13);
+        target->b[i].i32 = source->b[i].i32;
+        target->b[i].i64 = source->b[i].i64;
+        memcpy(target->b[i].buffer, source->b[i].buffer, 13);
     }
 }

@@ -1714,6 +1739,7 @@ static TestStruct2 *create_struct2(void)
 {
     TestStruct2 *obj = g_malloc0(sizeof(*obj));
     obj->size = 3;
+    obj->size2 = 3;

     return obj;
 }
@@ -1727,6 +1753,9 @@ static TestStruct2 *create_struct2_init(void)
         obj->a[i].i32 = i + 21;
         obj->a[i].i64 = i + 31;
         snprintf((char *)obj->a[i].buffer, 13, "bye%d  world!", i);
+        obj->b[i].i32 = i + 41;
+        obj->b[i].i64 = i + 51;
+        snprintf((char *)obj->b[i].buffer, 13, "bye%d  world!", i + 3);
     }

     return obj;
@@ -1750,6 +1779,7 @@ static void test_struct_varray(void)

         sub_struct_size = sizeof(uint32_t) + sizeof(uint64_t) + 13;
         memset(obj->a, 0, sizeof(obj->a));
+        memset(obj->b, 0, sizeof(obj->b));
         obj->size = j;
         obj_struct2->size = j;
         wire_struct_varray[0] = j;
@@ -1764,6 +1794,9 @@ static void test_struct_varray(void)
         for (i = j; i < 3; i++) {
             STRUCT_NOT_EQUAL((&obj->a[i]), (&obj_struct2->a[i]));
         }
+        for (i = 0; i < 3; i++) {
+            STRUCT_EQUAL((&obj->b[i]), (&obj_struct2->b[i]));
+        }
     }
 }
 #undef STRUCT_EQUAL
-- 
1.9.0




reply via email to

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