From patchwork Mon Apr 21 14:41:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 341143 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 BCF661400DF for ; Tue, 22 Apr 2014 13:22:05 +1000 (EST) Received: from localhost ([::1]:49738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcGD0-000856-U8 for incoming@patchwork.ozlabs.org; Mon, 21 Apr 2014 11:32:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60042) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcFSd-00076U-AY for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WcFSW-0004bA-Ia for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:44:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcFSW-0004b0-B9 for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:44:36 -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 s3LEiYbN031666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 21 Apr 2014 10:44:35 -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 s3LEfi8A019220; Mon, 21 Apr 2014 10:44:33 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 21 Apr 2014 16:41:44 +0200 Message-Id: <1398091304-10677-125-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 124/124] vmstate: Test for VMSTATE_ARRAY_OF_POINTER 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 Signed-off-by: Juan Quintela --- tests/test-vmstate.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index ca1f6e2..008dee4 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -1142,6 +1142,7 @@ static void test_vbuffer_simple(void) typedef struct TestPointer { uint8_t *u8_1p; uint8_t *u8_2p; + uint32_t *u32_p[VMSTATE_ARRAY_SIZE]; } TestPointer; static const VMStateDescription vmstate_pointer_simple = { @@ -1153,6 +1154,8 @@ static const VMStateDescription vmstate_pointer_simple = { VMSTATE_POINTER(u8_1p, TestPointer, NULL, vmstate_info_uint8, uint8_t), VMSTATE_POINTER_UNSAFE(u8_2p, TestPointer, vmstate_info_uint16, uint16_t), + VMSTATE_ARRAY_OF_POINTER(u32_p, TestPointer, VMSTATE_ARRAY_SIZE, + vmstate_info_uint32, uint32_t*), VMSTATE_END_OF_LIST() } }; @@ -1160,6 +1163,11 @@ static const VMStateDescription vmstate_pointer_simple = { uint8_t wire_pointer_simple[] = { /* u8_1p */ 0x11, /* u8_2p */ 0x02, 0x2b, + /* u32_p */ 0x00, 0x00, 0x00, 0x21, + 0x00, 0x00, 0x00, 0x2b, + 0x00, 0x00, 0x00, 0x35, + 0x00, 0x00, 0x00, 0x3f, + 0x00, 0x00, 0x00, 0x49, QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; @@ -1167,23 +1175,32 @@ static void obj_pointer_copy(void *arg1, void *arg2) { TestPointer *target = arg1; TestPointer *source = arg2; + int i; *target->u8_1p = *source->u8_1p; *((uint16_t *)target->u8_2p) = *((uint16_t *)source->u8_2p); + for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) { + *target->u32_p[i] = *source->u32_p[i]; + } } static TestPointer *create_pointer(void) { TestPointer *obj = g_malloc0(sizeof(*obj)); + int i; + obj->u8_1p = g_malloc0(sizeof(*obj->u8_1p)); obj->u8_2p = g_malloc0(sizeof(uint16_t)); - + for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) { + obj->u32_p[i] = g_malloc0(sizeof(uint32_t)); + } return obj; } static void test_pointer_simple(void) { TestPointer *obj, *obj_clone, *obj_pointer; + int i; obj_pointer = create_pointer(); obj = create_pointer(); @@ -1194,6 +1211,10 @@ static void test_pointer_simple(void) *obj->u8_1p = 22; *((uint16_t *)obj->u8_2p) = 777; + for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) { + *obj_pointer->u32_p[i] = 10 * i + 33; + } + save_vmstate(&vmstate_pointer_simple, obj_pointer); compare_vmstate(wire_pointer_simple, sizeof(wire_pointer_simple)); @@ -1205,6 +1226,10 @@ static void test_pointer_simple(void) g_assert_cmpint(*obj->u8_1p, ==, *obj_pointer->u8_1p); g_assert_cmpint(*((uint16_t *)obj->u8_2p), ==, *((uint16_t *)obj_pointer->u8_2p)); + + for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) { + g_assert_cmpint(*obj->u32_p[i], ==, *obj_pointer->u32_p[i]); + } } #undef FIELD_EQUAL