vmstate-simplification queue
cover vmstate-simplification queue
Hi
As agreed on previous email, this is the next part for the VMSTATE SIMPLICATION series.
- Added another removal of minimum_version_id_old
- Improve error detection as discussed with David.
- Port existing tests and add tests for primitive types (integers)
- Add tests for _TEST() for primitieve types
- Add tests for FLOAT64/BITMAP/UNUSED
- Add tests for equal comparisons
Please, review.
The following changes since commit db80facefa62dff42bb50c73b0f03eda5f732b49:
migration: catch unknown flags in ram_load (2014-06-16 04:55:27 +0200)
are available in the git repository at:
git://github.com/juanquintela/qemu.git tags/vmstate-simplification/20140616
for you to fetch changes up to ea8060b30d1db88ab8e7904279264ad55842c835:
vmstate: s/VMSTATE_INT32_LE/VMSTATE_INT32_POSITIVE_LE/ (2014-06-16 05:38:42 +0200)
----------------------------------------------------------------
vmstate-simplification/next for 20140616
----------------------------------------------------------------
Juan Quintela (26):
migration: Remove unneeded minimum_version_id_old
vmstate: Return error in case of error
vmstate: Refactor & increase tests for primitive types
vmstate: Port versioned tests to new format
vmstate: Create test functions for versions until 15
vmstate: Remove VMSTATE_UINTL_EQUAL_V
vmstate: Change VMSTATE_INTTL_V to VMSTATE_INTTL_TEST
vmstate: Remove unused VMSTATE_UINTTL_ARRAY_V
vmstate: Test for VMSTATE_BOOL_TEST
vmstate: Test for VMSTATE_INT8_TEST
vmstate: Test for VMSTATE_INT16_TEST
vmstate: Test for VMSTATE_INT32_TEST
vmstate: test for VMSTATE_INT64_TEST
vmstate: Test for VMSTATE_UINT8_TEST
vmstate: Test for VMSTATE_UINT16_TEST
vmstate: Test for VMSTATE_UINT32_TEST
vmstate: Test for VMSTATE_UINT64_TEST
vmstate: Test for VMSTATE_FLOAT64
vmstate: Test for VMSTATE_UNUSED
vmstate: Test for VMSTATE_BITMAP
vmstate: Test for VMSTATE_UINT8_EQUAL
vmstate: Test for VMSTATE_UINT16_EQUAL
vmstate: Test for VMSTATE_UINT32_EQUAL
vmstate: Test for VMSTATE_UINT64_EQUAL
vmstate: Test for VMSTATE_INT32_EQUAL
vmstate: Test for VMSTATE_INT32_LE
Michael S. Tsirkin (1):
vmstate: s/VMSTATE_INT32_LE/VMSTATE_INT32_POSITIVE_LE/
cpus.c | 2 +- hw/arm/stellaris.c | 2 +- hw/char/serial.c | 4 +- hw/display/pl110.c | 2 +- hw/gpio/pl061.c | 2 +- hw/ide/core.c | 2 +- hw/input/ps2.c | 2 +- hw/intc/ioapic_common.c | 5 +- hw/misc/arm_sysctl.c | 10 +- hw/net/lan9118.c | 18 +- hw/net/ne2000.c | 2 +- hw/net/rtl8139.c | 2 +- hw/nvram/eeprom93xx.c | 7 +- hw/nvram/fw_cfg.c | 2 +- hw/sd/sd.c | 2 +- hw/timer/ds1338.c | 2 +- hw/timer/hpet.c | 2 +- hw/timer/i8254_common.c | 3 +- hw/timer/mc146818rtc.c | 12 +- hw/usb/hcd-ehci.c | 4 +- hw/usb/hcd-ohci.c | 7 +- hw/usb/hcd-uhci.c | 4 +- include/hw/hw.h | 31 +- include/migration/vmstate.h | 132 ++++--- target-i386/machine.c | 66 ++-- tests/test-vmstate.c | 854 ++++++++++++++++++++++++++++++++------------ vmstate.c | 26 ++ 27 files changed, 809 insertions(+), 398 deletions(-)
PATCH 1/27 migration: Remove unneeded minimum_version_id_old
Once there, make checkpatch happy.
--- hw/usb/hcd-ohci.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/usb/hcd-ohci.c +2 -5
@@ -1988,8 +1988,7 @@ static const VMStateDescription vmstate_ohci_state_port = { .name = "ohci-core/port", .version_id = 1, .minimum_version_id = 1, - .minimum_version_id_old = 1, - .fields = (VMStateField []) { + .fields = (VMStateField []) {VMSTATE_UINT32 (ctrl, OHCIPort),VMSTATE_END_OF_LIST () },
@@ -2015,9 +2014,8 @@ static const VMStateDescription vmstate_ohci_eof_timer = { .name = "ohci-core/eof-timer", .version_id = 1, .minimum_version_id = 1, - .minimum_version_id_old = 1, .pre_load = ohci_eof_timer_pre_load, - .fields = (VMStateField []) { + .fields = (VMStateField []) {VMSTATE_TIMER (eof_timer, OHCIState),VMSTATE_END_OF_LIST () },
@@ -2078,7 +2076,6 @@ static const VMStateDescription vmstate_ohci = { .name = "ohci", .version_id = 1, .minimum_version_id = 1, - .minimum_version_id_old = 1, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, OHCIPCIState),VMSTATE_STRUCT (state, OHCIPCIState,1 , vmstate_ohci_state, OHCIState),
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 01/27] migration: Remove unneeded minimum_version_id_old
Quoted 3 lines · * Juan Quintela ([email protected]) wrote:
Once there, make checkpatch happy.
Signed-off-by Juan Quintela <[email protected]>
Quoted 41 lines
--- hw/usb/hcd-ohci.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/usb/hcd-ohci.c +2
-5@@ -1988,8 +1988,7 @@ static const VMStateDescription vmstate_ohci_state_port = { .name = "ohci-core/port", .version_id = 1, .minimum_version_id = 1, - .minimum_version_id_old = 1, - .fields = (VMStateField []) { + .fields = (VMStateField []) {VMSTATE_UINT32 (ctrl, OHCIPort),VMSTATE_END_OF_LIST () },@@ -2015,9 +2014,8 @@ static const VMStateDescription vmstate_ohci_eof_timer = { .name = "ohci-core/eof-timer", .version_id = 1, .minimum_version_id = 1, - .minimum_version_id_old = 1, .pre_load = ohci_eof_timer_pre_load, - .fields = (VMStateField []) { + .fields = (VMStateField []) {VMSTATE_TIMER (eof_timer, OHCIState),VMSTATE_END_OF_LIST () },@@ -2078,7 +2076,6 @@ static const VMStateDescription vmstate_ohci = { .name = "ohci", .version_id = 1, .minimum_version_id = 1, - .minimum_version_id_old = 1, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, OHCIPCIState),VMSTATE_STRUCT (state, OHCIPCIState,1 , vmstate_ohci_state, OHCIState),Signature · 1 line
1.9.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 2/27 vmstate: Return error in case of error
In reply to Juan QuintelaIf there is an error while loading a field, we should stop reading and not continue with the rest of fields. And we should also set an error in qemu_file.
--- vmstate.c | 4 ++++ 1 file changed, 4 insertions(+)
vmstate.c +4 -0
@@ -98,7 +98,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, ret = field->info->get (f, addr, size); } +if (ret >=0 ) { + ret =qemu_file_get_error (f); + }if (ret <0 ) { +qemu_file_set_error (f, ret);trace_vmstate_load_field_error (field->name, ret);return ret; }
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 02/27] vmstate: Return error in case of error
Quoted 16 lines · * Juan Quintela ([email protected]) wrote:
If there is an error while loading a field, we should stop reading and not continue with the rest of fields. And we should also set an error in
qemu_file.Signed-off-by Juan Quintela <[email protected]>--- vmstate.c | 4 ++++ 1 file changed, 4 insertions(+)vmstate.c +0
-0@@ -98,7 +98,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, ret = field->info->get (f, addr, size);
vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 108
Quoted 10 lines
vmstate.c +4
-0} +if (ret >=0 ) { + ret =qemu_file_get_error (f); + }if (ret <0 ) { +qemu_file_set_error (f, ret);trace_vmstate_load_field_error (field->name, ret);return ret; }
I wonder about turning that trace into an error_report; the process is doomed anyway at this point and it would be nice to know why.
Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 3/27 vmstate: Refactor & increase tests for primitive types
In reply to Juan QuintelaThis commit refactor the simple tests to test all integer types. We move to hex because it is easier to read values of different types.
--- tests/test-vmstate.c | 273 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 212 insertions(+), 61 deletions(-)
tests/test-vmstate.c +212 -61
@@ -54,80 +54,232 @@ static QEMUFile *open_test_file(bool write)return qemu_fdopen (fd, write ?"wb" :"rb" ); } -typedef struct TestSruct { -uint32_t a, b, c, e; -uint64_t d, f; -bool skip_c_e; -}TestStruct ; +#define SUCCESS (val) \ + g_assert_cmpint((val), ==, 0) +#define FAILURE (val) \ + g_assert_cmpint((val), !=, 0) -static const VMStateDescription vmstate_simple = { - .name ="test" , - .version_id =1 , - .minimum_version_id =1 , - .fields = (VMStateField []) { -VMSTATE_UINT32 (a, TestStruct), -VMSTATE_UINT32 (b, TestStruct), -VMSTATE_UINT32 (c, TestStruct), -VMSTATE_UINT64 (d, TestStruct), -VMSTATE_END_OF_LIST () - } -}; +static void save_vmstate (const VMStateDescription *desc,void *obj) +{ +QEMUFile *f =open_test_file (true); + +/* Save file with vmstate */ +vmstate_save_state (f, desc, obj); +qemu_put_byte (f,QEMU_VM_EOF ); +g_assert (!qemu_file_get_error (f)); +qemu_fclose (f); +} -static void test_simple_save (void ) +static void compare_vmstate (uint8_t *wire,size_t size) { -QEMUFile *fsave =open_test_file (true); -TestStruct obj = { .a =1 , .b =2 , .c =3 , .d =4 }; -vmstate_save_state (fsave, &vmstate_simple, &obj); -g_assert (!qemu_file_get_error (fsave)); -qemu_fclose (fsave); +QEMUFile *f =open_test_file (false); +uint8_t result[size]; -QEMUFile *loading =open_test_file (false); -uint8_t expected[] = { -0 ,0 ,0 ,1 ,/* a */ -0 ,0 ,0 ,2 ,/* b */ -0 ,0 ,0 ,3 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,4 ,/* d */ - }; -uint8_t result[sizeof (expected)]; - g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, +/* read back as binary */ + + g_assert_cmpint(qemu_get_buffer(f, result, sizeof(result)), ==,sizeof (result)); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0); +g_assert (!qemu_file_get_error (f)); + +/* Compare that what is on the file is the same that what we +expected to be there */ +SUCCESS (memcmp (result, wire,sizeof (result)));/* Must reach EOF */ -qemu_get_byte (loading); - g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); +qemu_get_byte (f); + g_assert_cmpint(qemu_file_get_error(f), ==, -EIO); -qemu_fclose (loading); +qemu_fclose (f); } -static void test_simple_load (void ) +static int load_vmstate_one (const VMStateDescription *desc,void *obj, +int version,uint8_t *wire,size_t size) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); +QEMUFile *f; +int ret; + + f =open_test_file (true); +qemu_put_buffer (f, wire, size); +qemu_fclose (f); + + f =open_test_file (false); + ret =vmstate_load_state (f, desc, obj, version); +if (ret) { +g_assert (qemu_file_get_error (f)); + }else { +g_assert (!qemu_file_get_error (f)); + } +qemu_fclose (f); +return ret; +} -QEMUFile *loading =open_test_file (false); -TestStruct obj; -vmstate_load_state (loading, &vmstate_simple, &obj,1 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); -qemu_fclose (loading); + +static int load_vmstate (const VMStateDescription *desc, +void *obj,void *obj_clone, +void (*obj_copy)(void *,void *), +int version,uint8_t *wire,size_t size) +{ +/* We test with zero size */ +obj_copy (obj_clone, obj); +FAILURE (load_vmstate_one (desc, obj, version, wire,0 )); + +/* Stream ends with QEMU_EOF, so we need at least 3 bytes to be +* able to test in the middle */ + +if (size >3 ) { + +/* We test with size - 2. We can't test size - 1 due to EOF tricks */ +obj_copy (obj, obj_clone); +FAILURE (load_vmstate_one (desc, obj, version, wire, size -2 )); + +/* Test with size/2, first half of real state */ +obj_copy (obj, obj_clone); +FAILURE (load_vmstate_one (desc, obj, version, wire, size/2 )); + +/* Test with size/2, second half of real state */ +obj_copy (obj, obj_clone); +FAILURE (load_vmstate_one (desc, obj, version, wire + (size/2 ), size/2 )); + + } +obj_copy (obj, obj_clone); +return load_vmstate_one (desc, obj, version, wire, size); +} + +/* Test struct that we are going to use for our tests */ + +typedef struct TestSimple { +bool b_1, b_2; +uint8_t u8_1; +uint16_t u16_1; +uint32_t u32_1; +uint64_t u64_1; +int8_t i8_1, i8_2; +int16_t i16_1, i16_2; +int32_t i32_1, i32_2; +int64_t i64_1, i64_2; +}TestSimple ; + +/* Object instantiation, we are going to use it in more than one test */ + +TestSimple obj_simple = { + .b_1 = true, + .b_2 = false, + .u8_1 =130 , + .u16_1 =512 , + .u32_1 =70000 , + .u64_1 =12121212 , + .i8_1 =65 , + .i8_2 =-65 , + .i16_1 =512 , + .i16_2 =-512 , + .i32_1 =70000 , + .i32_2 =-70000 , + .i64_1 =12121212 , + .i64_2 =-12121212 , +}; + +/* Description of the values. If you add a primitive type +you are expected to add a test here */ + +static const VMStateDescription vmstate_simple_primitive = { + .name ="simple/primitive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BOOL (b_1, TestSimple), +VMSTATE_BOOL (b_2, TestSimple), +VMSTATE_UINT8 (u8_1, TestSimple), +VMSTATE_UINT16 (u16_1, TestSimple), +VMSTATE_UINT32 (u32_1, TestSimple), +VMSTATE_UINT64 (u64_1, TestSimple), +VMSTATE_INT8 (i8_1, TestSimple), +VMSTATE_INT8 (i8_2, TestSimple), +VMSTATE_INT16 (i16_1, TestSimple), +VMSTATE_INT16 (i16_2, TestSimple), +VMSTATE_INT32 (i32_1, TestSimple), +VMSTATE_INT32 (i32_2, TestSimple), +VMSTATE_INT64 (i64_1, TestSimple), +VMSTATE_INT64 (i64_2, TestSimple), +VMSTATE_END_OF_LIST () + } +}; + +/* It describes what goes through the wire. Our tests are basically: + +* save test +- save a struct a vmstate to a file +- read that file back (binary read, no vmstate) +- compare it with what we expect to be on the wire +* load test +- save to the file what we expect to be on the wire +- read struct back with vmstate in a different +- compare back with the original struct +*/ + +uint8_t wire_simple_primitive[] = { +/* b_1 */ 0x01 , +/* b_2 */ 0x00 , +/* u8_1 */ 0x82 , +/* u16_1 */ 0x02 ,0x00 , +/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , +/* u64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* i8_1 */ 0x41 , +/* i8_2 */ 0xbf , +/* i16_1 */ 0x02 ,0x00 , +/* i16_2 */ 0xfe ,0x0 , +/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , +/* i32_2 */ 0xff ,0xfe ,0xee ,0x90 , +/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* i64_2 */ 0xff ,0xff ,0xff ,0xff ,0xff ,0x47 ,0x0b ,0x84 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; + +static void obj_simple_copy (void *target,void *source) +{ +memcpy (target, source,sizeof (TestSimple)); +} + +static void test_simple_primitive (void ) +{ +TestSimple obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +save_vmstate (&vmstate_simple_primitive, &obj_simple); + +compare_vmstate (wire_simple_primitive,sizeof (wire_simple_primitive)); + +SUCCESS (load_vmstate (&vmstate_simple_primitive, &obj, &obj_clone, + obj_simple_copy,1 , wire_simple_primitive, +sizeof (wire_simple_primitive))); + +#define FIELD_EQUAL (name) g_assert_cmpint(obj.name, ==, obj_simple.name) + +FIELD_EQUAL (b_1); +FIELD_EQUAL (b_2); +FIELD_EQUAL (u8_1); +FIELD_EQUAL (u16_1); +FIELD_EQUAL (u32_1); +FIELD_EQUAL (u64_1); +FIELD_EQUAL (i8_1); +FIELD_EQUAL (i8_2); +FIELD_EQUAL (i16_1); +FIELD_EQUAL (i16_2); +FIELD_EQUAL (i32_1); +FIELD_EQUAL (i32_2); +FIELD_EQUAL (i64_1); +FIELD_EQUAL (i64_2); } +#undef FIELD_EQUAL + +typedef struct TestStruct { +uint32_t a, b, c, e; +uint64_t d, f; +bool skip_c_e; +}TestStruct ;static const VMStateDescription vmstate_versioned = { - .name ="test" , + .name ="test/versioned" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) {
@@ -202,7 +354,7 @@ static bool test_skip(void *opaque, int version_id) }static const VMStateDescription vmstate_skipping = { - .name ="test" , + .name ="test/skip" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) {
@@ -337,8 +489,7 @@ int main(int argc, char **argv) temp_fd =mkstemp (temp_file);g_test_init (&argc, &argv,NULL ); -g_test_add_func ("/vmstate/simple/save" , test_simple_save); -g_test_add_func ("/vmstate/simple/load" , test_simple_load); +g_test_add_func ("/vmstate/simple/primitive" , test_simple_primitive);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);
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 03/27] vmstate: Refactor & increase tests for primitive types
Quoted 4 lines · * Juan Quintela ([email protected]) wrote:
This commit refactor the simple tests to test all integer types. We move to hex because it is easier to read values of different types.
Signed-off-by Juan Quintela <[email protected]>
Quoted 322 lines
--- tests/test-vmstate.c | 273 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 212 insertions(+), 61 deletions(-)tests/test-vmstate.c +212
-61@@ -54,80 +54,232 @@ static QEMUFile *open_test_file(bool write)return qemu_fdopen (fd, write ?"wb" :"rb" ); } -typedef struct TestSruct { -uint32_t a, b, c, e; -uint64_t d, f; -bool skip_c_e; -}TestStruct ; +#define SUCCESS (val) \ + g_assert_cmpint((val), ==, 0) +#define FAILURE (val) \ + g_assert_cmpint((val), !=, 0) -static const VMStateDescription vmstate_simple = { - .name ="test" , - .version_id =1 , - .minimum_version_id =1 , - .fields = (VMStateField []) { -VMSTATE_UINT32 (a, TestStruct), -VMSTATE_UINT32 (b, TestStruct), -VMSTATE_UINT32 (c, TestStruct), -VMSTATE_UINT64 (d, TestStruct), -VMSTATE_END_OF_LIST () - } -}; +static void save_vmstate (const VMStateDescription *desc,void *obj) +{ +QEMUFile *f =open_test_file (true); + +/* Save file with vmstate */ +vmstate_save_state (f, desc, obj); +qemu_put_byte (f,QEMU_VM_EOF ); +g_assert (!qemu_file_get_error (f)); +qemu_fclose (f); +} -static void test_simple_save (void ) +static void compare_vmstate (uint8_t *wire,size_t size) { -QEMUFile *fsave =open_test_file (true); -TestStruct obj = { .a =1 , .b =2 , .c =3 , .d =4 }; -vmstate_save_state (fsave, &vmstate_simple, &obj); -g_assert (!qemu_file_get_error (fsave)); -qemu_fclose (fsave); +QEMUFile *f =open_test_file (false); +uint8_t result[size]; -QEMUFile *loading =open_test_file (false); -uint8_t expected[] = { -0 ,0 ,0 ,1 ,/* a */ -0 ,0 ,0 ,2 ,/* b */ -0 ,0 ,0 ,3 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,4 ,/* d */ - }; -uint8_t result[sizeof (expected)]; - g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, +/* read back as binary */ + + g_assert_cmpint(qemu_get_buffer(f, result, sizeof(result)), ==,sizeof (result)); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0); +g_assert (!qemu_file_get_error (f)); + +/* Compare that what is on the file is the same that what we +expected to be there */ +SUCCESS (memcmp (result, wire,sizeof (result)));/* Must reach EOF */ -qemu_get_byte (loading); - g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); +qemu_get_byte (f); + g_assert_cmpint(qemu_file_get_error(f), ==, -EIO); -qemu_fclose (loading); +qemu_fclose (f); } -static void test_simple_load (void ) +static int load_vmstate_one (const VMStateDescription *desc,void *obj, +int version,uint8_t *wire,size_t size) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); +QEMUFile *f; +int ret; + + f =open_test_file (true); +qemu_put_buffer (f, wire, size); +qemu_fclose (f); + + f =open_test_file (false); + ret =vmstate_load_state (f, desc, obj, version); +if (ret) { +g_assert (qemu_file_get_error (f)); + }else { +g_assert (!qemu_file_get_error (f)); + } +qemu_fclose (f); +return ret; +} -QEMUFile *loading =open_test_file (false); -TestStruct obj; -vmstate_load_state (loading, &vmstate_simple, &obj,1 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); -qemu_fclose (loading); + +static int load_vmstate (const VMStateDescription *desc, +void *obj,void *obj_clone, +void (*obj_copy)(void *,void *), +int version,uint8_t *wire,size_t size) +{ +/* We test with zero size */ +obj_copy (obj_clone, obj); +FAILURE (load_vmstate_one (desc, obj, version, wire,0 )); + +/* Stream ends with QEMU_EOF, so we need at least 3 bytes to be +* able to test in the middle */ + +if (size >3 ) { + +/* We test with size - 2. We can't test size - 1 due to EOF tricks */ +obj_copy (obj, obj_clone); +FAILURE (load_vmstate_one (desc, obj, version, wire, size -2 )); + +/* Test with size/2, first half of real state */ +obj_copy (obj, obj_clone); +FAILURE (load_vmstate_one (desc, obj, version, wire, size/2 )); + +/* Test with size/2, second half of real state */ +obj_copy (obj, obj_clone); +FAILURE (load_vmstate_one (desc, obj, version, wire + (size/2 ), size/2 )); + + } +obj_copy (obj, obj_clone); +return load_vmstate_one (desc, obj, version, wire, size); +} + +/* Test struct that we are going to use for our tests */ + +typedef struct TestSimple { +bool b_1, b_2; +uint8_t u8_1; +uint16_t u16_1; +uint32_t u32_1; +uint64_t u64_1; +int8_t i8_1, i8_2; +int16_t i16_1, i16_2; +int32_t i32_1, i32_2; +int64_t i64_1, i64_2; +}TestSimple ; + +/* Object instantiation, we are going to use it in more than one test */ + +TestSimple obj_simple = { + .b_1 = true, + .b_2 = false, + .u8_1 =130 , + .u16_1 =512 , + .u32_1 =70000 , + .u64_1 =12121212 , + .i8_1 =65 , + .i8_2 =-65 , + .i16_1 =512 , + .i16_2 =-512 , + .i32_1 =70000 , + .i32_2 =-70000 , + .i64_1 =12121212 , + .i64_2 =-12121212 , +}; + +/* Description of the values. If you add a primitive type +you are expected to add a test here */ + +static const VMStateDescription vmstate_simple_primitive = { + .name ="simple/primitive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BOOL (b_1, TestSimple), +VMSTATE_BOOL (b_2, TestSimple), +VMSTATE_UINT8 (u8_1, TestSimple), +VMSTATE_UINT16 (u16_1, TestSimple), +VMSTATE_UINT32 (u32_1, TestSimple), +VMSTATE_UINT64 (u64_1, TestSimple), +VMSTATE_INT8 (i8_1, TestSimple), +VMSTATE_INT8 (i8_2, TestSimple), +VMSTATE_INT16 (i16_1, TestSimple), +VMSTATE_INT16 (i16_2, TestSimple), +VMSTATE_INT32 (i32_1, TestSimple), +VMSTATE_INT32 (i32_2, TestSimple), +VMSTATE_INT64 (i64_1, TestSimple), +VMSTATE_INT64 (i64_2, TestSimple), +VMSTATE_END_OF_LIST () + } +}; + +/* It describes what goes through the wire. Our tests are basically: + +* save test +- save a struct a vmstate to a file +- read that file back (binary read, no vmstate) +- compare it with what we expect to be on the wire +* load test +- save to the file what we expect to be on the wire +- read struct back with vmstate in a different +- compare back with the original struct +*/ + +uint8_t wire_simple_primitive[] = { +/* b_1 */ 0x01 , +/* b_2 */ 0x00 , +/* u8_1 */ 0x82 , +/* u16_1 */ 0x02 ,0x00 , +/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , +/* u64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* i8_1 */ 0x41 , +/* i8_2 */ 0xbf , +/* i16_1 */ 0x02 ,0x00 , +/* i16_2 */ 0xfe ,0x0 , +/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , +/* i32_2 */ 0xff ,0xfe ,0xee ,0x90 , +/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* i64_2 */ 0xff ,0xff ,0xff ,0xff ,0xff ,0x47 ,0x0b ,0x84 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; + +static void obj_simple_copy (void *target,void *source) +{ +memcpy (target, source,sizeof (TestSimple)); +} + +static void test_simple_primitive (void ) +{ +TestSimple obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +save_vmstate (&vmstate_simple_primitive, &obj_simple); + +compare_vmstate (wire_simple_primitive,sizeof (wire_simple_primitive)); + +SUCCESS (load_vmstate (&vmstate_simple_primitive, &obj, &obj_clone, + obj_simple_copy,1 , wire_simple_primitive, +sizeof (wire_simple_primitive))); + +#define FIELD_EQUAL (name) g_assert_cmpint(obj.name, ==, obj_simple.name) + +FIELD_EQUAL (b_1); +FIELD_EQUAL (b_2); +FIELD_EQUAL (u8_1); +FIELD_EQUAL (u16_1); +FIELD_EQUAL (u32_1); +FIELD_EQUAL (u64_1); +FIELD_EQUAL (i8_1); +FIELD_EQUAL (i8_2); +FIELD_EQUAL (i16_1); +FIELD_EQUAL (i16_2); +FIELD_EQUAL (i32_1); +FIELD_EQUAL (i32_2); +FIELD_EQUAL (i64_1); +FIELD_EQUAL (i64_2); } +#undef FIELD_EQUAL + +typedef struct TestStruct { +uint32_t a, b, c, e; +uint64_t d, f; +bool skip_c_e; +}TestStruct ;static const VMStateDescription vmstate_versioned = { - .name ="test" , + .name ="test/versioned" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) {@@ -202,7 +354,7 @@ static bool test_skip(void *opaque, int version_id) }static const VMStateDescription vmstate_skipping = { - .name ="test" , + .name ="test/skip" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) {@@ -337,8 +489,7 @@ int main(int argc, char **argv) temp_fd =mkstemp (temp_file);g_test_init (&argc, &argv,NULL ); -g_test_add_func ("/vmstate/simple/save" , test_simple_save); -g_test_add_func ("/vmstate/simple/load" , test_simple_load); +g_test_add_func ("/vmstate/simple/primitive" , test_simple_primitive);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);Signature · 1 line
1.9.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 4/27 vmstate: Port versioned tests to new format
In reply to Juan Quintela--- tests/test-vmstate.c | 363 ++++++++++++++++++++++++++------------------------- 1 file changed, 185 insertions(+), 178 deletions(-)
tests/test-vmstate.c +185 -178
@@ -272,217 +272,226 @@ static void test_simple_primitive(void) }#undef FIELD_EQUAL -typedef struct TestStruct { +typedef struct TestVersioned {uint32_t a, b, c, e;uint64_t d, f;bool skip_c_e; -}TestStruct ; +}TestVersioned ; + +TestVersioned obj_versioned = { + .a =10 , + .b =200 , + .c =30 , + .d =40 , + .e =500 , + .f =600 , + .skip_c_e = true, +}; -static const VMStateDescription vmstate_versioned = { +static const VMStateDescription vmstate_simple_versioned = { .name ="test/versioned" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) { -VMSTATE_UINT32 (a, TestStruct), -VMSTATE_UINT32_V (b, TestStruct,2 ),/* Versioned field in the middle, so -* we catch bugs more easily. -*/ -VMSTATE_UINT32 (c, TestStruct), -VMSTATE_UINT64 (d, TestStruct), -VMSTATE_UINT32_V (e, TestStruct,2 ), -VMSTATE_UINT64_V (f, TestStruct,2 ), +VMSTATE_UINT32 (a, TestVersioned), +/* Versioned field in the middle, so we catch bugs more +* easily. */ +VMSTATE_UINT32_V (b, TestVersioned,2 ), +VMSTATE_UINT32 (c, TestVersioned), +VMSTATE_UINT64 (d, TestVersioned), +VMSTATE_UINT32_V (e, TestVersioned,2 ), +VMSTATE_UINT64_V (f, TestVersioned,2 ),VMSTATE_END_OF_LIST () } }; -static void test_load_v1 (void ) +uint8_t wire_simple_v1[] = { +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* c */ 0x00 ,0x00 ,0x00 ,0x1e , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; + +uint8_t wire_simple_v2[] = { +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* b */ 0x00 ,0x00 ,0x00 ,0xc8 , +/* c */ 0x00 ,0x00 ,0x00 ,0x1e , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +/* e */ 0x00 ,0x00 ,0x01 ,0xf4 , +/* f */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x58 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; + +static void obj_versioned_copy (void *arg1,void *arg2) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .b =200 , .e =500 , .f =600 }; -vmstate_load_state (loading, &vmstate_versioned, &obj,1 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 200); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 500); - g_assert_cmpint(obj.f, ==, 600); -qemu_fclose (loading); +TestVersioned *target = arg1; +TestVersioned *source = arg2; + + target->a = source->a; + target->b = source->b; + target->c = source->c; + target->d = source->d; + target->e = source->e; + target->f = source->f; + target->skip_c_e = source->skip_c_e; } -static void test_load_v2 (void ) +static void test_simple_v2 (void ) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -0 ,0 ,0 ,50 ,/* e */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,60 ,/* f */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj; -vmstate_load_state (loading, &vmstate_versioned, &obj,2 ); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 50); - g_assert_cmpint(obj.f, ==, 60); -qemu_fclose (loading); +TestVersioned obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +save_vmstate (&vmstate_simple_versioned, &obj_versioned); + +compare_vmstate (wire_simple_v2,sizeof (wire_simple_v2)); + +SUCCESS (load_vmstate (&vmstate_simple_versioned, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_v2, +sizeof (wire_simple_v2))); + +#define FIELD_EQUAL (name) g_assert_cmpint(obj.name, ==, obj_versioned.name) +#define FIELD_NOT_EQUAL (name) \ + g_assert_cmpint(obj.name, !=, obj_versioned.name) +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_EQUAL (e); +FIELD_EQUAL (f); +} + +static void test_simple_v1 (void ) +{ +TestVersioned obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +SUCCESS (load_vmstate (&vmstate_simple_versioned, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_v1, +sizeof (wire_simple_v1))); + +FIELD_EQUAL (a); +FIELD_NOT_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_NOT_EQUAL (f); }static bool test_skip (void *opaque,int version_id) { -TestStruct *t = (TestStruct *)opaque; +TestVersioned *t = opaque;return !t->skip_c_e; } -static const VMStateDescription vmstate_skipping = { - .name ="test/skip" , +static const VMStateDescription vmstate_simple_skipping = { + .name ="simple/skip" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) { -VMSTATE_UINT32 (a, TestStruct), -VMSTATE_UINT32 (b, TestStruct), -VMSTATE_UINT32_TEST (c, TestStruct, test_skip), -VMSTATE_UINT64 (d, TestStruct), -VMSTATE_UINT32_TEST (e, TestStruct, test_skip), -VMSTATE_UINT64_V (f, TestStruct,2 ), +VMSTATE_BOOL (skip_c_e, TestVersioned), +VMSTATE_UINT32 (a, TestVersioned), +VMSTATE_UINT32 (b, TestVersioned), +VMSTATE_UINT32_TEST (c, TestVersioned, test_skip), +VMSTATE_UINT64 (d, TestVersioned), +VMSTATE_UINT32_TEST (e, TestVersioned, test_skip), +VMSTATE_UINT64_V (f, TestVersioned,2 ),VMSTATE_END_OF_LIST () } }; +uint8_t wire_simple_no_skip[] = { +/* s */ 0x00 , +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* b */ 0x00 ,0x00 ,0x00 ,0xc8 , +/* c */ 0x00 ,0x00 ,0x00 ,0x1e , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +/* e */ 0x00 ,0x00 ,0x01 ,0xf4 , +/* f */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x58 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; -static void test_save_noskip (void ) -{ -QEMUFile *fsave =open_test_file (true); -TestStruct obj = { .a =1 , .b =2 , .c =3 , .d =4 , .e =5 , .f =6 , - .skip_c_e = false }; -vmstate_save_state (fsave, &vmstate_skipping, &obj); -g_assert (!qemu_file_get_error (fsave)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -uint8_t expected[] = { -0 ,0 ,0 ,1 ,/* a */ -0 ,0 ,0 ,2 ,/* b */ -0 ,0 ,0 ,3 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,4 ,/* d */ -0 ,0 ,0 ,5 ,/* e */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,6 ,/* f */ - }; -uint8_t result[sizeof (expected)]; - g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, -sizeof (result)); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0); - -/* Must reach EOF */ -qemu_get_byte (loading); - g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); - -qemu_fclose (loading); -} +uint8_t wire_simple_skip[] = { +/* s */ 0x01 , +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* b */ 0x00 ,0x00 ,0x00 ,0xc8 , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +/* f */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x58 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; -static void test_save_skip (void ) +static void test_simple_no_skip (void ) { -QEMUFile *fsave =open_test_file (true); -TestStruct obj = { .a =1 , .b =2 , .c =3 , .d =4 , .e =5 , .f =6 , - .skip_c_e = true }; -vmstate_save_state (fsave, &vmstate_skipping, &obj); -g_assert (!qemu_file_get_error (fsave)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -uint8_t expected[] = { -0 ,0 ,0 ,1 ,/* a */ -0 ,0 ,0 ,2 ,/* b */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,4 ,/* d */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,6 ,/* f */ - }; -uint8_t result[sizeof (expected)]; - g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, -sizeof (result)); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0); +TestVersioned obj, obj_clone; - -/* Must reach EOF */ -qemu_get_byte (loading); - g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); - -qemu_fclose (loading); +memset (&obj,0 ,sizeof (obj)); + obj_versioned.skip_c_e = false; +save_vmstate (&vmstate_simple_skipping, &obj_versioned); + +compare_vmstate (wire_simple_no_skip,sizeof (wire_simple_no_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_no_skip, +sizeof (wire_simple_no_skip) -8 )); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_EQUAL (e); +FIELD_NOT_EQUAL (f); + +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_no_skip, +sizeof (wire_simple_no_skip))); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_EQUAL (e); +FIELD_EQUAL (f); } -static void test_load_noskip (void ) +static void test_simple_skip (void ) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -0 ,0 ,0 ,50 ,/* e */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,60 ,/* f */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .skip_c_e = false }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 50); - g_assert_cmpint(obj.f, ==, 60); -qemu_fclose (loading); -} +TestVersioned obj, obj_clone; -static void test_load_skip (void ) -{ -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,60 ,/* f */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .skip_c_e = true, .c =300 , .e =500 }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 300); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 500); - g_assert_cmpint(obj.f, ==, 60); -qemu_fclose (loading); +memset (&obj,0 ,sizeof (obj)); + obj_versioned.skip_c_e = true; +save_vmstate (&vmstate_simple_skipping, &obj_versioned); + +compare_vmstate (wire_simple_skip,sizeof (wire_simple_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_skip, +sizeof (wire_simple_skip) -8 )); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_NOT_EQUAL (f); + +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_skip, +sizeof (wire_simple_skip))); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_EQUAL (f); } +#undef FIELD_EQUAL +#undef FIELD_NOT_EQUALint main (int argc,char **argv) {
@@ -490,12 +499,10 @@ 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/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); -g_test_add_func ("/vmstate/field_exists/load/skip" , test_load_skip); -g_test_add_func ("/vmstate/field_exists/save/noskip" , test_save_noskip); -g_test_add_func ("/vmstate/field_exists/save/skip" , test_save_skip); +g_test_add_func ("/vmstate/simple/v1" , test_simple_v1); +g_test_add_func ("/vmstate/simple/v2" , test_simple_v2); +g_test_add_func ("/vmstate/simple/skip" , test_simple_skip); +g_test_add_func ("/vmstate/simple/no_skip" , test_simple_no_skip);g_test_run ();close (temp_fd);
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 04/27] vmstate: Port versioned tests to new format
Quoted 98 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- tests/test-vmstate.c | 363 ++++++++++++++++++++++++++------------------------- 1 file changed, 185 insertions(+), 178 deletions(-)tests/test-vmstate.c +39
-33@@ -272,217 +272,226 @@ static void test_simple_primitive(void) }#undef FIELD_EQUAL -typedef struct TestStruct { +typedef struct TestVersioned {uint32_t a, b, c, e;uint64_t d, f;bool skip_c_e; -}TestStruct ; +}TestVersioned ; + +TestVersioned obj_versioned = { + .a =10 , + .b =200 , + .c =30 , + .d =40 , + .e =500 , + .f =600 , + .skip_c_e = true, +}; -static const VMStateDescription vmstate_versioned = { +static const VMStateDescription vmstate_simple_versioned = { .name ="test/versioned" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) { -VMSTATE_UINT32 (a, TestStruct), -VMSTATE_UINT32_V (b, TestStruct,2 ),/* Versioned field in the middle, so -* we catch bugs more easily. -*/ -VMSTATE_UINT32 (c, TestStruct), -VMSTATE_UINT64 (d, TestStruct), -VMSTATE_UINT32_V (e, TestStruct,2 ), -VMSTATE_UINT64_V (f, TestStruct,2 ), +VMSTATE_UINT32 (a, TestVersioned), +/* Versioned field in the middle, so we catch bugs more +* easily. */ +VMSTATE_UINT32_V (b, TestVersioned,2 ), +VMSTATE_UINT32 (c, TestVersioned), +VMSTATE_UINT64 (d, TestVersioned), +VMSTATE_UINT32_V (e, TestVersioned,2 ), +VMSTATE_UINT64_V (f, TestVersioned,2 ),VMSTATE_END_OF_LIST () } }; -static void test_load_v1 (void ) +uint8_t wire_simple_v1[] = { +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* c */ 0x00 ,0x00 ,0x00 ,0x1e , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; + +uint8_t wire_simple_v2[] = { +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* b */ 0x00 ,0x00 ,0x00 ,0xc8 , +/* c */ 0x00 ,0x00 ,0x00 ,0x1e , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +/* e */ 0x00 ,0x00 ,0x01 ,0xf4 , +/* f */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x58 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; + +static void obj_versioned_copy (void *arg1,void *arg2) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .b =200 , .e =500 , .f =600 }; -vmstate_load_state (loading, &vmstate_versioned, &obj,1 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 200); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 500); - g_assert_cmpint(obj.f, ==, 600); -qemu_fclose (loading);
tests/test-vmstate.c static void test_simple_primitive(void) · line 336
Quoted 10 lines
tests/test-vmstate.c +10
-0+TestVersioned *target = arg1; +TestVersioned *source = arg2; + + target->a = source->a; + target->b = source->b; + target->c = source->c; + target->d = source->d; + target->e = source->e; + target->f = source->f; + target->skip_c_e = source->skip_c_e;
Why's that not simply *target = *source?
Quoted 32 lines
tests/test-vmstate.c +5
-24} -static void test_load_v2 (void ) +static void test_simple_v2 (void ) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -0 ,0 ,0 ,50 ,/* e */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,60 ,/* f */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj; -vmstate_load_state (loading, &vmstate_versioned, &obj,2 ); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 50); - g_assert_cmpint(obj.f, ==, 60); -qemu_fclose (loading); +TestVersioned obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +save_vmstate (&vmstate_simple_versioned, &obj_versioned);
tests/test-vmstate.c static void test_simple_primitive(void) · line 354
Quoted 10 lines
tests/test-vmstate.c +10
-0+ +compare_vmstate (wire_simple_v2,sizeof (wire_simple_v2)); + +SUCCESS (load_vmstate (&vmstate_simple_versioned, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_v2, +sizeof (wire_simple_v2))); + +#define FIELD_EQUAL (name) g_assert_cmpint(obj.name, ==, obj_versioned.name) +#define FIELD_NOT_EQUAL (name) \ + g_assert_cmpint(obj.name, !=, obj_versioned.name)
Given that macro is shared with the next few functions it would be seem to declare it outside of the function.
Quoted 133 lines
tests/test-vmstate.c +53
-62+FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_EQUAL (e); +FIELD_EQUAL (f); +} + +static void test_simple_v1 (void ) +{ +TestVersioned obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +SUCCESS (load_vmstate (&vmstate_simple_versioned, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_v1, +sizeof (wire_simple_v1))); + +FIELD_EQUAL (a); +FIELD_NOT_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_NOT_EQUAL (f); }static bool test_skip (void *opaque,int version_id) { -TestStruct *t = (TestStruct *)opaque; +TestVersioned *t = opaque;return !t->skip_c_e; } -static const VMStateDescription vmstate_skipping = { - .name ="test/skip" , +static const VMStateDescription vmstate_simple_skipping = { + .name ="simple/skip" , .version_id =2 , .minimum_version_id =1 , .fields = (VMStateField []) { -VMSTATE_UINT32 (a, TestStruct), -VMSTATE_UINT32 (b, TestStruct), -VMSTATE_UINT32_TEST (c, TestStruct, test_skip), -VMSTATE_UINT64 (d, TestStruct), -VMSTATE_UINT32_TEST (e, TestStruct, test_skip), -VMSTATE_UINT64_V (f, TestStruct,2 ), +VMSTATE_BOOL (skip_c_e, TestVersioned), +VMSTATE_UINT32 (a, TestVersioned), +VMSTATE_UINT32 (b, TestVersioned), +VMSTATE_UINT32_TEST (c, TestVersioned, test_skip), +VMSTATE_UINT64 (d, TestVersioned), +VMSTATE_UINT32_TEST (e, TestVersioned, test_skip), +VMSTATE_UINT64_V (f, TestVersioned,2 ),VMSTATE_END_OF_LIST () } }; +uint8_t wire_simple_no_skip[] = { +/* s */ 0x00 , +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* b */ 0x00 ,0x00 ,0x00 ,0xc8 , +/* c */ 0x00 ,0x00 ,0x00 ,0x1e , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +/* e */ 0x00 ,0x00 ,0x01 ,0xf4 , +/* f */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x58 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; -static void test_save_noskip (void ) -{ -QEMUFile *fsave =open_test_file (true); -TestStruct obj = { .a =1 , .b =2 , .c =3 , .d =4 , .e =5 , .f =6 , - .skip_c_e = false }; -vmstate_save_state (fsave, &vmstate_skipping, &obj); -g_assert (!qemu_file_get_error (fsave)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -uint8_t expected[] = { -0 ,0 ,0 ,1 ,/* a */ -0 ,0 ,0 ,2 ,/* b */ -0 ,0 ,0 ,3 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,4 ,/* d */ -0 ,0 ,0 ,5 ,/* e */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,6 ,/* f */ - }; -uint8_t result[sizeof (expected)]; - g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, -sizeof (result)); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0); - -/* Must reach EOF */ -qemu_get_byte (loading); - g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); - -qemu_fclose (loading); -} +uint8_t wire_simple_skip[] = { +/* s */ 0x01 , +/* a */ 0x00 ,0x00 ,0x00 ,0x0a , +/* b */ 0x00 ,0x00 ,0x00 ,0xc8 , +/* d */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x28 , +/* f */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x58 , +QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ +}; -static void test_save_skip (void ) +static void test_simple_no_skip (void ) { -QEMUFile *fsave =open_test_file (true); -TestStruct obj = { .a =1 , .b =2 , .c =3 , .d =4 , .e =5 , .f =6 , - .skip_c_e = true }; -vmstate_save_state (fsave, &vmstate_skipping, &obj); -g_assert (!qemu_file_get_error (fsave)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -uint8_t expected[] = { -0 ,0 ,0 ,1 ,/* a */ -0 ,0 ,0 ,2 ,/* b */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,4 ,/* d */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,6 ,/* f */ - }; -uint8_t result[sizeof (expected)]; - g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, -sizeof (result)); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0); +TestVersioned obj, obj_clone; - -/* Must reach EOF */ -qemu_get_byte (loading);
tests/test-vmstate.c static void test_simple_primitive(void) · line 432
Quoted 10 lines
tests/test-vmstate.c +7
-3- g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); - -qemu_fclose (loading); +memset (&obj,0 ,sizeof (obj)); + obj_versioned.skip_c_e = false; +save_vmstate (&vmstate_simple_skipping, &obj_versioned); + +compare_vmstate (wire_simple_no_skip,sizeof (wire_simple_no_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */
A bit nasty.
Quoted 100 lines
tests/test-vmstate.c +46
-50+SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_no_skip, +sizeof (wire_simple_no_skip) -8 )); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_EQUAL (e); +FIELD_NOT_EQUAL (f); + +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_no_skip, +sizeof (wire_simple_no_skip))); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_EQUAL (c); +FIELD_EQUAL (d); +FIELD_EQUAL (e); +FIELD_EQUAL (f); } -static void test_load_noskip (void ) +static void test_simple_skip (void ) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -0 ,0 ,0 ,50 ,/* e */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,60 ,/* f */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .skip_c_e = false }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 50); - g_assert_cmpint(obj.f, ==, 60); -qemu_fclose (loading); -} +TestVersioned obj, obj_clone; -static void test_load_skip (void ) -{ -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,20 ,/* b */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,60 ,/* f */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .skip_c_e = true, .c =300 , .e =500 }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 20); - g_assert_cmpint(obj.c, ==, 300); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 500); - g_assert_cmpint(obj.f, ==, 60); -qemu_fclose (loading); +memset (&obj,0 ,sizeof (obj)); + obj_versioned.skip_c_e = true; +save_vmstate (&vmstate_simple_skipping, &obj_versioned); + +compare_vmstate (wire_simple_skip,sizeof (wire_simple_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_skip, +sizeof (wire_simple_skip) -8 )); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_NOT_EQUAL (f); + + SUCCESS(load_vmstate(&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy, 2, wire_simple_skip,
tests/test-vmstate.c static void test_simple_primitive(void) · line 492
Quoted 10 lines
tests/test-vmstate.c +9
-0+ sizeof(wire_simple_skip))); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_EQUAL (f); }
Couldn't those functions just be merged and take a flag?
Quoted 26 lines
tests/test-vmstate.c +6
-6+#undef FIELD_EQUAL +#undef FIELD_NOT_EQUALint main (int argc,char **argv) {@@ -490,12 +499,10 @@ 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/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); -g_test_add_func ("/vmstate/field_exists/load/skip" , test_load_skip); -g_test_add_func ("/vmstate/field_exists/save/noskip" , test_save_noskip); -g_test_add_func ("/vmstate/field_exists/save/skip" , test_save_skip); +g_test_add_func ("/vmstate/simple/v1" , test_simple_v1); +g_test_add_func ("/vmstate/simple/v2" , test_simple_v2); +g_test_add_func ("/vmstate/simple/skip" , test_simple_skip); +g_test_add_func ("/vmstate/simple/no_skip" , test_simple_no_skip);g_test_run ();close (temp_fd);Signature · 1 line
1.9.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 04/27] vmstate: Port versioned tests to new format
Quoted 30 lines · Dr. David Alan Gilbert
Quoted 29 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>tests/test-vmstate.c +5
-21+static void obj_versioned_copy (void *arg1,void *arg2) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .b =200 , .e =500 , .f =600 }; -vmstate_load_state (loading, &vmstate_versioned, &obj,1 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 200); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 500); - g_assert_cmpint(obj.f, ==, 600); -qemu_fclose (loading); +TestVersioned *target = arg1; +TestVersioned *source = arg2; + + target->a = source->a;
Quoted 8 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 336
Quoted 6 lines
tests/test-vmstate.c +6
-0+ target->b = source->b; + target->c = source->c; + target->d = source->d; + target->e = source->e; + target->f = source->f; + target->skip_c_e = source->skip_c_e;Why's that not simply *target = *source?
To be able to only copy some of the fields, depending on what we want to test O:-)
Quoted 9 lines
Quoted 9 lines
tests/test-vmstate.c +9
-0+TestVersioned obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +save_vmstate (&vmstate_simple_versioned, &obj_versioned); + +compare_vmstate (wire_simple_v2,sizeof (wire_simple_v2)); + + SUCCESS(load_vmstate(&vmstate_simple_versioned, &obj, &obj_clone, + obj_versioned_copy, 2, wire_simple_v2,
Quoted 9 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 354
Quoted 5 lines
tests/test-vmstate.c +5
-0+ sizeof(wire_simple_v2))); + +#define FIELD_EQUAL (name) g_assert_cmpint(obj.name, ==, obj_versioned.name) +#define FIELD_NOT_EQUAL (name) \ + g_assert_cmpint(obj.name, !=, obj_versioned.name)Given that macro is shared with the next few functions it would be seem to declare it outside of the function.
It is not always the same (see the whole series otherwise). I ended finding easier to do it this way. I ended defining it the 1st time that I needed it. That is coherent with the whole series, but I can change it (don't really matter).
Quoted 9 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 432
Quoted 7 lines
tests/test-vmstate.c +7
-0+memset (&obj,0 ,sizeof (obj)); + obj_versioned.skip_c_e = false; +save_vmstate (&vmstate_simple_skipping, &obj_versioned); + +compare_vmstate (wire_simple_no_skip,sizeof (wire_simple_no_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ A bit nasty.
Any better ideas?
Quoted 27 lines
Quoted 26 lines
tests/test-vmstate.c +26
-0+compare_vmstate (wire_simple_skip,sizeof (wire_simple_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_skip, +sizeof (wire_simple_skip) -8 )); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_NOT_EQUAL (f); + +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_skip, +sizeof (wire_simple_skip))); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_EQUAL (f);
Quoted 4 lines
Quoted 1 line
}
Couldn't those functions just be merged and take a flag? I think it is clear this way, but that is the same to me.
FIELD_EQUAL(a)FIELD_NOT_EQUAL(a)
vs
COMPARE_FIELD(a, true)COMPARE_FILED(b, false)
For me, I don't need to go to the definition of the macro in the 1st case, and I do on the second one.
Or do you mean anything different?
Thanks, Juan.
Re: [Qemu-devel] [PATCH 04/27] vmstate: Port versioned tests to new format
Quoted 40 lines · * Juan Quintela ([email protected]) wrote:
Quoted 30 lines · Dr. David Alan Gilbert
Quoted 29 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>tests/test-vmstate.c +5
-21+static void obj_versioned_copy (void *arg1,void *arg2) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ - }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .b =200 , .e =500 , .f =600 }; -vmstate_load_state (loading, &vmstate_versioned, &obj,1 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 200); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 500); - g_assert_cmpint(obj.f, ==, 600); -qemu_fclose (loading); +TestVersioned *target = arg1; +TestVersioned *source = arg2; + + target->a = source->a;Quoted 8 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 336
Quoted 6 lines
tests/test-vmstate.c +6
-0+ target->b = source->b; + target->c = source->c; + target->d = source->d; + target->e = source->e; + target->f = source->f; + target->skip_c_e = source->skip_c_e;Why's that not simply *target = *source?
Quoted 2 lines
To be able to only copy some of the fields, depending on what we want to test O:-)
But those last 7 lines do copy every field don't they?
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
tests/test-vmstate.c +9
-0+TestVersioned obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +save_vmstate (&vmstate_simple_versioned, &obj_versioned); + +compare_vmstate (wire_simple_v2,sizeof (wire_simple_v2)); + + SUCCESS(load_vmstate(&vmstate_simple_versioned, &obj, &obj_clone, + obj_versioned_copy, 2, wire_simple_v2,Quoted 9 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 354
Quoted 5 lines
tests/test-vmstate.c +5
-0+ sizeof(wire_simple_v2))); + +#define FIELD_EQUAL (name) g_assert_cmpint(obj.name, ==, obj_versioned.name) +#define FIELD_NOT_EQUAL (name) \ + g_assert_cmpint(obj.name, !=, obj_versioned.name)Given that macro is shared with the next few functions it would be seem to declare it outside of the function.
Quoted 4 lines
It is not always the same (see the whole series otherwise). I ended finding easier to do it this way. I ended defining it the 1st time that I needed it. That is coherent with the whole series, but I can change it (don't really matter).
OK.
Quoted 11 lines
Quoted 9 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 432
Quoted 7 lines
tests/test-vmstate.c +7
-0+memset (&obj,0 ,sizeof (obj)); + obj_versioned.skip_c_e = false; +save_vmstate (&vmstate_simple_skipping, &obj_versioned); + +compare_vmstate (wire_simple_no_skip,sizeof (wire_simple_no_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ A bit nasty.
Quoted 1 line
Any better ideas?
Not really; but it's very reliant on the current format - although perhaps demonstrates just how delicate that is.
Quoted 37 lines
Quoted 27 lines
Quoted 26 lines
tests/test-vmstate.c +26
-0+compare_vmstate (wire_simple_skip,sizeof (wire_simple_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_skip, +sizeof (wire_simple_skip) -8 )); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_NOT_EQUAL (f); + +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_skip, +sizeof (wire_simple_skip))); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_EQUAL (f);Quoted 4 lines
Quoted 1 line
}
Couldn't those functions just be merged and take a flag? I think it is clear this way, but that is the same to me.
FIELD_EQUAL(a)FIELD_NOT_EQUAL(a)vs
Quoted 7 lines
COMPARE_FIELD(a, true)COMPARE_FILED(b, false)For me, I don't need to go to the definition of the macro in the 1st case, and I do on the second one.
Or do you mean anything different?
I meant test_simple_no_skip vs test_simple_skip; they seem to duplicate a lot.
Dave
Quoted 3 lines
Thanks, Juan.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 04/27] vmstate: Port versioned tests to new format
Quoted 42 lines · Dr. David Alan Gilbert
Quoted 41 lines · * Juan Quintela ([email protected]) wrote:
Quoted 39 lines · Dr. David Alan Gilbert
Quoted 26 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>tests/test-vmstate.c +1
-6+static void obj_versioned_copy (void *arg1,void *arg2) { -QEMUFile *fsave =open_test_file (true); -uint8_t buf[] = { -0 ,0 ,0 ,10 ,/* a */ -0 ,0 ,0 ,30 ,/* c */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,/* d */ -QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */
tests/test-vmstate.c +0
-15- }; -qemu_put_buffer (fsave, buf,sizeof (buf)); -qemu_fclose (fsave); - -QEMUFile *loading =open_test_file (false); -TestStruct obj = { .b =200 , .e =500 , .f =600 }; -vmstate_load_state (loading, &vmstate_versioned, &obj,1 ); -g_assert (!qemu_file_get_error (loading)); - g_assert_cmpint(obj.a, ==, 10); - g_assert_cmpint(obj.b, ==, 200); - g_assert_cmpint(obj.c, ==, 30); - g_assert_cmpint(obj.d, ==, 40); - g_assert_cmpint(obj.e, ==, 500); - g_assert_cmpint(obj.f, ==, 600); -qemu_fclose (loading);tests/test-vmstate.c static void test_simple_primitive(void) · line 336
Quoted 10 lines
tests/test-vmstate.c +10
-0+TestVersioned *target = arg1; +TestVersioned *source = arg2; + + target->a = source->a; + target->b = source->b; + target->c = source->c; + target->d = source->d; + target->e = source->e; + target->f = source->f; + target->skip_c_e = source->skip_c_e;Why's that not simply *target = *source?
Quoted 4 lines
Quoted 2 lines
To be able to only copy some of the fields, depending on what we want to test O:-)
But those last 7 lines do copy every field don't they?
They do.
Quoted 38 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
tests/test-vmstate.c +10
-0+TestVersioned obj, obj_clone; + +memset (&obj,0 ,sizeof (obj)); +save_vmstate (&vmstate_simple_versioned, &obj_versioned); + +compare_vmstate (wire_simple_v2,sizeof (wire_simple_v2)); + +SUCCESS (load_vmstate (&vmstate_simple_versioned, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_v2, +sizeof (wire_simple_v2)));Quoted 9 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 354
Quoted 5 lines
(quoted diff) +2
-0+ +#define FIELD_EQUAL(name) g_assert_cmpint(obj.name, ==,obj_versioned.name)
tests/test-vmstate.c +2
-0+#define FIELD_NOT_EQUAL (name) \ + g_assert_cmpint(obj.name, !=, obj_versioned.name)Given that macro is shared with the next few functions it would be seem to declare it outside of the function.
Quoted 4 lines
It is not always the same (see the whole series otherwise). I ended finding easier to do it this way. I ended defining it the 1st time that I needed it. That is coherent with the whole series, but I can change it (don't really matter).
OK.
Quoted 11 lines
Quoted 9 lines
tests/test-vmstate.c static void test_simple_primitive(void) · line 432
Quoted 7 lines
tests/test-vmstate.c +7
-0+memset (&obj,0 ,sizeof (obj)); + obj_versioned.skip_c_e = false; +save_vmstate (&vmstate_simple_skipping, &obj_versioned); + +compare_vmstate (wire_simple_no_skip,sizeof (wire_simple_no_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ A bit nasty.
Quoted 4 lines
Quoted 1 line
Any better ideas?
Not really; but it's very reliant on the current format - although perhaps demonstrates just how delicate that is.
Yeap, anyways, that is how the test was written, nothing to do with the refactoring. Improvements on top welcome O:-)
Quoted 40 lines
Quoted 40 lines
Quoted 27 lines
Quoted 26 lines
tests/test-vmstate.c +26
-0+compare_vmstate (wire_simple_skip,sizeof (wire_simple_skip)); + +/* We abuse the fact that f has a 0x00 value in the right position */ +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,1 , wire_simple_skip, +sizeof (wire_simple_skip) -8 )); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_NOT_EQUAL (f); + +SUCCESS (load_vmstate (&vmstate_simple_skipping, &obj, &obj_clone, + obj_versioned_copy,2 , wire_simple_skip, +sizeof (wire_simple_skip))); + +FIELD_EQUAL (skip_c_e); +FIELD_EQUAL (a); +FIELD_EQUAL (b); +FIELD_NOT_EQUAL (c); +FIELD_EQUAL (d); +FIELD_NOT_EQUAL (e); +FIELD_EQUAL (f);Quoted 4 lines
Quoted 1 line
}
Couldn't those functions just be merged and take a flag? I think it is clear this way, but that is the same to me.
FIELD_EQUAL(a)FIELD_NOT_EQUAL(a)vs
COMPARE_FIELD(a, true)COMPARE_FILED(b, false)
Quoted 6 lines
Quoted 4 lines
For me, I don't need to go to the definition of the macro in the 1st case, and I do on the second one.
Or do you mean anything different?
I meant
test_simple_no_skipvstest_simple_skip; they seem to duplicate a lot.
They were there on the original test, i.e. doesn't mater for the refactoring. Basically we are doing is testing the "test" function O:-)
Later, Juan.
PATCH 5/27 vmstate: Create test functions for versions until 15
In reply to Juan QuintelaUsing macros, just to avoid repeating code.
--- include/migration/vmstate.h | 16 ++++++++++++++++ vmstate.c | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+)
include/migration/vmstate.h +16 -0
@@ -778,4 +778,20 @@ void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);void vmstate_unregister_ram (struct MemoryRegion *memory,DeviceState *dev);void vmstate_register_ram_global (struct MemoryRegion *memory); +/* Return true if version_id > X */ +bool vmstate_2_plus (void *opaque,int version_id); +bool vmstate_3_plus (void *opaque,int version_id); +bool vmstate_4_plus (void *opaque,int version_id); +bool vmstate_5_plus (void *opaque,int version_id); +bool vmstate_6_plus (void *opaque,int version_id); +bool vmstate_7_plus (void *opaque,int version_id); +bool vmstate_8_plus (void *opaque,int version_id); +bool vmstate_9_plus (void *opaque,int version_id); +bool vmstate_10_plus (void *opaque,int version_id); +bool vmstate_11_plus (void *opaque,int version_id); +bool vmstate_12_plus (void *opaque,int version_id); +bool vmstate_13_plus (void *opaque,int version_id); +bool vmstate_14_plus (void *opaque,int version_id); +bool vmstate_15_plus (void *opaque,int version_id); +#endif
vmstate.c +22 -0
@@ -671,3 +671,25 @@ const VMStateInfo vmstate_info_bitmap = { .get = get_bitmap, .put = put_bitmap, }; + +/* version is X or bigger */ +#define VMSTATE_X_PLUS (X )\ +bool vmstate_##X##_plus(void *opaque, int version_id)\ +{\ + return version_id >= X;\ +} + +VMSTATE_X_PLUS(2) +VMSTATE_X_PLUS(3) +VMSTATE_X_PLUS(4) +VMSTATE_X_PLUS(5) +VMSTATE_X_PLUS(6) +VMSTATE_X_PLUS(7) +VMSTATE_X_PLUS(8) +VMSTATE_X_PLUS(9) +VMSTATE_X_PLUS(10) +VMSTATE_X_PLUS(11) +VMSTATE_X_PLUS(12) +VMSTATE_X_PLUS(13) +VMSTATE_X_PLUS(14) +VMSTATE_X_PLUS (15 )
Signature · 1 line
1.9.3
PATCH 6/27 vmstate: Remove VMSTATE_UINTL_EQUAL_V
In reply to Juan QuintelaIt was not used anywhere.
--- include/hw/hw.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
include/hw/hw.h +4 -6
@@ -51,22 +51,20 @@ int qemu_boot_set(const char *boot_order);#if TARGET_LONG_BITS ==64 #define VMSTATE_UINTTL_V (_f, _s, _v) \ VMSTATE_UINT64_V(_f, _s, _v) -#define VMSTATE_UINTTL_EQUAL_V (_f, _s, _v) \ - VMSTATE_UINT64_EQUAL_V(_f, _s, _v) +#define VMSTATE_UINTTL_EQUAL (_f, _s) \ + VMSTATE_UINT64_EQUAL(_f, _s)#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)#else #define VMSTATE_UINTTL_V (_f, _s, _v) \ VMSTATE_UINT32_V(_f, _s, _v) -#define VMSTATE_UINTTL_EQUAL_V (_f, _s, _v) \ - VMSTATE_UINT32_EQUAL_V(_f, _s, _v) +#define VMSTATE_UINTTL_EQUAL (_f, _s) \ + VMSTATE_UINT32_EQUAL(_f, _s)#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)#endif #define VMSTATE_UINTTL (_f, _s) \ VMSTATE_UINTTL_V(_f, _s, 0) -#define VMSTATE_UINTTL_EQUAL (_f, _s) \ - VMSTATE_UINTTL_EQUAL_V(_f, _s, 0)#define VMSTATE_UINTTL_ARRAY (_f, _s, _n) \ VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
Signature · 1 line
1.9.3
PATCH 7/27 vmstate: Change VMSTATE_INTTL_V to VMSTATE_INTTL_TEST
In reply to Juan QuintelaAnd fix all users.VMSTATE_UINT64_TEST don't exist. Create it.
--- include/hw/hw.h | 10 +++++----- include/migration/vmstate.h | 3 +++ target-i386/machine.c | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-)
include/hw/hw.h +5 -5
@@ -49,22 +49,22 @@ int qemu_boot_set(const char *boot_order);#ifdef NEED_CPU_H #if TARGET_LONG_BITS ==64 -#define VMSTATE_UINTTL_V (_f, _s, _v) \ - VMSTATE_UINT64_V(_f, _s, _v) +#define VMSTATE_UINTTL_TEST (_f, _s, _t) \ + VMSTATE_UINT64_TEST(_f, _s, _t)#define VMSTATE_UINTTL_EQUAL (_f, _s) \ VMSTATE_UINT64_EQUAL(_f, _s)#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)#else -#define VMSTATE_UINTTL_V (_f, _s, _v) \ - VMSTATE_UINT32_V(_f, _s, _v) +#define VMSTATE_UINTTL_TEST (_f, _s, _t) \ + VMSTATE_UINT32_TEST(_f, _s, _t)#define VMSTATE_UINTTL_EQUAL (_f, _s) \ VMSTATE_UINT32_EQUAL(_f, _s)#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)#endif #define VMSTATE_UINTTL (_f, _s) \ - VMSTATE_UINTTL_V(_f, _s, 0) + VMSTATE_UINTTL_TEST(_f, _s, NULL)#define VMSTATE_UINTTL_ARRAY (_f, _s, _n) \ VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
include/migration/vmstate.h +3 -0
@@ -613,6 +613,9 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT32_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) +#define VMSTATE_UINT64_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) +#define VMSTATE_FLOAT64_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
target-i386/machine.c +2 -2
@@ -632,8 +632,8 @@ const VMStateDescription vmstate_x86_cpu = {/* Hack: In v7 size changed from 32 to 64 bits on x86_64 */ VMSTATE_HACK_UINT32 (env.sysenter_esp,X86CPU , less_than_7),VMSTATE_HACK_UINT32 (env.sysenter_eip,X86CPU , less_than_7), -VMSTATE_UINTTL_V (env.sysenter_esp,X86CPU ,7 ), -VMSTATE_UINTTL_V (env.sysenter_eip,X86CPU ,7 ), +VMSTATE_UINTTL_TEST (env.sysenter_esp,X86CPU , vmstate_7_plus), +VMSTATE_UINTTL_TEST (env.sysenter_eip,X86CPU , vmstate_7_plus), #elseVMSTATE_UINTTL (env.sysenter_esp,X86CPU ), VMSTATE_UINTTL(env.sysenter_eip, X86CPU),
Signature · 1 line
1.9.3
PATCH 8/27 vmstate: Remove unused VMSTATE_UINTTL_ARRAY_V
In reply to Juan Quintela--- include/hw/hw.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
include/hw/hw.h +4 -7
@@ -53,21 +53,18 @@ int qemu_boot_set(const char *boot_order); VMSTATE_UINT64_TEST(_f, _s, _t)#define VMSTATE_UINTTL_EQUAL (_f, _s) \ VMSTATE_UINT64_EQUAL(_f, _s) -#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ - VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) +#define VMSTATE_UINTTL_ARRAY (_f, _s, _n) \ + VMSTATE_UINT64_ARRAY(_f, _s, _n)#else #define VMSTATE_UINTTL_TEST (_f, _s, _t) \ VMSTATE_UINT32_TEST(_f, _s, _t)#define VMSTATE_UINTTL_EQUAL (_f, _s) \ VMSTATE_UINT32_EQUAL(_f, _s) -#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ - VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) +#define VMSTATE_UINTTL_ARRAY (_f, _s, _n) \ + VMSTATE_UINT32_ARRAY(_f, _s, _n)#endif #define VMSTATE_UINTTL (_f, _s) \ VMSTATE_UINTTL_TEST(_f, _s, NULL) -#define VMSTATE_UINTTL_ARRAY (_f, _s, _n) \ - VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0) -#endif #endif
Signature · 1 line
1.9.3
PATCH 9/27 vmstate: Test for VMSTATE_BOOL_TEST
In reply to Juan QuintelaRemove VMSTATE_BOOL_V, we are removing versioning, would use only tests.
--- include/migration/vmstate.h | 6 +++--- tests/test-vmstate.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-)
include/migration/vmstate.h +3 -3
@@ -535,8 +535,8 @@ extern const VMStateInfo vmstate_info_bitmap;VMSTATE_STRUCT_ARRAY_TEST (_field, _state, _num,NULL , _version, \ _vmsd, _type) -#define VMSTATE_BOOL_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool) +#define VMSTATE_BOOL_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool)#define VMSTATE_INT8_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
@@ -557,7 +557,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)#define VMSTATE_BOOL (_f, _s) \ - VMSTATE_BOOL_V(_f, _s, 0) + VMSTATE_BOOL_TEST(_f, _s, NULL)#define VMSTATE_INT8 (_f, _s) \ VMSTATE_INT8_V(_f, _s, 0)
tests/test-vmstate.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 10/27 vmstate: Test for VMSTATE_INT8_TEST
In reply to Juan QuintelaRemove VMSTATE_INT8_V, we are removing versioning, would use only tests.
--- include/migration/vmstate.h | 6 +++--- tests/test-vmstate.c | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-)
include/migration/vmstate.h +3 -3
@@ -538,8 +538,8 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_BOOL_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool) -#define VMSTATE_INT8_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) +#define VMSTATE_INT8_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)#define VMSTATE_INT16_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)#define VMSTATE_INT32_V (_f, _s, _v) \
@@ -560,7 +560,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_BOOL_TEST(_f, _s, NULL)#define VMSTATE_INT8 (_f, _s) \ - VMSTATE_INT8_V(_f, _s, 0) + VMSTATE_INT8_TEST(_f, _s, NULL)#define VMSTATE_INT16 (_f, _s) \ VMSTATE_INT16_V(_f, _s, 0)#define VMSTATE_INT32 (_f, _s) \
tests/test-vmstate.c +4 -0
@@ -289,12 +289,15 @@ static const VMStateDescription vmstate_simple_test = { .fields = (VMStateField[]) {VMSTATE_BOOL_TEST (b_1, TestSimple, test_true),VMSTATE_BOOL_TEST (b_2, TestSimple, test_false), +VMSTATE_INT8_TEST (i8_1, TestSimple, test_true), +VMSTATE_INT8_TEST (i8_2, TestSimple, test_false),VMSTATE_END_OF_LIST () } };uint8_t wire_simple_test[] = {/* b_1 */ 0x01 , +/* i8_1 */ 0x41 ,QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ };
@@ -312,6 +315,7 @@ static void test_simple_test(void) sizeof(wire_simple_test)));FIELD_EQUAL (b_1); +FIELD_EQUAL (i8_1); }#undef FIELD_EQUAL
Signature · 1 line
1.9.3
PATCH 11/27 vmstate: Test for VMSTATE_INT16_TEST
In reply to Juan QuintelaRemove VMSTATES_INT16_V, we are removing versioning, would use only tests.
--- include/migration/vmstate.h | 6 +++--- tests/test-vmstate.c | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-)
include/migration/vmstate.h +3 -3
@@ -540,8 +540,8 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT8_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t) -#define VMSTATE_INT16_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) +#define VMSTATE_INT16_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)#define VMSTATE_INT32_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)#define VMSTATE_INT64_V (_f, _s, _v) \
@@ -562,7 +562,7 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT8 (_f, _s) \ VMSTATE_INT8_TEST(_f, _s, NULL)#define VMSTATE_INT16 (_f, _s) \ - VMSTATE_INT16_V(_f, _s, 0) + VMSTATE_INT16_TEST(_f, _s, NULL)#define VMSTATE_INT32 (_f, _s) \ VMSTATE_INT32_V(_f, _s, 0)#define VMSTATE_INT64 (_f, _s) \
tests/test-vmstate.c +4 -0
@@ -291,6 +291,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_BOOL_TEST (b_2, TestSimple, test_false),VMSTATE_INT8_TEST (i8_1, TestSimple, test_true),VMSTATE_INT8_TEST (i8_2, TestSimple, test_false), +VMSTATE_INT16_TEST (i16_1, TestSimple, test_true), +VMSTATE_INT16_TEST (i16_2, TestSimple, test_false), VMSTATE_END_OF_LIST() } };
@@ -298,6 +300,7 @@ static const VMStateDescription vmstate_simple_test = {uint8_t wire_simple_test[] = {/* b_1 */ 0x01 ,/* i8_1 */ 0x41 , +/* i16_1 */ 0x02 ,0x00 ,QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ };
@@ -316,6 +319,7 @@ static void test_simple_test(void)FIELD_EQUAL (b_1);FIELD_EQUAL (i8_1); +FIELD_EQUAL (i16_1); }#undef FIELD_EQUAL
Signature · 1 line
1.9.3
PATCH 12/27 vmstate: Test for VMSTATE_INT32_TEST
In reply to Juan QuintelaRemove VMSTATE_INT32_V, we are removing versioning. Move all users to use tests.
--- hw/input/ps2.c | 2 +- include/migration/vmstate.h | 6 +++--- target-i386/machine.c | 4 ++-- tests/test-vmstate.c | 4 ++++ 4 files changed, 10 insertions(+), 6 deletions(-)
hw/input/ps2.c +1 -1
@@ -700,7 +700,7 @@ static const VMStateDescription vmstate_ps2_keyboard = {VMSTATE_STRUCT (common, PS2KbdState,0 , vmstate_ps2_common, PS2State),VMSTATE_INT32 (scan_enabled, PS2KbdState),VMSTATE_INT32 (translate, PS2KbdState), -VMSTATE_INT32_V (scancode_set, PS2KbdState,3 ), +VMSTATE_INT32_TEST (scancode_set, PS2KbdState, vmstate_3_plus),VMSTATE_END_OF_LIST () }, .subsections = (VMStateSubsection []) {
include/migration/vmstate.h +3 -3
@@ -542,8 +542,8 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)#define VMSTATE_INT16_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t) -#define VMSTATE_INT32_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) +#define VMSTATE_INT32_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)#define VMSTATE_INT64_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
@@ -564,7 +564,7 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT16 (_f, _s) \ VMSTATE_INT16_TEST(_f, _s, NULL)#define VMSTATE_INT32 (_f, _s) \ - VMSTATE_INT32_V(_f, _s, 0) + VMSTATE_INT32_TEST(_f, _s, NULL)#define VMSTATE_INT64 (_f, _s) \ VMSTATE_INT64_V(_f, _s, 0)
target-i386/machine.c +2 -2
@@ -679,10 +679,10 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT64_V (env.mtrr_deftype,X86CPU ,8 ),VMSTATE_MTRR_VARS (env.mtrr_var,X86CPU ,8 ,8 ),/* KVM-related states */ -VMSTATE_INT32_V (env.interrupt_injected,X86CPU ,9 ), +VMSTATE_INT32_TEST (env.interrupt_injected,X86CPU , vmstate_9_plus),VMSTATE_UINT32_V (env.mp_state,X86CPU ,9 ),VMSTATE_UINT64_V (env.tsc,X86CPU ,9 ), -VMSTATE_INT32_V (env.exception_injected,X86CPU ,11 ), +VMSTATE_INT32_TEST (env.exception_injected,X86CPU , vmstate_11_plus),VMSTATE_UINT8_V (env.soft_interrupt,X86CPU ,11 ),VMSTATE_UINT8_V (env.nmi_injected,X86CPU ,11 ), VMSTATE_UINT8_V(env.nmi_pending, X86CPU, 11),
tests/test-vmstate.c +4 -0
@@ -293,6 +293,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_INT8_TEST (i8_2, TestSimple, test_false),VMSTATE_INT16_TEST (i16_1, TestSimple, test_true),VMSTATE_INT16_TEST (i16_2, TestSimple, test_false), +VMSTATE_INT32_TEST (i32_1, TestSimple, test_true), +VMSTATE_INT32_TEST (i32_2, TestSimple, test_false), VMSTATE_END_OF_LIST() } };
@@ -301,6 +303,7 @@ uint8_t wire_simple_test[] = {/* b_1 */ 0x01 ,/* i8_1 */ 0x41 ,/* i16_1 */ 0x02 ,0x00 , +/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -320,6 +323,7 @@ static void test_simple_test(void)FIELD_EQUAL (b_1);FIELD_EQUAL (i8_1);FIELD_EQUAL (i16_1); +FIELD_EQUAL (i32_1); }#undef FIELD_EQUAL
Signature · 1 line
1.9.3
PATCH 13/27 vmstate: test for VMSTATE_INT64_TEST
In reply to Juan QuintelaRemove VMSTATE_INT64_V, we are removing versioning. Move all users to VMSTATE_INT64_TEST.
--- cpus.c | 2 +- hw/timer/mc146818rtc.c | 2 +- hw/usb/hcd-uhci.c | 2 +- include/migration/vmstate.h | 6 +++--- tests/test-vmstate.c | 4 ++++ 5 files changed, 10 insertions(+), 6 deletions(-)
cpus.c +1 -1
@@ -433,7 +433,7 @@ static const VMStateDescription vmstate_timers = { .fields = (VMStateField[]) {VMSTATE_INT64 (cpu_ticks_offset, TimersState),VMSTATE_INT64 (dummy, TimersState), -VMSTATE_INT64_V (cpu_clock_offset, TimersState,2 ), +VMSTATE_INT64_TEST (cpu_clock_offset, TimersState, vmstate_2_plus),VMSTATE_END_OF_LIST () } };
hw/timer/mc146818rtc.c +1 -1
@@ -732,7 +732,7 @@ static const VMStateDescription vmstate_rtc = {VMSTATE_UINT32_V (period, RTCState,2 ),VMSTATE_UINT64_V (base_rtc, RTCState,3 ),VMSTATE_UINT64_V (last_update, RTCState,3 ), -VMSTATE_INT64_V (offset, RTCState,3 ), +VMSTATE_INT64_TEST (offset, RTCState, vmstate_3_plus),VMSTATE_TIMER_V (update_timer, RTCState,3 ),VMSTATE_UINT64_V (next_alarm_time, RTCState,3 ),VMSTATE_END_OF_LIST ()
hw/usb/hcd-uhci.c +1 -1
@@ -423,7 +423,7 @@ static const VMStateDescription vmstate_uhci = {VMSTATE_UINT8 (sof_timing, UHCIState),VMSTATE_UINT8 (status2, UHCIState),VMSTATE_TIMER (frame_timer, UHCIState), -VMSTATE_INT64_V (expire_time, UHCIState,2 ), +VMSTATE_INT64_TEST (expire_time, UHCIState, vmstate_3_plus),VMSTATE_UINT32_V (pending_int_mask, UHCIState,3 ), VMSTATE_END_OF_LIST() }
include/migration/vmstate.h +3 -3
@@ -544,8 +544,8 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)#define VMSTATE_INT32_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t) -#define VMSTATE_INT64_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) +#define VMSTATE_INT64_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)#define VMSTATE_UINT8_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
@@ -566,7 +566,7 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT32 (_f, _s) \ VMSTATE_INT32_TEST(_f, _s, NULL)#define VMSTATE_INT64 (_f, _s) \ - VMSTATE_INT64_V(_f, _s, 0) + VMSTATE_INT64_TEST(_f, _s, NULL)#define VMSTATE_UINT8 (_f, _s) \ VMSTATE_UINT8_V(_f, _s, 0)
tests/test-vmstate.c +4 -0
@@ -295,6 +295,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_INT16_TEST (i16_2, TestSimple, test_false),VMSTATE_INT32_TEST (i32_1, TestSimple, test_true),VMSTATE_INT32_TEST (i32_2, TestSimple, test_false), +VMSTATE_INT64_TEST (i64_1, TestSimple, test_true), +VMSTATE_INT64_TEST (i64_2, TestSimple, test_false), VMSTATE_END_OF_LIST() } };
@@ -304,6 +306,7 @@ uint8_t wire_simple_test[] = {/* i8_1 */ 0x41 ,/* i16_1 */ 0x02 ,0x00 ,/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , +/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -324,6 +327,7 @@ static void test_simple_test(void)FIELD_EQUAL (i8_1);FIELD_EQUAL (i16_1);FIELD_EQUAL (i32_1); +FIELD_EQUAL (i64_1); }#undef FIELD_EQUAL
Signature · 1 line
1.9.3
PATCH 14/27 vmstate: Test for VMSTATE_UINT8_TEST
In reply to Juan QuintelaRemove VMSTATE_UINT8_V, we are removing versioning. Move all users to VMSTATE_UINT8_TEST.
--- hw/char/serial.c | 2 +- hw/ide/core.c | 2 +- hw/net/ne2000.c | 2 +- hw/timer/ds1338.c | 2 +- hw/timer/hpet.c | 2 +- include/migration/vmstate.h | 9 +++------ target-i386/machine.c | 10 +++++----- tests/test-vmstate.c | 7 ++++++- 8 files changed, 19 insertions(+), 17 deletions(-)
hw/char/serial.c +1 -1
@@ -612,7 +612,7 @@ const VMStateDescription vmstate_serial = {VMSTATE_UINT8 (lsr, SerialState),VMSTATE_UINT8 (msr, SerialState),VMSTATE_UINT8 (scr, SerialState), -VMSTATE_UINT8_V (fcr_vmstate, SerialState,3 ), +VMSTATE_UINT8_TEST (fcr_vmstate, SerialState, vmstate_3_plus), VMSTATE_END_OF_LIST() } };
hw/ide/core.c +1 -1
@@ -2404,7 +2404,7 @@ const VMStateDescription vmstate_ide_drive = {VMSTATE_UINT8 (lba48, IDEState),VMSTATE_UINT8 (sense_key, IDEState),VMSTATE_UINT8 (asc, IDEState), -VMSTATE_UINT8_V (cdrom_changed, IDEState,3 ), +VMSTATE_UINT8_TEST (cdrom_changed, IDEState, vmstate_3_plus),VMSTATE_END_OF_LIST () }, .subsections = (VMStateSubsection []) {
hw/net/ne2000.c +1 -1
@@ -617,7 +617,7 @@ const VMStateDescription vmstate_ne2000 = { .minimum_version_id = 0, .post_load = ne2000_post_load, .fields = (VMStateField []) { -VMSTATE_UINT8_V (rxcr, NE2000State,2 ), +VMSTATE_UINT8_TEST (rxcr, NE2000State, vmstate_2_plus),VMSTATE_UINT8 (cmd, NE2000State),VMSTATE_UINT32 (start, NE2000State),VMSTATE_UINT32 (stop, NE2000State),
hw/timer/ds1338.c +1 -1
@@ -43,7 +43,7 @@ static const VMStateDescription vmstate_ds1338 = { .fields = (VMStateField[]) {VMSTATE_I2C_SLAVE (parent_obj, DS1338State),VMSTATE_INT64 (offset, DS1338State), -VMSTATE_UINT8_V (wday_offset, DS1338State,2 ), +VMSTATE_UINT8_TEST (wday_offset, DS1338State, vmstate_2_plus),VMSTATE_UINT8_ARRAY (nvram, DS1338State,NVRAM_SIZE ),VMSTATE_INT32 (ptr, DS1338State),VMSTATE_BOOL (addr_byte, DS1338State),
hw/timer/hpet.c +1 -1
@@ -315,7 +315,7 @@ static const VMStateDescription vmstate_hpet = {VMSTATE_UINT64 (config, HPETState),VMSTATE_UINT64 (isr, HPETState),VMSTATE_UINT64 (hpet_counter, HPETState), -VMSTATE_UINT8_V (num_timers, HPETState,2 ), +VMSTATE_UINT8_TEST (num_timers, HPETState, vmstate_2_plus),VMSTATE_VALIDATE ("num_timers in range" , hpet_validate_num_timers),VMSTATE_STRUCT_VARRAY_UINT8 (timer, HPETState, num_timers,0 , vmstate_hpet_timer, HPETTimer),
include/migration/vmstate.h +3 -6
@@ -547,8 +547,8 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT64_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t) -#define VMSTATE_UINT8_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) +#define VMSTATE_UINT8_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)#define VMSTATE_UINT16_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)#define VMSTATE_UINT32_V (_f, _s, _v) \
@@ -569,7 +569,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_INT64_TEST(_f, _s, NULL)#define VMSTATE_UINT8 (_f, _s) \ - VMSTATE_UINT8_V(_f, _s, 0) + VMSTATE_UINT8_TEST(_f, _s, NULL)#define VMSTATE_UINT16 (_f, _s) \ VMSTATE_UINT16_V(_f, _s, 0)#define VMSTATE_UINT32 (_f, _s) \
@@ -604,9 +604,6 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT32_POSITIVE_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) -#define VMSTATE_UINT8_TEST (_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) -#define VMSTATE_UINT16_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
target-i386/machine.c +5 -5
@@ -673,7 +673,7 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT16_V (env.intercept_dr_read,X86CPU ,5 ),VMSTATE_UINT16_V (env.intercept_dr_write,X86CPU ,5 ),VMSTATE_UINT32_V (env.intercept_exceptions,X86CPU ,5 ), -VMSTATE_UINT8_V (env.v_tpr,X86CPU ,5 ), +VMSTATE_UINT8_TEST (env.v_tpr,X86CPU , vmstate_5_plus),/* MTRRs */ VMSTATE_UINT64_ARRAY_V (env.mtrr_fixed,X86CPU ,11 ,8 ), VMSTATE_UINT64_V(env.mtrr_deftype, X86CPU, 8),
@@ -683,10 +683,10 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT32_V (env.mp_state,X86CPU ,9 ),VMSTATE_UINT64_V (env.tsc,X86CPU ,9 ),VMSTATE_INT32_TEST (env.exception_injected,X86CPU , vmstate_11_plus), -VMSTATE_UINT8_V (env.soft_interrupt,X86CPU ,11 ), -VMSTATE_UINT8_V (env.nmi_injected,X86CPU ,11 ), -VMSTATE_UINT8_V (env.nmi_pending,X86CPU ,11 ), -VMSTATE_UINT8_V (env.has_error_code,X86CPU ,11 ), +VMSTATE_UINT8_TEST (env.soft_interrupt,X86CPU , vmstate_11_plus), +VMSTATE_UINT8_TEST (env.nmi_injected,X86CPU , vmstate_11_plus), +VMSTATE_UINT8_TEST (env.nmi_pending,X86CPU , vmstate_11_plus), +VMSTATE_UINT8_TEST (env.has_error_code,X86CPU , vmstate_11_plus),VMSTATE_UINT32_V (env.sipi_vector,X86CPU ,11 ),/* MCE */ VMSTATE_UINT64_V(env.mcg_cap, X86CPU, 10),
tests/test-vmstate.c +6 -1
@@ -150,7 +150,7 @@ static int load_vmstate(const VMStateDescription *desc, typedef struct TestSimple { bool b_1, b_2; - uint8_t u8_1; + uint8_t u8_1, u8_2; uint16_t u16_1; uint32_t u32_1; uint64_t u64_1;
@@ -166,6 +166,7 @@ TestSimple obj_simple = { .b_1 = true, .b_2 = false, .u8_1 = 130, + .u8_2 = 222, .u16_1 = 512, .u32_1 = 70000, .u64_1 = 12121212,
@@ -297,6 +298,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_INT32_TEST (i32_2, TestSimple, test_false),VMSTATE_INT64_TEST (i64_1, TestSimple, test_true),VMSTATE_INT64_TEST (i64_2, TestSimple, test_false), +VMSTATE_UINT8_TEST (u8_1, TestSimple, test_true), +VMSTATE_UINT8_TEST (u8_2, TestSimple, test_false), VMSTATE_END_OF_LIST() } };
@@ -307,6 +310,7 @@ uint8_t wire_simple_test[] = {/* i16_1 */ 0x02 ,0x00 ,/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 ,/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* u8_1 */ 0x82 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -328,6 +332,7 @@ static void test_simple_test(void)FIELD_EQUAL (i16_1);FIELD_EQUAL (i32_1);FIELD_EQUAL (i64_1); +FIELD_EQUAL (u8_1); }#undef FIELD_EQUAL
Signature · 1 line
1.9.3
PATCH 15/27 vmstate: Test for VMSTATE_UINT16_TEST
In reply to Juan QuintelaRemove VMSTATE_UINT16_V, we are removing versioning. Move all users to VMSTATE_UINT16_TEST.
--- hw/char/serial.c | 2 +- hw/net/lan9118.c | 4 ++-- include/migration/vmstate.h | 9 +++------ target-i386/machine.c | 8 ++++---- tests/test-vmstate.c | 7 ++++++- 5 files changed, 16 insertions(+), 14 deletions(-)
hw/char/serial.c +1 -1
@@ -603,7 +603,7 @@ const VMStateDescription vmstate_serial = { .pre_save = serial_pre_save, .post_load = serial_post_load, .fields = (VMStateField []) { -VMSTATE_UINT16_V (divider, SerialState,2 ), +VMSTATE_UINT16_TEST (divider, SerialState, vmstate_2_plus),VMSTATE_UINT8 (rbr, SerialState),VMSTATE_UINT8 (ier, SerialState),VMSTATE_UINT8 (iir, SerialState),
hw/net/lan9118.c +2 -2
@@ -310,8 +310,8 @@ static const VMStateDescription vmstate_lan9118 = {VMSTATE_INT32 (rxp_pad, lan9118_state),VMSTATE_UINT32_V (write_word_prev_offset, lan9118_state,2 ),VMSTATE_UINT32_V (write_word_n, lan9118_state,2 ), -VMSTATE_UINT16_V (write_word_l, lan9118_state,2 ), -VMSTATE_UINT16_V (write_word_h, lan9118_state,2 ), +VMSTATE_UINT16_TEST (write_word_l, lan9118_state, vmstate_2_plus), +VMSTATE_UINT16_TEST (write_word_h, lan9118_state, vmstate_2_plus),VMSTATE_UINT32_V (read_word_prev_offset, lan9118_state,2 ),VMSTATE_UINT32_V (read_word_n, lan9118_state,2 ), VMSTATE_UINT32_V(read_long, lan9118_state, 2),
include/migration/vmstate.h +3 -6
@@ -549,8 +549,8 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT8_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) -#define VMSTATE_UINT16_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) +#define VMSTATE_UINT16_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)#define VMSTATE_UINT32_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)#define VMSTATE_UINT64_V (_f, _s, _v) \
@@ -571,7 +571,7 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT8 (_f, _s) \ VMSTATE_UINT8_TEST(_f, _s, NULL)#define VMSTATE_UINT16 (_f, _s) \ - VMSTATE_UINT16_V(_f, _s, 0) + VMSTATE_UINT16_TEST(_f, _s, NULL)#define VMSTATE_UINT32 (_f, _s) \ VMSTATE_UINT32_V(_f, _s, 0)#define VMSTATE_UINT64 (_f, _s) \
@@ -604,9 +604,6 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT32_POSITIVE_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) -#define VMSTATE_UINT16_TEST (_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t) -#define VMSTATE_UINT32_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
target-i386/machine.c +4 -4
@@ -668,10 +668,10 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT64_V (env.vm_vmcb,X86CPU ,5 ),VMSTATE_UINT64_V (env.tsc_offset,X86CPU ,5 ),VMSTATE_UINT64_V (env.intercept,X86CPU ,5 ), -VMSTATE_UINT16_V (env.intercept_cr_read,X86CPU ,5 ), -VMSTATE_UINT16_V (env.intercept_cr_write,X86CPU ,5 ), -VMSTATE_UINT16_V (env.intercept_dr_read,X86CPU ,5 ), -VMSTATE_UINT16_V (env.intercept_dr_write,X86CPU ,5 ), +VMSTATE_UINT16_TEST (env.intercept_cr_read,X86CPU , vmstate_5_plus), +VMSTATE_UINT16_TEST (env.intercept_cr_write,X86CPU , vmstate_5_plus), +VMSTATE_UINT16_TEST (env.intercept_dr_read,X86CPU , vmstate_5_plus), +VMSTATE_UINT16_TEST (env.intercept_dr_write,X86CPU , vmstate_5_plus),VMSTATE_UINT32_V (env.intercept_exceptions,X86CPU ,5 ), VMSTATE_UINT8_TEST(env.v_tpr, X86CPU, vmstate_5_plus),/* MTRRs */
tests/test-vmstate.c +6 -1
@@ -151,7 +151,7 @@ static int load_vmstate(const VMStateDescription *desc, typedef struct TestSimple { bool b_1, b_2; uint8_t u8_1, u8_2; - uint16_t u16_1; + uint16_t u16_1, u16_2; uint32_t u32_1; uint64_t u64_1; int8_t i8_1, i8_2;
@@ -168,6 +168,7 @@ TestSimple obj_simple = { .u8_1 = 130, .u8_2 = 222, .u16_1 = 512, + .u16_2 = 666, .u32_1 = 70000, .u64_1 = 12121212, .i8_1 = 65,
@@ -300,6 +301,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_INT64_TEST (i64_2, TestSimple, test_false),VMSTATE_UINT8_TEST (u8_1, TestSimple, test_true),VMSTATE_UINT8_TEST (u8_2, TestSimple, test_false), +VMSTATE_UINT16_TEST (u16_1, TestSimple, test_true), +VMSTATE_UINT16_TEST (u16_2, TestSimple, test_false), VMSTATE_END_OF_LIST() } };
@@ -311,6 +314,7 @@ uint8_t wire_simple_test[] = {/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 ,/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c ,/* u8_1 */ 0x82 , +/* u16_1 */ 0x02 ,0x00 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -333,6 +337,7 @@ static void test_simple_test(void)FIELD_EQUAL (i32_1);FIELD_EQUAL (i64_1);FIELD_EQUAL (u8_1); +FIELD_EQUAL (u16_1); }#undef FIELD_EQUAL
Signature · 1 line
1.9.3
PATCH 16/27 vmstate: Test for VMSTATE_UINT32_TEST
In reply to Juan QuintelaRemove VMSTATE_UINT32_V, we are removing versioning. Move all users to VMSTATE_UINT32_TEST.
--- hw/arm/stellaris.c | 2 +- hw/display/pl110.c | 2 +- hw/gpio/pl061.c | 2 +- hw/intc/ioapic_common.c | 2 +- hw/misc/arm_sysctl.c | 10 +++++----- hw/net/lan9118.c | 14 ++++++++------ hw/net/rtl8139.c | 2 +- hw/nvram/fw_cfg.c | 2 +- hw/timer/i8254_common.c | 3 ++- hw/timer/mc146818rtc.c | 4 ++-- hw/usb/hcd-ehci.c | 4 ++-- hw/usb/hcd-uhci.c | 2 +- include/migration/vmstate.h | 9 +++------ target-i386/machine.c | 10 +++++----- tests/test-vmstate.c | 14 +++++++++----- 15 files changed, 43 insertions(+), 39 deletions(-)
hw/arm/stellaris.c +1 -1
@@ -657,7 +657,7 @@ static const VMStateDescription vmstate_stellaris_sys = {VMSTATE_UINT32 (int_status, ssys_state),VMSTATE_UINT32 (resc, ssys_state),VMSTATE_UINT32 (rcc, ssys_state), -VMSTATE_UINT32_V (rcc2, ssys_state,2 ), +VMSTATE_UINT32_TEST (rcc2, ssys_state, vmstate_2_plus),VMSTATE_UINT32_ARRAY (rcgc, ssys_state,3 ),VMSTATE_UINT32_ARRAY (scgc, ssys_state,3 ), VMSTATE_UINT32_ARRAY(dcgc, ssys_state, 3),
hw/display/pl110.c +1 -1
@@ -86,7 +86,7 @@ static const VMStateDescription vmstate_pl110 = {VMSTATE_INT32 (invalidate, PL110State),VMSTATE_UINT32_ARRAY (palette, PL110State,256 ),VMSTATE_UINT32_ARRAY (raw_palette, PL110State,128 ), -VMSTATE_UINT32_V (mux_ctrl, PL110State,2 ), +VMSTATE_UINT32_TEST (mux_ctrl, PL110State, vmstate_2_plus), VMSTATE_END_OF_LIST() } };
hw/gpio/pl061.c +1 -1
@@ -86,7 +86,7 @@ static const VMStateDescription vmstate_pl061 = {VMSTATE_UINT32 (den, PL061State),VMSTATE_UINT32 (cr, PL061State),VMSTATE_UINT32 (float_high, PL061State), -VMSTATE_UINT32_V (amsel, PL061State,2 ), +VMSTATE_UINT32_TEST (amsel, PL061State, vmstate_2_plus), VMSTATE_END_OF_LIST() } };
hw/intc/ioapic_common.c +1 -1
@@ -92,7 +92,7 @@ static const VMStateDescription vmstate_ioapic_common = {VMSTATE_UINT8 (id, IOAPICCommonState),VMSTATE_UINT8 (ioregsel, IOAPICCommonState),VMSTATE_UNUSED_V (2 ,8 ),/* to account for qemu-kvm's v2 format */ -VMSTATE_UINT32_V (irr, IOAPICCommonState,2 ), +VMSTATE_UINT32_TEST (irr, IOAPICCommonState, vmstate_2_plus),VMSTATE_UINT64_ARRAY (ioredtbl, IOAPICCommonState,IOAPIC_NUM_PINS ), VMSTATE_END_OF_LIST() }
hw/misc/arm_sysctl.c +5 -5
@@ -60,11 +60,11 @@ static const VMStateDescription vmstate_arm_sysctl = {VMSTATE_UINT32 (flags, arm_sysctl_state),VMSTATE_UINT32 (nvflags, arm_sysctl_state),VMSTATE_UINT32 (resetlevel, arm_sysctl_state), -VMSTATE_UINT32_V (sys_mci, arm_sysctl_state,2 ), -VMSTATE_UINT32_V (sys_cfgdata, arm_sysctl_state,2 ), -VMSTATE_UINT32_V (sys_cfgctrl, arm_sysctl_state,2 ), -VMSTATE_UINT32_V (sys_cfgstat, arm_sysctl_state,2 ), -VMSTATE_UINT32_V (sys_clcd, arm_sysctl_state,3 ), +VMSTATE_UINT32_TEST (sys_mci, arm_sysctl_state, vmstate_2_plus), +VMSTATE_UINT32_TEST (sys_cfgdata, arm_sysctl_state, vmstate_2_plus), +VMSTATE_UINT32_TEST (sys_cfgctrl, arm_sysctl_state, vmstate_2_plus), +VMSTATE_UINT32_TEST (sys_cfgstat, arm_sysctl_state, vmstate_2_plus), +VMSTATE_UINT32_TEST (sys_clcd, arm_sysctl_state, vmstate_3_plus),VMSTATE_UINT32_ARRAY_V (mb_clock, arm_sysctl_state,6 ,4 ),VMSTATE_VARRAY_UINT32 (db_clock, arm_sysctl_state, db_num_clocks, 4, vmstate_info_uint32, uint32_t),
hw/net/lan9118.c +8 -6
@@ -308,14 +308,16 @@ static const VMStateDescription vmstate_lan9118 = { VMSTATE_INT32(rxp_offset, lan9118_state), VMSTATE_INT32(rxp_size, lan9118_state), VMSTATE_INT32(rxp_pad, lan9118_state), - VMSTATE_UINT32_V(write_word_prev_offset, lan9118_state, 2), - VMSTATE_UINT32_V(write_word_n, lan9118_state, 2), + VMSTATE_UINT32_TEST(write_word_prev_offset, lan9118_state, + vmstate_2_plus), + VMSTATE_UINT32_TEST(write_word_n, lan9118_state, vmstate_2_plus), VMSTATE_UINT16_TEST(write_word_l, lan9118_state, vmstate_2_plus), VMSTATE_UINT16_TEST(write_word_h, lan9118_state, vmstate_2_plus), - VMSTATE_UINT32_V(read_word_prev_offset, lan9118_state, 2), - VMSTATE_UINT32_V(read_word_n, lan9118_state, 2), - VMSTATE_UINT32_V(read_long, lan9118_state, 2), - VMSTATE_UINT32_V(mode_16bit, lan9118_state, 2), + VMSTATE_UINT32_TEST(read_word_prev_offset, lan9118_state, + vmstate_2_plus), + VMSTATE_UINT32_TEST(read_word_n, lan9118_state, vmstate_2_plus), + VMSTATE_UINT32_TEST(read_long, lan9118_state, vmstate_2_plus), + VMSTATE_UINT32_TEST(mode_16bit, lan9118_state, vmstate_2_plus),VMSTATE_END_OF_LIST () } };
hw/net/rtl8139.c +1 -1
@@ -3363,7 +3363,7 @@ static const VMStateDescription vmstate_rtl8139 = {VMSTATE_STRUCT (tally_counters, RTL8139State,0 , vmstate_tally_counters, RTL8139TallyCounters), -VMSTATE_UINT32_V (cplus_enabled, RTL8139State,4 ), +VMSTATE_UINT32_TEST (cplus_enabled, RTL8139State, vmstate_4_plus),VMSTATE_END_OF_LIST () }, .subsections = (VMStateSubsection []) {
hw/nvram/fw_cfg.c +1 -1
@@ -380,7 +380,7 @@ static const VMStateDescription vmstate_fw_cfg = { .fields = (VMStateField[]) {VMSTATE_UINT16 (cur_entry, FWCfgState),VMSTATE_UINT16_HACK (cur_offset, FWCfgState, is_version_1), -VMSTATE_UINT32_V (cur_offset, FWCfgState,2 ), +VMSTATE_UINT32_TEST (cur_offset, FWCfgState, vmstate_2_plus),VMSTATE_END_OF_LIST () } };
hw/timer/i8254_common.c +2 -1
@@ -266,7 +266,8 @@ static const VMStateDescription vmstate_pit_common = { .pre_save = pit_dispatch_pre_save, .post_load = pit_dispatch_post_load, .fields = (VMStateField []) { -VMSTATE_UINT32_V (channels[0 ].irq_disabled, PITCommonState,3 ), +VMSTATE_UINT32_TEST (channels[0 ].irq_disabled, PITCommonState, + vmstate_3_plus),VMSTATE_STRUCT_ARRAY (channels, PITCommonState,3 ,2 , vmstate_pit_channel, PITChannelState), VMSTATE_INT64(channels[0].next_transition_time,
hw/timer/mc146818rtc.c +2 -2
@@ -728,8 +728,8 @@ static const VMStateDescription vmstate_rtc = {VMSTATE_TIMER (periodic_timer, RTCState),VMSTATE_INT64 (next_periodic_time, RTCState),VMSTATE_UNUSED (3 *8 ), -VMSTATE_UINT32_V (irq_coalesced, RTCState,2 ), -VMSTATE_UINT32_V (period, RTCState,2 ), +VMSTATE_UINT32_TEST (irq_coalesced, RTCState, vmstate_2_plus), +VMSTATE_UINT32_TEST (period, RTCState, vmstate_2_plus),VMSTATE_UINT64_V (base_rtc, RTCState,3 ),VMSTATE_UINT64_V (last_update, RTCState,3 ), VMSTATE_INT64_TEST(offset, RTCState, vmstate_3_plus),
hw/usb/hcd-ehci.c +2 -2
@@ -2419,8 +2419,8 @@ const VMStateDescription vmstate_ehci = {/* mmio registers */ VMSTATE_UINT32 (usbcmd, EHCIState),VMSTATE_UINT32 (usbsts, EHCIState), -VMSTATE_UINT32_V (usbsts_pending, EHCIState,2 ), -VMSTATE_UINT32_V (usbsts_frindex, EHCIState,2 ), +VMSTATE_UINT32_TEST (usbsts_pending, EHCIState, vmstate_2_plus), +VMSTATE_UINT32_TEST (usbsts_frindex, EHCIState, vmstate_2_plus),VMSTATE_UINT32 (usbintr, EHCIState),VMSTATE_UINT32 (frindex, EHCIState), VMSTATE_UINT32(ctrldssegment, EHCIState),
hw/usb/hcd-uhci.c +1 -1
@@ -424,7 +424,7 @@ static const VMStateDescription vmstate_uhci = {VMSTATE_UINT8 (status2, UHCIState),VMSTATE_TIMER (frame_timer, UHCIState),VMSTATE_INT64_TEST (expire_time, UHCIState, vmstate_3_plus), -VMSTATE_UINT32_V (pending_int_mask, UHCIState,3 ), +VMSTATE_UINT32_TEST (pending_int_mask, UHCIState, vmstate_3_plus), VMSTATE_END_OF_LIST() } };
include/migration/vmstate.h +3 -6
@@ -551,8 +551,8 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)#define VMSTATE_UINT16_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t) -#define VMSTATE_UINT32_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) +#define VMSTATE_UINT32_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)#define VMSTATE_UINT64_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
@@ -573,7 +573,7 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT16 (_f, _s) \ VMSTATE_UINT16_TEST(_f, _s, NULL)#define VMSTATE_UINT32 (_f, _s) \ - VMSTATE_UINT32_V(_f, _s, 0) + VMSTATE_UINT32_TEST(_f, _s, NULL)#define VMSTATE_UINT64 (_f, _s) \ VMSTATE_UINT64_V(_f, _s, 0)
@@ -604,9 +604,6 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT32_POSITIVE_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) -#define VMSTATE_UINT32_TEST (_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) -#define VMSTATE_UINT64_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
target-i386/machine.c +5 -5
@@ -658,10 +658,10 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT64 (env.fmask,X86CPU ),VMSTATE_UINT64 (env.kernelgsbase,X86CPU ), #endif -VMSTATE_UINT32_V (env.smbase,X86CPU ,4 ), +VMSTATE_UINT32_TEST (env.smbase,X86CPU , vmstate_4_plus),VMSTATE_UINT64_V (env.pat,X86CPU ,5 ), -VMSTATE_UINT32_V (env.hflags2,X86CPU ,5 ), +VMSTATE_UINT32_TEST (env.hflags2,X86CPU , vmstate_5_plus),VMSTATE_UINT32_TEST (parent_obj.halted,X86CPU , version_is_5), VMSTATE_UINT64_V(env.vm_hsave, X86CPU, 5),
@@ -672,7 +672,7 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT16_TEST (env.intercept_cr_write,X86CPU , vmstate_5_plus),VMSTATE_UINT16_TEST (env.intercept_dr_read,X86CPU , vmstate_5_plus),VMSTATE_UINT16_TEST (env.intercept_dr_write,X86CPU , vmstate_5_plus), -VMSTATE_UINT32_V (env.intercept_exceptions,X86CPU ,5 ), +VMSTATE_UINT32_TEST (env.intercept_exceptions,X86CPU , vmstate_5_plus),VMSTATE_UINT8_TEST (env.v_tpr,X86CPU , vmstate_5_plus),/* MTRRs */ VMSTATE_UINT64_ARRAY_V(env.mtrr_fixed, X86CPU, 11, 8),
@@ -680,14 +680,14 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_MTRR_VARS (env.mtrr_var,X86CPU ,8 ,8 ),/* KVM-related states */ VMSTATE_INT32_TEST (env.interrupt_injected,X86CPU , vmstate_9_plus), -VMSTATE_UINT32_V (env.mp_state,X86CPU ,9 ), +VMSTATE_UINT32_TEST (env.mp_state,X86CPU , vmstate_9_plus),VMSTATE_UINT64_V (env.tsc,X86CPU ,9 ),VMSTATE_INT32_TEST (env.exception_injected,X86CPU , vmstate_11_plus),VMSTATE_UINT8_TEST (env.soft_interrupt,X86CPU , vmstate_11_plus),VMSTATE_UINT8_TEST (env.nmi_injected,X86CPU , vmstate_11_plus),VMSTATE_UINT8_TEST (env.nmi_pending,X86CPU , vmstate_11_plus),VMSTATE_UINT8_TEST (env.has_error_code,X86CPU , vmstate_11_plus), -VMSTATE_UINT32_V (env.sipi_vector,X86CPU ,11 ), +VMSTATE_UINT32_TEST (env.sipi_vector,X86CPU , vmstate_11_plus),/* MCE */ VMSTATE_UINT64_V (env.mcg_cap,X86CPU ,10 ), VMSTATE_UINT64_V(env.mcg_status, X86CPU, 10),
tests/test-vmstate.c +9 -5
@@ -152,7 +152,7 @@ typedef struct TestSimple {bool b_1, b_2;uint8_t u8_1, u8_2;uint16_t u16_1, u16_2; -uint32_t u32_1; +uint32_t u32_1, u32_2;uint64_t u64_1;int8_t i8_1, i8_2;int16_t i16_1, i16_2;
@@ -170,6 +170,7 @@ TestSimple obj_simple = { .u16_1 = 512, .u16_2 = 666, .u32_1 = 70000, + .u32_2 = 88888, .u64_1 = 12121212, .i8_1 = 65, .i8_2 = -65,
@@ -303,6 +304,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_UINT8_TEST (u8_2, TestSimple, test_false),VMSTATE_UINT16_TEST (u16_1, TestSimple, test_true),VMSTATE_UINT16_TEST (u16_2, TestSimple, test_false), +VMSTATE_UINT32_TEST (u32_1, TestSimple, test_true), +VMSTATE_UINT32_TEST (u32_2, TestSimple, test_false), VMSTATE_END_OF_LIST() } };
@@ -315,6 +318,7 @@ uint8_t wire_simple_test[] = {/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c ,/* u8_1 */ 0x82 ,/* u16_1 */ 0x02 ,0x00 , +/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -338,6 +342,7 @@ static void test_simple_test(void)FIELD_EQUAL (i64_1);FIELD_EQUAL (u8_1);FIELD_EQUAL (u16_1); +FIELD_EQUAL (u32_1); }#undef FIELD_EQUAL
@@ -363,12 +368,11 @@ static const VMStateDescription vmstate_simple_versioned = { .minimum_version_id = 1, .fields = (VMStateField []) {VMSTATE_UINT32 (a, TestVersioned), -/* Versioned field in the middle, so we catch bugs more -* easily. */ -VMSTATE_UINT32_V (b, TestVersioned,2 ), +/* Versioned field in the middle, so we catch bugs more easily. */ +VMSTATE_UINT32_TEST (b, TestVersioned, vmstate_2_plus),VMSTATE_UINT32 (c, TestVersioned),VMSTATE_UINT64 (d, TestVersioned), -VMSTATE_UINT32_V (e, TestVersioned,2 ), +VMSTATE_UINT32_TEST (e, TestVersioned, vmstate_2_plus),VMSTATE_UINT64_V (f, TestVersioned,2 ),VMSTATE_END_OF_LIST () }
Signature · 1 line
1.9.3
PATCH 17/27 vmstate: Test for VMSTATE_UINT64_TEST
In reply to Juan QuintelaRemove VMSTATE_UINT64_V, we are removing versioning. Move all users to VMSTATE_UINT64_TEST.
--- hw/timer/mc146818rtc.c | 6 +++--- include/migration/vmstate.h | 9 +++------ target-i386/machine.c | 30 +++++++++++++++--------------- tests/test-vmstate.c | 11 ++++++++--- 4 files changed, 29 insertions(+), 27 deletions(-)
hw/timer/mc146818rtc.c +3 -3
@@ -730,11 +730,11 @@ static const VMStateDescription vmstate_rtc = { VMSTATE_UNUSED(3*8), VMSTATE_UINT32_TEST(irq_coalesced, RTCState, vmstate_2_plus), VMSTATE_UINT32_TEST(period, RTCState, vmstate_2_plus), - VMSTATE_UINT64_V(base_rtc, RTCState, 3), - VMSTATE_UINT64_V(last_update, RTCState, 3), + VMSTATE_UINT64_TEST(base_rtc, RTCState, vmstate_3_plus), + VMSTATE_UINT64_TEST(last_update, RTCState, vmstate_3_plus), VMSTATE_INT64_TEST(offset, RTCState, vmstate_3_plus), VMSTATE_TIMER_V(update_timer, RTCState, 3), - VMSTATE_UINT64_V(next_alarm_time, RTCState, 3), + VMSTATE_UINT64_TEST(next_alarm_time, RTCState, vmstate_3_plus),VMSTATE_END_OF_LIST () } };
include/migration/vmstate.h +3 -6
@@ -553,8 +553,8 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)#define VMSTATE_UINT32_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) -#define VMSTATE_UINT64_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) +#define VMSTATE_UINT64_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)#define VMSTATE_BOOL (_f, _s) \ VMSTATE_BOOL_TEST(_f, _s, NULL)
@@ -575,7 +575,7 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT32 (_f, _s) \ VMSTATE_UINT32_TEST(_f, _s, NULL)#define VMSTATE_UINT64 (_f, _s) \ - VMSTATE_UINT64_V(_f, _s, 0) + VMSTATE_UINT64_TEST(_f, _s, NULL)#define VMSTATE_UINT8_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
@@ -604,9 +604,6 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_INT32_POSITIVE_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) -#define VMSTATE_UINT64_TEST (_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) -#define VMSTATE_FLOAT64_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
target-i386/machine.c +15 -15
@@ -660,14 +660,14 @@ const VMStateDescription vmstate_x86_cpu = {#endif VMSTATE_UINT32_TEST (env.smbase,X86CPU , vmstate_4_plus), -VMSTATE_UINT64_V (env.pat,X86CPU ,5 ), +VMSTATE_UINT64_TEST (env.pat,X86CPU , vmstate_5_plus),VMSTATE_UINT32_TEST (env.hflags2,X86CPU , vmstate_5_plus),VMSTATE_UINT32_TEST (parent_obj.halted,X86CPU , version_is_5), -VMSTATE_UINT64_V (env.vm_hsave,X86CPU ,5 ), -VMSTATE_UINT64_V (env.vm_vmcb,X86CPU ,5 ), -VMSTATE_UINT64_V (env.tsc_offset,X86CPU ,5 ), -VMSTATE_UINT64_V (env.intercept,X86CPU ,5 ), +VMSTATE_UINT64_TEST (env.vm_hsave,X86CPU , vmstate_5_plus), +VMSTATE_UINT64_TEST (env.vm_vmcb,X86CPU , vmstate_5_plus), +VMSTATE_UINT64_TEST (env.tsc_offset,X86CPU , vmstate_5_plus), +VMSTATE_UINT64_TEST (env.intercept,X86CPU , vmstate_5_plus),VMSTATE_UINT16_TEST (env.intercept_cr_read,X86CPU , vmstate_5_plus),VMSTATE_UINT16_TEST (env.intercept_cr_write,X86CPU , vmstate_5_plus), VMSTATE_UINT16_TEST(env.intercept_dr_read, X86CPU, vmstate_5_plus),
@@ -676,12 +676,12 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT8_TEST (env.v_tpr,X86CPU , vmstate_5_plus),/* MTRRs */ VMSTATE_UINT64_ARRAY_V (env.mtrr_fixed,X86CPU ,11 ,8 ), -VMSTATE_UINT64_V (env.mtrr_deftype,X86CPU ,8 ), +VMSTATE_UINT64_TEST (env.mtrr_deftype,X86CPU , vmstate_8_plus),VMSTATE_MTRR_VARS (env.mtrr_var,X86CPU ,8 ,8 ),/* KVM-related states */ VMSTATE_INT32_TEST (env.interrupt_injected,X86CPU , vmstate_9_plus),VMSTATE_UINT32_TEST (env.mp_state,X86CPU , vmstate_9_plus), -VMSTATE_UINT64_V (env.tsc,X86CPU ,9 ), +VMSTATE_UINT64_TEST (env.tsc,X86CPU , vmstate_9_plus),VMSTATE_INT32_TEST (env.exception_injected,X86CPU , vmstate_11_plus),VMSTATE_UINT8_TEST (env.soft_interrupt,X86CPU , vmstate_11_plus), VMSTATE_UINT8_TEST(env.nmi_injected, X86CPU, vmstate_11_plus),
@@ -689,18 +689,18 @@ const VMStateDescription vmstate_x86_cpu = {VMSTATE_UINT8_TEST (env.has_error_code,X86CPU , vmstate_11_plus),VMSTATE_UINT32_TEST (env.sipi_vector,X86CPU , vmstate_11_plus),/* MCE */ -VMSTATE_UINT64_V (env.mcg_cap,X86CPU ,10 ), -VMSTATE_UINT64_V (env.mcg_status,X86CPU ,10 ), -VMSTATE_UINT64_V (env.mcg_ctl,X86CPU ,10 ), +VMSTATE_UINT64_TEST (env.mcg_cap,X86CPU , vmstate_10_plus), +VMSTATE_UINT64_TEST (env.mcg_status,X86CPU , vmstate_10_plus), +VMSTATE_UINT64_TEST (env.mcg_ctl,X86CPU , vmstate_10_plus),VMSTATE_UINT64_ARRAY_V (env.mce_banks,X86CPU ,MCE_BANKS_DEF *4 ,10 ),/* rdtscp */ -VMSTATE_UINT64_V (env.tsc_aux,X86CPU ,11 ), +VMSTATE_UINT64_TEST (env.tsc_aux,X86CPU , vmstate_11_plus),/* KVM pvclock msr */ -VMSTATE_UINT64_V (env.system_time_msr,X86CPU ,11 ), -VMSTATE_UINT64_V (env.wall_clock_msr,X86CPU ,11 ), +VMSTATE_UINT64_TEST (env.system_time_msr,X86CPU , vmstate_11_plus), +VMSTATE_UINT64_TEST (env.wall_clock_msr,X86CPU , vmstate_11_plus),/* XSAVE related fields */ -VMSTATE_UINT64_V (env.xcr0,X86CPU ,12 ), -VMSTATE_UINT64_V (env.xstate_bv,X86CPU ,12 ), +VMSTATE_UINT64_TEST (env.xcr0,X86CPU , vmstate_12_plus), +VMSTATE_UINT64_TEST (env.xstate_bv,X86CPU , vmstate_12_plus),VMSTATE_YMMH_REGS_VARS (env.ymmh_regs,X86CPU ,CPU_NB_REGS ,12 ),VMSTATE_END_OF_LIST ()/* The above list is not sorted /wrt version numbers, watch out! */
tests/test-vmstate.c +8 -3
@@ -153,7 +153,7 @@ typedef struct TestSimple {uint8_t u8_1, u8_2;uint16_t u16_1, u16_2;uint32_t u32_1, u32_2; -uint64_t u64_1; +uint64_t u64_1, u64_2;int8_t i8_1, i8_2;int16_t i16_1, i16_2;int32_t i32_1, i32_2;
@@ -172,6 +172,7 @@ TestSimple obj_simple = { .u32_1 = 70000, .u32_2 = 88888, .u64_1 = 12121212, + .u64_2 = 34343434, .i8_1 = 65, .i8_2 = -65, .i16_1 = 512,
@@ -306,6 +307,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_UINT16_TEST (u16_2, TestSimple, test_false),VMSTATE_UINT32_TEST (u32_1, TestSimple, test_true),VMSTATE_UINT32_TEST (u32_2, TestSimple, test_false), +VMSTATE_UINT64_TEST (u64_1, TestSimple, test_true), +VMSTATE_UINT64_TEST (u64_2, TestSimple, test_false), VMSTATE_END_OF_LIST() } };
@@ -319,6 +322,7 @@ uint8_t wire_simple_test[] = {/* u8_1 */ 0x82 ,/* u16_1 */ 0x02 ,0x00 ,/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , +/* u64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -343,6 +347,7 @@ static void test_simple_test(void)FIELD_EQUAL (u8_1);FIELD_EQUAL (u16_1);FIELD_EQUAL (u32_1); +FIELD_EQUAL (u64_1); }#undef FIELD_EQUAL
@@ -373,7 +378,7 @@ static const VMStateDescription vmstate_simple_versioned = {VMSTATE_UINT32 (c, TestVersioned),VMSTATE_UINT64 (d, TestVersioned),VMSTATE_UINT32_TEST (e, TestVersioned, vmstate_2_plus), -VMSTATE_UINT64_V (f, TestVersioned,2 ), +VMSTATE_UINT64_TEST (f, TestVersioned, vmstate_2_plus), VMSTATE_END_OF_LIST() } };
@@ -467,7 +472,7 @@ static const VMStateDescription vmstate_simple_skipping = {VMSTATE_UINT32_TEST (c, TestVersioned, test_skip),VMSTATE_UINT64 (d, TestVersioned),VMSTATE_UINT32_TEST (e, TestVersioned, test_skip), -VMSTATE_UINT64_V (f, TestVersioned,2 ), +VMSTATE_UINT64_TEST (f, TestVersioned, vmstate_2_plus), VMSTATE_END_OF_LIST() } };
Signature · 1 line
1.9.3
PATCH 18/27 vmstate: Test for VMSTATE_FLOAT64
In reply to Juan QuintelaRemove unused VMSTATE_FLOAT64_V.
--- include/migration/vmstate.h | 5 +---- tests/test-vmstate.c | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-)
include/migration/vmstate.h +1 -4
@@ -605,11 +605,8 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) -#define VMSTATE_FLOAT64_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64) -#define VMSTATE_FLOAT64 (_f, _s) \ - VMSTATE_FLOAT64_V(_f, _s, 0) + VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_float64, float64)#define VMSTATE_TIMER_TEST (_f, _s, _test) \ VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
tests/test-vmstate.c +5 -0
@@ -158,6 +158,7 @@ typedef struct TestSimple {int16_t i16_1, i16_2;int32_t i32_1, i32_2;int64_t i64_1, i64_2; +float64 f64; } TestSimple;/* Object instantiation, we are going to use it in more than one test */
@@ -181,6 +182,7 @@ TestSimple obj_simple = { .i32_2 = -70000, .i64_1 = 12121212, .i64_2 = -12121212, + .f64 = float64_pi, };/* Description of the values. If you add a primitive type
@@ -205,6 +207,7 @@ static const VMStateDescription vmstate_simple_primitive = {VMSTATE_INT32 (i32_2, TestSimple),VMSTATE_INT64 (i64_1, TestSimple),VMSTATE_INT64 (i64_2, TestSimple), +VMSTATE_FLOAT64 (f64, TestSimple), VMSTATE_END_OF_LIST() } };
@@ -236,6 +239,7 @@ uint8_t wire_simple_primitive[] = {/* i32_2 */ 0xff ,0xfe ,0xee ,0x90 ,/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c ,/* i64_2 */ 0xff ,0xff ,0xff ,0xff ,0xff ,0x47 ,0x0b ,0x84 , +/* f64 */ 0x40 ,0x09 ,0x21 ,0xfb ,0x54 ,0x44 ,0x2d ,0x18 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -273,6 +277,7 @@ static void test_simple_primitive(void)FIELD_EQUAL (i32_2);FIELD_EQUAL (i64_1);FIELD_EQUAL (i64_2); +FIELD_EQUAL (f64); }static bool test_true (void *opaque,int version_id)
Signature · 1 line
1.9.3
PATCH 19/27 vmstate: Test for VMSTATE_UNUSED
In reply to Juan QuintelaRemove VMSTATE_UNUSED_V and fix only user.
--- hw/intc/ioapic_common.c | 3 ++- include/migration/vmstate.h | 11 ++--------- tests/test-vmstate.c | 5 +++++ 3 files changed, 9 insertions(+), 10 deletions(-)
hw/intc/ioapic_common.c +2 -1
@@ -91,7 +91,8 @@ static const VMStateDescription vmstate_ioapic_common = { .fields = (VMStateField[]) {VMSTATE_UINT8 (id, IOAPICCommonState),VMSTATE_UINT8 (ioregsel, IOAPICCommonState), -VMSTATE_UNUSED_V (2 ,8 ),/* to account for qemu-kvm's v2 format */ +/* to account for qemu-kvm's v2 format */ +VMSTATE_UNUSED_TEST (vmstate_2_plus,8 ),VMSTATE_UINT32_TEST (irr, IOAPICCommonState, vmstate_2_plus),VMSTATE_UINT64_ARRAY (ioredtbl, IOAPICCommonState,IOAPIC_NUM_PINS ),VMSTATE_END_OF_LIST ()
include/migration/vmstate.h +2 -9
@@ -491,10 +491,9 @@ extern const VMStateInfo vmstate_info_bitmap; .offset = offsetof(_state, _field), \ } -#define VMSTATE_UNUSED_BUFFER (_test, _version, _size) { \ +#define VMSTATE_UNUSED_TEST (_test, _size) { \ .name = "unused", \ .field_exists = (_test), \ - .version_id = (_version), \ .size = (_size), \ .info = &vmstate_info_unused_buffer, \ .flags = VMS_BUFFER, \
@@ -728,14 +727,8 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_BUFFER_UNSAFE (_field, _state, _version, _size) \ VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size) -#define VMSTATE_UNUSED_V (_v, _size) \ - VMSTATE_UNUSED_BUFFER(NULL, _v, _size) -#define VMSTATE_UNUSED (_size) \ - VMSTATE_UNUSED_V(0, _size) - -#define VMSTATE_UNUSED_TEST (_test, _size) \ - VMSTATE_UNUSED_BUFFER(_test, 0, _size) + VMSTATE_UNUSED_TEST(NULL, _size)#define VMSTATE_END_OF_LIST () \ {}
tests/test-vmstate.c +5 -0
@@ -208,6 +208,7 @@ static const VMStateDescription vmstate_simple_primitive = {VMSTATE_INT64 (i64_1, TestSimple),VMSTATE_INT64 (i64_2, TestSimple),VMSTATE_FLOAT64 (f64, TestSimple), +VMSTATE_UNUSED (5 ), VMSTATE_END_OF_LIST() } };
@@ -240,6 +241,7 @@ uint8_t wire_simple_primitive[] = {/* i64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c ,/* i64_2 */ 0xff ,0xff ,0xff ,0xff ,0xff ,0x47 ,0x0b ,0x84 ,/* f64 */ 0x40 ,0x09 ,0x21 ,0xfb ,0x54 ,0x44 ,0x2d ,0x18 , +/* unused */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -314,6 +316,8 @@ static const VMStateDescription vmstate_simple_test = {VMSTATE_UINT32_TEST (u32_2, TestSimple, test_false),VMSTATE_UINT64_TEST (u64_1, TestSimple, test_true),VMSTATE_UINT64_TEST (u64_2, TestSimple, test_false), +VMSTATE_UNUSED_TEST (test_true,5 ), +VMSTATE_UNUSED_TEST (test_false,5 ), VMSTATE_END_OF_LIST() } };
@@ -328,6 +332,7 @@ uint8_t wire_simple_test[] = {/* u16_1 */ 0x02 ,0x00 ,/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 ,/* u64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* unused */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
Signature · 1 line
1.9.3
PATCH 20/27 vmstate: Test for VMSTATE_BITMAP
In reply to Juan QuintelaRemove the unused version field (was unused).
--- hw/sd/sd.c | 2 +- include/migration/vmstate.h | 4 +-- tests/test-vmstate.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-)
hw/sd/sd.c +1 -1
@@ -456,7 +456,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),
include/migration/vmstate.h +2 -2
@@ -502,9 +502,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, \
tests/test-vmstate.c +75 -0
93 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 21/27 vmstate: Test for VMSTATE_UINT8_EQUAL
In reply to Juan QuintelaWe introduce another full test.
--- include/migration/vmstate.h | 2 +- tests/test-vmstate.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-)
include/migration/vmstate.h +1 -1
@@ -577,7 +577,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_UINT64_TEST(_f, _s, NULL)#define VMSTATE_UINT8_EQUAL (_f, _s) \ - VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t) + VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint8_equal, uint8_t)#define VMSTATE_UINT16_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
tests/test-vmstate.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 22/27 vmstate: Test for VMSTATE_UINT16_EQUAL
In reply to Juan QuintelaWe change only user of VMSTATE_UINT16_EQUAL_V to VMSTATE_UINT16_EQUAL_TEST.
--- hw/nvram/eeprom93xx.c | 7 ++++++- include/migration/vmstate.h | 8 ++++---- tests/test-vmstate.c | 8 +++++++- 3 files changed, 17 insertions(+), 6 deletions(-)
hw/nvram/eeprom93xx.c +6 -1
@@ -121,6 +121,11 @@ static bool is_old_eeprom_version(void *opaque, int version_id)return version_id ==OLD_EEPROM_VERSION ; } +static bool is_eeprom_version (void *opaque,int version_id) +{ +return version_id ==EEPROM_VERSION ; +} +static const VMStateDescription vmstate_eeprom = { .name ="eeprom" , .version_id =EEPROM_VERSION ,
@@ -138,7 +143,7 @@ static const VMStateDescription vmstate_eeprom = {VMSTATE_UINT8 (addrbits, eeprom_t),VMSTATE_UINT16_HACK_TEST (size, eeprom_t, is_old_eeprom_version),VMSTATE_UNUSED_TEST (is_old_eeprom_version,1 ), -VMSTATE_UINT16_EQUAL_V (size, eeprom_t,EEPROM_VERSION ), +VMSTATE_UINT16_EQUAL_TEST (size, eeprom_t, is_eeprom_version),VMSTATE_UINT16 (data, eeprom_t),VMSTATE_VARRAY_UINT16_UNSAFE (contents, eeprom_t, size,0 , vmstate_info_uint16, uint16_t),
include/migration/vmstate.h +4 -4
@@ -579,11 +579,11 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT8_EQUAL (_f, _s) \ VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint8_equal, uint8_t) -#define VMSTATE_UINT16_EQUAL (_f, _s) \ - VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t) +#define VMSTATE_UINT16_EQUAL_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16_equal, uint16_t) -#define VMSTATE_UINT16_EQUAL_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t) +#define VMSTATE_UINT16_EQUAL (_f, _s) \ + VMSTATE_UINT16_EQUAL_TEST(_f, _s, NULL)#define VMSTATE_INT32_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
tests/test-vmstate.c +7 -1
@@ -152,7 +152,7 @@ static int load_vmstate(const VMStateDescription *desc, typedef struct TestSimple { bool b_1, b_2; uint8_t u8_1, u8_2; - uint16_t u16_1, u16_2; + uint16_t u16_1, u16_2, u16_3; uint32_t u32_1, u32_2; uint64_t u64_1, u64_2; int8_t i8_1, i8_2;
@@ -171,6 +171,7 @@ TestSimple obj_simple = { .u8_2 = 222, .u16_1 = 512, .u16_2 = 666, + .u16_3 = 513, .u32_1 = 70000, .u32_2 = 88888, .u64_1 = 12121212,
@@ -368,12 +369,17 @@ static const VMStateDescription vmstate_simple_compare = { .minimum_version_id_old = 1, .fields = (VMStateField []) {VMSTATE_UINT8_EQUAL (u8_1, TestSimple), +VMSTATE_UINT16_EQUAL (u16_1, TestSimple), +VMSTATE_UINT16_EQUAL_TEST (u16_2, TestSimple, test_false), +VMSTATE_UINT16_EQUAL_TEST (u16_3, TestSimple, test_true),VMSTATE_END_OF_LIST () } };uint8_t wire_simple_compare[] = {/* u8_1 */ 0x82 , +/* u16_1 */ 0x02 ,0x00 , +/* u16_3 */ 0x02 ,0x01 ,QEMU_VM_EOF ,/* just to ensure we won't get EOF reported prematurely */ };
Signature · 1 line
1.9.3
PATCH 23/27 vmstate: Test for VMSTATE_UINT32_EQUAL
In reply to Juan QuintelaRemove unused VMSTATE_UINT32_EQUAL_V.
--- include/migration/vmstate.h | 9 +++------ tests/test-vmstate.c | 2 ++ 2 files changed, 5 insertions(+), 6 deletions(-)
include/migration/vmstate.h +3 -6
@@ -585,15 +585,12 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT16_EQUAL (_f, _s) \ VMSTATE_UINT16_EQUAL_TEST(_f, _s, NULL) +#define VMSTATE_UINT32_EQUAL (_f, _s) \ + VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint32_equal, uint32_t) +#define VMSTATE_INT32_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) -#define VMSTATE_UINT32_EQUAL_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t) - -#define VMSTATE_UINT32_EQUAL (_f, _s) \ - VMSTATE_UINT32_EQUAL_V(_f, _s, 0) -#define VMSTATE_UINT64_EQUAL_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
tests/test-vmstate.c +2 -0
@@ -372,6 +372,7 @@ static const VMStateDescription vmstate_simple_compare = {VMSTATE_UINT16_EQUAL (u16_1, TestSimple),VMSTATE_UINT16_EQUAL_TEST (u16_2, TestSimple, test_false),VMSTATE_UINT16_EQUAL_TEST (u16_3, TestSimple, test_true), +VMSTATE_UINT32_EQUAL (u32_1, TestSimple), VMSTATE_END_OF_LIST() } };
@@ -380,6 +381,7 @@ uint8_t wire_simple_compare[] = {/* u8_1 */ 0x82 ,/* u16_1 */ 0x02 ,0x00 ,/* u16_3 */ 0x02 ,0x01 , +/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
Signature · 1 line
1.9.3
PATCH 24/27 vmstate: Test for VMSTATE_UINT64_EQUAL
In reply to Juan QuintelaRemove unused VMSTATE_UINT64_EQUAL_V.
--- include/migration/vmstate.h | 10 +++------- tests/test-vmstate.c | 2 ++ 2 files changed, 5 insertions(+), 7 deletions(-)
include/migration/vmstate.h +3 -7
@@ -588,19 +588,15 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT32_EQUAL (_f, _s) \ VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint32_equal, uint32_t) +#define VMSTATE_UINT64_EQUAL (_f, _s) \ + VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint64_equal, uint64_t) +#define VMSTATE_INT32_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) -#define VMSTATE_UINT64_EQUAL_V (_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t) - -#define VMSTATE_UINT64_EQUAL (_f, _s) \ - VMSTATE_UINT64_EQUAL_V(_f, _s, 0) -#define VMSTATE_INT32_POSITIVE_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) -#define VMSTATE_FLOAT64 (_f, _s) \ VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_float64, float64)
tests/test-vmstate.c +2 -0
@@ -373,6 +373,7 @@ static const VMStateDescription vmstate_simple_compare = {VMSTATE_UINT16_EQUAL_TEST (u16_2, TestSimple, test_false),VMSTATE_UINT16_EQUAL_TEST (u16_3, TestSimple, test_true),VMSTATE_UINT32_EQUAL (u32_1, TestSimple), +VMSTATE_UINT64_EQUAL (u64_1, TestSimple), VMSTATE_END_OF_LIST() } };
@@ -382,6 +383,7 @@ uint8_t wire_simple_compare[] = {/* u16_1 */ 0x02 ,0x00 ,/* u16_3 */ 0x02 ,0x01 ,/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , +/* u64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
Signature · 1 line
1.9.3
PATCH 25/27 vmstate: Test for VMSTATE_INT32_EQUAL
In reply to Juan Quintela--- include/migration/vmstate.h | 2 +- tests/test-vmstate.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
include/migration/vmstate.h +1 -1
@@ -592,7 +592,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint64_equal, uint64_t)#define VMSTATE_INT32_EQUAL (_f, _s) \ - VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) + VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_equal, int32_t)#define VMSTATE_INT32_POSITIVE_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
tests/test-vmstate.c +2 -0
@@ -374,6 +374,7 @@ static const VMStateDescription vmstate_simple_compare = {VMSTATE_UINT16_EQUAL_TEST (u16_3, TestSimple, test_true),VMSTATE_UINT32_EQUAL (u32_1, TestSimple),VMSTATE_UINT64_EQUAL (u64_1, TestSimple), +VMSTATE_INT32_EQUAL (i32_1, TestSimple), VMSTATE_END_OF_LIST() } };
@@ -384,6 +385,7 @@ uint8_t wire_simple_compare[] = {/* u16_3 */ 0x02 ,0x01 ,/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 ,/* u64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
Signature · 1 line
1.9.3
PATCH 26/27 vmstate: Test for VMSTATE_INT32_LE
In reply to Juan QuintelaAdd tests for less/more than the value on destination.
--- include/migration/vmstate.h | 2 +- tests/test-vmstate.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-)
include/migration/vmstate.h +1 -1
@@ -595,7 +595,7 @@ extern const VMStateInfo vmstate_info_bitmap; VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_equal, int32_t)#define VMSTATE_INT32_POSITIVE_LE (_f, _s) \ - VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) + VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_le, int32_t)#define VMSTATE_FLOAT64 (_f, _s) \ VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_float64, float64)
tests/test-vmstate.c +19 -1
@@ -374,7 +374,8 @@ static const VMStateDescription vmstate_simple_compare = {VMSTATE_UINT16_EQUAL_TEST (u16_3, TestSimple, test_true),VMSTATE_UINT32_EQUAL (u32_1, TestSimple),VMSTATE_UINT64_EQUAL (u64_1, TestSimple), -VMSTATE_INT32_EQUAL (i32_1, TestSimple), +VMSTATE_INT32_EQUAL (i32_2, TestSimple), +VMSTATE_INT32_LE (i32_1, TestSimple), VMSTATE_END_OF_LIST() } };
@@ -385,6 +386,7 @@ uint8_t wire_simple_compare[] = {/* u16_3 */ 0x02 ,0x01 ,/* u32_1 */ 0x00 ,0x01 ,0x11 ,0x70 ,/* u64_1 */ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xb8 ,0xf4 ,0x7c , +/* i32_2 */ 0xff ,0xfe ,0xee ,0x90 ,/* i32_1 */ 0x00 ,0x01 ,0x11 ,0x70 , QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ };
@@ -412,6 +414,22 @@ static void test_simple_compare(void)FAILURE (load_vmstate (&vmstate_simple_compare, &obj, &obj_clone, obj_simple_copy,1 , wire_simple_compare,sizeof (wire_simple_compare))); + +/* testing less equal */ + +/* we change the value, so it is not equal anymore */ +memcpy (&obj, &obj_simple,sizeof (obj)); + obj.i32_1 =8000 ; +FAILURE (load_vmstate (&vmstate_simple_compare, &obj, &obj_clone, + obj_simple_copy,1 , wire_simple_compare, +sizeof (wire_simple_compare))); + +/* we change the value, so it is not equal anymore */ +memcpy (&obj, &obj_simple,sizeof (obj)); + obj.i32_1 =80000 ; +SUCCESS (load_vmstate (&vmstate_simple_compare, &obj, &obj_clone, + obj_simple_copy,1 , wire_simple_compare, +sizeof (wire_simple_compare))); }#undef FIELD_EQUAL
Signature · 1 line
1.9.3
PATCH 27/27 vmstate: s/VMSTATE_INT32_LE/VMSTATE_INT32_POSITIVE_LE/
In reply to Juan QuintelaFrom: "Michael S. Tsirkin" <[email protected]>
As the macro verifies the value is positive, rename it to make the function clearer.
--- tests/test-vmstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/test-vmstate.c +1 -1
@@ -375,7 +375,7 @@ static const VMStateDescription vmstate_simple_compare = {VMSTATE_UINT32_EQUAL (u32_1, TestSimple),VMSTATE_UINT64_EQUAL (u64_1, TestSimple),VMSTATE_INT32_EQUAL (i32_2, TestSimple), -VMSTATE_INT32_LE (i32_1, TestSimple), +VMSTATE_INT32_POSITIVE_LE (i32_1, TestSimple), VMSTATE_END_OF_LIST() } };
Signature · 1 line
1.9.3