/*
 *  Test code for VMState
 *
 *  Copyright (c) 2013 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "qemu/osdep.h"

#include "../migration/migration.h"
#include "migration/vmstate.h"
#include "migration/qemu-file-types.h"
#include "../migration/qemu-file.h"
#include "../migration/savevm.h"
#include "qemu/module.h"
#include "io/channel-file.h"

static int temp_fd;


/* Duplicate temp_fd and seek to the beginning of the file */
static QEMUFile *open_test_file(bool write)
{
    int fd;
    QIOChannel *ioc;
    QEMUFile *f;

    fd = dup(temp_fd);
    g_assert(fd >= 0);
    lseek(fd, 0, SEEK_SET);
    if (write) {
        g_assert_cmpint(ftruncate(fd, 0), ==, 0);
    }
    ioc = QIO_CHANNEL(qio_channel_file_new_fd(fd));
    if (write) {
        f = qemu_file_new_output(ioc);
    } else {
        f = qemu_file_new_input(ioc);
    }
    object_unref(OBJECT(ioc));
    return f;
}

#define SUCCESS(val) \
    g_assert_cmpint((val), ==, 0)

#define FAILURE(val) \
    g_assert_cmpint((val), !=, 0)

static void save_vmstate(const VMStateDescription *desc, void *obj)
{
    QEMUFile *f = open_test_file(true);

    /* Save file with vmstate */
    int ret = vmstate_save_state(f, desc, obj, NULL);
    g_assert(!ret);
    qemu_put_byte(f, QEMU_VM_EOF);
    g_assert(!qemu_file_get_error(f));
    qemu_fclose(f);
}

static void save_buffer(const uint8_t *buf, size_t buf_size)
{
    QEMUFile *fsave = open_test_file(true);
    qemu_put_buffer(fsave, buf, buf_size);
    qemu_fclose(fsave);
}

static void compare_vmstate(const uint8_t *wire, size_t size)
{
    QEMUFile *f = open_test_file(false);
    g_autofree uint8_t *result = g_malloc(size);

    /* read back as binary */

    g_assert_cmpint(qemu_get_buffer(f, result, size), ==, size);
    g_assert(!qemu_file_get_error(f));

    /* Compare that what is on the file is the same that what we
       expected to be there */
    SUCCESS(memcmp(result, wire, size));

    /* Must reach EOF */
    qemu_get_byte(f);
    g_assert_cmpint(qemu_file_get_error(f), ==, -EIO);

    qemu_fclose(f);
}

static int load_vmstate_one(const VMStateDescription *desc, void *obj,
                            int version, const uint8_t *wire, size_t size)
{
    QEMUFile *f;
    int ret;

    f = open_test_file(true);
    qemu_put_buffer(f, wire, size);
    qemu_fclose(f);

    f = open_test_file(false);
    ret = vmstate_load_state(f, desc, obj, version);
    if (ret) {
        g_assert(qemu_file_get_error(f));
    } else{
        g_assert(!qemu_file_get_error(f));
    }
    qemu_fclose(f);
    return ret;
}


static int load_vmstate(const VMStateDescription *desc,
                        void *obj, void *obj_clone,
                        void (*obj_copy)(void *, void*),
                        int version, const uint8_t *wire, size_t size)
{
    /* We test with zero size */
    obj_copy(obj_clone, obj);
    FAILURE(load_vmstate_one(desc, obj, version, wire, 0));

    /* Stream ends with QEMU_EOF, so we need at least 3 bytes to be
     * able to test in the middle */

    if (size > 3) {

        /* We test with size - 2. We can't test size - 1 due to EOF tricks */
        obj_copy(obj, obj_clone);
        FAILURE(load_vmstate_one(desc, obj, version, wire, size - 2));

        /* Test with size/2, first half of real state */
        obj_copy(obj, obj_clone);
        FAILURE(load_vmstate_one(desc, obj, version, wire, size/2));

        /* Test with size/2, second half of real state */
        obj_copy(obj, obj_clone);
        FAILURE(load_vmstate_one(desc, obj, version, wire + (size/2), size/2));

    }
    obj_copy(obj, obj_clone);
    return load_vmstate_one(desc, obj, version, wire, size);
}

/* Test struct that we are going to use for our tests */

typedef struct TestSimple {
    bool     b_1,   b_2;
    uint8_t  u8_1;
    uint16_t u16_1;
    uint32_t u32_1;
    uint64_t u64_1;
    int8_t   i8_1,  i8_2;
    int16_t  i16_1, i16_2;
    int32_t  i32_1, i32_2;
    int64_t  i64_1, i64_2;
} TestSimple;

/* Object instantiation, we are going to use it in more than one test */

TestSimple obj_simple = {
    .b_1 = true,
    .b_2 = false,
    .u8_1 = 130,
    .u16_1 = 512,
    .u32_1 = 70000,
    .u64_1 = 12121212,
    .i8_1 = 65,
    .i8_2 = -65,
    .i16_1 = 512,
    .i16_2 = -512,
    .i32_1 = 70000,
    .i32_2 = -70000,
    .i64_1 = 12121212,
    .i64_2 = -12121212,
};

/* Description of the values.  If you add a primitive type
   you are expected to add a test here */

static const VMStateDescription vmstate_simple_primitive = {
    .name = "simple/primitive",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_BOOL(b_1, TestSimple),
        VMSTATE_BOOL(b_2, TestSimple),
        VMSTATE_UINT8(u8_1, TestSimple),
        VMSTATE_UINT16(u16_1, TestSimple),
        VMSTATE_UINT32(u32_1, TestSimple),
        VMSTATE_UINT64(u64_1, TestSimple),
        VMSTATE_INT8(i8_1, TestSimple),
        VMSTATE_INT8(i8_2, TestSimple),
        VMSTATE_INT16(i16_1, TestSimple),
        VMSTATE_INT16(i16_2, TestSimple),
        VMSTATE_INT32(i32_1, TestSimple),
        VMSTATE_INT32(i32_2, TestSimple),
        VMSTATE_INT64(i64_1, TestSimple),
        VMSTATE_INT64(i64_2, TestSimple),
        VMSTATE_END_OF_LIST()
    }
};

/* It describes what goes through the wire.  Our tests are basically:

   * save test
     - save a struct a vmstate to a file
     - read that file back (binary read, no vmstate)
     - compare it with what we expect to be on the wire
   * load test
     - save to the file what we expect to be on the wire
     - read struct back with vmstate in a different
     - compare back with the original struct
*/

uint8_t wire_simple_primitive[] = {
    /* b_1 */   0x01,
    /* b_2 */   0x00,
    /* u8_1 */  0x82,
    /* u16_1 */ 0x02, 0x00,
    /* u32_1 */ 0x00, 0x01, 0x11, 0x70,
    /* u64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
    /* i8_1 */  0x41,
    /* i8_2 */  0xbf,
    /* i16_1 */ 0x02, 0x00,
    /* i16_2 */ 0xfe, 0x0,
    /* i32_1 */ 0x00, 0x01, 0x11, 0x70,
    /* i32_2 */ 0xff, 0xfe, 0xee, 0x90,
    /* i64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
    /* i64_2 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0x47, 0x0b, 0x84,
    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};

static void obj_simple_copy(void *target, void *source)
{
    memcpy(target, source, sizeof(TestSimple));
}

static void test_simple_primitive(void)
{
    TestSimple obj, obj_clone;

    memset(&obj, 0, sizeof(obj));
    save_vmstate(&vmstate_simple_primitive, &obj_simple);

    compare_vmstate(wire_simple_primitive, sizeof(wire_simple_primitive));

    SUCCESS(load_vmstate(&vmstate_simple_primitive, &obj, &obj_clone,
                         obj_simple_copy, 1, wire_simple_primitive,
                         sizeof(wire_simple_primitive)));

#define FIELD_EQUAL(name)   g_assert_cmpint(obj.name, ==, obj_simple.name)

    FIELD_EQUAL(b_1);
    FIELD_EQUAL(b_2);
    FIELD_EQUAL(u8_1);
    FIELD_EQUAL(u16_1);
    FIELD_EQUAL(u32_1);
    FIELD_EQUAL(u64_1);
    FIELD_EQUAL(i8_1);
    FIELD_EQUAL(i8_2);
    FIELD_EQUAL(i16_1);
    FIELD_EQUAL(i16_2);
    FIELD_EQUAL(i32_1);
    FIELD_EQUAL(i32_2);
    FIELD_EQUAL(i64_1);
    FIELD_EQUAL(i64_2);
}

typedef struct TestSimpleArray {
    uint16_t u16_1[3];
} TestSimpleArray;

/* Object instantiation, we are going to use it in more than one test */

TestSimpleArray obj_simple_arr = {
    .u16_1 = { 0x42, 0x43, 0x44 },
};

/* Description of the values.  If you add a primitive type
   you are expected to add a test here */

static const VMStateDescription vmstate_simple_arr = {
    .name = "simple/array",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_UINT16_ARRAY(u16_1, TestSimpleArray, 3),
        VMSTATE_END_OF_LIST()
    }
};

uint8_t wire_simple_arr[] = {
    /* u16_1 */ 0x00, 0x42,
    /* u16_1 */ 0x00, 0x43,
    /* u16_1 */ 0x00, 0x44,
    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};

static void obj_simple_arr_copy(void *target, void *source)
{
    memcpy(target, source, sizeof(TestSimpleArray));
}

static void test_simple_array(void)
{
    TestSimpleArray obj, obj_clone;

    memset(&obj, 0, sizeof(obj));
    save_vmstate(&vmstate_simple_arr, &obj_simple_arr);

    compare_vmstate(wire_simple_arr, sizeof(wire_simple_arr));

    SUCCESS(load_vmstate(&vmstate_simple_arr, &obj, &obj_clone,
                         obj_simple_arr_copy, 1, wire_simple_arr,
                         sizeof(wire_simple_arr)));
}

typedef struct TestStruct {
    uint32_t a, b, c, e;
    uint64_t d, f;
    bool skip_c_e;
} TestStruct;

static const VMStateDescription vmstate_versioned = {
    .name = "test/versioned",
    .version_id = 2,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_UINT32(a, TestStruct),
        VMSTATE_UINT32_V(b, TestStruct, 2), /* Versioned field in the middle, so
                                             * we catch bugs more easily.
                                             */
        VMSTATE_UINT32(c, TestStruct),
        VMSTATE_UINT64(d, TestStruct),
        VMSTATE_UINT32_V(e, TestStruct, 2),
        VMSTATE_UINT64_V(f, TestStruct, 2),
        VMSTATE_END_OF_LIST()
    }
};

static void test_load_v1(void)
{
    uint8_t buf[] = {
        0, 0, 0, 10,             /* a */
        0, 0, 0, 30,             /* c */
        0, 0, 0, 0, 0, 0, 0, 40, /* d */
        QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
    };
    save_buffer(buf, sizeof(buf));

    QEMUFile *loading = open_test_file(false);
    TestStruct obj = { .b = 200, .e = 500, .f = 600 };
    vmstate_load_state(loading, &vmstate_versioned, &obj, 1);
    g_assert(!qemu_file_get_error(loading));
    g_assert_cmpint(obj.a, ==, 10);
    g_assert_cmpint(obj.b, ==, 200);
    g_assert_cmpint(obj.c, ==, 30);
    g_assert_cmpint(obj.d, ==, 40);
    g_assert_cmpint(obj.e, ==, 500);
    g_assert_cmpint(obj.f, ==, 600);
    qemu_fclose(loading);
}

static void test_load_v2(void)
{
    uint8_t buf[] = {
        0, 0, 0, 10,             /* a */
        0, 0, 0, 20,             /* b */
        0, 0, 0, 30,             /* c */
        0, 0, 0, 0, 0, 0, 0, 40, /* d */
        0, 0, 0, 50,             /* e */
        0, 0, 0, 0, 0, 0, 0, 60, /* f */
        QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
    };
    save_buffer(buf, sizeof(buf));

    QEMUFile *loading = open_test_file(false);
    TestStruct obj;
    vmstate_load_state(loading, &vmstate_versioned, &obj, 2);
    g_assert_cmpint(obj.a, ==, 10);
    g_assert_cmpint(obj.b, ==, 20);
    g_assert_cmpint(obj.c, ==, 30);
    g_assert_cmpint(obj.d, ==, 40);
    g_assert_cmpint(obj.e, ==, 50);
    g_assert_cmpint(obj.f, ==, 60);
    qemu_fclose(loading);
}

static bool test_skip(void *opaque, int version_id)
{
    TestStruct *t = (TestStruct *)opaque;
    return !t->skip_c_e;
}

static const VMStateDescription vmstate_skipping = {
    .name = "test/skip",
    .version_id = 2,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_UINT32(a, TestStruct),
        VMSTATE_UINT32(b, TestStruct),
        VMSTATE_UINT32_TEST(c, TestStruct, test_skip),
        VMSTATE_UINT64(d, TestStruct),
        VMSTATE_UINT32_TEST(e, TestStruct, test_skip),
        VMSTATE_UINT64_V(f, TestStruct, 2),
        VMSTATE_END_OF_LIST()
    }
};


static void test_save_noskip(void)
{
    QEMUFile *fsave = open_test_file(true);
    TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6,
                       .skip_c_e = false };
    int ret = vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL);
    g_assert(!ret);
    g_assert(!qemu_file_get_error(fsave));

    uint8_t expected[] = {
        0, 0, 0, 1,             /* a */
        0, 0, 0, 2,             /* b */
        0, 0, 0, 3,             /* c */
        0, 0, 0, 0, 0, 0, 0, 4, /* d */
        0, 0, 0, 5,             /* e */
        0, 0, 0, 0, 0, 0, 0, 6, /* f */
    };

    qemu_fclose(fsave);
    compare_vmstate(expected, sizeof(expected));
}

static void test_save_skip(void)
{
    QEMUFile *fsave = open_test_file(true);
    TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6,
                       .skip_c_e = true };
    int ret = vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL);
    g_assert(!ret);
    g_assert(!qemu_file_get_error(fsave));

    uint8_t expected[] = {
        0, 0, 0, 1,             /* a */
        0, 0, 0, 2,             /* b */
        0, 0, 0, 0, 0, 0, 0, 4, /* d */
        0, 0, 0, 0, 0, 0, 0, 6, /* f */
    };

    qemu_fclose(fsave);
    compare_vmstate(expected, sizeof(expected));
}

static void test_load_noskip(void)
{
    uint8_t buf[] = {
        0, 0, 0, 10,             /* a */
        0, 0, 0, 20,             /* b */
        0, 0, 0, 30,             /* c */
        0, 0, 0, 0, 0, 0, 0, 40, /* d */
        0, 0, 0, 50,             /* e */
        0, 0, 0, 0, 0, 0, 0, 60, /* f */
        QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
    };
    save_buffer(buf, sizeof(buf));

    QEMUFile *loading = open_test_file(false);
    TestStruct obj = { .skip_c_e = false };
    vmstate_load_state(loading, &vmstate_skipping, &obj, 2);
    g_assert(!qemu_file_get_error(loading));
    g_assert_cmpint(obj.a, ==, 10);
    g_assert_cmpint(obj.b, ==, 20);
    g_assert_cmpint(obj.c, ==, 30);
    g_assert_cmpint(obj.d, ==, 40);
    g_assert_cmpint(obj.e, ==, 50);
    g_assert_cmpint(obj.f, ==, 60);
    qemu_fclose(loading);
}

static void test_load_skip(void)
{
    uint8_t buf[] = {
        0, 0, 0, 10,             /* a */
        0, 0, 0, 20,             /* b */
        0, 0, 0, 0, 0, 0, 0, 40, /* d */
        0, 0, 0, 0, 0, 0, 0, 60, /* f */
        QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
    };
    save_buffer(buf, sizeof(buf));

    QEMUFile *loading = open_test_file(false);
    TestStruct obj = { .skip_c_e = true, .c = 300, .e = 500 };
    vmstate_load_state(loading, &vmstate_skipping, &obj, 2);
    g_assert(!qemu_file_get_error(loading));
    g_assert_cmpint(obj.a, ==, 10);
    g_assert_cmpint(obj.b, ==, 20);
    g_assert_cmpint(obj.c, ==, 300);
    g_assert_cmpint(obj.d, ==, 40);
    g_assert_cmpint(obj.e, ==, 500);
    g_assert_cmpint(obj.f, ==, 60);
    qemu_fclose(loading);
}

typedef struct {
    int32_t i;
} TestStructTriv;

const VMStateDescription vmsd_tst = {
    .name = "test/tst",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_INT32(i, TestStructTriv),
        VMSTATE_END_OF_LIST()
    }
};

/* test array migration */

#define AR_SIZE 4

typedef struct {
    TestStructTriv *ar[AR_SIZE];
} TestArrayOfPtrToStuct;

const VMStateDescription vmsd_arps = {
    .name = "test/arps",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(ar, TestArrayOfPtrToStuct,
                AR_SIZE, 0, vmsd_tst, TestStructTriv),
        VMSTATE_END_OF_LIST()
    }
};

static uint8_t wire_arr_ptr_no0[] = {
    0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x02,
    0x00, 0x00, 0x00, 0x03,
    QEMU_VM_EOF
};

static void test_arr_ptr_str_no0_save(void)
{
    TestStructTriv ar[AR_SIZE] = {{.i = 0}, {.i = 1}, {.i = 2}, {.i = 3} };
    TestArrayOfPtrToStuct sample = {.ar = {&ar[0], &ar[1], &ar[2], &ar[3]} };

    save_vmstate(&vmsd_arps, &sample);
    compare_vmstate(wire_arr_ptr_no0, sizeof(wire_arr_ptr_no0));
}

static void test_arr_ptr_str_no0_load(void)
{
    TestStructTriv ar_gt[AR_SIZE] = {{.i = 0}, {.i = 1}, {.i = 2}, {.i = 3} };
    TestStructTriv ar[AR_SIZE] = {};
    TestArrayOfPtrToStuct obj = {.ar = {&ar[0], &ar[1], &ar[2], &ar[3]} };
    int idx;

    save_buffer(wire_arr_ptr_no0, sizeof(wire_arr_ptr_no0));
    SUCCESS(load_vmstate_one(&vmsd_arps, &obj, 1,
                          wire_arr_ptr_no0, sizeof(wire_arr_ptr_no0)));
    for (idx = 0; idx < AR_SIZE; ++idx) {
        /* compare the target array ar with the ground truth array ar_gt */
        g_assert_cmpint(ar_gt[idx].i, ==, ar[idx].i);
    }
}

static uint8_t wire_arr_ptr_0[] = {
    0x00, 0x00, 0x00, 0x00,
    VMS_NULLPTR_MARKER,
    0x00, 0x00, 0x00, 0x02,
    0x00, 0x00, 0x00, 0x03,
    QEMU_VM_EOF
};

static void test_arr_ptr_str_0_save(void)
{
    TestStructTriv ar[AR_SIZE] = {{.i = 0}, {.i = 1}, {.i = 2}, {.i = 3} };
    TestArrayOfPtrToStuct sample = {.ar = {&ar[0], NULL, &ar[2], &ar[3]} };

    save_vmstate(&vmsd_arps, &sample);
    compare_vmstate(wire_arr_ptr_0, sizeof(wire_arr_ptr_0));
}

static void test_arr_ptr_str_0_load(void)
{
    TestStructTriv ar_gt[AR_SIZE] = {{.i = 0}, {.i = 0}, {.i = 2}, {.i = 3} };
    TestStructTriv ar[AR_SIZE] = {};
    TestArrayOfPtrToStuct obj = {.ar = {&ar[0], NULL, &ar[2], &ar[3]} };
    int idx;

    save_buffer(wire_arr_ptr_0, sizeof(wire_arr_ptr_0));
    SUCCESS(load_vmstate_one(&vmsd_arps, &obj, 1,
                          wire_arr_ptr_0, sizeof(wire_arr_ptr_0)));
    for (idx = 0; idx < AR_SIZE; ++idx) {
        /* compare the target array ar with the ground truth array ar_gt */
        g_assert_cmpint(ar_gt[idx].i, ==, ar[idx].i);
    }
    for (idx = 0; idx < AR_SIZE; ++idx) {
        if (idx == 1) {
            g_assert_cmpint((uintptr_t)(obj.ar[idx]), ==, 0);
        } else {
            g_assert_cmpint((uintptr_t)(obj.ar[idx]), !=, 0);
        }
    }
}

typedef struct TestArrayOfPtrToInt {
    int32_t *ar[AR_SIZE];
} TestArrayOfPtrToInt;

const VMStateDescription vmsd_arpp = {
    .name = "test/arps",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_ARRAY_OF_POINTER(ar, TestArrayOfPtrToInt,
                AR_SIZE, 0, vmstate_info_int32, int32_t*),
        VMSTATE_END_OF_LIST()
    }
};

static void test_arr_ptr_prim_0_save(void)
{
    int32_t ar[AR_SIZE] = {0 , 1, 2, 3};
    TestArrayOfPtrToInt  sample = {.ar = {&ar[0], NULL, &ar[2], &ar[3]} };

    save_vmstate(&vmsd_arpp, &sample);
    compare_vmstate(wire_arr_ptr_0, sizeof(wire_arr_ptr_0));
}

static void test_arr_ptr_prim_0_load(void)
{
    int32_t ar_gt[AR_SIZE] = {0, 1, 2, 3};
    int32_t ar[AR_SIZE] = {3 , 42, 1, 0};
    TestArrayOfPtrToInt obj = {.ar = {&ar[0], NULL, &ar[2], &ar[3]} };
    int idx;

    save_buffer(wire_arr_ptr_0, sizeof(wire_arr_ptr_0));
    SUCCESS(load_vmstate_one(&vmsd_arpp, &obj, 1,
                          wire_arr_ptr_0, sizeof(wire_arr_ptr_0)));
    for (idx = 0; idx < AR_SIZE; ++idx) {
        /* compare the target array ar with the ground truth array ar_gt */
        if (idx == 1) {
            g_assert_cmpint(42, ==, ar[idx]);
        } else {
            g_assert_cmpint(ar_gt[idx], ==, ar[idx]);
        }
    }
}

/* test QTAILQ migration */
typedef struct TestQtailqElement TestQtailqElement;

struct TestQtailqElement {
    bool     b;
    uint8_t  u8;
    QTAILQ_ENTRY(TestQtailqElement) next;
};

typedef struct TestQtailq {
    int16_t  i16;
    QTAILQ_HEAD(, TestQtailqElement) q;
    int32_t  i32;
} TestQtailq;

static const VMStateDescription vmstate_q_element = {
    .name = "test/queue-element",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_BOOL(b, TestQtailqElement),
        VMSTATE_UINT8(u8, TestQtailqElement),
        VMSTATE_END_OF_LIST()
    },
};

static const VMStateDescription vmstate_q = {
    .name = "test/queue",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_INT16(i16, TestQtailq),
        VMSTATE_QTAILQ_V(q, TestQtailq, 1, vmstate_q_element, TestQtailqElement,
                         next),
        VMSTATE_INT32(i32, TestQtailq),
        VMSTATE_END_OF_LIST()
    }
};

uint8_t wire_q[] = {
    /* i16 */                     0xfe, 0x0,
    /* start of element 0 of q */ 0x01,
    /* .b  */                     0x01,
    /* .u8 */                     0x82,
    /* start of element 1 of q */ 0x01,
    /* b */                       0x00,
    /* u8 */                      0x41,
    /* end of q */                0x00,
    /* i32 */                     0x00, 0x01, 0x11, 0x70,
    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};

static void test_save_q(void)
{
    TestQtailq obj_q = {
        .i16 = -512,
        .i32 = 70000,
    };

    TestQtailqElement obj_qe1 = {
        .b = true,
        .u8 = 130,
    };

    TestQtailqElement obj_qe2 = {
        .b = false,
        .u8 = 65,
    };

    QTAILQ_INIT(&obj_q.q);
    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe1, next);
    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe2, next);

    save_vmstate(&vmstate_q, &obj_q);
    compare_vmstate(wire_q, sizeof(wire_q));
}

static void test_load_q(void)
{
    TestQtailq obj_q = {
        .i16 = -512,
        .i32 = 70000,
    };

    TestQtailqElement obj_qe1 = {
        .b = true,
        .u8 = 130,
    };

    TestQtailqElement obj_qe2 = {
        .b = false,
        .u8 = 65,
    };

    QTAILQ_INIT(&obj_q.q);
    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe1, next);
    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe2, next);

    QEMUFile *fsave = open_test_file(true);

    qemu_put_buffer(fsave, wire_q, sizeof(wire_q));
    g_assert(!qemu_file_get_error(fsave));
    qemu_fclose(fsave);

    QEMUFile *fload = open_test_file(false);
    TestQtailq tgt;

    QTAILQ_INIT(&tgt.q);
    vmstate_load_state(fload, &vmstate_q, &tgt, 1);
    char eof = qemu_get_byte(fload);
    g_assert(!qemu_file_get_error(fload));
    g_assert_cmpint(tgt.i16, ==, obj_q.i16);
    g_assert_cmpint(tgt.i32, ==, obj_q.i32);
    g_assert_cmpint(eof, ==, QEMU_VM_EOF);

    TestQtailqElement *qele_from = QTAILQ_FIRST(&obj_q.q);
    TestQtailqElement *qlast_from = QTAILQ_LAST(&obj_q.q);
    TestQtailqElement *qele_to = QTAILQ_FIRST(&tgt.q);
    TestQtailqElement *qlast_to = QTAILQ_LAST(&tgt.q);

    while (1) {
        g_assert_cmpint(qele_to->b, ==, qele_from->b);
        g_assert_cmpint(qele_to->u8, ==, qele_from->u8);
        if ((qele_from == qlast_from) || (qele_to == qlast_to)) {
            break;
        }
        qele_from = QTAILQ_NEXT(qele_from, next);
        qele_to = QTAILQ_NEXT(qele_to, next);
    }

    g_assert_cmpint((uintptr_t) qele_from, ==, (uintptr_t) qlast_from);
    g_assert_cmpint((uintptr_t) qele_to, ==, (uintptr_t) qlast_to);

    /* clean up */
    TestQtailqElement *qele;
    while (!QTAILQ_EMPTY(&tgt.q)) {
        qele = QTAILQ_LAST(&tgt.q);
        QTAILQ_REMOVE(&tgt.q, qele, next);
        free(qele);
        qele = NULL;
    }
    qemu_fclose(fload);
}

/* interval (key) */
typedef struct TestGTreeInterval {
    uint64_t low;
    uint64_t high;
} TestGTreeInterval;

#define VMSTATE_INTERVAL                               \
{                                                      \
    .name = "interval",                                \
    .version_id = 1,                                   \
    .minimum_version_id = 1,                           \
    .fields = (VMStateField[]) {                       \
        VMSTATE_UINT64(low, TestGTreeInterval),        \
        VMSTATE_UINT64(high, TestGTreeInterval),       \
        VMSTATE_END_OF_LIST()                          \
    }                                                  \
}

/* mapping (value) */
typedef struct TestGTreeMapping {
    uint64_t phys_addr;
    uint32_t flags;
} TestGTreeMapping;

#define VMSTATE_MAPPING                               \
{                                                     \
    .name = "mapping",                                \
    .version_id = 1,                                  \
    .minimum_version_id = 1,                          \
    .fields = (VMStateField[]) {                      \
        VMSTATE_UINT64(phys_addr, TestGTreeMapping),  \
        VMSTATE_UINT32(flags, TestGTreeMapping),      \
        VMSTATE_END_OF_LIST()                         \
    },                                                \
}

static const VMStateDescription vmstate_interval_mapping[2] = {
    VMSTATE_MAPPING,   /* value */
    VMSTATE_INTERVAL   /* key   */
};

typedef struct TestGTreeDomain {
    int32_t  id;
    GTree    *mappings;
} TestGTreeDomain;

typedef struct TestGTreeIOMMU {
    int32_t  id;
    GTree    *domains;
} TestGTreeIOMMU;

/* Interval comparison function */
static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
{
    TestGTreeInterval *inta = (TestGTreeInterval *)a;
    TestGTreeInterval *intb = (TestGTreeInterval *)b;

    if (inta->high < intb->low) {
        return -1;
    } else if (intb->high < inta->low) {
        return 1;
    } else {
        return 0;
    }
}

/* ID comparison function */
static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
{
    guint ua = GPOINTER_TO_UINT(a);
    guint ub = GPOINTER_TO_UINT(b);
    return (ua > ub) - (ua < ub);
}

static void destroy_domain(gpointer data)
{
    TestGTreeDomain *domain = (TestGTreeDomain *)data;

    g_tree_destroy(domain->mappings);
    g_free(domain);
}

static int domain_preload(void *opaque)
{
    TestGTreeDomain *domain = opaque;

    domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp,
                                       NULL, g_free, g_free);
    return 0;
}

static int iommu_preload(void *opaque)
{
    TestGTreeIOMMU *iommu = opaque;

    iommu->domains = g_tree_new_full((GCompareDataFunc)int_cmp,
                                     NULL, NULL, destroy_domain);
    return 0;
}

static const VMStateDescription vmstate_domain = {
    .name = "domain",
    .version_id = 1,
    .minimum_version_id = 1,
    .pre_load = domain_preload,
    .fields = (VMStateField[]) {
        VMSTATE_INT32(id, TestGTreeDomain),
        VMSTATE_GTREE_V(mappings, TestGTreeDomain, 1,
                        vmstate_interval_mapping,
                        TestGTreeInterval, TestGTreeMapping),
        VMSTATE_END_OF_LIST()
    }
};

/* test QLIST Migration */

typedef struct TestQListElement {
    uint32_t  id;
    QLIST_ENTRY(TestQListElement) next;
} TestQListElement;

typedef struct TestQListContainer {
    uint32_t  id;
    QLIST_HEAD(, TestQListElement) list;
} TestQListContainer;

static const VMStateDescription vmstate_qlist_element = {
    .name = "test/queue list",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_UINT32(id, TestQListElement),
        VMSTATE_END_OF_LIST()
    }
};

static const VMStateDescription vmstate_iommu = {
    .name = "iommu",
    .version_id = 1,
    .minimum_version_id = 1,
    .pre_load = iommu_preload,
    .fields = (VMStateField[]) {
        VMSTATE_INT32(id, TestGTreeIOMMU),
        VMSTATE_GTREE_DIRECT_KEY_V(domains, TestGTreeIOMMU, 1,
                                   &vmstate_domain, TestGTreeDomain),
        VMSTATE_END_OF_LIST()
    }
};

static const VMStateDescription vmstate_container = {
    .name = "test/container/qlist",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_UINT32(id, TestQListContainer),
        VMSTATE_QLIST_V(list, TestQListContainer, 1, vmstate_qlist_element,
                        TestQListElement, next),
        VMSTATE_END_OF_LIST()
    }
};

uint8_t first_domain_dump[] = {
    /* id */
    0x00, 0x0, 0x0, 0x6,
    0x00, 0x0, 0x0, 0x2, /* 2 mappings */
    0x1, /* start of a */
    /* a */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF,
    /* map_a */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00,
    0x00, 0x00, 0x00, 0x01,
    0x1, /* start of b */
    /* b */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0xFF,
    /* map_b */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x02,
    0x0, /* end of gtree */
    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};

static TestGTreeDomain *create_first_domain(void)
{
    TestGTreeDomain *domain;
    TestGTreeMapping *map_a, *map_b;
    TestGTreeInterval *a, *b;

    domain = g_new0(TestGTreeDomain, 1);
    domain->id = 6;

    a = g_new0(TestGTreeInterval, 1);
    a->low = 0x1000;
    a->high = 0x1FFF;

    b = g_new0(TestGTreeInterval, 1);
    b->low = 0x4000;
    b->high = 0x4FFF;

    map_a = g_new0(TestGTreeMapping, 1);
    map_a->phys_addr = 0xa000;
    map_a->flags = 1;

    map_b = g_new0(TestGTreeMapping, 1);
    map_b->phys_addr = 0xe0000;
    map_b->flags = 2;

    domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp, NULL,
                                        (GDestroyNotify)g_free,
                                        (GDestroyNotify)g_free);
    g_tree_insert(domain->mappings, a, map_a);
    g_tree_insert(domain->mappings, b, map_b);
    return domain;
}

static void test_gtree_save_domain(void)
{
    TestGTreeDomain *first_domain = create_first_domain();

    save_vmstate(&vmstate_domain, first_domain);
    compare_vmstate(first_domain_dump, sizeof(first_domain_dump));
    destroy_domain(first_domain);
}

struct match_node_data {
    GTree *tree;
    gpointer key;
    gpointer value;
};

struct tree_cmp_data {
    GTree *tree1;
    GTree *tree2;
    GTraverseFunc match_node;
};

static gboolean match_interval_mapping_node(gpointer key,
                                            gpointer value, gpointer data)
{
    TestGTreeMapping *map_a, *map_b;
    TestGTreeInterval *a, *b;
    struct match_node_data *d = (struct match_node_data *)data;
    a = (TestGTreeInterval *)key;
    b = (TestGTreeInterval *)d->key;

    map_a = (TestGTreeMapping *)value;
    map_b = (TestGTreeMapping *)d->value;

    assert(a->low == b->low);
    assert(a->high == b->high);
    assert(map_a->phys_addr == map_b->phys_addr);
    assert(map_a->flags == map_b->flags);
    g_tree_remove(d->tree, key);
    return true;
}

static gboolean diff_tree(gpointer key, gpointer value, gpointer data)
{
    struct tree_cmp_data *tp = (struct tree_cmp_data *)data;
    struct match_node_data d = {tp->tree2, key, value};

    g_tree_foreach(tp->tree2, tp->match_node, &d);
    g_tree_remove(tp->tree1, key);
    return false;
}

static void compare_trees(GTree *tree1, GTree *tree2,
                          GTraverseFunc function)
{
    struct tree_cmp_data tp = {tree1, tree2, function};

    g_tree_foreach(tree1, diff_tree, &tp);
    assert(g_tree_nnodes(tree1) == 0);
    assert(g_tree_nnodes(tree2) == 0);
}

static void diff_domain(TestGTreeDomain *d1, TestGTreeDomain *d2)
{
    assert(d1->id == d2->id);
    compare_trees(d1->mappings, d2->mappings, match_interval_mapping_node);
}

static gboolean match_domain_node(gpointer key, gpointer value, gpointer data)
{
    uint64_t id1, id2;
    TestGTreeDomain *d1, *d2;
    struct match_node_data *d = (struct match_node_data *)data;

    id1 = (uint64_t)(uintptr_t)key;
    id2 = (uint64_t)(uintptr_t)d->key;
    d1 = (TestGTreeDomain *)value;
    d2 = (TestGTreeDomain *)d->value;
    assert(id1 == id2);
    diff_domain(d1, d2);
    g_tree_remove(d->tree, key);
    return true;
}

static void diff_iommu(TestGTreeIOMMU *iommu1, TestGTreeIOMMU *iommu2)
{
    assert(iommu1->id == iommu2->id);
    compare_trees(iommu1->domains, iommu2->domains, match_domain_node);
}

static void test_gtree_load_domain(void)
{
    TestGTreeDomain *dest_domain = g_new0(TestGTreeDomain, 1);
    TestGTreeDomain *orig_domain = create_first_domain();
    QEMUFile *fload, *fsave;
    char eof;

    fsave = open_test_file(true);
    qemu_put_buffer(fsave, first_domain_dump, sizeof(first_domain_dump));
    g_assert(!qemu_file_get_error(fsave));
    qemu_fclose(fsave);

    fload = open_test_file(false);

    vmstate_load_state(fload, &vmstate_domain, dest_domain, 1);
    eof = qemu_get_byte(fload);
    g_assert(!qemu_file_get_error(fload));
    g_assert_cmpint(orig_domain->id, ==, dest_domain->id);
    g_assert_cmpint(eof, ==, QEMU_VM_EOF);

    diff_domain(orig_domain, dest_domain);
    destroy_domain(orig_domain);
    destroy_domain(dest_domain);
    qemu_fclose(fload);
}

uint8_t iommu_dump[] = {
    /* iommu id */
    0x00, 0x0, 0x0, 0x7,
    0x00, 0x0, 0x0, 0x2, /* 2 domains */
    0x1,/* start of domain 5 */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x0, 0x5, /* key = 5 */
        0x00, 0x0, 0x0, 0x5, /* domain1 id */
        0x00, 0x0, 0x0, 0x1, /* 1 mapping */
        0x1, /* start of mappings */
            /* c */
            0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF,
            /* map_c */
            0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00,
            0x00, 0x0, 0x0, 0x3,
            0x0, /* end of domain1 mappings*/
    0x1,/* start of domain 6 */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x0, 0x6, /* key = 6 */
        0x00, 0x0, 0x0, 0x6, /* domain6 id */
            0x00, 0x0, 0x0, 0x2, /* 2 mappings */
            0x1, /* start of a */
            /* a */
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF,
            /* map_a */
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00,
            0x00, 0x00, 0x00, 0x01,
            0x1, /* start of b */
            /* b */
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0xFF,
            /* map_b */
            0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x02,
            0x0, /* end of domain6 mappings*/
    0x0, /* end of domains */
    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};

static TestGTreeIOMMU *create_iommu(void)
{
    TestGTreeIOMMU *iommu = g_new0(TestGTreeIOMMU, 1);
    TestGTreeDomain *first_domain = create_first_domain();
    TestGTreeDomain *second_domain;
    TestGTreeMapping *map_c;
    TestGTreeInterval *c;

    iommu->id = 7;
    iommu->domains = g_tree_new_full((GCompareDataFunc)int_cmp, NULL,
                                     NULL,
                                     destroy_domain);

    second_domain = g_new0(TestGTreeDomain, 1);
    second_domain->id = 5;
    second_domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp,
                                              NULL,
                                              (GDestroyNotify)g_free,
                                              (GDestroyNotify)g_free);

    g_tree_insert(iommu->domains, GUINT_TO_POINTER(6), first_domain);
    g_tree_insert(iommu->domains, (gpointer)0x0000000000000005, second_domain);

    c = g_new0(TestGTreeInterval, 1);
    c->low = 0x1000000;
    c->high = 0x1FFFFFF;

    map_c = g_new0(TestGTreeMapping, 1);
    map_c->phys_addr = 0xF000000;
    map_c->flags = 0x3;

    g_tree_insert(second_domain->mappings, c, map_c);
    return iommu;
}

static void destroy_iommu(TestGTreeIOMMU *iommu)
{
    g_tree_destroy(iommu->domains);
    g_free(iommu);
}

static void test_gtree_save_iommu(void)
{
    TestGTreeIOMMU *iommu = create_iommu();

    save_vmstate(&vmstate_iommu, iommu);
    compare_vmstate(iommu_dump, sizeof(iommu_dump));
    destroy_iommu(iommu);
}

static void test_gtree_load_iommu(void)
{
    TestGTreeIOMMU *dest_iommu = g_new0(TestGTreeIOMMU, 1);
    TestGTreeIOMMU *orig_iommu = create_iommu();
    QEMUFile *fsave, *fload;
    char eof;

    fsave = open_test_file(true);
    qemu_put_buffer(fsave, iommu_dump, sizeof(iommu_dump));
    g_assert(!qemu_file_get_error(fsave));
    qemu_fclose(fsave);

    fload = open_test_file(false);
    vmstate_load_state(fload, &vmstate_iommu, dest_iommu, 1);
    eof = qemu_get_byte(fload);
    g_assert(!qemu_file_get_error(fload));
    g_assert_cmpint(orig_iommu->id, ==, dest_iommu->id);
    g_assert_cmpint(eof, ==, QEMU_VM_EOF);

    diff_iommu(orig_iommu, dest_iommu);
    destroy_iommu(orig_iommu);
    destroy_iommu(dest_iommu);
    qemu_fclose(fload);
}

static uint8_t qlist_dump[] = {
    0x00, 0x00, 0x00, 0x01, /* container id */
    0x1, /* start of a */
    0x00, 0x00, 0x00, 0x0a,
    0x1, /* start of b */
    0x00, 0x00, 0x0b, 0x00,
    0x1, /* start of c */
    0x00, 0x0c, 0x00, 0x00,
    0x1, /* start of d */
    0x0d, 0x00, 0x00, 0x00,
    0x0, /* end of list */
    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};

static TestQListContainer *alloc_container(void)
{
    TestQListElement *a = g_new(TestQListElement, 1);
    TestQListElement *b = g_new(TestQListElement, 1);
    TestQListElement *c = g_new(TestQListElement, 1);
    TestQListElement *d = g_new(TestQListElement, 1);
    TestQListContainer *container = g_new(TestQListContainer, 1);

    a->id = 0x0a;
    b->id = 0x0b00;
    c->id = 0xc0000;
    d->id = 0xd000000;
    container->id = 1;

    QLIST_INIT(&container->list);
    QLIST_INSERT_HEAD(&container->list, d, next);
    QLIST_INSERT_HEAD(&container->list, c, next);
    QLIST_INSERT_HEAD(&container->list, b, next);
    QLIST_INSERT_HEAD(&container->list, a, next);
    return container;
}

static void free_container(TestQListContainer *container)
{
    TestQListElement *iter, *tmp;

    QLIST_FOREACH_SAFE(iter, &container->list, next, tmp) {
        QLIST_REMOVE(iter, next);
        g_free(iter);
    }
    g_free(container);
}

static void compare_containers(TestQListContainer *c1, TestQListContainer *c2)
{
    TestQListElement *first_item_c1, *first_item_c2;

    while (!QLIST_EMPTY(&c1->list)) {
        first_item_c1 = QLIST_FIRST(&c1->list);
        first_item_c2 = QLIST_FIRST(&c2->list);
        assert(first_item_c2);
        assert(first_item_c1->id == first_item_c2->id);
        QLIST_REMOVE(first_item_c1, next);
        QLIST_REMOVE(first_item_c2, next);
        g_free(first_item_c1);
        g_free(first_item_c2);
    }
    assert(QLIST_EMPTY(&c2->list));
}

/*
 * Check the prev & next fields are correct by doing list
 * manipulations on the container. We will do that for both
 * the source and the destination containers
 */
static void manipulate_container(TestQListContainer *c)
{
     TestQListElement *prev = NULL, *iter = QLIST_FIRST(&c->list);
     TestQListElement *elem;

     elem = g_new(TestQListElement, 1);
     elem->id = 0x12;
     QLIST_INSERT_AFTER(iter, elem, next);

     elem = g_new(TestQListElement, 1);
     elem->id = 0x13;
     QLIST_INSERT_HEAD(&c->list, elem, next);

     while (iter) {
        prev = iter;
        iter = QLIST_NEXT(iter, next);
     }

     elem = g_new(TestQListElement, 1);
     elem->id = 0x14;
     QLIST_INSERT_BEFORE(prev, elem, next);

     elem = g_new(TestQListElement, 1);
     elem->id = 0x15;
     QLIST_INSERT_AFTER(prev, elem, next);

     QLIST_REMOVE(prev, next);
     g_free(prev);
}

static void test_save_qlist(void)
{
    TestQListContainer *container = alloc_container();

    save_vmstate(&vmstate_container, container);
    compare_vmstate(qlist_dump, sizeof(qlist_dump));
    free_container(container);
}

static void test_load_qlist(void)
{
    QEMUFile *fsave, *fload;
    TestQListContainer *orig_container = alloc_container();
    TestQListContainer *dest_container = g_new0(TestQListContainer, 1);
    char eof;

    QLIST_INIT(&dest_container->list);

    fsave = open_test_file(true);
    qemu_put_buffer(fsave, qlist_dump, sizeof(qlist_dump));
    g_assert(!qemu_file_get_error(fsave));
    qemu_fclose(fsave);

    fload = open_test_file(false);
    vmstate_load_state(fload, &vmstate_container, dest_container, 1);
    eof = qemu_get_byte(fload);
    g_assert(!qemu_file_get_error(fload));
    g_assert_cmpint(eof, ==, QEMU_VM_EOF);
    manipulate_container(orig_container);
    manipulate_container(dest_container);
    compare_containers(orig_container, dest_container);
    free_container(orig_container);
    free_container(dest_container);
    qemu_fclose(fload);
}

typedef struct TmpTestStruct {
    TestStruct *parent;
    int64_t diff;
} TmpTestStruct;

static int tmp_child_pre_save(void *opaque)
{
    struct TmpTestStruct *tts = opaque;

    tts->diff = tts->parent->b - tts->parent->a;

    return 0;
}

static int tmp_child_post_load(void *opaque, int version_id)
{
    struct TmpTestStruct *tts = opaque;

    tts->parent->b = tts->parent->a + tts->diff;

    return 0;
}

static const VMStateDescription vmstate_tmp_back_to_parent = {
    .name = "test/tmp_child_parent",
    .fields = (VMStateField[]) {
        VMSTATE_UINT64(f, TestStruct),
        VMSTATE_END_OF_LIST()
    }
};

static const VMStateDescription vmstate_tmp_child = {
    .name = "test/tmp_child",
    .pre_save = tmp_child_pre_save,
    .post_load = tmp_child_post_load,
    .fields = (VMStateField[]) {
        VMSTATE_INT64(diff, TmpTestStruct),
        VMSTATE_STRUCT_POINTER(parent, TmpTestStruct,
                               vmstate_tmp_back_to_parent, TestStruct),
        VMSTATE_END_OF_LIST()
    }
};

static const VMStateDescription vmstate_with_tmp = {
    .name = "test/with_tmp",
    .version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_UINT32(a, TestStruct),
        VMSTATE_UINT64(d, TestStruct),
        VMSTATE_WITH_TMP(TestStruct, TmpTestStruct, vmstate_tmp_child),
        VMSTATE_END_OF_LIST()
    }
};

static void obj_tmp_copy(void *target, void *source)
{
    memcpy(target, source, sizeof(TestStruct));
}

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

    uint8_t const wire_with_tmp[] = {
        /* u32 a */ 0x00, 0x00, 0x00, 0x02,
        /* u64 d */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
        /* diff  */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
        /* u64 f */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
        QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
    };

    memset(&obj, 0, sizeof(obj));
    obj.a = 2;
    obj.b = 4;
    obj.d = 1;
    obj.f = 8;
    save_vmstate(&vmstate_with_tmp, &obj);

    compare_vmstate(wire_with_tmp, sizeof(wire_with_tmp));

    memset(&obj, 0, sizeof(obj));
    SUCCESS(load_vmstate(&vmstate_with_tmp, &obj, &obj_clone,
                         obj_tmp_copy, 1, wire_with_tmp,
                         sizeof(wire_with_tmp)));
    g_assert_cmpint(obj.a, ==, 2); /* From top level vmsd */
    g_assert_cmpint(obj.b, ==, 4); /* from the post_load */
    g_assert_cmpint(obj.d, ==, 1); /* From top level vmsd */
    g_assert_cmpint(obj.f, ==, 8); /* From the child->parent */
}

int main(int argc, char **argv)
{
    g_autofree char *temp_file = g_strdup_printf("%s/vmst.test.XXXXXX",
                                                 g_get_tmp_dir());
    temp_fd = mkstemp(temp_file);
    g_assert(temp_fd >= 0);

    module_call_init(MODULE_INIT_QOM);

    g_setenv("QTEST_SILENT_ERRORS", "1", 1);

    g_test_init(&argc, &argv, NULL);
    g_test_add_func("/vmstate/simple/primitive", test_simple_primitive);
    g_test_add_func("/vmstate/simple/array", test_simple_array);
    g_test_add_func("/vmstate/versioned/load/v1", test_load_v1);
    g_test_add_func("/vmstate/versioned/load/v2", test_load_v2);
    g_test_add_func("/vmstate/field_exists/load/noskip", test_load_noskip);
    g_test_add_func("/vmstate/field_exists/load/skip", test_load_skip);
    g_test_add_func("/vmstate/field_exists/save/noskip", test_save_noskip);
    g_test_add_func("/vmstate/field_exists/save/skip", test_save_skip);
    g_test_add_func("/vmstate/array/ptr/str/no0/save",
                    test_arr_ptr_str_no0_save);
    g_test_add_func("/vmstate/array/ptr/str/no0/load",
                    test_arr_ptr_str_no0_load);
    g_test_add_func("/vmstate/array/ptr/str/0/save", test_arr_ptr_str_0_save);
    g_test_add_func("/vmstate/array/ptr/str/0/load",
                    test_arr_ptr_str_0_load);
    g_test_add_func("/vmstate/array/ptr/prim/0/save",
                    test_arr_ptr_prim_0_save);
    g_test_add_func("/vmstate/array/ptr/prim/0/load",
                    test_arr_ptr_prim_0_load);
    g_test_add_func("/vmstate/qtailq/save/saveq", test_save_q);
    g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q);
    g_test_add_func("/vmstate/gtree/save/savedomain", test_gtree_save_domain);
    g_test_add_func("/vmstate/gtree/load/loaddomain", test_gtree_load_domain);
    g_test_add_func("/vmstate/gtree/save/saveiommu", test_gtree_save_iommu);
    g_test_add_func("/vmstate/gtree/load/loadiommu", test_gtree_load_iommu);
    g_test_add_func("/vmstate/qlist/save/saveqlist", test_save_qlist);
    g_test_add_func("/vmstate/qlist/load/loadqlist", test_load_qlist);
    g_test_add_func("/vmstate/tmp_struct", test_tmp_struct);
    g_test_run();

    close(temp_fd);
    unlink(temp_file);

    return 0;
}
