From patchwork Mon Apr 21 14:41:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 340995 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 C55331400E0 for ; Tue, 22 Apr 2014 13:13:23 +1000 (EST) Received: from localhost ([::1]:49661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcG5L-00049X-Uk for incoming@patchwork.ozlabs.org; Mon, 21 Apr 2014 11:24:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcFRq-00061W-6q for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:44:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WcFRj-0004Mf-8V for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:43:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5280) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcFRi-0004MX-VW for qemu-devel@nongnu.org; Mon, 21 Apr 2014 10:43:47 -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 s3LEhkOj005632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 21 Apr 2014 10:43:46 -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 s3LEfi7Y019220; Mon, 21 Apr 2014 10:43:45 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 21 Apr 2014 16:41:08 +0200 Message-Id: <1398091304-10677-89-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 088/124] vmstate: Test for VMSTATE_UINT8_SUB_ARRAY 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 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 308f94d..0a4f81a 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -802,6 +802,54 @@ static void test_array_test(void) ELEM_NOT_EQUAL(i32_2, i); } } + +static const VMStateDescription vmstate_array_sub = { + .name = "array/sub", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8_SUB_ARRAY(u8_1, TestArray, 0, VMSTATE_ARRAY_SIZE), + VMSTATE_UINT8_SUB_ARRAY(u8_2, TestArray, 2 , 2), + VMSTATE_END_OF_LIST() + } +}; + +uint8_t wire_array_sub[] = { + /* u8_1 */ 0x01, 0x02, 0x03, 0x04, 0x05, + /* u8_2 {3,4} */ 0x03, 0x02, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static void test_array_sub(void) +{ + TestArray obj, obj_clone; + int i; + + memset(&obj, 0, sizeof(obj)); + obj.size = VMSTATE_ARRAY_SIZE; + + save_vmstate(&vmstate_array_sub, &obj_array); + + compare_vmstate(wire_array_sub, sizeof(wire_array_sub)); + + SUCCESS(load_vmstate(&vmstate_array_sub, &obj, &obj_clone, + obj_array_copy, 1, wire_array_sub, + sizeof(wire_array_sub))); + + for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) { + ELEM_EQUAL(u8_1, i); + } + for (i = 0; i < 2; i++) { + ELEM_NOT_EQUAL(u8_2, i); + } + for (i = 2; i < 4; i++) { + ELEM_EQUAL(u8_2, i); + } + for (i = 4; i < VMSTATE_ARRAY_SIZE; i++) { + ELEM_NOT_EQUAL(u8_2, i); + } +} #undef FIELD_EQUAL #undef ELEM_EQUAL #undef ELEM_EQUAL_2D @@ -1042,6 +1090,7 @@ int main(int argc, char **argv) g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap); g_test_add_func("/vmstate/array/primitive", test_array_primitive); g_test_add_func("/vmstate/array/test", test_array_test); + g_test_add_func("/vmstate/array/sub", test_array_sub); g_test_run(); close(temp_fd);