Remove VMSTATE_BOOL_V, we are removing versioning, would use only tests. Signed-off-by: Juan Quintela <quint...@redhat.com> --- include/migration/vmstate.h | 6 ++-- tests/test-vmstate.c | 75 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 4 deletions(-)
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index e97ac2f..184d564 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -526,8 +526,8 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \ _vmsd, _type) -#define VMSTATE_BOOL_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool) +#define VMSTATE_BOOL_TEST(_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool) #define VMSTATE_INT8_V(_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) @@ -548,7 +548,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) #define VMSTATE_BOOL(_f, _s) \ - VMSTATE_BOOL_V(_f, _s, 0) + VMSTATE_BOOL_TEST(_f, _s, NULL) #define VMSTATE_INT8(_f, _s) \ VMSTATE_INT8_V(_f, _s, 0) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 39a769e..7ca32af 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -209,7 +209,6 @@ static void test_simple_primitive(void) FIELD_ASSERT(i32_2); FIELD_ASSERT(i64_1); FIELD_ASSERT(i64_2); -#undef FIELD_ASSERT /* We save the file again. We want the EOF this time */ @@ -226,6 +225,79 @@ static void test_simple_primitive(void) qemu_fclose(loading); } +static bool test_true(void *opaque, int version_id) +{ + return true; +} + +static bool test_false(void *opaque, int version_id) +{ + return false; +} + +static const VMStateDescription vmstate_simple_test = { + .name = "simple/test", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_BOOL_TEST(b_1, TestSimple, test_true), + VMSTATE_BOOL_TEST(b_2, TestSimple, test_false), + VMSTATE_END_OF_LIST() + } +}; + +uint8_t wire_simple_test[] = { + /* b_1 */ 0x01, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static void test_simple_test(void) +{ + QEMUFile *fsave = open_test_file(true); + + /* Save file with vmstate */ + vmstate_save_state(fsave, &vmstate_simple_test, &obj_simple); + g_assert(!qemu_file_get_error(fsave)); + qemu_fclose(fsave); + + QEMUFile *loading = open_test_file(false); + /* we don't need QEMU_VM_EOF */ + uint8_t result[sizeof(wire_simple_test)-1]; + + /* read back as binary */ + + g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, + sizeof(result)); + g_assert(!qemu_file_get_error(loading)); + + /* Compare that what is on the file is the same that what we + expected to be there */ + SUCCESS(memcmp(result, wire_simple_test, sizeof(result))); + + /* Must reach EOF */ + qemu_get_byte(loading); + g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); + + qemu_fclose(loading); + + /* We save the file again. We want the EOF this time */ + + fsave = open_test_file(true); + qemu_put_buffer(fsave, wire_simple_test, sizeof(wire_simple_test)); + qemu_fclose(fsave); + + loading = open_test_file(false); + TestSimple obj; + SUCCESS(vmstate_load_state(loading, &vmstate_simple_test, &obj, 1)); + g_assert(!qemu_file_get_error(loading)); + + FIELD_ASSERT(b_1); + + qemu_fclose(loading); +} +#undef FIELD_ASSERT + typedef struct TestStruct { uint32_t a, b, c, e; uint64_t d, f; @@ -444,6 +516,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); g_test_add_func("/vmstate/simple/primitive", test_simple_primitive); + g_test_add_func("/vmstate/simple/test", test_simple_test); 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); -- 1.9.0