[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 03/15] qapi: Require all branches of flat union e
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v7 03/15] qapi: Require all branches of flat union enum to be covered |
Date: |
Fri, 20 May 2016 16:40:12 -0600 |
We were previously enforcing that all flat union branches were
found in the corresponding enum, but not that all enum values
were covered by branches. The resulting generated code would
abort() if the user passes the uncovered enum value.
Signed-off-by: Eric Blake <address@hidden>
---
v7: new patch
---
scripts/qapi.py | 8 ++++++++
tests/Makefile | 1 +
tests/qapi-schema/flat-union-incomplete-branch.err | 1 +
tests/qapi-schema/flat-union-incomplete-branch.exit | 1 +
tests/qapi-schema/flat-union-incomplete-branch.json | 9 +++++++++
tests/qapi-schema/flat-union-incomplete-branch.out | 0
6 files changed, 20 insertions(+)
create mode 100644 tests/qapi-schema/flat-union-incomplete-branch.err
create mode 100644 tests/qapi-schema/flat-union-incomplete-branch.exit
create mode 100644 tests/qapi-schema/flat-union-incomplete-branch.json
create mode 100644 tests/qapi-schema/flat-union-incomplete-branch.out
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 4dde43a..82d96e2 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -612,6 +612,14 @@ def check_union(expr, expr_info):
"enum '%s'" %
(key, enum_define["enum_name"]))
+ # If discriminator is user-defined, ensure all values are covered
+ if enum_define:
+ for value in enum_define['enum_values']:
+ if value not in members.keys():
+ raise QAPIExprError(expr_info,
+ "Union '%s' data missing '%s' branch"
+ % (name, value))
+
def check_alternate(expr, expr_info):
name = expr['alternate']
diff --git a/tests/Makefile b/tests/Makefile
index 0d06406..c608f9a 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -314,6 +314,7 @@ qapi-schema += flat-union-base-any.json
qapi-schema += flat-union-base-union.json
qapi-schema += flat-union-clash-member.json
qapi-schema += flat-union-empty.json
+qapi-schema += flat-union-incomplete-branch.json
qapi-schema += flat-union-inline.json
qapi-schema += flat-union-int-branch.json
qapi-schema += flat-union-invalid-branch-key.json
diff --git a/tests/qapi-schema/flat-union-incomplete-branch.err
b/tests/qapi-schema/flat-union-incomplete-branch.err
new file mode 100644
index 0000000..e826bf0
--- /dev/null
+++ b/tests/qapi-schema/flat-union-incomplete-branch.err
@@ -0,0 +1 @@
+tests/qapi-schema/flat-union-incomplete-branch.json:6: Union 'TestUnion' data
missing 'value2' branch
diff --git a/tests/qapi-schema/flat-union-incomplete-branch.exit
b/tests/qapi-schema/flat-union-incomplete-branch.exit
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/tests/qapi-schema/flat-union-incomplete-branch.exit
@@ -0,0 +1 @@
+1
diff --git a/tests/qapi-schema/flat-union-incomplete-branch.json
b/tests/qapi-schema/flat-union-incomplete-branch.json
new file mode 100644
index 0000000..25a411b
--- /dev/null
+++ b/tests/qapi-schema/flat-union-incomplete-branch.json
@@ -0,0 +1,9 @@
+# we require all branches of the union to be covered
+{ 'enum': 'TestEnum',
+ 'data': [ 'value1', 'value2' ] }
+{ 'struct': 'TestTypeA',
+ 'data': { 'string': 'str' } }
+{ 'union': 'TestUnion',
+ 'base': { 'type': 'TestEnum' },
+ 'discriminator': 'type',
+ 'data': { 'value1': 'TestTypeA' } }
diff --git a/tests/qapi-schema/flat-union-incomplete-branch.out
b/tests/qapi-schema/flat-union-incomplete-branch.out
new file mode 100644
index 0000000..e69de29
--
2.5.5
- [Qemu-devel] [PATCH v7 00/15] qapi netdev_add introspection (post-introspection cleanups subset F), Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 01/15] qapi: Consolidate object visitors, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 03/15] qapi: Require all branches of flat union enum to be covered,
Eric Blake <=
- [Qemu-devel] [PATCH v7 04/15] qapi: Hide tag_name data member of variants, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 05/15] qapi: Add type.is_empty() helper, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 02/15] net: use Netdev instead of NetClientOptions in client init, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 06/15] qapi: Plumb in 'box' to qapi generator lower levels, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 07/15] qapi: Implement boxed types for commands/events, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 10/15] qapi-event: Reduce chance of collision with event data, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 14/15] qapi: Allow anonymous branch types in flat union, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 12/15] net: Use correct type for bool flag, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 13/15] net: Complete qapi-fication of netdev_add, Eric Blake, 2016/05/20
- [Qemu-devel] [PATCH v7 15/15] schema: Drop pointless empty type CpuInfoOther, Eric Blake, 2016/05/20