qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 115/124] vmstate: Test for VMSTATE_STRUCT_POINTER


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

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

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 93537f7..c7ecaeb 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1415,6 +1415,7 @@ static const VMStateDescription vmstate_sub_struct = {
 typedef struct TestStruct {
     SubStruct sub;
     SubStruct sub2;
+    SubStruct *subp;
 } TestStruct;

 static const VMStateDescription vmstate_struct_simple = {
@@ -1424,10 +1425,17 @@ static const VMStateDescription vmstate_struct_simple = 
{
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
         VMSTATE_STRUCT(sub, TestStruct, vmstate_sub_struct, SubStruct),
+        VMSTATE_STRUCT_POINTER(subp, TestStruct, vmstate_sub_struct, 
SubStruct),
         VMSTATE_END_OF_LIST()
     }
 };

+SubStruct sub_struct = {
+    .i32 = 22,
+    .i64 = 44,
+    .buffer = "hello field!",
+};
+
 TestStruct obj_struct = {
     .sub = {
         .i32 = 33,
@@ -1439,14 +1447,21 @@ TestStruct obj_struct = {
         .i64 = 99,
         .buffer = "bye   world!",
     },
+    .subp = &sub_struct,
 };

 /* This is the binary representation on the wire of that struct */
 uint8_t wire_struct_simple[] = {
+    /* sub */
     /* i32 */       0x00, 0x00, 0x00, 0x21,
     /* i64 */       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d,
     /* buffer */    0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f,
                     0x72, 0x6c, 0x64, 0x21, 0x00,
+    /* subp */
+    /* i32 */       0x00, 0x00, 0x00, 0x16,
+    /* i64 */       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c,
+    /* buffer */    0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x69,
+                    0x65, 0x6c, 0x64, 0x21, 0x00,
     QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -1462,15 +1477,21 @@ static void obj_struct_copy(void *arg1, void *arg2)
     target->sub2.i32 = source->sub2.i32;
     target->sub2.i64 = source->sub2.i64;
     memcpy(target->sub2.buffer, source->sub2.buffer, 13);
+
+    target->subp->i32 = source->subp->i32;
+    target->subp->i64 = source->subp->i64;
+    memcpy(target->subp->buffer, source->subp->buffer, 13);
 }

 static void test_struct_simple(void)
 {
     TestStruct obj, obj_clone;

-
     memset(&obj, 0, sizeof(obj));

+    obj.subp = g_malloc0(sizeof(SubStruct));
+    obj_clone.subp = g_malloc0(sizeof(SubStruct));
+
     save_vmstate(&vmstate_struct_simple, &obj_struct);

     compare_vmstate(wire_struct_simple, sizeof(wire_struct_simple));
@@ -1497,6 +1518,7 @@ static void test_struct_simple(void)

     STRUCT_EQUAL((&obj.sub), (&obj_struct.sub));
     STRUCT_NOT_EQUAL((&obj.sub2), (&obj_struct.sub2));
+    STRUCT_EQUAL(obj.subp, obj_struct.subp);
 }

 static const VMStateDescription vmstate_struct_test = {
@@ -1525,6 +1547,9 @@ static void test_struct_test(void)

     memset(&obj, 0, sizeof(obj));

+    obj.subp = g_malloc0(sizeof(SubStruct));
+    obj_clone.subp = g_malloc0(sizeof(SubStruct));
+
     save_vmstate(&vmstate_struct_test, &obj_struct);

     compare_vmstate(wire_struct_test, sizeof(wire_struct_test));
-- 
1.9.0




reply via email to

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