From nobody Mon Feb 9 06:27:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647881087511346.9929522758248; Mon, 21 Mar 2022 09:44:47 -0700 (PDT) Received: from localhost ([::1]:50904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWL9C-0000kb-CB for importer@patchew.org; Mon, 21 Mar 2022 12:44:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWL7K-00079r-Cr for qemu-devel@nongnu.org; Mon, 21 Mar 2022 12:42:50 -0400 Received: from [2a00:1450:4864:20::536] (port=46033 helo=mail-ed1-x536.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nWL7I-0007ck-Ph for qemu-devel@nongnu.org; Mon, 21 Mar 2022 12:42:50 -0400 Received: by mail-ed1-x536.google.com with SMTP id u26so2997322eda.12 for ; Mon, 21 Mar 2022 09:42:48 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id o2-20020a50d802000000b00410d7f0c52csm8289385edj.8.2022.03.21.09.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 09:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gX6EOlTl67BBZkn2jdiMxQvQHOFK6dHd/5w2dropqn8=; b=EwcREvGlFelTn9dkea+ZzbdaWVA8oCS2hxEkWjVj6GnOiz6yczi0uTvmiRZPnmqSww 0rXRi4VwEm0zKpYBpbpttiPCKA76pRG0RcTV9goO2w0v4S1LR1fx/o2ivfI7Pv/75mLv wmhC2EAON767Mo8V30pyH9QX+jVh3KgJ5D3+NCMPrI2yqLAVH+aHR1wFj6b2uTnsaKCe jwA81bb1Vu3guEUIddMS6LEpO2XD9R0DULfr9/VdvfWm93SzRfyo8MSUt2oVGpuYLLzG po+XGwJXz1GrkxDNmG9P3404y+tSUgC88MHjUyvleoPkxMWX5Z6TVd8N+ZUx6JHdVStQ jFEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=gX6EOlTl67BBZkn2jdiMxQvQHOFK6dHd/5w2dropqn8=; b=lsXyYXRxvqMBQmpdZNYkyVnVUullDSw7GkNJHm+u2zdCVhyBzt4SFLFaUMozn4ZQ9t UCEbFZWvKkzahkzAHDVs0DYAwdbnDFL5mwNzlVP8tejGJyaEjvnQYOpSRvVCO12vVyK6 pynmC4C+TRy6K1ipanQ5mDl05/k7sDD9MpK+x0Nre00eoE991begMCrcL77C/+L9mqIN x6P0tQ0OUguJugrL5uU281eAxCfmXxgCNWWtP4VxlsyX4fheavW+vqWW3Yk/hmmFC7W7 EqsQ3mo4hDOoNbVlVNJfCse1sqTvVilPqbYcX/J9qxp/pHiRZjDFmJWZeVHXP0sJXod5 PFSA== X-Gm-Message-State: AOAM533ConSqG6NY75wVroiFB513sUFQ/deaK4vVkY/GYDiTpTfJAcRY kJFrEmmbCtFn+F2u3igWmfmZ4GZZBEU= X-Google-Smtp-Source: ABdhPJxG8LqouPsUMoWcJvKas/E9QPwnnatmov2zneTKXWKH0Pd8m/u0YJyv2BcD+Ds8HsenBV0JPQ== X-Received: by 2002:a05:6402:1909:b0:418:d876:3119 with SMTP id e9-20020a056402190900b00418d8763119mr24473825edz.266.1647880967344; Mon, 21 Mar 2022 09:42:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 1/3] qapi-schema: support alternates with array type Date: Mon, 21 Mar 2022 17:42:41 +0100 Message-Id: <20220321164243.200569-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321164243.200569-1-pbonzini@redhat.com> References: <20220321164243.200569-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::536 (failed) 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=2a00:1450:4864:20::536; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x536.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647881089236100001 Content-Type: text/plain; charset="utf-8" Detect array types as alternate branches, and turn the JSON list into a QAPISchemaArrayType. Array types in an alternate are represented with QTYPE_QLIST in the type field. Signed-off-by: Paolo Bonzini Reviewed-by: Markus Armbruster --- scripts/qapi/expr.py | 2 +- scripts/qapi/schema.py | 4 ++++ tests/qapi-schema/alternate-array.err | 2 -- tests/qapi-schema/alternate-array.json | 2 -- tests/qapi-schema/alternate-array.out | 18 ++++++++++++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 3cb389e875..48578e1698 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -554,7 +554,7 @@ def check_alternate(expr: _JSONObject, info: QAPISource= Info) -> None: check_name_lower(key, info, source) check_keys(value, info, source, ['type'], ['if']) check_if(value, info, source) - check_type(value['type'], info, source) + check_type(value['type'], info, source, allow_array=3DTrue) =20 =20 def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None: diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index b7b3fc0ce4..3728340c37 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -243,6 +243,7 @@ def alternate_qtype(self): 'number': 'QTYPE_QNUM', 'int': 'QTYPE_QNUM', 'boolean': 'QTYPE_QBOOL', + 'array': 'QTYPE_QLIST', 'object': 'QTYPE_QDICT' } return json2qtype.get(self.json_type()) @@ -1069,6 +1070,9 @@ def _def_struct_type(self, expr, info, doc): None)) =20 def _make_variant(self, case, typ, ifcond, info): + if isinstance(typ, list): + assert len(typ) =3D=3D 1 + typ =3D self._make_array_type(typ[0], info) return QAPISchemaVariant(case, info, typ, ifcond) =20 def _def_union_type(self, expr, info, doc): diff --git a/tests/qapi-schema/alternate-array.err b/tests/qapi-schema/alte= rnate-array.err index b1aa1f4e8d..e69de29bb2 100644 --- a/tests/qapi-schema/alternate-array.err +++ b/tests/qapi-schema/alternate-array.err @@ -1,2 +0,0 @@ -alternate-array.json: In alternate 'Alt': -alternate-array.json:5: 'data' member 'two' cannot be an array diff --git a/tests/qapi-schema/alternate-array.json b/tests/qapi-schema/alt= ernate-array.json index f241aac122..b878a2db77 100644 --- a/tests/qapi-schema/alternate-array.json +++ b/tests/qapi-schema/alternate-array.json @@ -1,5 +1,3 @@ -# we do not allow array branches in alternates -# TODO: should we support this? { 'struct': 'One', 'data': { 'name': 'str' } } { 'alternate': 'Alt', diff --git a/tests/qapi-schema/alternate-array.out b/tests/qapi-schema/alte= rnate-array.out index e69de29bb2..a657d85738 100644 --- a/tests/qapi-schema/alternate-array.out +++ b/tests/qapi-schema/alternate-array.out @@ -0,0 +1,18 @@ +module ./builtin +object q_empty +enum QType + prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool +module alternate-array.json +object One + member name: str optional=3DFalse +alternate Alt + tag type + case one: One + case two: intList --=20 2.35.1 From nobody Mon Feb 9 06:27:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164788108874169.47570256785627; Mon, 21 Mar 2022 09:44:48 -0700 (PDT) Received: from localhost ([::1]:51042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWL9D-0000qH-N2 for importer@patchew.org; Mon, 21 Mar 2022 12:44:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWL7L-0007AX-HP for qemu-devel@nongnu.org; Mon, 21 Mar 2022 12:42:51 -0400 Received: from [2a00:1450:4864:20::52f] (port=43859 helo=mail-ed1-x52f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nWL7J-0007d2-LL for qemu-devel@nongnu.org; Mon, 21 Mar 2022 12:42:51 -0400 Received: by mail-ed1-x52f.google.com with SMTP id b24so18539827edu.10 for ; Mon, 21 Mar 2022 09:42:49 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id o2-20020a50d802000000b00410d7f0c52csm8289385edj.8.2022.03.21.09.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 09:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sk8pvpH+MlV1NIvcix5A72DAjg7Ob/Kh/1bdPx8dB0c=; b=fusprzqZG38XonKXSZRkoquCFKBLWPTSn/oetoy4dnif9Xfb5RBPgKIP5sNn+y66oz DcFEp5rmfYrtT/M3Z2JRh5/LYxEwX7hIwjhw/4mxrolJcYnEZ7X/VnvkXQoK++bMwfJS MAdmCzd/gPiXE5+xYcjCSPZjQhcN8BGpBo/A6xpAD9SZWtnU+CptnPenPoIk86VFeoPg SRfJfRGCN1z7SjWsk524bq3J/xo4DBVQGuEVJizBr8Haq8zl+v9gRSY0s9m2j7c9Y/xw o+pBszlFDMvP4dr8QhacgWTazXjNxb5LerVtkHQL93dmbs6oEtWVNt90w7ws+OK4Xevr NMSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Sk8pvpH+MlV1NIvcix5A72DAjg7Ob/Kh/1bdPx8dB0c=; b=40HYFnksmztqZHNiC3B1GNOqnuiscYa8L2xQYNTdCnCewdjxzm/DlNmP8F17NZh/JV qaz4DlxifGNxHLJbT6ZTp0cKOY0F8lUyKhohoP14McamFHuYfTGvhknnL6u58iVAtZrq 1Jbw27vkd3y+LnuAo/hln46k1IzrdPCK7KnK55qpb+pPiZ21ISARVsULd8iAzt9ZbnkF CfQqizsY8L3D6W8Y0X6Ez+IIuUy/YjNpamf6JyD6PGBNCeHmqaiSfsI3wn9ysLUsTe2J 5pUoGhvSCnl/DWKWFoTmXTwpc3CnYUBzstMTjCdkK4qfMMLUrtTCfVqrRPdSM9TTPS5U +H/g== X-Gm-Message-State: AOAM533c1A8KyjIoGkQsnj+QKtL+ubee4L7p7rdUJAYZ0IFiUilB+ZVR ijQhiz87FYWipcxYo0Zrp5xjLJALrTw= X-Google-Smtp-Source: ABdhPJyRoiVPlXr+lmJzBa5FWItGyeGlZLg5g46PRo/zEfKsq53AJrCsWMTLpC4irN9/u3SMUrPlcg== X-Received: by 2002:a05:6402:d0e:b0:418:f011:275e with SMTP id eb14-20020a0564020d0e00b00418f011275emr23507330edb.323.1647880968342; Mon, 21 Mar 2022 09:42:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/3] qapi-schema: test: add a qapi-schema-test for array alternates Date: Mon, 21 Mar 2022 17:42:42 +0100 Message-Id: <20220321164243.200569-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321164243.200569-1-pbonzini@redhat.com> References: <20220321164243.200569-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52f (failed) 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=2a00:1450:4864:20::52f; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647881090947100003 Content-Type: text/plain; charset="utf-8" Check that conflicts among array alternates are detected correctly. Signed-off-by: Paolo Bonzini Reviewed-by: Markus Armbruster --- tests/qapi-schema/alternate-conflict-lists.err | 2 ++ tests/qapi-schema/alternate-conflict-lists.json | 6 +++++ tests/qapi-schema/alternate-conflict-lists.out | 0 tests/qapi-schema/meson.build | 1 + 4 files changed, 8 insertions(+) create mode 100644 tests/qapi-schema/alternate-conflict-lists.err create mode 100644 tests/qapi-schema/alternate-conflict-lists.json create mode 100644 tests/qapi-schema/alternate-conflict-lists.out diff --git a/tests/qapi-schema/alternate-conflict-lists.err b/tests/qapi-sc= hema/alternate-conflict-lists.err new file mode 100644 index 0000000000..288b75a2ff --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-lists.err @@ -0,0 +1,2 @@ +alternate-conflict-lists.json: In alternate 'Alt': +alternate-conflict-lists.json:5: branch 'two' can't be distinguished from = 'one' diff --git a/tests/qapi-schema/alternate-conflict-lists.json b/tests/qapi-s= chema/alternate-conflict-lists.json new file mode 100644 index 0000000000..90710da115 --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-lists.json @@ -0,0 +1,6 @@ +# Two lists conflict even if their inner types would be compatible +{ 'struct': 'One', + 'data': { 'name': 'str' } } +{ 'alternate': 'Alt', + 'data': { 'one': [ 'int' ], + 'two': [ 'str' ] } } diff --git a/tests/qapi-schema/alternate-conflict-lists.out b/tests/qapi-sc= hema/alternate-conflict-lists.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index caf0791ba8..c18dd7d02f 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -11,6 +11,7 @@ schemas =3D [ 'alternate-conflict-dict.json', 'alternate-conflict-enum-bool.json', 'alternate-conflict-enum-int.json', + 'alternate-conflict-lists.json', 'alternate-conflict-string.json', 'alternate-conflict-bool-string.json', 'alternate-conflict-num-string.json', --=20 2.35.1 From nobody Mon Feb 9 06:27:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647881265172124.25386135814426; Mon, 21 Mar 2022 09:47:45 -0700 (PDT) Received: from localhost ([::1]:57712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWLC4-0005TP-45 for importer@patchew.org; Mon, 21 Mar 2022 12:47:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWL7M-0007BT-8s for qemu-devel@nongnu.org; Mon, 21 Mar 2022 12:42:52 -0400 Received: from [2a00:1450:4864:20::52c] (port=34531 helo=mail-ed1-x52c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nWL7K-0007d8-GI for qemu-devel@nongnu.org; Mon, 21 Mar 2022 12:42:51 -0400 Received: by mail-ed1-x52c.google.com with SMTP id h1so18558038edj.1 for ; Mon, 21 Mar 2022 09:42:50 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id o2-20020a50d802000000b00410d7f0c52csm8289385edj.8.2022.03.21.09.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 09:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OfhcIiLCY45YF/Ut1w62m8ui11c4whw09XU1Y5ZWGnU=; b=etcDERE97ferYwARvLG6VLfhPq3WCSK3EhA6eZlkbTF46qE4GyeJpBhRnn/DZueCDZ CMLVXO5/MJyv/EyIRILpBHsmgfZk349Q6IMdIOnjSaj2Co90mSKSkSyn3+QOwrAPtv69 BcSva1QPSBbhnbnk6T4qc4MR7rUBQFFOJxS1o+yZT17ltm5ZruIoFRwSCE9E5XyAivJ8 qjJSOCWFe9e3VGg2/j+82hMEQ5RSmTiLzB2jOFrnXhOhIDGjD9osF2BEw2lNzZNRTdYm cIppwLsUbMlzkom19OrA7Ne+lpxwniK4LrP18oWMl/PUOJLqeNtdpLeSApaaaC4y4zAA LGFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=OfhcIiLCY45YF/Ut1w62m8ui11c4whw09XU1Y5ZWGnU=; b=MnLHTjOjwv5Jgb5C91jYOz46oIRbVwIhu7spNl8Pzw4cpMuc7zCNIImCAI4JFcZssO Mj4gxAZKuKbsh/OxtpOFfNZsymgDJwid2x5Bl4q5oac1yg0kggzQnTt3LgfMQ8phn5E6 PD5qZwRWP4W3kbm2LP+KIFAuUDkkzZM47OJWpdtSgvQkyvGdDn8yUNplYNB3qNM9lDql i+8wAwKjlQ6Wc4Hd1fkGd9+UJoWvY0Bl/BPoncthJgHNvuagk6nSz0OLwGYfaLFZJCTd 7l/KvlHO8fYZJywd83GpUZZqFK7LaRnvNrgrm0AWdaLVYsig9ohp7fzYg+Bj5lUV77g1 6k9w== X-Gm-Message-State: AOAM532vt5tfkDAcY3sYtmnAa9TR4S7cmu+fmRzgI1+/S8WpetdygdB6 en/gtW0KG2pc/RgLvye5QmLKuTLVVuM= X-Google-Smtp-Source: ABdhPJxcKFpyVITHq65sijmLrsEGvf3IU7bOWcoUnfeUL0PqtIIopImxFbAg7PhAEdNe4TN0wk2muw== X-Received: by 2002:aa7:c683:0:b0:418:f5f3:9684 with SMTP id n3-20020aa7c683000000b00418f5f39684mr23605511edq.184.1647880969213; Mon, 21 Mar 2022 09:42:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 3/3] qapi-schema: test: add a unit test for parsing array alternates Date: Mon, 21 Mar 2022 17:42:43 +0100 Message-Id: <20220321164243.200569-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321164243.200569-1-pbonzini@redhat.com> References: <20220321164243.200569-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52c (failed) 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=2a00:1450:4864:20::52c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52c.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647881266460100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Markus Armbruster --- tests/qapi-schema/qapi-schema-test.json | 1 + tests/qapi-schema/qapi-schema-test.out | 4 +++ tests/unit/test-qobject-input-visitor.c | 43 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 43b8697002..ba7302f42b 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -119,6 +119,7 @@ { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } } { 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } } { 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } } +{ 'alternate': 'AltListInt', 'data': { 'l': ['int'], 'i': 'int' } } =20 # for testing use of 'str' within alternates { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 1f9585fa9b..043d75c655 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -121,6 +121,10 @@ alternate AltEnumInt tag type case e: EnumOne case i: int +alternate AltListInt + tag type + case l: intList + case i: int alternate AltStrObj tag type case s: str diff --git a/tests/unit/test-qobject-input-visitor.c b/tests/unit/test-qobj= ect-input-visitor.c index 6f59a7f432..2af002dd82 100644 --- a/tests/unit/test-qobject-input-visitor.c +++ b/tests/unit/test-qobject-input-visitor.c @@ -776,6 +776,7 @@ static void test_visitor_in_alternate_number(TestInputV= isitorData *data, AltEnumNum *aen; AltNumEnum *ans; AltEnumInt *asi; + AltListInt *ali; =20 /* Parsing an int */ =20 @@ -802,6 +803,12 @@ static void test_visitor_in_alternate_number(TestInput= VisitorData *data, g_assert_cmpint(asi->u.i, =3D=3D, 42); qapi_free_AltEnumInt(asi); =20 + v =3D visitor_input_test_init(data, "42"); + visit_type_AltListInt(v, NULL, &ali, &error_abort); + g_assert_cmpint(ali->type, =3D=3D, QTYPE_QNUM); + g_assert_cmpint(ali->u.i, =3D=3D, 42); + qapi_free_AltListInt(ali); + /* Parsing a double */ =20 v =3D visitor_input_test_init(data, "42.5"); @@ -827,6 +834,40 @@ static void test_visitor_in_alternate_number(TestInput= VisitorData *data, qapi_free_AltEnumInt(asi); } =20 +static void test_visitor_in_alternate_list(TestInputVisitorData *data, + const void *unused) +{ + intList *item; + Visitor *v; + AltListInt *ali; + int i; + + v =3D visitor_input_test_init(data, "[ 42, 43, 44 ]"); + visit_type_AltListInt(v, NULL, &ali, &error_abort); + g_assert(ali !=3D NULL); + + g_assert_cmpint(ali->type, =3D=3D, QTYPE_QLIST); + for (i =3D 0, item =3D ali->u.l; item; item =3D item->next, i++) { + char string[12]; + + snprintf(string, sizeof(string), "string%d", i); + g_assert_cmpint(item->value, =3D=3D, 42 + i); + } + + qapi_free_AltListInt(ali); + ali =3D NULL; + + /* An empty list is valid */ + v =3D visitor_input_test_init(data, "[]"); + visit_type_AltListInt(v, NULL, &ali, &error_abort); + g_assert(ali !=3D NULL); + + g_assert_cmpint(ali->type, =3D=3D, QTYPE_QLIST); + g_assert(!ali->u.l); + qapi_free_AltListInt(ali); + ali =3D NULL; +} + static void input_visitor_test_add(const char *testpath, const void *user_data, void (*test_func)(TestInputVisitorData = *data, @@ -1188,6 +1229,8 @@ int main(int argc, char **argv) NULL, test_visitor_in_wrong_type); input_visitor_test_add("/visitor/input/alternate-number", NULL, test_visitor_in_alternate_number); + input_visitor_test_add("/visitor/input/alternate-list", + NULL, test_visitor_in_alternate_list); input_visitor_test_add("/visitor/input/fail/struct", NULL, test_visitor_in_fail_struct); input_visitor_test_add("/visitor/input/fail/struct-nested", --=20 2.35.1