[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 036/124] vmstate: Test for VMSTATE_ARRAY_BOOL_TEST
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 036/124] vmstate: Test for VMSTATE_ARRAY_BOOL_TEST |
Date: |
Mon, 21 Apr 2014 16:40:16 +0200 |
We add all the boilerplate code for testing arrays.
We change only user of VMSTATE_ARRAY_BOOL_V to VMSTATE_ARRAY_BOOL_TEST.
Signed-off-by: Juan Quintela <address@hidden>
---
hw/audio/hda-codec.c | 3 +-
include/migration/vmstate.h | 8 +--
tests/test-vmstate.c | 117 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+), 5 deletions(-)
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index 09559ef..1c1a138 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -603,7 +603,8 @@ static const VMStateDescription vmstate_hda_audio = {
vmstate_hda_audio_stream,
HDAAudioStream),
VMSTATE_BOOL_ARRAY(running_compat, HDAAudioState, 16),
- VMSTATE_BOOL_ARRAY_V(running_real, HDAAudioState, 2 * 16, 2),
+ VMSTATE_BOOL_ARRAY_TEST(running_real, HDAAudioState, 2 * 16,
+ vmstate_2_plus),
VMSTATE_END_OF_LIST()
}
};
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index e86d9bd..490f0f4 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -600,11 +600,11 @@ extern const VMStateInfo vmstate_info_bitmap;
#define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
-#define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
- VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
+#define VMSTATE_BOOL_ARRAY_TEST(_f, _s, _n, _t) \
+ VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_bool, bool)
-#define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
- VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
+#define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
+ VMSTATE_BOOL_ARRAY_TEST(_f, _s, _n, NULL)
#define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 3b93ab9..5cc5706 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -506,6 +506,121 @@ static void test_simple_bitmap(void)
#undef FIELD_EQUAL
}
+#define VMSTATE_ARRAY_SIZE 5
+
+typedef struct TestArray {
+ int32_t size;
+ bool b_1[VMSTATE_ARRAY_SIZE];
+ bool b_2[VMSTATE_ARRAY_SIZE];
+} TestArray;
+
+TestArray obj_array = {
+ .size = VMSTATE_ARRAY_SIZE,
+ .b_1 = { false, true, false, true, false},
+ .b_2 = { true, false, true, false, true},
+};
+
+static const VMStateDescription vmstate_array_primitive = {
+ .name = "array/primitive",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_INT32_EQUAL(size, TestArray),
+ VMSTATE_BOOL_ARRAY(b_1, TestArray, VMSTATE_ARRAY_SIZE),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+uint8_t wire_array_primitive[] = {
+ /* size */ 0x00, 0x00, 0x00, 0x05,
+ /* b_1 */ 0x00, 0x01, 0x00, 0x01, 0x00,
+ QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_array_copy(void *arg1, void *arg2)
+{
+ TestArray *target = arg1;
+ TestArray *source = arg2;
+ int i;
+
+ target->size = source->size;
+
+ for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+ target->b_1[i] = source->b_1[i];
+ target->b_2[i] = source->b_2[i];
+ }
+}
+
+static void test_array_primitive(void)
+{
+ TestArray obj, obj_clone;
+ int i;
+
+ memset(&obj, 0, sizeof(obj));
+ obj.size = VMSTATE_ARRAY_SIZE;
+
+ save_vmstate(&vmstate_array_primitive, &obj_array);
+
+ compare_vmstate(wire_array_primitive, sizeof(wire_array_primitive));
+
+ SUCCESS(load_vmstate(&vmstate_array_primitive, &obj, &obj_clone,
+ obj_array_copy, 1, wire_array_primitive,
+ sizeof(wire_array_primitive)));
+
+#define FIELD_EQUAL(name) g_assert_cmpint(obj.name, ==, obj_array.name)
+#define ELEM_EQUAL(name, i) \
+ g_assert_cmpint(obj.name[i], ==, obj_array.name[i])
+
+ FIELD_EQUAL(size);
+ for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+ ELEM_EQUAL(b_1, i);
+ }
+}
+
+static const VMStateDescription vmstate_array_test = {
+ .name = "array/test",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_INT32_EQUAL(size, TestArray),
+ VMSTATE_BOOL_ARRAY_TEST(b_1, TestArray, VMSTATE_ARRAY_SIZE, test_true),
+ VMSTATE_BOOL_ARRAY_TEST(b_2, TestArray, VMSTATE_ARRAY_SIZE,
test_false),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+uint8_t wire_array_test[] = {
+ /* size */ 0x00, 0x00, 0x00, 0x05,
+ /* b_1 */ 0x00, 0x01, 0x00, 0x01, 0x00,
+ QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void test_array_test(void)
+{
+ TestArray obj, obj_clone;
+ int i;
+
+ memset(&obj, 0, sizeof(obj));
+ obj.size = VMSTATE_ARRAY_SIZE;
+
+ save_vmstate(&vmstate_array_test, &obj_array);
+
+ compare_vmstate(wire_array_test, sizeof(wire_array_test));
+
+ SUCCESS(load_vmstate(&vmstate_array_test, &obj, &obj_clone,
+ obj_array_copy, 1, wire_array_test,
+ sizeof(wire_array_test)));
+
+ FIELD_EQUAL(size);
+ for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+ ELEM_EQUAL(b_1, i);
+ }
+}
+#undef FIELD_EQUAL
+#undef ELEM_EQUAL
+
typedef struct TestVersioned {
uint32_t a, b, c, e;
uint64_t d, f;
@@ -739,6 +854,8 @@ int main(int argc, char **argv)
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/array/primitive", test_array_primitive);
+ g_test_add_func("/vmstate/array/test", test_array_test);
g_test_run();
close(temp_fd);
--
1.9.0
- [Qemu-devel] [PATCH 026/124] vmstate: Test for VMSTATE_UNUSED, (continued)
- [Qemu-devel] [PATCH 026/124] vmstate: Test for VMSTATE_UNUSED, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 027/124] vmstate: Test for VMSTATE_BITMAP, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 028/124] vmstate: Test for VMSTATE_UINT8_EQUAL, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 030/124] vmstate: Test for VMSTATE_UINT32_EQUAL, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 029/124] vmstate: Test for VMSTATE_UINT16_EQUAL, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 031/124] vmstate: Test for VMSTATE_UINT64_EQUAL, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 032/124] vmstate: Test for VMSTATE_INT32_EQUAL, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 033/124] vmstate: Test for VMSTATE_INT32_LE, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 034/124] vmstate: s/VMSTATE_INT32_LE/VMSTATE_INT32_POSITIVE_LE/, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 036/124] vmstate: Test for VMSTATE_ARRAY_BOOL_TEST,
Juan Quintela <=
- [Qemu-devel] [PATCH 035/124] vmstate: Move VMSTATE_TIMER_V to VMSTATE_TIMER_TEST, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 037/124] vmstate: Test for VMSTATE_UINT8_ARRAY, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 039/124] vmstate: Test for VMSTATE_UINT32_ARRAY{_TEST}, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 040/124] vmstate: Test for VMSTATE_UINT64_ARRAY{_TEST}, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 038/124] vmstate: Test for VMSTATE_UINT16_ARRAY, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 041/124] vmstate: Test for VMSTATE_INT16_ARRAY, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 042/124] vmstate: Test for VMSTATE_INT32_ARRAY{_TEST}, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 045/124] vmstate: Test for VMSTATE_UINT8_2DARRAY, Juan Quintela, 2014/04/21
- [Qemu-devel] [PATCH 043/124] vmstate: Test for VMSTATE_INT64_ARRAY, Juan Quintela, 2014/04/21