From patchwork Mon Oct 31 19:53:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianjun Duan X-Patchwork-Id: 689587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t74tN6Sg8z9sD6 for ; Tue, 1 Nov 2016 06:58:36 +1100 (AEDT) Received: from localhost ([::1]:38316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1Ij4-0001Ve-1l for incoming@patchwork.ozlabs.org; Mon, 31 Oct 2016 15:58:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1IfA-0006WS-Sa for qemu-devel@nongnu.org; Mon, 31 Oct 2016 15:54:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1If5-0004zt-Vy for qemu-devel@nongnu.org; Mon, 31 Oct 2016 15:54:32 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48929 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 1c1If5-0004zc-MC for qemu-devel@nongnu.org; Mon, 31 Oct 2016 15:54:27 -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 u9VJs6tu059505 for ; Mon, 31 Oct 2016 15:54:27 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 26ebstkhxk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 31 Oct 2016 15:54:26 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 31 Oct 2016 13:54:25 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 31 Oct 2016 13:54:20 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 4DF0819D803F; Mon, 31 Oct 2016 13:53:44 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u9VJsKpr16056678; Mon, 31 Oct 2016 12:54:20 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E0CD97805F; Mon, 31 Oct 2016 13:54:19 -0600 (MDT) Received: from jianjun-w530.ibm.com (unknown [9.65.70.185]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id D9D1378037; Mon, 31 Oct 2016 13:54:15 -0600 (MDT) From: Jianjun Duan To: qemu-devel@nongnu.org Date: Mon, 31 Oct 2016 12:53:56 -0700 X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477943636-21024-1-git-send-email-duanj@linux.vnet.ibm.com> References: <1477943636-21024-1-git-send-email-duanj@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16103119-0016-0000-0000-0000050BC15A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006010; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00775109; UDB=6.00372577; IPR=6.00552101; BA=6.00004845; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013162; XFM=3.00000011; UTC=2016-10-31 19:54:25 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16103119-0017-0000-0000-0000343C59A5 Message-Id: <1477943636-21024-4-git-send-email-duanj@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-31_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610310347 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [QEMU PATCH v10 3/3] tests/migration: Add test for QTAILQ migration 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: veroniabahaa@gmail.com, peter.maydell@linaro.org, dgilbert@redhat.com, duanj@linux.vnet.ibm.com, mst@redhat.com, quintela@redhat.com, mark.cave-ayland@ilande.co.uk, mdroth@linux.vnet.ibm.com, mreitz@redhat.com, blauwirbel@gmail.com, amit.shah@redhat.com, qemu-ppc@nongnu.org, kraxel@redhat.com, kwolf@redhat.com, dmitry@daynix.com, pbonzini@redhat.com, rth@twiddle.net, leon.alrae@imgtec.com, aurelien@aurel32.net, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a test for QTAILQ migration to tests/test-vmstate.c. Signed-off-by: Jianjun Duan Reviewed-by: Juan Quintela --- tests/test-vmstate.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index d8da26f..a992408 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -475,6 +475,164 @@ static void test_load_skip(void) qemu_fclose(loading); } + +/* test QTAILQ migration */ +typedef struct TestQtailqElement TestQtailqElement; + +struct TestQtailqElement { + bool b; + uint8_t u8; + QTAILQ_ENTRY(TestQtailqElement) next; +}; + +typedef struct TestQtailq { + int16_t i16; + QTAILQ_HEAD(TestQtailqHead, TestQtailqElement) q; + int32_t i32; +} TestQtailq; + +static const VMStateDescription vmstate_q_element = { + .name = "test/queue-element", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_BOOL(b, TestQtailqElement), + VMSTATE_UINT8(u8, TestQtailqElement), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_q = { + .name = "test/queue", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_INT16(i16, TestQtailq), + VMSTATE_QTAILQ_V(q, TestQtailq, 1, vmstate_q_element, TestQtailqElement, + next), + VMSTATE_INT32(i32, TestQtailq), + VMSTATE_END_OF_LIST() + } +}; + +static void test_save_q(void) +{ + TestQtailq obj_q = { + .i16 = -512, + .i32 = 70000, + }; + + TestQtailqElement obj_qe1 = { + .b = true, + .u8 = 130, + }; + + TestQtailqElement obj_qe2 = { + .b = false, + .u8 = 65, + }; + + uint8_t wire_q[] = { + /* i16 */ 0xfe, 0x0, + /* start of element 0 of q */ 0x01, + /* .b */ 0x01, + /* .u8 */ 0x82, + /* start of element 1 of q */ 0x01, + /* b */ 0x00, + /* u8 */ 0x41, + /* end of q */ 0x00, + /* i32 */ 0x00, 0x01, 0x11, 0x70, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ + }; + + QTAILQ_INIT(&obj_q.q); + QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe1, next); + QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe2, next); + + save_vmstate(&vmstate_q, &obj_q); + compare_vmstate(wire_q, sizeof(wire_q)); +} + +static void test_load_q(void) +{ + TestQtailq obj_q = { + .i16 = -512, + .i32 = 70000, + }; + + TestQtailqElement obj_qe1 = { + .b = true, + .u8 = 130, + }; + + TestQtailqElement obj_qe2 = { + .b = false, + .u8 = 65, + }; + + uint8_t wire_q[] = { + /* i16 */ 0xfe, 0x0, + /* start of element 0 of q */ 0x01, + /* .b */ 0x01, + /* .u8 */ 0x82, + /* start of element 1 of q */ 0x01, + /* b */ 0x00, + /* u8 */ 0x41, + /* end of q */ 0x00, + /* i32 */ 0x00, 0x01, 0x11, 0x70, + }; + + QTAILQ_INIT(&obj_q.q); + QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe1, next); + QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe2, next); + + QEMUFile *fsave = open_test_file(true); + + qemu_put_buffer(fsave, wire_q, sizeof(wire_q)); + qemu_put_byte(fsave, QEMU_VM_EOF); + g_assert(!qemu_file_get_error(fsave)); + qemu_fclose(fsave); + + QEMUFile *fload = open_test_file(false); + TestQtailq tgt; + + QTAILQ_INIT(&tgt.q); + vmstate_load_state(fload, &vmstate_q, &tgt, 1); + char eof = qemu_get_byte(fload); + g_assert(!qemu_file_get_error(fload)); + g_assert_cmpint(tgt.i16, ==, obj_q.i16); + g_assert_cmpint(tgt.i32, ==, obj_q.i32); + g_assert_cmpint(eof, ==, QEMU_VM_EOF); + + TestQtailqElement *qele_from = QTAILQ_FIRST(&obj_q.q); + TestQtailqElement *qlast_from = QTAILQ_LAST(&obj_q.q, TestQtailqHead); + TestQtailqElement *qele_to = QTAILQ_FIRST(&tgt.q); + TestQtailqElement *qlast_to = QTAILQ_LAST(&tgt.q, TestQtailqHead); + + while (1) { + g_assert_cmpint(qele_to->b, ==, qele_from->b); + g_assert_cmpint(qele_to->u8, ==, qele_from->u8); + if ((qele_from == qlast_from) || (qele_to == qlast_to)) { + break; + } + qele_from = QTAILQ_NEXT(qele_from, next); + qele_to = QTAILQ_NEXT(qele_to, next); + } + + g_assert_cmpint((uint64_t) qele_from, ==, (uint64_t) qlast_from); + g_assert_cmpint((uint64_t) qele_to, ==, (uint64_t) qlast_to); + + /* clean up */ + TestQtailqElement *qele; + while (!QTAILQ_EMPTY(&tgt.q)) { + qele = QTAILQ_LAST(&tgt.q, TestQtailqHead); + QTAILQ_REMOVE(&tgt.q, qele, next); + free(qele); + qele = NULL; + } + qemu_fclose(fload); +} + int main(int argc, char **argv) { temp_fd = mkstemp(temp_file); @@ -489,6 +647,8 @@ 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/qtailq/save/saveq", test_save_q); + g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q); g_test_run(); close(temp_fd);