qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
	marcandre.lureau@redhat.com, armbru@redhat.com,
	DirtY.iCE.hu@gmail.com
Subject: [Qemu-devel] [PATCH RFC v4 13/29] qapi: Add tests for empty unions
Date: Wed,  9 Sep 2015 22:06:15 -0600	[thread overview]
Message-ID: <1441857991-7309-14-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1441857991-7309-1-git-send-email-eblake@redhat.com>

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 <eblake@redhat.com>
---
 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        | 4 ++++
 15 files changed, 28 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 1d06fa8..d1d647f 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -246,6 +246,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..c5500da
--- /dev/null
+++ b/tests/qapi-schema/union-empty.out
@@ -0,0 +1,4 @@
+object :empty
+object Union
+    tag type
+enum UnionKind []
-- 
2.4.3

  parent reply	other threads:[~2015-09-10  4:06 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-10  4:06 [Qemu-devel] [PATCH RFC v4 00/29] qapi-ify netdev_add, and other post-introspection cleanups Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 01/29] qapi: Provide nicer array names in introspection Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 02/29] net: use Netdev instead of NetClientOptions in client init Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 03/29] qapi: use 'type' in generated C code to match QMP union wire form Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 04/29] vnc: hoist allocation of VncBasicInfo to callers Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 05/29] qapi: Unbox base members Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 06/29] qapi-visit: Remove redundant functions for flat union base Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 07/29] qapi: Test use of 'number' within alternates Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 08/29] qapi: Simplify visiting of alternate types Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 09/29] qapi: Hide tag_name data member of variants Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 10/29] qapi: Fix alternates that accept 'number' but not 'int' Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 11/29] qapi: Don't pass pre-existing error to later call Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 12/29] qapi: Use consistent generated code patterns Eric Blake
2015-09-10  4:06 ` Eric Blake [this message]
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 14/29] qapi: Rework deallocation of partial struct Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 15/29] qapi: Avoid use of 'data' member of qapi unions Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 16/29] qapi: Forbid empty unions and useless alternates Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 17/29] qapi: Drop useless 'data' member of unions Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 18/29] qapi: Remove dead visitor code Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 19/29] qapi: Document visitor interfaces Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 20/29] qapi: Plug leaks in test-qmp-input-visitor Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 21/29] qapi: Test failure in middle of array parse Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 22/29] qapi: Change visit_type_FOO() to no longer return partial objects Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 23/29] qapi: Plumb in 'box' to qapi generator lower levels Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 24/29] qapi: Implement boxed structs for commands/events Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 25/29] qapi: Support boxed unions Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 26/29] qapi: Clean up qapi.py per pep8 Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 27/29] qapi: Change Netdev into a flat union Eric Blake
2015-09-17  9:15   ` Wen Congyang
2015-09-17 14:34     ` Eric Blake
2015-09-17 20:11       ` Eric Blake
2015-09-18  0:52         ` Wen Congyang
2015-09-18  6:56           ` Markus Armbruster
2015-09-18  8:36             ` Wen Congyang
2015-09-18 12:37             ` Eric Blake
2015-09-18 12:36           ` Eric Blake
2015-09-18  9:03         ` Yang Hongyang
2015-09-18 12:29           ` Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 28/29] net: Use correct type for bool flag Eric Blake
2015-09-10  4:06 ` [Qemu-devel] [PATCH RFC v4 29/29] net: Complete qapi-fication of netdev_add Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441857991-7309-14-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=DirtY.iCE.hu@gmail.com \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).