From patchwork Mon Apr 21 14:40:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 341077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7DF6D1400EE for ; Tue, 22 Apr 2014 13:18:19 +1000 (EST) Received: from localhost ([::1]:49295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcFac-0002KT-A3 for incoming@patchwork.ozlabs.org; Mon, 21 Apr 2014 10:52:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcFQV-0003oB-3O for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:42:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WcFQO-0003zD-Ri for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:42:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcFQO-0003z9-Kn for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:42:24 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3LEgNnE001971 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 21 Apr 2014 10:42:24 -0400 Received: from trasno.mitica (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3LEfi6X019220; Mon, 21 Apr 2014 10:42:22 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 21 Apr 2014 16:40:07 +0200 Message-Id: <1398091304-10677-28-git-send-email-quintela@redhat.com> In-Reply-To: <1398091304-10677-1-git-send-email-quintela@redhat.com> References: <1398091304-10677-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 027/124] vmstate: Test for VMSTATE_BITMAP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Remove the unused version field (was unused). Signed-off-by: Juan Quintela --- hw/sd/sd.c | 2 +- include/migration/vmstate.h | 4 +-- tests/test-vmstate.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 4502ad1..7ee8c24 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -467,7 +467,7 @@ static const VMStateDescription sd_vmstate = { VMSTATE_UINT32(card_status, SDState), VMSTATE_PARTIAL_BUFFER(sd_status, SDState, 1), VMSTATE_UINT32(vhs, SDState), - VMSTATE_BITMAP(wp_groups, SDState, 0, wpgrps_size), + VMSTATE_BITMAP(wp_groups, SDState, wpgrps_size), VMSTATE_UINT32(blk_len, SDState), VMSTATE_UINT32(erase_start, SDState), VMSTATE_UINT32(erase_end, SDState), diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 553cc0a..52b0cc8 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -493,9 +493,9 @@ extern const VMStateInfo vmstate_info_bitmap; /* _field_size should be a int32_t field in the _state struct giving the * size of the bitmap _field in bits. */ -#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \ +#define VMSTATE_BITMAP(_field, _state, _field_size) { \ .name = (stringify(_field)), \ - .version_id = (_version), \ + .version_id = 0, \ .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ .info = &vmstate_info_bitmap, \ .flags = VMS_VBUFFER|VMS_POINTER, \ diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 2aa6d8b..f105e2c 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -28,6 +28,7 @@ #include "migration/migration.h" #include "migration/vmstate.h" #include "block/coroutine.h" +#include "qemu/bitmap.h" char temp_file[] = "/tmp/vmst.test.XXXXXX"; int temp_fd; @@ -361,6 +362,79 @@ static void test_simple_test(void) } #undef FIELD_EQUAL +typedef struct TestBitmap { + int32_t bitmap_size; + unsigned long *bitmap; +} TestBitmap; + +static const VMStateDescription vmstate_simple_bitmap = { + .name = "simple/bitmap", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_INT32_EQUAL(bitmap_size, TestBitmap), + VMSTATE_BITMAP(bitmap, TestBitmap, bitmap_size), + VMSTATE_END_OF_LIST() + } +}; + +/* This is the binary representation on the wire of that struct */ +uint8_t wire_simple_bitmap[] = { + 0x00, 0x00, 0x00, 0x40, /* size */ + 0x40, 0x00, 0x00, 0x00, /* bitmap */ + 0x40, 0x40, 0x00, 0x01, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +#define VMSTATE_BITMAP_SIZE 64 + +static void obj_bitmap_copy(void *arg1, void *arg2) +{ + TestBitmap *target = arg1; + TestBitmap *source = arg2; + + target->bitmap_size = source->bitmap_size; + memcpy(target->bitmap, source->bitmap, VMSTATE_BITMAP_SIZE / sizeof(long)); +} + +static TestBitmap *create_bitmap(void) +{ + TestBitmap *obj = g_malloc0(sizeof(*obj)); + obj->bitmap_size = VMSTATE_BITMAP_SIZE; + obj->bitmap = bitmap_new(VMSTATE_BITMAP_SIZE); + + return obj; +} + +static void test_simple_bitmap(void) +{ + TestBitmap *obj_bitmap, *obj, *obj_clone; + + obj_bitmap = create_bitmap(); + obj = create_bitmap(); + obj_clone = create_bitmap(); + + set_bit(0, obj_bitmap->bitmap); + set_bit(22, obj_bitmap->bitmap); + set_bit(30, obj_bitmap->bitmap); + set_bit(62, obj_bitmap->bitmap); + + save_vmstate(&vmstate_simple_bitmap, obj_bitmap); + + compare_vmstate(wire_simple_bitmap, sizeof(wire_simple_bitmap)); + + SUCCESS(load_vmstate(&vmstate_simple_bitmap, obj, obj_clone, + obj_bitmap_copy, 1, wire_simple_bitmap, + sizeof(wire_simple_bitmap))); + +#define FIELD_EQUAL(name) g_assert_cmpint(obj->name, ==, obj_bitmap->name) + FIELD_EQUAL(bitmap_size); + g_assert_cmpint(bitmap_equal(obj->bitmap, obj_bitmap->bitmap, + VMSTATE_BITMAP_SIZE), ==, 1); +#undef FIELD_EQUAL +} + typedef struct TestVersioned { uint32_t a, b, c, e; uint64_t d, f; @@ -592,6 +666,7 @@ int main(int argc, char **argv) g_test_add_func("/vmstate/simple/skip", test_simple_skip); g_test_add_func("/vmstate/simple/no_skip", test_simple_no_skip); g_test_add_func("/vmstate/simple/test", test_simple_test); + g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap); g_test_run(); close(temp_fd);