Signed-off-by: Juan Quintela <quint...@redhat.com> --- tests/test-vmstate.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index e1e2523..9f7256c 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -870,6 +870,7 @@ typedef struct TestBuffer { uint8_t partial[13]; uint8_t middle[13]; uint32_t scratch[5]; + uint32_t scratch2[5]; } TestBuffer; TestBuffer obj_buffer = { @@ -877,6 +878,7 @@ TestBuffer obj_buffer = { .partial = "This is Juan", .middle = "hello world!", .scratch = {21, 22, 23, 24, 25}, + .scratch2 = {31, 32, 33, 34, 35}, }; static const VMStateDescription vmstate_buffer_simple = { @@ -907,11 +909,15 @@ static void obj_buffer_copy(void *arg1, void *arg2) { TestBuffer *target = arg1; TestBuffer *source = arg2; + int i; memcpy(target->buffer, source->buffer, 6); memcpy(target->partial, source->partial, 13); memcpy(target->middle, source->middle, 13); - memcpy(target->scratch, source->scratch, 5 * sizeof(uint32_t)); + for (i = 0; i < 5; i++) { + target->scratch[0] = source->scratch[0]; + target->scratch2[0] = source->scratch2[0]; + } } static void test_buffer_simple(void) @@ -936,6 +942,35 @@ static void test_buffer_simple(void) SUCCESS(memcmp(obj.scratch, obj_buffer.scratch, sizeof(obj.scratch))); } +/* just sent the fields in the reverse order that are stored */ + +static int get_reverse(QEMUFile *f, void *pv, size_t size) +{ + int i; + uint32_t *s = pv; + + for (i = VMSTATE_ARRAY_SIZE - 1; i >= 0 ; i--) { + s[i] = qemu_get_be32(f); + } + return 0; +} + +static void put_reverse(QEMUFile *f, void *pv, size_t size) +{ + int i; + uint32_t *s = pv; + + for (i = VMSTATE_ARRAY_SIZE - 1; i >= 0 ; i--) { + qemu_put_be32(f, s[i]); + } +} + +static VMStateInfo vmstate_reverse = { + .name = "reverse", + .get = get_reverse, + .put = put_reverse, +}; + static const VMStateDescription vmstate_buffer_test = { .name = "buffer/test", .version_id = 1, @@ -944,12 +979,19 @@ static const VMStateDescription vmstate_buffer_test = { .fields = (VMStateField[]) { VMSTATE_BUFFER_TEST(buffer, TestBuffer, test_true), VMSTATE_BUFFER_TEST(partial, TestBuffer, test_false), + VMSTATE_BUFFER_UNSAFE_TEST(scratch, TestBuffer, test_true, + vmstate_reverse, 0), + VMSTATE_BUFFER_UNSAFE_TEST(scratch2, TestBuffer, test_false, + vmstate_reverse, 0), VMSTATE_END_OF_LIST() } }; uint8_t wire_buffer_test[] = { /* buffer */ 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, + /* scratch */ 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x16, + 0x00, 0x00, 0x00, 0x15, QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; @@ -969,6 +1011,8 @@ static void test_buffer_test(void) SUCCESS(memcmp(obj.buffer, obj_buffer.buffer, sizeof(obj.buffer))); FAILURE(memcmp(obj.partial, obj_buffer.partial, sizeof(obj.partial))); + SUCCESS(memcmp(obj.scratch, obj_buffer.scratch, sizeof(obj.scratch))); + FAILURE(memcmp(obj.scratch2, obj_buffer.scratch2, sizeof(obj.scratch2))); } typedef struct TestVBuffer { -- 1.9.0