We intruduce another full test. Signed-off-by: Juan Quintela <quint...@redhat.com> --- include/migration/vmstate.h | 2 +- tests/test-vmstate.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 9cfc356..2c7f150 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -568,7 +568,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_UINT64_TEST(_f, _s, NULL) #define VMSTATE_UINT8_EQUAL(_f, _s) \ - VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t) + VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint8_equal, uint8_t) #define VMSTATE_UINT16_EQUAL(_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index d5cecbf..c6e4b67 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -339,6 +339,75 @@ static void test_simple_test(void) qemu_fclose(loading); } + +static const VMStateDescription vmstate_simple_compare = { + .name = "simple/compare", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8_EQUAL(u8_1, TestSimple), + VMSTATE_END_OF_LIST() + } +}; + +uint8_t wire_simple_compare[] = { + /* u8_1 */ 0x82, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static void test_simple_compare(void) +{ + QEMUFile *fsave = open_test_file(true); + + /* Save file with vmstate */ + vmstate_save_state(fsave, &vmstate_simple_compare, &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_compare)-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_compare, 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_compare, sizeof(wire_simple_compare)); + qemu_fclose(fsave); + + TestSimple obj; + loading = open_test_file(false); + memcpy(&obj, &obj_simple, sizeof(obj)); + + SUCCESS(vmstate_load_state(loading, &vmstate_simple_compare, &obj, 1)); + g_assert(!qemu_file_get_error(loading)); + qemu_fclose(loading); + + loading = open_test_file(false); + memcpy(&obj, &obj_simple, sizeof(obj)); + /* we change the value, so it is not equal anymore */ + obj.u8_1 = 27; + + FAILURE(vmstate_load_state(loading, &vmstate_simple_compare, &obj, 1)); + g_assert(!qemu_file_get_error(loading)); + qemu_fclose(loading); +} #undef FIELD_ASSERT typedef struct TestBitmap { @@ -427,6 +496,7 @@ static void test_simple_bitmap(void) qemu_fclose(loading); } + #undef FIELD_ASSERT typedef struct TestStruct { @@ -648,6 +718,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/simple/compare", test_simple_compare); g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap); g_test_add_func("/vmstate/versioned/load/v1", test_load_v1); g_test_add_func("/vmstate/versioned/load/v2", test_load_v2); -- 1.9.0