[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 106/124] vmstate: Test for VMSTATE_BUFFER_UNSAFE_TES
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 106/124] vmstate: Test for VMSTATE_BUFFER_UNSAFE_TEST |
Date: |
Mon, 21 Apr 2014 16:41:26 +0200 |
Signed-off-by: Juan Quintela <address@hidden>
---
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
- [Qemu-devel] [PATCH 096/124] vmstate: Remove unused VMSTATE_SUB_VBUFFER, (continued)
- [Qemu-devel] [PATCH 096/124] vmstate: Remove unused VMSTATE_SUB_VBUFFER, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 097/124] vmstate: Remove unused VMSTATE_PARTIAL_VBUFFER_UINT32, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 099/124] vmstate: Rename VMSTATE_PARTIAL_VBUFFER to VMSTATE_VBUFFER_INT32, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 098/124] vmstate: Test for VMSTATE_PARTIAL_VBUFFER, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 100/124] vmstate: Create VMS_VBUFFER_UINT32, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 101/124] vmstate: Rename VMS_VBUFFER to VMST_VBUFFER_INT32 for consintency, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 102/124] vmstate: Test for VMSTATE_VBUFFER_UINT32, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 104/124] vmstate: Test for VMSTATE_POINTER, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 105/124] vmstate: Test for VMSTATE_POINTER_UNSAFE, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 103/124] vmstate: VMSTATE_POINTER() used the wrong type to calculate the size, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 106/124] vmstate: Test for VMSTATE_BUFFER_UNSAFE_TEST,
Juan Quintela <=
- [Qemu-devel] [PATCH 108/124] vmstate: Test for VMSTATE_ARRAY_INT32_UNSAFE, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 109/124] vmstate: Test for VMSTATE_VARRAY, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 107/124] vmstate: Test for VMSTATE_BUFFER_POINTER_UNSAFE, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 111/124] vmstate: Test for VMSTATE_VARRAY_UINT16_UNSAFE, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 113/124] vmstate: Test for VMSTATE_STRUCT{_TEST}, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 112/124] vmstate: Test for VMSTATE_VARRAY_INT32{_TEST}, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 117/124] vmstate: Test for VMSTATE_STRUCT_VARRAY_UINT8, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 118/124] vmstate: Test for VMSTATE_STRUCT_VARRAY_UINT32, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 119/124] vmstate: Test for VMSTATE_STRUCT_VARRAY_INT32, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 120/124] vmstate: Test for VMSTATE_STRUCT_VARRAY_POINTER_UINT16, Juan Quintela, 2014/04/21