Signed-off-by: Juan Quintela <quint...@redhat.com> --- tests/test-vmstate.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 308f94d..0a4f81a 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -802,6 +802,54 @@ static void test_array_test(void) ELEM_NOT_EQUAL(i32_2, i); } } + +static const VMStateDescription vmstate_array_sub = { + .name = "array/sub", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8_SUB_ARRAY(u8_1, TestArray, 0, VMSTATE_ARRAY_SIZE), + VMSTATE_UINT8_SUB_ARRAY(u8_2, TestArray, 2 , 2), + VMSTATE_END_OF_LIST() + } +}; + +uint8_t wire_array_sub[] = { + /* u8_1 */ 0x01, 0x02, 0x03, 0x04, 0x05, + /* u8_2 {3,4} */ 0x03, 0x02, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static void test_array_sub(void) +{ + TestArray obj, obj_clone; + int i; + + memset(&obj, 0, sizeof(obj)); + obj.size = VMSTATE_ARRAY_SIZE; + + save_vmstate(&vmstate_array_sub, &obj_array); + + compare_vmstate(wire_array_sub, sizeof(wire_array_sub)); + + SUCCESS(load_vmstate(&vmstate_array_sub, &obj, &obj_clone, + obj_array_copy, 1, wire_array_sub, + sizeof(wire_array_sub))); + + for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) { + ELEM_EQUAL(u8_1, i); + } + for (i = 0; i < 2; i++) { + ELEM_NOT_EQUAL(u8_2, i); + } + for (i = 2; i < 4; i++) { + ELEM_EQUAL(u8_2, i); + } + for (i = 4; i < VMSTATE_ARRAY_SIZE; i++) { + ELEM_NOT_EQUAL(u8_2, i); + } +} #undef FIELD_EQUAL #undef ELEM_EQUAL #undef ELEM_EQUAL_2D @@ -1042,6 +1090,7 @@ int main(int argc, char **argv) g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap); g_test_add_func("/vmstate/array/primitive", test_array_primitive); g_test_add_func("/vmstate/array/test", test_array_test); + g_test_add_func("/vmstate/array/sub", test_array_sub); g_test_run(); close(temp_fd); -- 1.9.0