From nobody Thu May 9 23:58:35 2024 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=1681986419; cv=none; d=zohomail.com; s=zohoarc; b=oBaAkB70C58Omsk95m4294OvGEMTP2n/3yCIS4u6+EYO4a2jdp/Y6uAl2jXFnwLmFinYB8xh08HrDjTIitxvI29PSOjkaT/1lYw5VycD8Dj3iZP6UHgHuASK+cQP6KcG69qDTY9dTL4SqTYJRFqlBYdlkqwJAJvOzMANmchZPog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681986419; 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=MixBzwKpNzN8vnzKRI6MHoLElLQUWr71FVJ+JO9iV3U=; b=oGjCxLdl3ZZgJDjKdmfMiV5tduLIEIDCkTCSrhy+yZ3NksNp+B5b2FtL9NpbRhKV1w69Ew2zAEYcb9KfMP3laaYpPREjxu0K69XpAgWIfeJTnTX7Mf9Rtm3tEVmfPC3jhX9d60NzYB+K68r9QmLB662+D8wHk89nRUpKBCgUGWw= 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 1681986419740177.61565722386877; Thu, 20 Apr 2023 03:26:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppRUl-0008K7-7o; Thu, 20 Apr 2023 06:26:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppRUj-0008J0-5H for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:26:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppRUh-00046P-Pu for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:26:28 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-130-lzZFIbgYNhCza-1VGIBiKg-1; Thu, 20 Apr 2023 06:26:23 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B6B171C087B3; Thu, 20 Apr 2023 10:26:22 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.28.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB8932166B33; Thu, 20 Apr 2023 10:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681986386; 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=MixBzwKpNzN8vnzKRI6MHoLElLQUWr71FVJ+JO9iV3U=; b=cR8l0/8L/ijPZRtYznOq9km1YZEkb30oahzOkd+y1AS/aYKtKq48dxh0AnSOjXU9meDQIm YqF/2/hP49gEs71H4YHCh2+Xik3bKbO2zgZcU122o2+3ZThPb2wxakzrvH5N50Xvrejjac 887tKHqgSNPB9KtLbyN3vrHp62kIIaM= X-MC-Unique: lzZFIbgYNhCza-1VGIBiKg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Het Gala , Markus Armbruster , Eric Blake , Michael Roth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 1/3] qapi: support updating expected test output via make Date: Thu, 20 Apr 2023 11:26:17 +0100 Message-Id: <20230420102619.348173-2-berrange@redhat.com> In-Reply-To: <20230420102619.348173-1-berrange@redhat.com> References: <20230420102619.348173-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681986420302100001 It is possible to pass --update to tests/qapi-schema/test-qapi.py to make it update the output files on error. This is inconvenient to achieve though when test-qapi.py is run indirectly by make/meson. Instead simply allow for an env variable to be set: $ QAPI_TEST_UPDATE=3D make check-qapi-schema Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- tests/qapi-schema/test-qapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 2160cef082..d58c31f539 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -206,6 +206,7 @@ def main(argv): parser.add_argument('-d', '--dir', action=3D'store', default=3D'', help=3D"directory containing tests") parser.add_argument('-u', '--update', action=3D'store_true', + default=3D'QAPI_TEST_UPDATE' in os.environ, help=3D"update expected test results") parser.add_argument('tests', nargs=3D'*', metavar=3D'TEST', action=3D'= store') args =3D parser.parse_args() --=20 2.40.0 From nobody Thu May 9 23:58:35 2024 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=1681986454; cv=none; d=zohomail.com; s=zohoarc; b=XxzHNneLzgTzu2hl3oCMMLLUh7lz1qQHduMJN3jaJ4bjr4+LlaV7q9krnfu8jPf+LLGQV2IrIYry2Jiq6lbuUYB3p5OwExN4rDQzAmqMA6gUwTA1MeQuTwmRvQGjKsPLDWJNj1VWTzrNBY6i2SKrvvgC+mGXjp/UumM6Pjivh/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681986454; 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=TmgFt0KlWbJEaFsZiFBWOrAX9ldU5Rh1wE0MyAsLQOI=; b=aJeJR+Xvqaa6wGiAwgnwz4J86YQfytweHN6Cv7c0k5buxQWwyDYdPRwmSxOuQjn2Zhsg3act+E9GoOtM/wgA9iW4iprSmNuPNv1nnIHVZFLJUEG2LulcBUyWfEyNdv4kFsdTNg3f//GoRe0zYsJowDn5AEvjc8CAQLWveUoJ1mE= 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 1681986454530177.8674440665544; Thu, 20 Apr 2023 03:27:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppRUn-0008Lo-9f; Thu, 20 Apr 2023 06:26:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppRUk-0008Jp-HZ for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:26:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppRUi-00046e-2p for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:26:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-NyoxslOnOvqKy-CgScaH3A-1; Thu, 20 Apr 2023 06:26:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC43F101A531; Thu, 20 Apr 2023 10:26:23 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.28.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3F752166B33; Thu, 20 Apr 2023 10:26:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681986387; 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=TmgFt0KlWbJEaFsZiFBWOrAX9ldU5Rh1wE0MyAsLQOI=; b=Mcu69mT3lK9a9vY/4akEuvrsVPssNFQDVU6LWkDRN/hH7bYvsaZKPJPJ6BgSfftnuPVblT if3Zd7Z2k/CewjfgKgcQHLWWLRDvjoie+k/09QuM3bKD0YfdZKJgmNn3RivVuze24CPRL/ R79zsTO6yW/0Z255tne0C73T5GqtbaU= X-MC-Unique: NyoxslOnOvqKy-CgScaH3A-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Het Gala , Markus Armbruster , Eric Blake , Michael Roth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 2/3] qapi: improve specificity of type/member descriptions Date: Thu, 20 Apr 2023 11:26:18 +0100 Message-Id: <20230420102619.348173-3-berrange@redhat.com> In-Reply-To: <20230420102619.348173-1-berrange@redhat.com> References: <20230420102619.348173-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681986455028100001 When describing member types always include the context of the containing type. Although this is often redundant, in some cases it will help to reduce ambiguity. Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/qapi/schema.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 207e4d71f3..da04b97ded 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -697,6 +697,7 @@ def connect_doc(self, doc): =20 def describe(self, info): role =3D self.role + meta =3D 'type' defined_in =3D self.defined_in assert defined_in =20 @@ -708,13 +709,17 @@ def describe(self, info): # Implicit type created for a command's dict 'data' assert role =3D=3D 'member' role =3D 'parameter' + meta =3D 'command' + defined_in =3D defined_in[:-4] elif defined_in.endswith('-base'): # Implicit type created for a union's dict 'base' role =3D 'base ' + role + defined_in =3D defined_in[:-5] else: assert False - elif defined_in !=3D info.defn_name: - return "%s '%s' of type '%s'" % (role, self.name, defined_in) + + if defined_in !=3D info.defn_name: + return "%s '%s' of %s '%s'" % (role, self.name, meta, defined_= in) return "%s '%s'" % (role, self.name) =20 =20 --=20 2.40.0 From nobody Thu May 9 23:58:35 2024 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=1681986463; cv=none; d=zohomail.com; s=zohoarc; b=gmpzBtj7hNF8o54fQ9MefxCYjfWOAaffWwtpP/xf6UOt0E31ivIKC4PTeWrow0hh8G3XCJZroF111bqk3t1EUCJKn+14g5H9f9TYZPpoDaWeLDOxszsOLQl90XLm53xfTVnoHdzZ9txf2yJIKcg5AvnSE74fUJXEr0HLAK+9mpE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681986463; 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=WXIYeVncZxtCtqrtI8o/EOSGn7Qny8LdoDxmUEM7mU4=; b=e0FsA/kjjF5J5Nz6RthQVFVFdAdBe65SdD685vncBvfAVbk+tH6+jsgyClUJan5K3Nh/gxEozAIYDN3Veex9IRCCmYJ6Pmqp61sidnEv2HPdkrqlx7bCoHwWdGmHs+zj6PlFsrJTVH2Wm/NzcdL6BG1FFF5c2WdpAU6bas+sK6Y= 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 1681986463899512.7029499766213; Thu, 20 Apr 2023 03:27:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppRUo-0008P5-UM; Thu, 20 Apr 2023 06:26:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppRUn-0008Ly-FN for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:26:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppRUh-00046R-QU for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:26:33 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-232-AivfL253NrStnD2NmTezgw-1; Thu, 20 Apr 2023 06:26:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C99031C087AB; Thu, 20 Apr 2023 10:26:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.28.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8EB82166B33; Thu, 20 Apr 2023 10:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681986386; 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=WXIYeVncZxtCtqrtI8o/EOSGn7Qny8LdoDxmUEM7mU4=; b=OF5Wn5KfPld85PzLIj/YeDUBFxfnA/LmGfKY0qJuHw0qW4uiqc53HXzsk9aSf0hVMIMVZl I/0yUmRy4n1jnMbo4al8oYnbQHQLIXoXmUPgBXMut1276wsTODRXf9Ro7eklijk45bxRwE sms9qHutVgp1nocHJ40B/Whr1klL5TM= X-MC-Unique: AivfL253NrStnD2NmTezgw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Het Gala , Markus Armbruster , Eric Blake , Michael Roth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 3/3] qapi: allow unions to contain further unions Date: Thu, 20 Apr 2023 11:26:19 +0100 Message-Id: <20230420102619.348173-4-berrange@redhat.com> In-Reply-To: <20230420102619.348173-1-berrange@redhat.com> References: <20230420102619.348173-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681986465226100002 This extends the QAPI schema validation to permit unions inside unions, provided the checks for clashing fields pass. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/qapi/schema.py | 6 +- tests/qapi-schema/meson.build | 2 + tests/qapi-schema/qapi-schema-test.json | 32 ++++++++++ tests/qapi-schema/qapi-schema-test.out | 29 ++++++++++ .../union-invalid-union-subfield.err | 2 + .../union-invalid-union-subfield.json | 30 ++++++++++ .../union-invalid-union-subfield.out | 0 .../union-invalid-union-subtype.err | 2 + .../union-invalid-union-subtype.json | 29 ++++++++++ .../union-invalid-union-subtype.out | 0 tests/unit/test-qobject-input-visitor.c | 47 +++++++++++++++ tests/unit/test-qobject-output-visitor.c | 58 +++++++++++++++++++ 12 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 tests/qapi-schema/union-invalid-union-subfield.err create mode 100644 tests/qapi-schema/union-invalid-union-subfield.json create mode 100644 tests/qapi-schema/union-invalid-union-subfield.out create mode 100644 tests/qapi-schema/union-invalid-union-subtype.err create mode 100644 tests/qapi-schema/union-invalid-union-subtype.json create mode 100644 tests/qapi-schema/union-invalid-union-subtype.out diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index da04b97ded..edb09f2ed2 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -465,9 +465,10 @@ def check(self, schema): # on behalf of info, which is not necessarily self.info def check_clash(self, info, seen): assert self._checked - assert not self.variants # not implemented for m in self.members: m.check_clash(info, seen) + if self.variants: + self.variants.check_clash(info, seen) =20 def connect_doc(self, doc=3DNone): super().connect_doc(doc) @@ -652,8 +653,7 @@ def check(self, schema, seen): self.info, "branch '%s' is not a value of %s" % (v.name, self.tag_member.type.describe())) - if (not isinstance(v.type, QAPISchemaObjectType) - or v.type.variants): + if not isinstance(v.type, QAPISchemaObjectType): raise QAPISemError( self.info, "%s cannot use %s" diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index d85b14f28c..1591eb322b 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -194,6 +194,8 @@ schemas =3D [ 'union-invalid-data.json', 'union-invalid-discriminator.json', 'union-invalid-if-discriminator.json', + 'union-invalid-union-subfield.json', + 'union-invalid-union-subtype.json', 'union-no-base.json', 'union-optional-discriminator.json', 'union-string-discriminator.json', diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index ba7302f42b..40f1a3d88d 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -114,6 +114,38 @@ { 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } } =20 +# this tests that unions can contain other unions in their branches +{ 'enum': 'TestUnionEnum', + 'data': [ 'value-a', 'value-b' ] } + +{ 'enum': 'TestUnionEnumA', + 'data': [ 'value-a1', 'value-a2' ] } + +{ 'struct': 'TestUnionTypeA1', + 'data': { 'integer': 'int', + 'name': 'str'} } + +{ 'struct': 'TestUnionTypeA2', + 'data': { 'integer': 'int', + 'size': 'int' } } + +{ 'union': 'TestUnionTypeA', + 'base': { 'type-a': 'TestUnionEnumA' }, + 'discriminator': 'type-a', + 'data': { 'value-a1': 'TestUnionTypeA1', + 'value-a2': 'TestUnionTypeA2' } } + +{ 'struct': 'TestUnionTypeB', + 'data': { 'integer': 'int', + 'onoff': 'bool' } } + +{ 'union': 'TestUnionInUnion', + 'base': { 'type': 'TestUnionEnum' }, + 'discriminator': 'type', + 'data': { 'value-a': 'TestUnionTypeA', + 'value-b': 'TestUnionTypeB' } } + + # for testing use of 'number' within alternates { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } } { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 043d75c655..9fe1038944 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -105,6 +105,35 @@ alternate UserDefAlternate object UserDefC member string1: str optional=3DFalse member string2: str optional=3DFalse +enum TestUnionEnum + member value-a + member value-b +enum TestUnionEnumA + member value-a1 + member value-a2 +object TestUnionTypeA1 + member integer: int optional=3DFalse + member name: str optional=3DFalse +object TestUnionTypeA2 + member integer: int optional=3DFalse + member size: int optional=3DFalse +object q_obj_TestUnionTypeA-base + member type-a: TestUnionEnumA optional=3DFalse +object TestUnionTypeA + base q_obj_TestUnionTypeA-base + tag type-a + case value-a1: TestUnionTypeA1 + case value-a2: TestUnionTypeA2 +object TestUnionTypeB + member integer: int optional=3DFalse + member onoff: bool optional=3DFalse +object q_obj_TestUnionInUnion-base + member type: TestUnionEnum optional=3DFalse +object TestUnionInUnion + base q_obj_TestUnionInUnion-base + tag type + case value-a: TestUnionTypeA + case value-b: TestUnionTypeB alternate AltEnumBool tag type case e: EnumOne diff --git a/tests/qapi-schema/union-invalid-union-subfield.err b/tests/qap= i-schema/union-invalid-union-subfield.err new file mode 100644 index 0000000000..91aa87bcd8 --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subfield.err @@ -0,0 +1,2 @@ +union-invalid-union-subfield.json: In union 'TestUnion': +union-invalid-union-subfield.json:25: member 'teeth' of type 'TestTypeFish= ' collides with base member 'teeth' diff --git a/tests/qapi-schema/union-invalid-union-subfield.json b/tests/qa= pi-schema/union-invalid-union-subfield.json new file mode 100644 index 0000000000..e1639d3a96 --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subfield.json @@ -0,0 +1,30 @@ +# Clash between common member and union variant's variant member +# Base's member 'teeth' clashes with TestTypeFish's + +{ 'enum': 'TestEnum', + 'data': [ 'animals', 'plants' ] } + +{ 'enum': 'TestAnimals', + 'data': [ 'fish', 'birds'] } + +{ 'struct': 'TestTypeFish', + 'data': { 'scales': 'int', 'teeth': 'int' } } + +{ 'struct': 'TestTypeBirds', + 'data': { 'feathers': 'int' } } + +{ 'union': 'TestTypeAnimals', + 'base': { 'atype': 'TestAnimals' }, + 'discriminator': 'atype', + 'data': { 'fish': 'TestTypeFish', + 'birds': 'TestTypeBirds' } } + +{ 'struct': 'TestTypePlants', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestUnion', + 'base': { 'type': 'TestEnum', + 'teeth': 'int' }, + 'discriminator': 'type', + 'data': { 'animals': 'TestTypeAnimals', + 'plants': 'TestTypePlants' } } diff --git a/tests/qapi-schema/union-invalid-union-subfield.out b/tests/qap= i-schema/union-invalid-union-subfield.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/union-invalid-union-subtype.err b/tests/qapi= -schema/union-invalid-union-subtype.err new file mode 100644 index 0000000000..3538dc2e70 --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subtype.err @@ -0,0 +1,2 @@ +union-invalid-union-subtype.json: In union 'TestUnion': +union-invalid-union-subtype.json:25: base member 'type' of type 'TestTypeA= ' collides with base member 'type' diff --git a/tests/qapi-schema/union-invalid-union-subtype.json b/tests/qap= i-schema/union-invalid-union-subtype.json new file mode 100644 index 0000000000..ce1de51d8d --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subtype.json @@ -0,0 +1,29 @@ +# Clash between common member and union variant's common member +# Base's member 'type' clashes with TestTypeA's + +{ 'enum': 'TestEnum', + 'data': [ 'value-a', 'value-b' ] } + +{ 'enum': 'TestEnumA', + 'data': [ 'value-a1', 'value-a2' ] } + +{ 'struct': 'TestTypeA1', + 'data': { 'integer': 'int' } } + +{ 'struct': 'TestTypeA2', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestTypeA', + 'base': { 'type': 'TestEnumA' }, + 'discriminator': 'type', + 'data': { 'value-a1': 'TestTypeA1', + 'value-a2': 'TestTypeA2' } } + +{ 'struct': 'TestTypeB', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestUnion', + 'base': { 'type': 'TestEnum' }, + 'discriminator': 'type', + 'data': { 'value-a': 'TestTypeA', + 'value-b': 'TestTypeB' } } diff --git a/tests/qapi-schema/union-invalid-union-subtype.out b/tests/qapi= -schema/union-invalid-union-subtype.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/test-qobject-input-visitor.c b/tests/unit/test-qobj= ect-input-visitor.c index 77fbf985be..9b3e2dbe14 100644 --- a/tests/unit/test-qobject-input-visitor.c +++ b/tests/unit/test-qobject-input-visitor.c @@ -706,6 +706,51 @@ static void test_visitor_in_union_flat(TestInputVisito= rData *data, g_assert(&base->enum1 =3D=3D &tmp->enum1); } =20 +static void test_visitor_in_union_in_union(TestInputVisitorData *data, + const void *unused) +{ + Visitor *v; + g_autoptr(TestUnionInUnion) tmp =3D NULL; + + v =3D visitor_input_test_init(data, + "{ 'type': 'value-a', " + " 'type-a': 'value-a1', " + " 'integer': 2, " + " 'name': 'fish' }"); + + visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, TEST_UNION_ENUM_VALUE_A); + g_assert_cmpint(tmp->u.value_a.type_a, =3D=3D, TEST_UNION_ENUMA_VALUE_= A1); + g_assert_cmpint(tmp->u.value_a.u.value_a1.integer, =3D=3D, 2); + g_assert_cmpint(strcmp(tmp->u.value_a.u.value_a1.name, "fish"), =3D=3D= , 0); + + qapi_free_TestUnionInUnion(tmp); + + v =3D visitor_input_test_init(data, + "{ 'type': 'value-a', " + " 'type-a': 'value-a2', " + " 'integer': 1729, " + " 'size': 87539319 }"); + + visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, TEST_UNION_ENUM_VALUE_A); + g_assert_cmpint(tmp->u.value_a.type_a, =3D=3D, TEST_UNION_ENUMA_VALUE_= A2); + g_assert_cmpint(tmp->u.value_a.u.value_a2.integer, =3D=3D, 1729); + g_assert_cmpint(tmp->u.value_a.u.value_a2.size, =3D=3D, 87539319); + + qapi_free_TestUnionInUnion(tmp); + + v =3D visitor_input_test_init(data, + "{ 'type': 'value-b', " + " 'integer': 1729, " + " 'onoff': true }"); + + visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, TEST_UNION_ENUM_VALUE_B); + g_assert_cmpint(tmp->u.value_b.integer, =3D=3D, 1729); + g_assert_cmpint(tmp->u.value_b.onoff, =3D=3D, true); +} + static void test_visitor_in_alternate(TestInputVisitorData *data, const void *unused) { @@ -1216,6 +1261,8 @@ int main(int argc, char **argv) NULL, test_visitor_in_null); input_visitor_test_add("/visitor/input/union-flat", NULL, test_visitor_in_union_flat); + input_visitor_test_add("/visitor/input/union-in-union", + NULL, test_visitor_in_union_in_union); input_visitor_test_add("/visitor/input/alternate", NULL, test_visitor_in_alternate); input_visitor_test_add("/visitor/input/errors", diff --git a/tests/unit/test-qobject-output-visitor.c b/tests/unit/test-qob= ject-output-visitor.c index 7f054289fe..1535b3ad17 100644 --- a/tests/unit/test-qobject-output-visitor.c +++ b/tests/unit/test-qobject-output-visitor.c @@ -352,6 +352,62 @@ static void test_visitor_out_union_flat(TestOutputVisi= torData *data, qapi_free_UserDefFlatUnion(tmp); } =20 +static void test_visitor_out_union_in_union(TestOutputVisitorData *data, + const void *unused) +{ + QDict *qdict; + + TestUnionInUnion *tmp =3D g_new0(TestUnionInUnion, 1); + tmp->type =3D TEST_UNION_ENUM_VALUE_A; + tmp->u.value_a.type_a =3D TEST_UNION_ENUMA_VALUE_A1; + tmp->u.value_a.u.value_a1.integer =3D 42; + tmp->u.value_a.u.value_a1.name =3D g_strdup("fish"); + + visit_type_TestUnionInUnion(data->ov, NULL, &tmp, &error_abort); + qdict =3D qobject_to(QDict, visitor_get(data)); + g_assert(qdict); + g_assert_cmpstr(qdict_get_str(qdict, "type"), =3D=3D, "value-a"); + g_assert_cmpstr(qdict_get_str(qdict, "type-a"), =3D=3D, "value-a1"); + g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 42); + g_assert_cmpstr(qdict_get_str(qdict, "name"), =3D=3D, "fish"); + + qapi_free_TestUnionInUnion(tmp); + + + visitor_reset(data); + tmp =3D g_new0(TestUnionInUnion, 1); + tmp->type =3D TEST_UNION_ENUM_VALUE_A; + tmp->u.value_a.type_a =3D TEST_UNION_ENUMA_VALUE_A2; + tmp->u.value_a.u.value_a2.integer =3D 1729; + tmp->u.value_a.u.value_a2.size =3D 87539319; + + visit_type_TestUnionInUnion(data->ov, NULL, &tmp, &error_abort); + qdict =3D qobject_to(QDict, visitor_get(data)); + g_assert(qdict); + g_assert_cmpstr(qdict_get_str(qdict, "type"), =3D=3D, "value-a"); + g_assert_cmpstr(qdict_get_str(qdict, "type-a"), =3D=3D, "value-a2"); + g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 1729); + g_assert_cmpint(qdict_get_int(qdict, "size"), =3D=3D, 87539319); + + qapi_free_TestUnionInUnion(tmp); + + + visitor_reset(data); + tmp =3D g_new0(TestUnionInUnion, 1); + tmp->type =3D TEST_UNION_ENUM_VALUE_B; + tmp->u.value_b.integer =3D 1729; + tmp->u.value_b.onoff =3D true; + + visit_type_TestUnionInUnion(data->ov, NULL, &tmp, &error_abort); + qdict =3D qobject_to(QDict, visitor_get(data)); + g_assert(qdict); + g_assert_cmpstr(qdict_get_str(qdict, "type"), =3D=3D, "value-b"); + g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 1729); + g_assert_cmpint(qdict_get_bool(qdict, "onoff"), =3D=3D, true); + + qapi_free_TestUnionInUnion(tmp); +} + static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) { @@ -586,6 +642,8 @@ int main(int argc, char **argv) &out_visitor_data, test_visitor_out_list_qapi_= free); output_visitor_test_add("/visitor/output/union-flat", &out_visitor_data, test_visitor_out_union_flat= ); + output_visitor_test_add("/visitor/output/union-in-union", + &out_visitor_data, test_visitor_out_union_in_u= nion); output_visitor_test_add("/visitor/output/alternate", &out_visitor_data, test_visitor_out_alternate); output_visitor_test_add("/visitor/output/null", --=20 2.40.0