From patchwork Tue Aug 18 14:19:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 508339 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 08505140293 for ; Wed, 19 Aug 2015 00:23:56 +1000 (AEST) Received: from localhost ([::1]:57467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRhnt-00022v-NQ for incoming@patchwork.ozlabs.org; Tue, 18 Aug 2015 10:23:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRhl9-0002t6-6l for qemu-devel@nongnu.org; Tue, 18 Aug 2015 10:21:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZRhl3-0005li-CM for qemu-devel@nongnu.org; Tue, 18 Aug 2015 10:21:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRhl2-0005lW-VL for qemu-devel@nongnu.org; Tue, 18 Aug 2015 10:20:57 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id A78983679D6; Tue, 18 Aug 2015 14:20:56 +0000 (UTC) Received: from red.redhat.com (ovpn-113-180.phx2.redhat.com [10.3.113.180]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7IEKBPi029844; Tue, 18 Aug 2015 10:20:55 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 18 Aug 2015 07:19:52 -0700 Message-Id: <1439907602-11414-11-git-send-email-eblake@redhat.com> In-Reply-To: <1439907602-11414-1-git-send-email-eblake@redhat.com> References: <1439907602-11414-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH RFC v3 10/20] qapi: Add tests for empty unions 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 The documentation claims that alternates are useful for allowing two types, although nothing enforces this. Meanwhile, it is silent on whether empty unions are allowed. In practice, the generated code will compile, in part because we have a 'void *data' branch; but for an empty alternate it always fails (at least as of my recent fix to use qtypes directly), and an empty union (whether simple or flat) always causes an abort(). Add some tests to expose the problems, and adjust existing tests that should be failing for other reasons. Not tested here: we have a namespace collision, where if the qapi schema lists 'data' as one of the possible branch names of a union, then the generated C code fails to compile due to a duplicate member 'data'. Signed-off-by: Eric Blake --- tests/Makefile | 1 + tests/qapi-schema/alternate-empty.err | 0 tests/qapi-schema/alternate-empty.exit | 1 + tests/qapi-schema/alternate-empty.json | 2 ++ tests/qapi-schema/alternate-empty.out | 3 +++ tests/qapi-schema/alternate-nested.json | 2 +- tests/qapi-schema/alternate-unknown.json | 2 +- tests/qapi-schema/flat-union-empty.err | 0 tests/qapi-schema/flat-union-empty.exit | 1 + tests/qapi-schema/flat-union-empty.json | 4 ++++ tests/qapi-schema/flat-union-empty.out | 7 +++++++ tests/qapi-schema/union-empty.err | 0 tests/qapi-schema/union-empty.exit | 1 + tests/qapi-schema/union-empty.json | 2 ++ tests/qapi-schema/union-empty.out | 3 +++ 15 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/qapi-schema/alternate-empty.err create mode 100644 tests/qapi-schema/alternate-empty.exit create mode 100644 tests/qapi-schema/alternate-empty.json create mode 100644 tests/qapi-schema/alternate-empty.out create mode 100644 tests/qapi-schema/flat-union-empty.err create mode 100644 tests/qapi-schema/flat-union-empty.exit create mode 100644 tests/qapi-schema/flat-union-empty.json create mode 100644 tests/qapi-schema/flat-union-empty.out create mode 100644 tests/qapi-schema/union-empty.err create mode 100644 tests/qapi-schema/union-empty.exit create mode 100644 tests/qapi-schema/union-empty.json create mode 100644 tests/qapi-schema/union-empty.out diff --git a/tests/Makefile b/tests/Makefile index 398dc4a..8838f11 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -242,6 +242,7 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ unclosed-list.json unclosed-object.json unclosed-string.json \ duplicate-key.json union-invalid-base.json union-bad-branch.json \ union-optional-branch.json union-unknown.json union-max.json \ + union-empty.json flat-union-empty.json alternate-empty.json \ flat-union-optional-discriminator.json flat-union-no-base.json \ flat-union-invalid-discriminator.json flat-union-inline.json \ flat-union-invalid-branch-key.json flat-union-reverse-define.json \ diff --git a/tests/qapi-schema/alternate-empty.err b/tests/qapi-schema/alternate-empty.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/alternate-empty.exit b/tests/qapi-schema/alternate-empty.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/alternate-empty.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/alternate-empty.json b/tests/qapi-schema/alternate-empty.json new file mode 100644 index 0000000..db3820f --- /dev/null +++ b/tests/qapi-schema/alternate-empty.json @@ -0,0 +1,2 @@ +# FIXME - alternates should list at least two types to be useful +{ 'alternate': 'Alt', 'data': { 'i': 'int' } } diff --git a/tests/qapi-schema/alternate-empty.out b/tests/qapi-schema/alternate-empty.out new file mode 100644 index 0000000..9b010d8 --- /dev/null +++ b/tests/qapi-schema/alternate-empty.out @@ -0,0 +1,3 @@ +object :empty +alternate Alt + case i: int diff --git a/tests/qapi-schema/alternate-nested.json b/tests/qapi-schema/alternate-nested.json index c4233b9..8e22186 100644 --- a/tests/qapi-schema/alternate-nested.json +++ b/tests/qapi-schema/alternate-nested.json @@ -2,4 +2,4 @@ { 'alternate': 'Alt1', 'data': { 'name': 'str', 'value': 'int' } } { 'alternate': 'Alt2', - 'data': { 'nested': 'Alt1' } } + 'data': { 'nested': 'Alt1', 'b': 'bool' } } diff --git a/tests/qapi-schema/alternate-unknown.json b/tests/qapi-schema/alternate-unknown.json index ad5c103..08c80dc 100644 --- a/tests/qapi-schema/alternate-unknown.json +++ b/tests/qapi-schema/alternate-unknown.json @@ -1,3 +1,3 @@ # we reject an alternate with unknown type in branch { 'alternate': 'Alt', - 'data': { 'unknown': 'MissingType' } } + 'data': { 'unknown': 'MissingType', 'i': 'int' } } diff --git a/tests/qapi-schema/flat-union-empty.err b/tests/qapi-schema/flat-union-empty.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/flat-union-empty.exit b/tests/qapi-schema/flat-union-empty.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/flat-union-empty.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/flat-union-empty.json b/tests/qapi-schema/flat-union-empty.json new file mode 100644 index 0000000..67dd297 --- /dev/null +++ b/tests/qapi-schema/flat-union-empty.json @@ -0,0 +1,4 @@ +# FIXME - flat unions should not be empty +{ 'enum': 'Empty', 'data': [ ] } +{ 'struct': 'Base', 'data': { 'type': 'Empty' } } +{ 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } } diff --git a/tests/qapi-schema/flat-union-empty.out b/tests/qapi-schema/flat-union-empty.out new file mode 100644 index 0000000..0e0665a --- /dev/null +++ b/tests/qapi-schema/flat-union-empty.out @@ -0,0 +1,7 @@ +object :empty +object Base + member type: Empty optional=False +enum Empty [] +object Union + base Base + tag type diff --git a/tests/qapi-schema/union-empty.err b/tests/qapi-schema/union-empty.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/union-empty.exit b/tests/qapi-schema/union-empty.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/union-empty.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/union-empty.json b/tests/qapi-schema/union-empty.json new file mode 100644 index 0000000..1785007 --- /dev/null +++ b/tests/qapi-schema/union-empty.json @@ -0,0 +1,2 @@ +# FIXME - unions should not be empty +{ 'union': 'Union', 'data': { } } diff --git a/tests/qapi-schema/union-empty.out b/tests/qapi-schema/union-empty.out new file mode 100644 index 0000000..8b5a7bf --- /dev/null +++ b/tests/qapi-schema/union-empty.out @@ -0,0 +1,3 @@ +object :empty +object Union +enum UnionKind []