From nobody Mon Feb 9 23:58:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629981750; cv=none; d=zohomail.com; s=zohoarc; b=gQp03poslYIuaqavj1pdLf6ArQMndnv6T3fT8SSVeqvbFFBTj+SwAiPsIHKkUVCXNx9cF+p8Qy/4FJ/G1ywcyDgVOfw2mU4JDVEqNl45F8btgVpwZ2GYVStWzKm1Dha+jyp0z4r81Dtfy++te6IH8AXgJGD10R18cW68q1cplOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629981750; 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=Y+leUpHX+6A8WbUTKT4sOwbpktub1GqAlJx4luuoj6Q=; b=ks3yjUwEwHkPpmukpS55/66JXTaZAhW/xJr/WreKoJkCUZWlIAG6KfxuWjBxFYuQ8hY1xZs1pg4Ydx9PVPNHv2jnpTRpVD3gOwayLkxmz/QEnKadRYv9s7ryY5DItqD5Z/QF/URJl2RIQqsUAq/isM2UlpnsBzuGmt/WTB8XlEY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629981750245598.5423101761727; Thu, 26 Aug 2021 05:42:30 -0700 (PDT) Received: from localhost ([::1]:36364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJEiD-0006zz-0M for importer@patchew.org; Thu, 26 Aug 2021 08:42:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJEYv-0004CO-G9 for qemu-devel@nongnu.org; Thu, 26 Aug 2021 08:32:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37351) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJEYh-0008Bb-VP for qemu-devel@nongnu.org; Thu, 26 Aug 2021 08:32:53 -0400 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-548-UI45yv0PPvCGnMoc1Trb8A-1; Thu, 26 Aug 2021 08:32:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D25651966320; Thu, 26 Aug 2021 12:32:31 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD0756A8E7; Thu, 26 Aug 2021 12:32:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B168111380BC; Thu, 26 Aug 2021 14:32:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629981154; h=from:from: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; bh=Y+leUpHX+6A8WbUTKT4sOwbpktub1GqAlJx4luuoj6Q=; b=ZmeSJfr61IohtAs2fyg/oAi5TVA9Vm4Ycf55s64IQkRjMACBLibO7fZMFLznwezxyw5Hdo OgOYxSI8G5rPP82VazKTTHWGBKiO6p/6wgnFwllwv0XHDS3xHQrlUniSbduIKHahASHbNJ EJE2wF8ycgfRwXqFl8+BxmN+rI9AEn0= X-MC-Unique: UI45yv0PPvCGnMoc1Trb8A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 08/11] qapi: add 'any' condition Date: Thu, 26 Aug 2021 14:32:22 +0200 Message-Id: <20210826123225.157891-9-armbru@redhat.com> In-Reply-To: <20210826123225.157891-1-armbru@redhat.com> References: <20210826123225.157891-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, WEIRD_QUOTING=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629981750912100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210804083105.97531-8-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- tests/unit/test-qmp-cmds.c | 1 + scripts/qapi/common.py | 4 ++-- scripts/qapi/expr.py | 6 +++--- tests/qapi-schema/bad-if-key.err | 2 +- tests/qapi-schema/bad-if-keys.err | 2 +- tests/qapi-schema/doc-good.json | 4 +++- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/doc-good.txt | 3 ++- tests/qapi-schema/enum-if-invalid.err | 2 +- tests/qapi-schema/qapi-schema-test.json | 8 +++++++- tests/qapi-schema/qapi-schema-test.out | 5 +++++ 11 files changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c index 1b0b7d99df..83efa39720 100644 --- a/tests/unit/test-qmp-cmds.c +++ b/tests/unit/test-qmp-cmds.c @@ -51,6 +51,7 @@ FeatureStruct1 *qmp_test_features0(bool has_fs0, FeatureS= truct0 *fs0, bool has_cfs1, CondFeatureStruct1 *cfs1, bool has_cfs2, CondFeatureStruct2 *cfs2, bool has_cfs3, CondFeatureStruct3 *cfs3, + bool has_cfs4, CondFeatureStruct4 *cfs4, Error **errp) { return g_new0(FeatureStruct1, 1); diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 3d7272a702..63a2e502fb 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -207,7 +207,7 @@ def cgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> = str: return ifcond =20 oper, operands =3D next(iter(ifcond.items())) - oper =3D {'all': '&&'}[oper] + oper =3D {'all': '&&', 'any': '||'}[oper] operands =3D [cgen_ifcond(o) for o in operands] return '(' + (') ' + oper + ' (').join(operands) + ')' =20 @@ -220,7 +220,7 @@ def docgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -= > str: return ifcond =20 oper, operands =3D next(iter(ifcond.items())) - oper =3D {'all': ' and '}[oper] + oper =3D {'all': ' and ', 'any': ' or '}[oper] operands =3D [docgen_ifcond(o) for o in operands] return '(' + oper.join(operands) + ')' =20 diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index d7a34655a7..f3ce10fb3e 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -290,16 +290,16 @@ def _check_if(cond: Union[str, object]) -> None: raise QAPISemError( info, "'if' condition dict of %s must have one key: " - "'all'" % source) + "'all' or 'any'" % source) check_keys(cond, info, "'if' condition", [], - ["all"]) + ["all", "any"]) =20 oper, operands =3D next(iter(cond.items())) if not operands: raise QAPISemError( info, "'if' condition [] of %s is useless" % source) =20 - if oper in ("all") and not isinstance(operands, list): + if oper in ("all", "any") and not isinstance(operands, list): raise QAPISemError( info, "'%s' condition of %s must be an array" % (oper, sou= rce)) for operand in operands: diff --git a/tests/qapi-schema/bad-if-key.err b/tests/qapi-schema/bad-if-ke= y.err index 725d5abae5..7236f46e7a 100644 --- a/tests/qapi-schema/bad-if-key.err +++ b/tests/qapi-schema/bad-if-key.err @@ -1,3 +1,3 @@ bad-if-key.json: In struct 'TestIfStruct': bad-if-key.json:2: 'if' condition has unknown key 'value' -Valid keys are 'all'. +Valid keys are 'all', 'any'. diff --git a/tests/qapi-schema/bad-if-keys.err b/tests/qapi-schema/bad-if-k= eys.err index b072db9a6f..db6d019d77 100644 --- a/tests/qapi-schema/bad-if-keys.err +++ b/tests/qapi-schema/bad-if-keys.err @@ -1,2 +1,2 @@ bad-if-keys.json: In struct 'TestIfStruct': -bad-if-keys.json:2: 'if' condition dict of struct must have one key: 'all' +bad-if-keys.json:2: 'if' condition dict of struct must have one key: 'all'= or 'any' diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index 25b1053e8a..e253d89ee0 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -103,7 +103,9 @@ 'features': [ 'union-feat1' ], 'base': 'Base', 'discriminator': 'base1', - 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' = } } } + 'data': { 'one': 'Variant1', + 'two': { 'type': 'Variant2', + 'if': { 'any': ['IFONE', 'IFTWO'] } } } } =20 ## # @SugaredUnion: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 689d084f3a..c44c346ec8 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -30,7 +30,7 @@ object Object tag base1 case one: Variant1 case two: Variant2 - if IFTWO + if OrderedDict([('any', ['IFONE', 'IFTWO'])]) feature union-feat1 object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt index 4490108cb7..251e9b746c 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -120,7 +120,8 @@ Members =20 The members of "Base" The members of "Variant1" when "base1" is ""one"" -The members of "Variant2" when "base1" is ""two"" (**If: **"IFTWO") +The members of "Variant2" when "base1" is ""two"" (**If: **"(IFONE or +IFTWO)") =20 Features ~~~~~~~~ diff --git a/tests/qapi-schema/enum-if-invalid.err b/tests/qapi-schema/enum= -if-invalid.err index df305cd79f..b96d94c48a 100644 --- a/tests/qapi-schema/enum-if-invalid.err +++ b/tests/qapi-schema/enum-if-invalid.err @@ -1,3 +1,3 @@ enum-if-invalid.json: In enum 'TestIfEnum': enum-if-invalid.json:2: 'if' condition has unknown key 'val' -Valid keys are 'all'. +Valid keys are 'all', 'any'. diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index e85a71c0f7..7737b32de8 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -291,6 +291,11 @@ 'features': [ { 'name': 'feature1', 'if': { 'all': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] } } ] } +{ 'struct': 'CondFeatureStruct4', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': 'feature1', + 'if': {'any': ['defined(TEST_IF_COND_1)', + 'defined(TEST_IF_COND_2)'] } } ] } =20 { 'enum': 'FeatureEnum1', 'data': [ 'eins', 'zwei', 'drei' ], @@ -314,7 +319,8 @@ '*fs4': 'FeatureStruct4', '*cfs1': 'CondFeatureStruct1', '*cfs2': 'CondFeatureStruct2', - '*cfs3': 'CondFeatureStruct3' }, + '*cfs3': 'CondFeatureStruct3', + '*cfs4': 'CondFeatureStruct4' }, 'returns': 'FeatureStruct1', 'features': [] } =20 diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index e74756cfd8..2f067d57af 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -390,6 +390,10 @@ object CondFeatureStruct3 member foo: int optional=3DFalse feature feature1 if OrderedDict([('all', ['defined(TEST_IF_COND_1)', 'defined(TEST_= IF_COND_2)'])]) +object CondFeatureStruct4 + member foo: int optional=3DFalse + feature feature1 + if OrderedDict([('any', ['defined(TEST_IF_COND_1)', 'defined(TEST_= IF_COND_2)'])]) enum FeatureEnum1 member eins member zwei @@ -417,6 +421,7 @@ object q_obj_test-features0-arg member cfs1: CondFeatureStruct1 optional=3DTrue member cfs2: CondFeatureStruct2 optional=3DTrue member cfs3: CondFeatureStruct3 optional=3DTrue + member cfs4: CondFeatureStruct4 optional=3DTrue command test-features0 q_obj_test-features0-arg -> FeatureStruct1 gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse command test-command-features1 None -> None --=20 2.31.1