diff mbox

[087/124] vmstate: Test for VMSTATE_SYNTHETIC

Message ID 1398091304-10677-88-git-send-email-quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela April 21, 2014, 2:41 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/test-vmstate.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox

Patch

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index a56c5cc..308f94d 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -187,6 +187,28 @@  TestSimple obj_simple = {
     .f64 = float64_pi,
 };

+static int get_42_as_uint32(QEMUFile *f, void *pv, size_t size)
+{
+    uint64_t v;
+    v = qemu_get_be32(f);
+    if (v != 42) {
+        return -1;
+    }
+    return 0;
+}
+
+static void put_42_as_uint32(QEMUFile *f, void *pv, size_t size)
+{
+    uint64_t v = 42;
+    qemu_put_be32(f, v);
+}
+
+static const VMStateInfo vmstate_42_as_uint32 = {
+    .name = "42_as_uint32",
+    .get  = get_42_as_uint32,
+    .put  = put_42_as_uint32,
+};
+
 /* Description of the values.  If you add a primitive type
    you are expected to add a test here */

@@ -211,6 +233,7 @@  static const VMStateDescription vmstate_simple_primitive = {
         VMSTATE_INT64(i64_2, TestSimple),
         VMSTATE_FLOAT64(f64, TestSimple),
         VMSTATE_UNUSED(5),
+        VMSTATE_SYNTHETIC("synthetic", vmstate_42_as_uint32, sizeof(uint32)),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -244,6 +267,7 @@  uint8_t wire_simple_primitive[] = {
     /* i64_2 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0x47, 0x0b, 0x84,
     /* f64 */   0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18,
     /* unused */0x00, 0x00, 0x00, 0x00, 0x00,
+    /* synthe */0x00, 0x00, 0x00, 0x2a,
     QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };