]> Git Repo - qemu.git/commitdiff
qapi: Add tests for empty unions
authorEric Blake <[email protected]>
Tue, 29 Sep 2015 22:21:05 +0000 (16:21 -0600)
committerMarkus Armbruster <[email protected]>
Mon, 12 Oct 2015 16:44:54 +0000 (18:44 +0200)
The documentation claims that alternates are useful for
allowing two or more 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 <[email protected]>
Message-Id: <1443565276[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
15 files changed:
tests/Makefile
tests/qapi-schema/alternate-empty.err [new file with mode: 0644]
tests/qapi-schema/alternate-empty.exit [new file with mode: 0644]
tests/qapi-schema/alternate-empty.json [new file with mode: 0644]
tests/qapi-schema/alternate-empty.out [new file with mode: 0644]
tests/qapi-schema/alternate-nested.json
tests/qapi-schema/alternate-unknown.json
tests/qapi-schema/flat-union-empty.err [new file with mode: 0644]
tests/qapi-schema/flat-union-empty.exit [new file with mode: 0644]
tests/qapi-schema/flat-union-empty.json [new file with mode: 0644]
tests/qapi-schema/flat-union-empty.out [new file with mode: 0644]
tests/qapi-schema/union-empty.err [new file with mode: 0644]
tests/qapi-schema/union-empty.exit [new file with mode: 0644]
tests/qapi-schema/union-empty.json [new file with mode: 0644]
tests/qapi-schema/union-empty.out [new file with mode: 0644]

index 49fdbe28aa1af5ec7d1c3271e5a8948410b02409..209eca9baee273630824765ea6b2f54f6cfa31fb 100644 (file)
@@ -229,6 +229,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
@@ -280,6 +281,7 @@ qapi-schema += flat-union-base-union.json
 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-empty.json
 qapi-schema += flat-union-inline.json
 qapi-schema += flat-union-int-branch.json
 qapi-schema += flat-union-invalid-branch-key.json
@@ -338,6 +340,7 @@ qapi-schema += union-base-no-discriminator.json
 qapi-schema += union-clash-branches.json
 qapi-schema += union-clash-data.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 (file)
index 0000000..e69de29
diff --git a/tests/qapi-schema/alternate-empty.exit b/tests/qapi-schema/alternate-empty.exit
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/qapi-schema/alternate-empty.json b/tests/qapi-schema/alternate-empty.json
new file mode 100644 (file)
index 0000000..db3820f
--- /dev/null
@@ -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 (file)
index 0000000..0f153b6
--- /dev/null
@@ -0,0 +1,4 @@
+object :empty
+alternate Alt
+    case i: int
+enum AltKind ['i']
index c4233b9f333325f75218accabe971d408622e47a..8e2218649158a5f322ee1c482c1d3a946d114527 100644 (file)
@@ -2,4 +2,4 @@
 { 'alternate': 'Alt1',
   'data': { 'name': 'str', 'value': 'int' } }
 { 'alternate': 'Alt2',
-  'data': { 'nested': 'Alt1' } }
+  'data': { 'nested': 'Alt1', 'b': 'bool' } }
index ad5c1030286336de436a74d50e5e760b9fc1fac6..08c80dced0e827d8ddd84c280faee9769e8bb614 100644 (file)
@@ -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 (file)
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 (file)
index 0000000..573541a
--- /dev/null
@@ -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 (file)
index 0000000..67dd297
--- /dev/null
@@ -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 (file)
index 0000000..0e0665a
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/tests/qapi-schema/union-empty.exit b/tests/qapi-schema/union-empty.exit
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/qapi-schema/union-empty.json b/tests/qapi-schema/union-empty.json
new file mode 100644 (file)
index 0000000..1785007
--- /dev/null
@@ -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 (file)
index 0000000..8b5a7bf
--- /dev/null
@@ -0,0 +1,3 @@
+object :empty
+object Union
+enum UnionKind []
This page took 0.039174 seconds and 4 git commands to generate.