From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WX08u-0005vd-Bt for qemu-devel@nongnu.org; Sun, 06 Apr 2014 23:22:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WX08m-0008F2-UU for qemu-devel@nongnu.org; Sun, 06 Apr 2014 23:22:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32284) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WX08m-0008Ek-MY for qemu-devel@nongnu.org; Sun, 06 Apr 2014 23:22:32 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s373MVDb027047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 6 Apr 2014 23:22:31 -0400 From: Juan Quintela Date: Mon, 7 Apr 2014 05:20:41 +0200 Message-Id: <1396840915-10384-24-git-send-email-quintela@redhat.com> In-Reply-To: <1396840915-10384-1-git-send-email-quintela@redhat.com> References: <1396840915-10384-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 23/97] vmstate: Test for VMSTATE_UINT8_EQUAL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org We intruduce another full test. Signed-off-by: Juan Quintela --- include/migration/vmstate.h | 2 +- tests/test-vmstate.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 9cfc356..2c7f150 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -568,7 +568,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) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index d5cecbf..c6e4b67 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -339,6 +339,75 @@ static void test_simple_test(void) qemu_fclose(loading); } + +static const VMStateDescription vmstate_simple_compare = { + .name = "simple/compare", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8_EQUAL(u8_1, TestSimple), + VMSTATE_END_OF_LIST() + } +}; + +uint8_t wire_simple_compare[] = { + /* u8_1 */ 0x82, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static void test_simple_compare(void) +{ + QEMUFile *fsave = open_test_file(true); + + /* Save file with vmstate */ + vmstate_save_state(fsave, &vmstate_simple_compare, &obj_simple); + g_assert(!qemu_file_get_error(fsave)); + qemu_fclose(fsave); + + QEMUFile *loading = open_test_file(false); + /* we don't need QEMU_VM_EOF */ + uint8_t result[sizeof(wire_simple_compare)-1]; + + /* read back as binary */ + + g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==, + sizeof(result)); + g_assert(!qemu_file_get_error(loading)); + + /* Compare that what is on the file is the same that what we + expected to be there */ + SUCCESS(memcmp(result, wire_simple_compare, sizeof(result))); + + /* Must reach EOF */ + qemu_get_byte(loading); + g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO); + + qemu_fclose(loading); + + /* We save the file again. We want the EOF this time */ + + fsave = open_test_file(true); + qemu_put_buffer(fsave, wire_simple_compare, sizeof(wire_simple_compare)); + qemu_fclose(fsave); + + TestSimple obj; + loading = open_test_file(false); + memcpy(&obj, &obj_simple, sizeof(obj)); + + SUCCESS(vmstate_load_state(loading, &vmstate_simple_compare, &obj, 1)); + g_assert(!qemu_file_get_error(loading)); + qemu_fclose(loading); + + loading = open_test_file(false); + memcpy(&obj, &obj_simple, sizeof(obj)); + /* we change the value, so it is not equal anymore */ + obj.u8_1 = 27; + + FAILURE(vmstate_load_state(loading, &vmstate_simple_compare, &obj, 1)); + g_assert(!qemu_file_get_error(loading)); + qemu_fclose(loading); +} #undef FIELD_ASSERT typedef struct TestBitmap { @@ -427,6 +496,7 @@ static void test_simple_bitmap(void) qemu_fclose(loading); } + #undef FIELD_ASSERT typedef struct TestStruct { @@ -648,6 +718,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); g_test_add_func("/vmstate/simple/primitive", test_simple_primitive); g_test_add_func("/vmstate/simple/test", test_simple_test); + g_test_add_func("/vmstate/simple/compare", test_simple_compare); g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap); g_test_add_func("/vmstate/versioned/load/v1", test_load_v1); g_test_add_func("/vmstate/versioned/load/v2", test_load_v2); -- 1.9.0