[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 22/97] vmstate: Test for VMSTATE_BITMAP
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 22/97] vmstate: Test for VMSTATE_BITMAP |
Date: |
Mon, 7 Apr 2014 05:20:40 +0200 |
Remove the unused version field (was unused).
Signed-off-by: Juan Quintela <address@hidden>
---
hw/sd/sd.c | 2 +-
include/migration/vmstate.h | 4 +-
tests/test-vmstate.c | 90 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 93 insertions(+), 3 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 4502ad1..7ee8c24 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -467,7 +467,7 @@ static const VMStateDescription sd_vmstate = {
VMSTATE_UINT32(card_status, SDState),
VMSTATE_PARTIAL_BUFFER(sd_status, SDState, 1),
VMSTATE_UINT32(vhs, SDState),
- VMSTATE_BITMAP(wp_groups, SDState, 0, wpgrps_size),
+ VMSTATE_BITMAP(wp_groups, SDState, wpgrps_size),
VMSTATE_UINT32(blk_len, SDState),
VMSTATE_UINT32(erase_start, SDState),
VMSTATE_UINT32(erase_end, SDState),
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index b350eac..9cfc356 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -493,9 +493,9 @@ extern const VMStateInfo vmstate_info_bitmap;
/* _field_size should be a int32_t field in the _state struct giving the
* size of the bitmap _field in bits.
*/
-#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
+#define VMSTATE_BITMAP(_field, _state, _field_size) { \
.name = (stringify(_field)), \
- .version_id = (_version), \
+ .version_id = 0, \
.size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
.info = &vmstate_info_bitmap, \
.flags = VMS_VBUFFER|VMS_POINTER, \
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index e4096f7..d5cecbf 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -28,6 +28,7 @@
#include "migration/migration.h"
#include "migration/vmstate.h"
#include "block/coroutine.h"
+#include "qemu/bitmap.h"
char temp_file[] = "/tmp/vmst.test.XXXXXX";
int temp_fd;
@@ -340,6 +341,94 @@ static void test_simple_test(void)
}
#undef FIELD_ASSERT
+typedef struct TestBitmap {
+ int32_t bitmap_size;
+ unsigned long *bitmap;
+} TestBitmap;
+
+static const VMStateDescription vmstate_simple_bitmap = {
+ .name = "simple/bitmap",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_INT32(bitmap_size, TestBitmap),
+ VMSTATE_BITMAP(bitmap, TestBitmap, bitmap_size),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+/* This is the binary representation on the wire of that struct */
+uint8_t wire_simple_bitmap[] = {
+ 0x00, 0x00, 0x00, 0x40, /* size */
+ 0x40, 0x00, 0x00, 0x00, /* bitmap */
+ 0x40, 0x40, 0x00, 0x01,
+ QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+#define VMSTATE_BITMAP_SIZE 64
+
+static void test_simple_bitmap(void)
+{
+ QEMUFile *fsave = open_test_file(true);
+
+ TestBitmap obj_simple;
+
+ obj_simple.bitmap_size = VMSTATE_BITMAP_SIZE;
+ obj_simple.bitmap = bitmap_new(VMSTATE_BITMAP_SIZE);
+ set_bit(0, obj_simple.bitmap);
+ set_bit(22, obj_simple.bitmap);
+ set_bit(30, obj_simple.bitmap);
+ set_bit(62, obj_simple.bitmap);
+
+ /* Save file with vmstate */
+ vmstate_save_state(fsave, &vmstate_simple_bitmap, &obj_simple);
+ g_assert(!qemu_file_get_error(fsave));
+ qemu_fclose(fsave);
+
+ QEMUFile *loading = open_test_file(false);
+ /* we don't need QEMU_VM_EOF */
+ uint8_t result[sizeof(wire_simple_bitmap)-1];
+
+ /* read back as binary */
+
+ g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==,
+ sizeof(result));
+ g_assert(!qemu_file_get_error(loading));
+
+ /* Compare that what is on the file is the same that what we
+ expected to be there */
+ SUCCESS(memcmp(result, wire_simple_bitmap, sizeof(result)));
+
+ /* Must reach EOF */
+ qemu_get_byte(loading);
+ g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO);
+
+ qemu_fclose(loading);
+
+ /* We save the file again. We want the EOF this time */
+
+ fsave = open_test_file(true);
+ qemu_put_buffer(fsave, wire_simple_bitmap, sizeof(wire_simple_bitmap));
+ qemu_fclose(fsave);
+
+ loading = open_test_file(false);
+ TestBitmap obj;
+
+ obj.bitmap = bitmap_new(VMSTATE_BITMAP_SIZE);
+
+ SUCCESS(vmstate_load_state(loading, &vmstate_simple_bitmap, &obj, 1));
+ g_assert(!qemu_file_get_error(loading));
+
+#define FIELD_ASSERT(name) g_assert_cmpint(obj.name, ==, obj_simple.name)
+ FIELD_ASSERT(bitmap_size);
+ g_assert_cmpint(bitmap_equal(obj.bitmap, obj_simple.bitmap,
+ obj_simple.bitmap_size), ==, 1);
+
+ qemu_fclose(loading);
+}
+#undef FIELD_ASSERT
+
typedef struct TestStruct {
uint32_t a, b, c, e;
uint64_t d, f;
@@ -559,6 +648,7 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
g_test_add_func("/vmstate/simple/primitive", test_simple_primitive);
g_test_add_func("/vmstate/simple/test", test_simple_test);
+ g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap);
g_test_add_func("/vmstate/versioned/load/v1", test_load_v1);
g_test_add_func("/vmstate/versioned/load/v2", test_load_v2);
g_test_add_func("/vmstate/field_exists/load/noskip", test_load_noskip);
--
1.9.0
- [Qemu-devel] [PATCH 02/97] savevm: Remove all the unneded version_minimum_id_old (Massive), (continued)
- [Qemu-devel] [PATCH 02/97] savevm: Remove all the unneded version_minimum_id_old (Massive), Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 13/97] vmstate: Test for VMSTATE_INT16_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 14/97] vmstate: Test for VMSTATE_INT32_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 15/97] vmstate: test for VMSTATE_INT64_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 16/97] vmstate: Test for VMSTATE_UINT8_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 17/97] vmstate: Test for VMSTATE_UINT16_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 19/97] vmstate: Test for VMSTATE_UINT64_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 18/97] vmstate: Test for VMSTATE_UINT32_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 21/97] vmstate: Test for VMSTATE_UNUSED, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 20/97] vmstate: Test for VMSTATE_FLOAT64, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 22/97] vmstate: Test for VMSTATE_BITMAP,
Juan Quintela <=
- [Qemu-devel] [PATCH 24/97] vmstate: Test for VMSTATE_UINT16_EQUAL, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 25/97] vmstate: Test for VMSTATE_UINT32_EQUAL, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 23/97] vmstate: Test for VMSTATE_UINT8_EQUAL, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 26/97] vmstate: Test for VMSTATE_UINT64_EQUAL, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 28/97] vmstate: Test for VMSTATE_INT32_LE, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 31/97] vmstate: Test for VMSTATE_ARRAY_BOOL_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 29/97] vmstate: s/VMSTATE_INT32_LE/VMSTATE_INT32_POSITIVE_LE/, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 30/97] vmstate: Move VMSTATE_TIMER_V to VMSTATE_TIMER_TEST, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 32/97] vmstate: Test for VMSTATE_UINT8_ARRAY, Juan Quintela, 2014/04/06
- [Qemu-devel] [PATCH 27/97] vmstate: Test for VMSTATE_INT32_EQUAL, Juan Quintela, 2014/04/06