qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 105/124] vmstate: Test for VMSTATE_POINTER_UNSAFE


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

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

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index c284bfc..e1e2523 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1059,6 +1059,7 @@ static void test_vbuffer_simple(void)

 typedef struct TestPointer {
     uint8_t  *u8_1p;
+    uint8_t  *u8_2p;
 } TestPointer;

 static const VMStateDescription vmstate_pointer_simple = {
@@ -1068,12 +1069,15 @@ static const VMStateDescription vmstate_pointer_simple 
= {
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
         VMSTATE_POINTER(u8_1p, TestPointer, NULL, vmstate_info_uint8, uint8_t),
+        VMSTATE_POINTER_UNSAFE(u8_2p, TestPointer,
+                               vmstate_info_uint16, uint16_t),
         VMSTATE_END_OF_LIST()
     }
 };

 uint8_t wire_pointer_simple[] = {
     /* u8_1p */   0x11,
+    /* u8_2p */   0x02, 0x2b,
     QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -1083,12 +1087,14 @@ static void obj_pointer_copy(void *arg1, void *arg2)
     TestPointer *source = arg2;

     *target->u8_1p = *source->u8_1p;
+    *((uint16_t *)target->u8_2p) = *((uint16_t *)source->u8_2p);
 }

 static TestPointer *create_pointer(void)
 {
     TestPointer *obj = g_malloc0(sizeof(*obj));
     obj->u8_1p = g_malloc0(sizeof(*obj->u8_1p));
+    obj->u8_2p = g_malloc0(sizeof(uint16_t));

     return obj;
 }
@@ -1102,7 +1108,9 @@ static void test_pointer_simple(void)
     obj_clone = create_pointer();

     *obj_pointer->u8_1p = 17;
+    *((uint16_t *)obj_pointer->u8_2p) = 555;
     *obj->u8_1p = 22;
+    *((uint16_t *)obj->u8_2p) = 777;

     save_vmstate(&vmstate_pointer_simple, obj_pointer);

@@ -1112,8 +1120,9 @@ static void test_pointer_simple(void)
                          obj_pointer_copy, 1, wire_pointer_simple,
                          sizeof(wire_pointer_simple)));

-#define FIELD_EQUAL(name)   g_assert_cmpint(*obj->name, ==, *obj_pointer->name)
-    FIELD_EQUAL(u8_1p);
+    g_assert_cmpint(*obj->u8_1p, ==, *obj_pointer->u8_1p);
+    g_assert_cmpint(*((uint16_t *)obj->u8_2p), ==,
+                    *((uint16_t *)obj_pointer->u8_2p));
 }
 #undef FIELD_EQUAL

-- 
1.9.0




reply via email to

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