From patchwork Mon Sep 21 21:57:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 520599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EFE6214012C for ; Tue, 22 Sep 2015 07:59:12 +1000 (AEST) Received: from localhost ([::1]:34180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze978-0000ZD-Oy for incoming@patchwork.ozlabs.org; Mon, 21 Sep 2015 17:59:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze96J-0007fs-JS for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ze96I-0000rT-IS for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze96I-0000rD-2b for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:18 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id B45E6C0B918E; Mon, 21 Sep 2015 21:58:17 +0000 (UTC) Received: from red.redhat.com (ovpn-113-166.phx2.redhat.com [10.3.113.166]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8LLw4bc027229; Mon, 21 Sep 2015 17:58:17 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 21 Sep 2015 15:57:32 -0600 Message-Id: <1442872682-6523-17-git-send-email-eblake@redhat.com> In-Reply-To: <1442872682-6523-1-git-send-email-eblake@redhat.com> References: <1442872682-6523-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Michael Roth , marcandre.lureau@redhat.com, DirtY.iCE.hu@gmail.com, armbru@redhat.com, ehabkost@redhat.com Subject: [Qemu-devel] [PATCH v5 16/46] qapi: Detect base class loops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It should be fairly obvious that qapi base classes need to form an acyclic graph, since QMP cannot specify the same key more than once, while base classes are included as flat members alongside other members added by the child. But prior to Markus' introspection commits (such as commit 75ebcd7f), the test in isolation would cause python to exit with a complaint about unbounded nesting; and after his patches (in particular ac88219a), it triggers an assertion failure. This patch includes both the test and the fix, since the .err file output for an assertion failure is too hard to rebase when other patches cause line number changes. Signed-off-by: Eric Blake --- "Commit ac88219a" above assumes the commit ids from the pending pull-qapi-2015-09-21 tag will be preserved --- scripts/qapi.py | 6 +++++- tests/Makefile | 1 + tests/qapi-schema/base-cycle.err | 1 + tests/qapi-schema/base-cycle.exit | 1 + tests/qapi-schema/base-cycle.json | 3 +++ tests/qapi-schema/base-cycle.out | 0 6 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/base-cycle.err create mode 100644 tests/qapi-schema/base-cycle.exit create mode 100644 tests/qapi-schema/base-cycle.json create mode 100644 tests/qapi-schema/base-cycle.out diff --git a/tests/qapi-schema/base-cycle.out b/tests/qapi-schema/base-cycle.out new file mode 100644 index 0000000..e69de29 diff --git a/scripts/qapi.py b/scripts/qapi.py index f5f1c60..c6a047b 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -920,7 +920,11 @@ class QAPISchemaObjectType(QAPISchemaType): self.members = None def check(self, schema): - assert self.members is not False # not running in cycles + if self.members is False: # check for cycles + assert self._base_name + raise QAPIExprError(self._info, + "Object %s cyclically depends on %s" + % (self.name, self._base_name)) if self.members: return self.members = False # mark as being checked diff --git a/tests/Makefile b/tests/Makefile index df16c9c..20b84b5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -248,6 +248,7 @@ qapi-schema += bad-ident.json qapi-schema += bad-type-bool.json qapi-schema += bad-type-dict.json qapi-schema += bad-type-int.json +qapi-schema += base-cycle.json qapi-schema += command-int.json qapi-schema += comments.json qapi-schema += double-data.json diff --git a/tests/qapi-schema/base-cycle.err b/tests/qapi-schema/base-cycle.err new file mode 100644 index 0000000..e0221b5 --- /dev/null +++ b/tests/qapi-schema/base-cycle.err @@ -0,0 +1 @@ +tests/qapi-schema/base-cycle.json:2: Object Base1 cyclically depends on Base2 diff --git a/tests/qapi-schema/base-cycle.exit b/tests/qapi-schema/base-cycle.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/base-cycle.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/base-cycle.json b/tests/qapi-schema/base-cycle.json new file mode 100644 index 0000000..2866772 --- /dev/null +++ b/tests/qapi-schema/base-cycle.json @@ -0,0 +1,3 @@ +# we reject a loop in base classes +{ 'struct': 'Base1', 'base': 'Base2', 'data': {} } +{ 'struct': 'Base2', 'base': 'Base1', 'data': {} }