From nobody Mon Feb 9 09:09:14 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.zohomail.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 1499430768439484.62629698591536; Fri, 7 Jul 2017 05:32:48 -0700 (PDT) Received: from localhost ([::1]:56212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTSR8-0000Yp-BN for importer@patchew.org; Fri, 07 Jul 2017 08:32:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTSHG-00009t-Rq for qemu-devel@nongnu.org; Fri, 07 Jul 2017 08:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTSHD-00060Z-Bt for qemu-devel@nongnu.org; Fri, 07 Jul 2017 08:22:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32772) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTSHD-0005zl-3N for qemu-devel@nongnu.org; Fri, 07 Jul 2017 08:22:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D4CCB8153 for ; Fri, 7 Jul 2017 12:22:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-61.gru2.redhat.com [10.97.116.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id BABD1600C2; Fri, 7 Jul 2017 12:22:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1D4CCB8153 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1D4CCB8153 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 09:22:13 -0300 Message-Id: <20170707122215.8819-2-ehabkost@redhat.com> In-Reply-To: <20170707122215.8819-1-ehabkost@redhat.com> References: <20170707122215.8819-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 12:22:26 +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 1/3] tests: Simplify abstract-interfaces check with a helper 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: Markus Armbruster 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" Add a new type_list_find() helper to device-introspect-test.c, to simplify the code at test_abstract_interfaces(). Reviewed-by: Eric Blake Signed-off-by: Eduardo Habkost --- Changes v2 -> v3: * None, rebase only. Changes v1 -> v2: * (none) --- tests/device-introspect-test.c | 43 ++++++++++++++++++++++++--------------= ---- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c index b1abb2a..f1e6ddd 100644 --- a/tests/device-introspect-test.c +++ b/tests/device-introspect-test.c @@ -45,6 +45,22 @@ static QList *qom_list_types(const char *implements, boo= l abstract) return ret; } =20 +/* Find an entry on a list returned by qom-list-types */ +static QDict *type_list_find(QList *types, const char *name) +{ + QListEntry *e; + + QLIST_FOREACH_ENTRY(types, e) { + QDict *d =3D qobject_to_qdict(qlist_entry_obj(e)); + const char *ename =3D qdict_get_str(d, "name"); + if (!strcmp(ename, name)) { + return d; + } + } + + return NULL; +} + static QList *device_type_list(bool abstract) { return qom_list_types("device", abstract); @@ -125,7 +141,7 @@ static void test_abstract_interfaces(void) { QList *all_types; QList *obj_types; - QListEntry *ae; + QListEntry *e; =20 qtest_start(common_args); /* qom-list-types implements=3Dinterface would return any type @@ -138,24 +154,15 @@ static void test_abstract_interfaces(void) all_types =3D qom_list_types(NULL, false); obj_types =3D qom_list_types("object", false); =20 - QLIST_FOREACH_ENTRY(all_types, ae) { - QDict *at =3D qobject_to_qdict(qlist_entry_obj(ae)); - const char *aname =3D qdict_get_str(at, "name"); - QListEntry *oe; - const char *found =3D NULL; - - QLIST_FOREACH_ENTRY(obj_types, oe) { - QDict *ot =3D qobject_to_qdict(qlist_entry_obj(oe)); - const char *oname =3D qdict_get_str(ot, "name"); - if (!strcmp(aname, oname)) { - found =3D oname; - break; - } - } + QLIST_FOREACH_ENTRY(all_types, e) { + QDict *d =3D qobject_to_qdict(qlist_entry_obj(e)); + + /* + * An interface (incorrectly) marked as non-abstract would + * appear on all_types, but not on obj_types: + */ + g_assert(type_list_find(obj_types, qdict_get_str(d, "name"))); =20 - /* Using g_assert_cmpstr() will give more useful failure - * messages than g_assert(found) */ - g_assert_cmpstr(aname, =3D=3D, found); } =20 QDECREF(all_types); --=20 2.9.4