From nobody Mon Feb 9 06:49:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488304716048631.6676526713576; Tue, 28 Feb 2017 09:58:36 -0800 (PST) Received: from localhost ([::1]:36005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cim2k-0002bn-Qp for importer@patchew.org; Tue, 28 Feb 2017 12:58:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cilkJ-0003gu-2i for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cilkF-0005Tb-GT for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cilkF-0005Rj-3R for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:27 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35E1581F01 for ; Tue, 28 Feb 2017 17:39:27 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SHdP9q014291 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 12:39:26 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 52726113861C; Tue, 28 Feb 2017 18:39:20 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 28 Feb 2017 18:39:14 +0100 Message-Id: <1488303560-18803-21-git-send-email-armbru@redhat.com> In-Reply-To: <1488303560-18803-1-git-send-email-armbru@redhat.com> References: <1488303560-18803-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 28 Feb 2017 17:39:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 20/26] test-string-input-visitor: Improve list coverage 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Lists with elements above INT64_MAX don't work (known bug). Empty lists don't work (weird). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-string-input-visitor.c | 85 +++++++++++++++++++++++++++++++++--= ---- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index a32828c..72f8732 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -65,31 +65,90 @@ static void test_visitor_in_int(TestInputVisitorData *d= ata, error_free_or_abort(&err); } =20 +static void check_ilist(Visitor *v, int64_t *expected, size_t n) +{ + int64List *res =3D NULL; + int64List *tail; + int i; + + visit_type_int64List(v, NULL, &res, &error_abort); + tail =3D res; + for (i =3D 0; i < n; i++) { + g_assert(tail); + g_assert_cmpint(tail->value, =3D=3D, expected[i]); + tail =3D tail->next; + } + g_assert(!tail); + + qapi_free_int64List(res); +} + +static void check_ulist(Visitor *v, uint64_t *expected, size_t n) +{ + uint64List *res =3D NULL; + uint64List *tail; + int i; + + /* BUG: unsigned numbers above INT64_MAX don't work */ + for (i =3D 0; i < n; i++) { + if (expected[i] > INT64_MAX) { + Error *err =3D NULL; + visit_type_uint64List(v, NULL, &res, &err); + error_free_or_abort(&err); + return; + } + } + + visit_type_uint64List(v, NULL, &res, &error_abort); + tail =3D res; + for (i =3D 0; i < n; i++) { + g_assert(tail); + g_assert_cmpuint(tail->value, =3D=3D, expected[i]); + tail =3D tail->next; + } + g_assert(!tail); + + qapi_free_uint64List(res); +} + static void test_visitor_in_intList(TestInputVisitorData *data, const void *unused) { - int64_t value[] =3D {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20}; - int16List *res =3D NULL, *tmp; + /* Note: the visitor *sorts* ranges *unsigned* */ + int64_t expect1[] =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 }; + int64_t expect2[] =3D { 32767, -32768, -32767 }; + int64_t expect3[] =3D { INT64_MAX, INT64_MIN }; + uint64_t expect4[] =3D { UINT64_MAX }; Error *err =3D NULL; + int64List *res =3D NULL; Visitor *v; - int i =3D 0; + + /* Valid lists */ =20 v =3D visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8"); + check_ilist(v, expect1, ARRAY_SIZE(expect1)); =20 - visit_type_int16List(v, NULL, &res, &error_abort); - tmp =3D res; - while (i < sizeof(value) / sizeof(value[0])) { - g_assert(tmp); - g_assert_cmpint(tmp->value, =3D=3D, value[i++]); - tmp =3D tmp->next; - } - g_assert(!tmp); + v =3D visitor_input_test_init(data, "32767,-32768--32767"); + check_ilist(v, expect2, ARRAY_SIZE(expect2)); =20 - qapi_free_int16List(res); + v =3D visitor_input_test_init(data, + "-9223372036854775808,9223372036854775807"= ); + check_ilist(v, expect3, ARRAY_SIZE(expect3)); + + v =3D visitor_input_test_init(data, "18446744073709551615"); + check_ulist(v, expect4, ARRAY_SIZE(expect4)); + + /* Empty list is invalid (weird) */ + + v =3D visitor_input_test_init(data, ""); + visit_type_int64List(v, NULL, &res, &err); + error_free_or_abort(&err); + + /* Not a list */ =20 v =3D visitor_input_test_init(data, "not an int list"); =20 - visit_type_int16List(v, NULL, &res, &err); + visit_type_int64List(v, NULL, &res, &err); error_free_or_abort(&err); g_assert(!res); } --=20 2.7.4