From nobody Sun Feb 8 17:42:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571920528; cv=none; d=zoho.com; s=zohoarc; b=e5b8LD1pSrZMyCk7z0d0GEtLg7yK2BUPWZnaXJnX2x98SvmJQzk4YtaSZVENcpbfvF+BpeL0YQTg9lxVErJdyz87hCldTIn0GNsrit6U4XgWlEBvPAIWTnFkdJsiCD+Z5CB4ZXYMZW94HgNsn7yNLFnWCbEPCWDTOWa7Pa+lPxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571920528; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DLJveUk/5+so2mFcEtyabzzrYOLY4y2ZHCF2VE4IX9Q=; b=RfmDPp4VWzkgEJNSmWl1OLql85h8bXaz7HdZnTxR5RvU3NJXh5Z5byq8Sn/++MYiNm8mKsqPXURkb2IDaqBI+hAx1bmnBEoAz36yknt6ZhLLqxF/7HGxHw/AzMlYx6ESlGVXAnK2uE0XxSN/QmEbcn5ccJGk7P4rXqovAbX5nFk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 15719205282841016.7951926437335; Thu, 24 Oct 2019 05:35:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-WJWlhMBPOCiwkZ2k--YIrw-1; Thu, 24 Oct 2019 08:35:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E787F801E72; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B75C15DC1E; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 640984E9F5; Thu, 24 Oct 2019 12:35:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9OCZ4Zb004437 for ; Thu, 24 Oct 2019 08:35:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49B1052E7; Thu, 24 Oct 2019 12:35:04 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8941752F6; Thu, 24 Oct 2019 12:35:01 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F232911384A8; Thu, 24 Oct 2019 14:34:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571920527; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DLJveUk/5+so2mFcEtyabzzrYOLY4y2ZHCF2VE4IX9Q=; b=bM6mVPapolfunUf9ZHyI6uCp7JSO0XAsLSUXHzfxYUT5qkJGS9YsYoptaAbmzUkGe7M2rM N1IxLn4zzsLAQdCf9EWpqJDTXj1EbSJjm4aKNCxc215g0RThtx0EIARIQrFdXd4xfxeT+K cW6KMIzWJF4fKQivq8XTui8XmrMgjHw= From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Oct 2019 14:34:40 +0200 Message-Id: <20191024123458.13505-2-armbru@redhat.com> In-Reply-To: <20191024123458.13505-1-armbru@redhat.com> References: <20191024123458.13505-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 01/19] tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: WJWlhMBPOCiwkZ2k--YIrw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Checking the value of qmp_dispatch() is repetitive. Factor out helpers do_qmp_dispatch() and do_qmp_dispatch_error(). Without this, the next commit would make things even more repetitive. Signed-off-by: Markus Armbruster --- tests/test-qmp-cmds.c | 72 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 27b0afe55a..e738bead86 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -144,34 +144,55 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_q= emu_x_EnumList *a, } =20 =20 +static QObject *do_qmp_dispatch(QDict *req, bool allow_oob) +{ + QDict *resp; + QObject *ret; + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); + g_assert(resp && !qdict_haskey(resp, "error")); + ret =3D qdict_get(resp, "return"); + g_assert(ret); + + qobject_ref(ret); + qobject_unref(resp); + return ret; +} + +static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass c= ls) +{ + QDict *resp; + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob); + g_assert(resp && qdict_haskey(resp, "error")); + + qobject_unref(resp); +} + /* test commands with no input and no return value */ static void test_dispatch_cmd(void) { QDict *req =3D qdict_new(); - QDict *resp; + QObject *ret; =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(!qdict_haskey(resp, "error")); + ret =3D do_qmp_dispatch(req, false); =20 - qobject_unref(resp); + qobject_unref(ret); qobject_unref(req); } =20 static void test_dispatch_cmd_oob(void) { QDict *req =3D qdict_new(); - QDict *resp; + QObject *ret; =20 qdict_put_str(req, "exec-oob", "test-flags-command"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), true); - assert(resp !=3D NULL); - assert(!qdict_haskey(resp, "error")); + ret =3D do_qmp_dispatch(req, true); =20 - qobject_unref(resp); + qobject_unref(ret); qobject_unref(req); } =20 @@ -180,15 +201,11 @@ static void test_dispatch_cmd_failure(void) { QDict *req =3D qdict_new(); QDict *args =3D qdict_new(); - QDict *resp; =20 qdict_put_str(req, "execute", "user_def_cmd2"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(qdict_haskey(resp, "error")); + do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); =20 - qobject_unref(resp); qobject_unref(req); =20 /* check that with extra arguments it throws an error */ @@ -198,11 +215,8 @@ static void test_dispatch_cmd_failure(void) =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp !=3D NULL); - assert(qdict_haskey(resp, "error")); + do_qmp_dispatch_error(req, false, ERROR_CLASS_GENERIC_ERROR); =20 - qobject_unref(resp); qobject_unref(req); } =20 @@ -217,20 +231,6 @@ static void test_dispatch_cmd_success_response(void) qobject_unref(req); } =20 -static QObject *test_qmp_dispatch(QDict *req) -{ - QDict *resp; - QObject *ret; - - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp && !qdict_haskey(resp, "error")); - ret =3D qdict_get(resp, "return"); - assert(ret); - qobject_ref(ret); - qobject_unref(resp); - return ret; -} - /* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io(void) { @@ -253,7 +253,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args); qdict_put_str(req, "execute", "user_def_cmd2"); =20 - ret =3D qobject_to(QDict, test_qmp_dispatch(req)); + ret =3D qobject_to(QDict, do_qmp_dispatch(req, false)); =20 assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); ret_dict =3D qdict_get_qdict(ret, "dict1"); @@ -274,12 +274,10 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args3); qdict_put_str(req, "execute", "guest-get-time"); =20 - ret3 =3D qobject_to(QNum, test_qmp_dispatch(req)); + ret3 =3D qobject_to(QNum, do_qmp_dispatch(req, false)); g_assert(qnum_get_try_int(ret3, &val)); g_assert_cmpint(val, =3D=3D, 66); qobject_unref(ret3); - - qobject_unref(req); } =20 /* test generated dealloc functions for generated types */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list