[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 116/124] vmstate: Test VMSTATE_STRUCT_ARRAY
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 116/124] vmstate: Test VMSTATE_STRUCT_ARRAY |
Date: |
Mon, 21 Apr 2014 16:41:36 +0200 |
Signed-off-by: Juan Quintela <address@hidden>
---
tests/test-vmstate.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index c7ecaeb..3d8ba20 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1416,6 +1416,8 @@ typedef struct TestStruct {
SubStruct sub;
SubStruct sub2;
SubStruct *subp;
+ SubStruct a[3];
+ SubStruct b[3];
} TestStruct;
static const VMStateDescription vmstate_struct_simple = {
@@ -1426,6 +1428,8 @@ static const VMStateDescription vmstate_struct_simple = {
.fields = (VMStateField[]) {
VMSTATE_STRUCT(sub, TestStruct, vmstate_sub_struct, SubStruct),
VMSTATE_STRUCT_POINTER(subp, TestStruct, vmstate_sub_struct,
SubStruct),
+ VMSTATE_STRUCT_ARRAY(a, TestStruct, 3,
+ vmstate_sub_struct, SubStruct),
VMSTATE_END_OF_LIST()
}
};
@@ -1448,6 +1452,34 @@ TestStruct obj_struct = {
.buffer = "bye world!",
},
.subp = &sub_struct,
+ .a = { {
+ .i32 = 55,
+ .i64 = 33,
+ .buffer = "bye0 world!",
+ }, {
+ .i32 = 44,
+ .i64 = 77,
+ .buffer = "bye1 world!",
+ }, {
+ .i32 = 33,
+ .i64 = 99,
+ .buffer = "bye2 world!",
+ },
+ },
+ .b = { {
+ .i32 = 56,
+ .i64 = 36,
+ .buffer = "bye3 world!",
+ }, {
+ .i32 = 46,
+ .i64 = 76,
+ .buffer = "bye4 world!",
+ }, {
+ .i32 = 36,
+ .i64 = 96,
+ .buffer = "bye5 world!",
+ },
+ },
};
/* This is the binary representation on the wire of that struct */
@@ -1462,6 +1494,21 @@ uint8_t wire_struct_simple[] = {
/* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c,
/* buffer */ 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x69,
0x65, 0x6c, 0x64, 0x21, 0x00,
+ /* a[0] */
+ /* i32 */ 0x00, 0x00, 0x00, 0x37,
+ /* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
+ /* buffer */ 0x62, 0x79, 0x65, 0x30, 0x20, 0x20, 0x77, 0x6f,
+ 0x72, 0x6c, 0x64, 0x21, 0x00,
+ /* a[1] */
+ /* i32 */ 0x00, 0x00, 0x00, 0x2c,
+ /* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d,
+ /* buffer */ 0x62, 0x79, 0x65, 0x31, 0x20, 0x20, 0x77, 0x6f,
+ 0x72, 0x6c, 0x64, 0x21, 0x00,
+ /* a[2] */
+ /* i32 */ 0x00, 0x00, 0x00, 0x21,
+ /* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63,
+ /* buffer */ 0x62, 0x79, 0x65, 0x32, 0x20, 0x20, 0x77, 0x6f,
+ 0x72, 0x6c, 0x64, 0x21, 0x00,
QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};
@@ -1469,6 +1516,7 @@ static void obj_struct_copy(void *arg1, void *arg2)
{
TestStruct *target = arg1;
TestStruct *source = arg2;
+ int i;
target->sub.i32 = source->sub.i32;
target->sub.i64 = source->sub.i64;
@@ -1481,11 +1529,22 @@ static void obj_struct_copy(void *arg1, void *arg2)
target->subp->i32 = source->subp->i32;
target->subp->i64 = source->subp->i64;
memcpy(target->subp->buffer, source->subp->buffer, 13);
+
+ for (i = 0; i < 3; i++) {
+ target->a[i].i32 = source->a[i].i32;
+ target->a[i].i64 = source->a[i].i64;
+ memcpy(target->a[i].buffer, source->a[i].buffer, 13);
+
+ target->b[i].i32 = source->b[i].i32;
+ target->b[i].i64 = source->b[i].i64;
+ memcpy(target->b[i].buffer, source->b[i].buffer, 13);
+ }
}
static void test_struct_simple(void)
{
TestStruct obj, obj_clone;
+ int i;
memset(&obj, 0, sizeof(obj));
@@ -1519,6 +1578,10 @@ static void test_struct_simple(void)
STRUCT_EQUAL((&obj.sub), (&obj_struct.sub));
STRUCT_NOT_EQUAL((&obj.sub2), (&obj_struct.sub2));
STRUCT_EQUAL(obj.subp, obj_struct.subp);
+ for (i = 0; i < 3; i++) {
+ STRUCT_EQUAL((&obj.a[i]), (&obj_struct.a[i]));
+ STRUCT_NOT_EQUAL((&obj.b[i]), (&obj_struct.b[i]));
+ }
}
static const VMStateDescription vmstate_struct_test = {
@@ -1528,6 +1591,10 @@ static const VMStateDescription vmstate_struct_test = {
.minimum_version_id_old = 1,
.fields = (VMStateField[]) {
VMSTATE_STRUCT(sub, TestStruct, vmstate_sub_struct, SubStruct),
+ VMSTATE_STRUCT_ARRAY_TEST(a, TestStruct, 3, test_true,
+ vmstate_sub_struct, SubStruct),
+ VMSTATE_STRUCT_ARRAY_TEST(b, TestStruct, 3, test_false,
+ vmstate_sub_struct, SubStruct),
VMSTATE_END_OF_LIST()
}
};
@@ -1538,12 +1605,28 @@ uint8_t wire_struct_test[] = {
/* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d,
/* buffer */ 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f,
0x72, 0x6c, 0x64, 0x21, 0x00,
+ /* a[0] */
+ /* i32 */ 0x00, 0x00, 0x00, 0x37,
+ /* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
+ /* buffer */ 0x62, 0x79, 0x65, 0x30, 0x20, 0x20, 0x77, 0x6f,
+ 0x72, 0x6c, 0x64, 0x21, 0x00,
+ /* a[1] */
+ /* i32 */ 0x00, 0x00, 0x00, 0x2c,
+ /* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d,
+ /* buffer */ 0x62, 0x79, 0x65, 0x31, 0x20, 0x20, 0x77, 0x6f,
+ 0x72, 0x6c, 0x64, 0x21, 0x00,
+ /* a[2] */
+ /* i32 */ 0x00, 0x00, 0x00, 0x21,
+ /* i64 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63,
+ /* buffer */ 0x62, 0x79, 0x65, 0x32, 0x20, 0x20, 0x77, 0x6f,
+ 0x72, 0x6c, 0x64, 0x21, 0x00,
QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
};
static void test_struct_test(void)
{
TestStruct obj, obj_clone;
+ int i;
memset(&obj, 0, sizeof(obj));
@@ -1560,6 +1643,11 @@ static void test_struct_test(void)
STRUCT_EQUAL((&obj.sub), (&obj_struct.sub));
STRUCT_NOT_EQUAL((&obj.sub2), (&obj_struct.sub2));
+
+ for (i = 0; i < 3; i++) {
+ STRUCT_EQUAL((&obj.a[i]), (&obj_struct.a[i]));
+ STRUCT_NOT_EQUAL((&obj.b[i]), (&obj_struct.b[i]));
+ }
}
#undef STRUCT_EQUAL
#undef STRUCT_NOT_EQUAL
--
1.9.0
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), (continued)
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Peter Maydell, 2014/04/21
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Juan Quintela, 2014/04/21
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Peter Maydell, 2014/04/21
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Paolo Bonzini, 2014/04/21
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Dr. David Alan Gilbert, 2014/04/22
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Paolo Bonzini, 2014/04/27
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Michael S. Tsirkin, 2014/04/27
- Re: [Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive), Juan Quintela, 2014/04/21
[Qemu-devel] [PATCH 115/124] vmstate: Test for VMSTATE_STRUCT_POINTER, Juan Quintela, 2014/04/21
[Qemu-devel] [PATCH 071/124] vmstate: Remove version field from VMSTATE_STRUCT_VARRAY_UINT32, Juan Quintela, 2014/04/21
[Qemu-devel] [PATCH 116/124] vmstate: Test VMSTATE_STRUCT_ARRAY,
Juan Quintela <=