All of lore.kernel.org
 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,
	ehabkost@redhat.com
Subject: [Qemu-devel] [PATCH v6 07/16] qapi: Add tests for empty unions
Date: Mon, 28 Sep 2015 21:27:20 -0600	[thread overview]
Message-ID: <1443497249-15361-8-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1443497249-15361-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 attempting to visit such a type will
cause an abort().  While there's no technical reason that a
degenerate union could not be made to work, it's harder to
justify the time spent in chasing known (the current abort()
during visit) and unknown corner cases, than it would be to
just outlaw them.  A future patch will probably take the
approach of forbidding them; in the meantime, we can at least
add testsuite coverage to make it obvious where things stand.

In addition to adding tests to expose the problems, we also
need to adjust existing tests that are meant to test something
else, but which could fail for the wrong reason if we reject
degenerate alternates/unions.

Note that empty structs are explicitly supported (for example,
right now they are the only way to specify that one branch of a
flat union adds no additional members), and empty enums are
covered by the testsuite as working (even if they do not seem
to have much use).

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v6: commit message improved, rebase to earlier added tests
---
 tests/Makefile                           | 3 +++
 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    | 4 ++++
 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, 30 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 d43b8e9..dd866af 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -226,6 +226,7 @@ qapi-schema += alternate-base.json
 qapi-schema += alternate-clash.json
 qapi-schema += alternate-conflict-dict.json
 qapi-schema += alternate-conflict-string.json
+qapi-schema += alternate-empty.json
 qapi-schema += alternate-good.json
 qapi-schema += alternate-nested.json
 qapi-schema += alternate-unknown.json
@@ -278,6 +279,7 @@ qapi-schema += flat-union-clash-branch.json
 qapi-schema += flat-union-clash-member.json
 qapi-schema += flat-union-clash-type.json
 qapi-schema += flat-union-cycle.json
+qapi-schema += flat-union-empty.json
 qapi-schema += flat-union-inline.json
 qapi-schema += flat-union-int-branch.json
 qapi-schema += flat-union-invalid-branch-key.json
@@ -336,6 +338,7 @@ qapi-schema += union-base-no-discriminator.json
 qapi-schema += union-clash-data.json
 qapi-schema += union-clash-members.json
 qapi-schema += union-clash-type.json
+qapi-schema += union-empty.json
 qapi-schema += union-invalid-base.json
 qapi-schema += union-max.json
 qapi-schema += union-optional-branch.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..0f153b6
--- /dev/null
+++ b/tests/qapi-schema/alternate-empty.out
@@ -0,0 +1,4 @@
+object :empty
+alternate Alt
+    case i: int
+enum AltKind ['i']
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 []
-- 
2.4.3

  parent reply	other threads:[~2015-09-29  3:27 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29  3:27 [Qemu-devel] [PATCH v6 00/16] post-introspection cleanups, subset A Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 01/16] qapi: Sort qapi-schema tests Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 02/16] qapi: Improve 'include' error message Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 03/16] qapi: Invoke exception superclass initializer Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 04/16] qapi: Clean up qapi.py per pep8 Eric Blake
2015-09-29 10:58   ` Markus Armbruster
2015-09-29 13:00     ` Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 05/16] qapi: Test for various name collisions Eric Blake
2015-09-29 12:33   ` Markus Armbruster
2015-09-29 14:11     ` Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 06/16] qapi: Avoid assertion failure on union 'type' collision Eric Blake
2015-09-29 12:36   ` Markus Armbruster
2015-09-29  3:27 ` Eric Blake [this message]
2015-09-29 13:17   ` [Qemu-devel] [PATCH v6 07/16] qapi: Add tests for empty unions Markus Armbruster
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 08/16] qapi: Test use of 'number' within alternates Eric Blake
2015-09-29 13:38   ` Markus Armbruster
2015-09-29 18:07     ` Eric Blake
2015-10-01  6:23       ` Markus Armbruster
2015-10-05 22:49     ` Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 09/16] qapi: Reuse code for flat union base validation Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 10/16] qapi: Consistent generated code: prefer error 'err' Eric Blake
2015-09-29 13:46   ` Markus Armbruster
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 11/16] qapi: Consistent generated code: prefer visitor 'v' Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 12/16] qapi: Consistent generated code: prefer common labels Eric Blake
2015-09-29 13:56   ` Markus Armbruster
2015-09-29 14:59     ` Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 13/16] qapi: Consistent generated code: prefer common indentation Eric Blake
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 14/16] qapi: Consistent generated code: minimize push_indent() usage Eric Blake
2015-09-29 14:10   ` Markus Armbruster
2015-09-29 15:07     ` Eric Blake
2015-10-01  6:26       ` Markus Armbruster
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 15/16] qapi: Share gen_err_check() Eric Blake
2015-09-29 14:31   ` Markus Armbruster
2015-09-29 15:15     ` Eric Blake
2015-10-01  6:33       ` Markus Armbruster
2015-09-29 20:33     ` Eric Blake
2015-10-01  6:40       ` Markus Armbruster
2015-09-29  3:27 ` [Qemu-devel] [PATCH v6 16/16] qapi: Share gen_visit_fields() Eric Blake
2015-09-29 14:38   ` Markus Armbruster

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=1443497249-15361-8-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ehabkost@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.