From patchwork Thu Oct 20 13:25:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Halil Pasic X-Patchwork-Id: 9386831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F206A607D0 for ; Thu, 20 Oct 2016 13:26:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1054294F5 for ; Thu, 20 Oct 2016 13:26:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5F7D29C2F; Thu, 20 Oct 2016 13:26:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 64307294F5 for ; Thu, 20 Oct 2016 13:26:39 +0000 (UTC) Received: from localhost ([::1]:54830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxDMk-0007jH-LQ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Oct 2016 09:26:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxDMH-0007fE-Sb for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:26:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxDMD-0005wC-SR for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:26:09 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51042 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxDMD-0005vq-Mk for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:26:05 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u9KDORNw040023 for ; Thu, 20 Oct 2016 09:26:05 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0b-001b2d01.pphosted.com with ESMTP id 266u9qty39-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 20 Oct 2016 09:26:04 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Oct 2016 14:26:02 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 20 Oct 2016 14:26:00 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 27A61219005F for ; Thu, 20 Oct 2016 14:25:16 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u9KDPxi615073506 for ; Thu, 20 Oct 2016 13:25:59 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u9KDPwIu030701 for ; Thu, 20 Oct 2016 07:25:59 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u9KDPvpe030655 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Thu, 20 Oct 2016 07:25:58 -0600 From: Halil Pasic To: qemu-devel@nongnu.org Date: Thu, 20 Oct 2016 15:25:55 +0200 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20161020132556.67321-1-pasic@linux.vnet.ibm.com> References: <20161020132556.67321-1-pasic@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16102013-0020-0000-0000-000002654D13 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16102013-0021-0000-0000-00003EAA6902 Message-Id: <20161020132556.67321-2-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-20_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610200240 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 1/2] tests/test-vmstate.c: add vBuffer test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , Halil Pasic , Guenther Hutzl , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Guenther Hutzl The unit test test-vmstate.c is missing tests for some of the complex vmstate macros. This patch adds a new test for VMSTATE_VBUFFER and VMSTATE_VBUFFER_ALLOC_UINT32. The added test does not cover start != 0 because it's broken and unused so our intention is to remove start altogether. Signed-off-by: Guenther Hutzl Signed-off-by: Halil Pasic Reviewed-by: Dr. David Alan Gilbert --- A proof for the brokenness (unit test) of .start is provided here: https://lists.gnu.org/archive/html/qemu-devel/2016-10/msg04042.html --- tests/test-vmstate.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index d8da26f..9a57aa0 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -475,6 +475,119 @@ static void test_load_skip(void) qemu_fclose(loading); } +/* vBuffer tests */ +#define BUF_SIZE 10 + +typedef struct TestVBuffer { + uint8_t u8_1; + int32_t buffer_size; + uint8_t *vBuffer_1; + uint32_t buffer_alloc_size; + uint8_t *vBuffer_alloc_1; + uint8_t u8_2; +} TestVBuffer; + +/* buffers padded with 0xFE at the end to easier detect overflow */ +uint8_t buf1[BUF_SIZE + 1] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0xfe}; +uint8_t buf2[BUF_SIZE + 1] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0xfe}; + +TestVBuffer obj_vbuffer = { + .u8_1 = 100, + .buffer_size = BUF_SIZE, + .vBuffer_1 = buf1, + .buffer_alloc_size = BUF_SIZE, + .vBuffer_alloc_1 = buf2, + .u8_2 = 200, +}; + +static const VMStateDescription vmstate_vbuffer = { + .name = "complex/vbuffer", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(u8_1, TestVBuffer), + VMSTATE_VBUFFER(vBuffer_1, TestVBuffer, 1, NULL, 0, + buffer_size), + VMSTATE_VBUFFER_ALLOC_UINT32(vBuffer_alloc_1, TestVBuffer, 1, NULL, 0, + buffer_alloc_size), + VMSTATE_UINT8(u8_2, TestVBuffer), + VMSTATE_END_OF_LIST() + } +}; + +uint8_t wire_vbuffer[] = { + /* u8_1 */ 0x64, + /* vBuffer_1 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x00, + /* vBuffer_alloc_1 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x00, + /* u8_2 */ 0xc8, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ +}; + +static void obj_vbuffer_copy(void *target, void *source) +{ + /* this proc copies all struct TestVBuffer entries from source to target + except the vBuffer pointers which should already point to the correct + locations. The buffer contents are also copied */ + TestVBuffer *s = (TestVBuffer *)source; + TestVBuffer *t = (TestVBuffer *)target; + + t->u8_1 = s->u8_1; + t->u8_2 = s->u8_2; + t->buffer_size = s->buffer_size; + t->buffer_alloc_size = s->buffer_alloc_size; + if (t->vBuffer_1 && s->vBuffer_1) { + memcpy(t->vBuffer_1, s->vBuffer_1, BUF_SIZE); + } + if (t->vBuffer_alloc_1 && s->vBuffer_alloc_1) { + memcpy(t->vBuffer_alloc_1, s->vBuffer_alloc_1, BUF_SIZE); + } +} + +static void test_complex_vbuffer(void) +{ + uint8_t buffer[BUF_SIZE]; + uint8_t buffer_clone[BUF_SIZE]; + TestVBuffer obj = { + .u8_1 = 0, + .buffer_size = BUF_SIZE, + .vBuffer_1 = buffer, + .buffer_alloc_size = BUF_SIZE, + .vBuffer_alloc_1 = NULL, + .u8_2 = 0, + }; + TestVBuffer obj_clone = { + .u8_1 = 0, + .buffer_size = BUF_SIZE, + .vBuffer_1 = buffer_clone, + .buffer_alloc_size = BUF_SIZE, + .vBuffer_alloc_1 = NULL, + .u8_2 = 0, + }; + + memset(buffer, 0, BUF_SIZE); + memset(buffer_clone, 0, BUF_SIZE); + + save_vmstate(&vmstate_vbuffer, &obj_vbuffer); + + compare_vmstate(wire_vbuffer, sizeof(wire_vbuffer)); + + SUCCESS(load_vmstate(&vmstate_vbuffer, &obj, &obj_clone, + obj_vbuffer_copy, 1, wire_vbuffer, + sizeof(wire_vbuffer))); + +#define FIELD_EQUAL(name) g_assert_cmpint(obj.name, ==, obj_vbuffer.name) +#define BUFFER_EQUAL(name) SUCCESS(memcmp(obj.name, obj_vbuffer.name, BUF_SIZE)) + + FIELD_EQUAL(u8_1); + BUFFER_EQUAL(vBuffer_1); + BUFFER_EQUAL(vBuffer_alloc_1); + FIELD_EQUAL(u8_2); +} +#undef FIELD_EQUAL +#undef BUFFER_EQUAL + int main(int argc, char **argv) { temp_fd = mkstemp(temp_file); @@ -489,6 +602,7 @@ int main(int argc, char **argv) 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/complex/vbuffer", test_complex_vbuffer); g_test_run(); close(temp_fd);