@@ -265,7 +265,6 @@ qapi-schema += enum-dict-member.json
qapi-schema += enum-int-member.json
qapi-schema += enum-max-member.json
qapi-schema += enum-missing-data.json
-qapi-schema += enum-union-clash.json
qapi-schema += enum-wrong-data.json
qapi-schema += escape-outside-string.json
qapi-schema += escape-too-big.json
@@ -316,6 +315,11 @@ qapi-schema += redefined-builtin.json
qapi-schema += redefined-command.json
qapi-schema += redefined-event.json
qapi-schema += redefined-type.json
+qapi-schema += reserved-command-q.json
+qapi-schema += reserved-member-has.json
+qapi-schema += reserved-member-q.json
+qapi-schema += reserved-type-kind.json
+qapi-schema += reserved-type-list.json
qapi-schema += returns-alternate.json
qapi-schema += returns-array-bad.json
qapi-schema += returns-dict.json
deleted file mode 100644
@@ -1 +0,0 @@
-tests/qapi-schema/enum-union-clash.json:2: enum 'UnionKind' should not end in 'Kind'
@@ -11,6 +11,10 @@
# An empty enum, although unusual, is currently acceptable
{ 'enum': 'MyEnum', 'data': [ ] }
+# Likewise for an empty struct, including an empty base
+{ 'struct': 'Empty1', 'data': { } }
+{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
+
# for testing override of default naming heuristic
{ 'enum': 'QEnumTwo',
'prefix': 'QENUM_TWO',
@@ -81,6 +81,9 @@ event EVENT_A None
event EVENT_B None
event EVENT_C :obj-EVENT_C-arg
event EVENT_D :obj-EVENT_D-arg
+object Empty1
+object Empty2
+ base Empty1
enum EnumOne ['value1', 'value2', 'value3']
object EventStructOne
member struct1: UserDefOne optional=False
similarity index 100%
rename from tests/qapi-schema/enum-union-clash.out
rename to tests/qapi-schema/reserved-command-q.err
new file mode 100644
@@ -0,0 +1 @@
+0
new file mode 100644
@@ -0,0 +1,7 @@
+# C entity name collision
+# FIXME - This parses, but fails to compile, because it attempts to declare
+# two 'qmp_q_unix' functions (one for 'q-unix', the other because c_name()
+# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should
+# reject attempts to explicitly use 'q_' names, to reserve it for qapi.
+{ 'command': 'unix' }
+{ 'command': 'q-unix' }
new file mode 100644
@@ -0,0 +1,5 @@
+object :empty
+command q-unix None -> None
+ gen=True success_response=True
+command unix None -> None
+ gen=True success_response=True
new file mode 100644
new file mode 100644
@@ -0,0 +1 @@
+0
new file mode 100644
@@ -0,0 +1,6 @@
+# C member name collision
+# FIXME - This parses, but fails to compile, because the C struct is given
+# two 'has_a' members, one from the flag for optional 'a', and the other
+# from member 'has-a'. Either reject this at parse time, or munge the C
+# names to avoid the collision.
+{ 'command': 'oops', 'data': { '*a': 'str', 'has-a': 'str' } }
new file mode 100644
@@ -0,0 +1,6 @@
+object :empty
+object :obj-oops-arg
+ member a: str optional=True
+ member has-a: str optional=False
+command oops :obj-oops-arg -> None
+ gen=True success_response=True
new file mode 100644
new file mode 100644
@@ -0,0 +1 @@
+0
new file mode 100644
@@ -0,0 +1,6 @@
+# C member name collision
+# FIXME - This parses, but fails to compile, because it attempts to declare
+# two 'q_unix' members (one for 'q-unix', the other because c_name()
+# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should
+# reject attempts to explicitly use 'q_' names, to reserve it for qapi.
+{ 'struct': 'Foo', 'data': { 'unix':'int', 'q-unix':'bool' } }
new file mode 100644
@@ -0,0 +1,4 @@
+object :empty
+object Foo
+ member unix: int optional=False
+ member q-unix: bool optional=False
new file mode 100644
@@ -0,0 +1 @@
+tests/qapi-schema/reserved-type-kind.json:2: enum 'UnionKind' should not end in 'Kind'
similarity index 100%
rename from tests/qapi-schema/enum-union-clash.exit
rename to tests/qapi-schema/reserved-type-kind.exit
similarity index 69%
rename from tests/qapi-schema/enum-union-clash.json
rename to tests/qapi-schema/reserved-type-kind.json
@@ -1,4 +1,2 @@
# we reject types that would conflict with implicit union enum
{ 'enum': 'UnionKind', 'data': [ 'oops' ] }
-{ 'union': 'Union',
- 'data': { 'a': 'int' } }
new file mode 100644
new file mode 100644
new file mode 100644
@@ -0,0 +1 @@
+0
new file mode 100644
@@ -0,0 +1,5 @@
+# Potential C name collision
+# FIXME - This parses and compiles on its own, but prevents the user from
+# creating a type named 'Foo' and using ['Foo'] for an array. We should
+# reject the use of any type names ending in 'List'.
+{ 'struct': 'FooList', 'data': { 's': 'str' } }
new file mode 100644
@@ -0,0 +1,3 @@
+object :empty
+object FooList
+ member s: str optional=False
Add some testsuite coverage to ensure future patches are on the right track: Our current C representation of qapi arrays is done by appending 'List' to the element name; but we are not preventing the creation of an object type with the same name. Add reserved-type-list.json to test this. Then rename enum-union-clash.json to reserved-type-kind.json to cover the reservation that we DO detect, and shorten it to match the fact that the name is reserved even if there is no clash. We are failing to detect a collision between a QMP member and the implicit 'has_*' flag for another optional QMP member. The easiest fix would be for a future patch to reserve the entire "has[-_]" namespace for member names (the collision is also possible for branch names within flat unions, but only as long as branch names can collide with QMP names; however, since future patches are about to remove that, it is not worth testing here). Add reserved-member-has.json to test this. A similar collision exists between a QMP member where c_name() munges what might otherwise be a reserved name to start with 'q_', and another member explicitly starts with "q[-_]". Again, the easiest solution for a future patch will be reserving the entire namespace, but here for commands as well as members. Add reserved-member-q.json and reserved-command-q.json to test this; separate tests since arguably our munging of command 'unix' to 'qmp_q_unix()' could be done without a q_, which is different than the munging of a member 'unix' to 'foo.q_unix'. Finally, our testsuite does not have any compilation coverage of struct inheritance with empty qapi structs. Update qapi-schema-test.json to test this. Note that there is currently no technical reason to forbid type name patterns from member names, or member name patterns from types, since the two are not in the same namespace in C and won't collide; but it's not worth adding positive tests of these corner cases at this time, especially while there is other churn pending in patches that rearrange which collisions actually happen. Signed-off-by: Eric Blake <eblake@redhat.com> --- v11: wording fixes in tests, updated commit message, rename test cases to consistent reserved-WHERE-WHAT.json naming v10: retitle, split off 'u' collisions and positive tests for later, add 'q_' collisions and empty struct inheritance, improve commit message, rename args-name-has to args-has-clash v9: new patch --- tests/Makefile | 6 +++++- tests/qapi-schema/enum-union-clash.err | 1 - tests/qapi-schema/qapi-schema-test.json | 4 ++++ tests/qapi-schema/qapi-schema-test.out | 3 +++ tests/qapi-schema/{enum-union-clash.out => reserved-command-q.err} | 0 tests/qapi-schema/reserved-command-q.exit | 1 + tests/qapi-schema/reserved-command-q.json | 7 +++++++ tests/qapi-schema/reserved-command-q.out | 5 +++++ tests/qapi-schema/reserved-member-has.err | 0 tests/qapi-schema/reserved-member-has.exit | 1 + tests/qapi-schema/reserved-member-has.json | 6 ++++++ tests/qapi-schema/reserved-member-has.out | 6 ++++++ tests/qapi-schema/reserved-member-q.err | 0 tests/qapi-schema/reserved-member-q.exit | 1 + tests/qapi-schema/reserved-member-q.json | 6 ++++++ tests/qapi-schema/reserved-member-q.out | 4 ++++ tests/qapi-schema/reserved-type-kind.err | 1 + .../qapi-schema/{enum-union-clash.exit => reserved-type-kind.exit} | 0 .../qapi-schema/{enum-union-clash.json => reserved-type-kind.json} | 2 -- tests/qapi-schema/reserved-type-kind.out | 0 tests/qapi-schema/reserved-type-list.err | 0 tests/qapi-schema/reserved-type-list.exit | 1 + tests/qapi-schema/reserved-type-list.json | 5 +++++ tests/qapi-schema/reserved-type-list.out | 3 +++ 24 files changed, 59 insertions(+), 4 deletions(-) delete mode 100644 tests/qapi-schema/enum-union-clash.err rename tests/qapi-schema/{enum-union-clash.out => reserved-command-q.err} (100%) create mode 100644 tests/qapi-schema/reserved-command-q.exit create mode 100644 tests/qapi-schema/reserved-command-q.json create mode 100644 tests/qapi-schema/reserved-command-q.out create mode 100644 tests/qapi-schema/reserved-member-has.err create mode 100644 tests/qapi-schema/reserved-member-has.exit create mode 100644 tests/qapi-schema/reserved-member-has.json create mode 100644 tests/qapi-schema/reserved-member-has.out create mode 100644 tests/qapi-schema/reserved-member-q.err create mode 100644 tests/qapi-schema/reserved-member-q.exit create mode 100644 tests/qapi-schema/reserved-member-q.json create mode 100644 tests/qapi-schema/reserved-member-q.out create mode 100644 tests/qapi-schema/reserved-type-kind.err rename tests/qapi-schema/{enum-union-clash.exit => reserved-type-kind.exit} (100%) rename tests/qapi-schema/{enum-union-clash.json => reserved-type-kind.json} (69%) create mode 100644 tests/qapi-schema/reserved-type-kind.out create mode 100644 tests/qapi-schema/reserved-type-list.err create mode 100644 tests/qapi-schema/reserved-type-list.exit create mode 100644 tests/qapi-schema/reserved-type-list.json create mode 100644 tests/qapi-schema/reserved-type-list.out