From nobody Sun Feb 8 23:05:05 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 1488195106525222.8647571441336; Mon, 27 Feb 2017 03:31:46 -0800 (PST) Received: from localhost ([::1]:51822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciJWp-0007GD-Q3 for importer@patchew.org; Mon, 27 Feb 2017 06:31:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciJMb-0006DN-3F for qemu-devel@nongnu.org; Mon, 27 Feb 2017 06:21:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciJMV-00013H-4Z for qemu-devel@nongnu.org; Mon, 27 Feb 2017 06:21:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45006) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciJMO-0000vQ-EO; Mon, 27 Feb 2017 06:20:56 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 89B1880F96; Mon, 27 Feb 2017 11:20:56 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RBKt7q019473 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 06:20:56 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 54496113861F; Mon, 27 Feb 2017 12:20:50 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 12:20:47 +0100 Message-Id: <1488194450-28056-22-git-send-email-armbru@redhat.com> In-Reply-To: <1488194450-28056-1-git-send-email-armbru@redhat.com> References: <1488194450-28056-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Feb 2017 11:20:56 +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 21/24] test-qapi-util: New, covering qapi/qapi-util.c 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: kwolf@redhat.com, "mdroth@linux.vnet.ibm.commdroth"@linux.vnet.ibm.com, pkrempa@redhat.com, qemu-block@nongnu.org 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" Signed-off-by: Markus Armbruster Reviewed-by: Kevin Wolf --- tests/.gitignore | 1 + tests/Makefile.include | 3 +++ tests/test-qapi-util.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 55 insertions(+) create mode 100644 tests/test-qapi-util.c diff --git a/tests/.gitignore b/tests/.gitignore index 30b7740..a966740 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -53,6 +53,7 @@ test-mul64 test-opts-visitor test-qapi-event.[ch] test-qapi-types.[ch] +test-qapi-util test-qapi-visit.[ch] test-qdev-global-props test-qemu-opts diff --git a/tests/Makefile.include b/tests/Makefile.include index 2171e4a..2b8301e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -128,6 +128,8 @@ gcov-files-check-bufferiszero-y =3D util/bufferiszero.c check-unit-y +=3D tests/test-uuid$(EXESUF) check-unit-y +=3D tests/ptimer-test$(EXESUF) gcov-files-ptimer-test-y =3D hw/core/ptimer.c +check-unit-y +=3D tests/test-qapi-util$(EXESUF) +gcov-files-test-qapi-util-y =3D qapi/qapi-util.c =20 check-block-$(CONFIG_POSIX) +=3D tests/qemu-iotests-quick.sh =20 @@ -733,6 +735,7 @@ tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contr= ib/ivshmem-server/ivshmem tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o contrib/libvho= st-user/libvhost-user.o $(test-util-obj-y) tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o +tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) =20 tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"L= INK","$(TARGET_DIR)$@") diff --git a/tests/test-qapi-util.c b/tests/test-qapi-util.c new file mode 100644 index 0000000..39db8bf --- /dev/null +++ b/tests/test-qapi-util.c @@ -0,0 +1,51 @@ +/* + * Unit tests for QAPI utility functions + * + * Copyright (C) 2017 Red Hat Inc. + * + * Authors: + * Markus Armbruster , + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/util.h" +#include "test-qapi-types.h" + +static void test_qapi_enum_parse(void) +{ + Error *err =3D NULL; + int ret; + + ret =3D qapi_enum_parse(QType_lookup, NULL, QTYPE__MAX, QTYPE_NONE, + &error_abort); + g_assert_cmpint(ret, =3D=3D, QTYPE_NONE); + + ret =3D qapi_enum_parse(QType_lookup, "junk", QTYPE__MAX, -1, + NULL); + g_assert_cmpint(ret, =3D=3D, -1); + + ret =3D qapi_enum_parse(QType_lookup, "junk", QTYPE__MAX, -1, + &err); + error_free_or_abort(&err); + + ret =3D qapi_enum_parse(QType_lookup, "none", QTYPE__MAX, -1, + &error_abort); + g_assert_cmpint(ret, =3D=3D, QTYPE_NONE); + + ret =3D qapi_enum_parse(QType_lookup, QType_lookup[QTYPE__MAX - 1], + QTYPE__MAX, QTYPE__MAX - 1, + &error_abort); + g_assert_cmpint(ret, =3D=3D, QTYPE__MAX - 1); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/qapi/util/qapi_enum_parse", test_qapi_enum_parse); + g_test_run(); + return 0; +} --=20 2.7.4