diff options
author | Eric Blake <eblake@redhat.com> | 2016-07-13 21:50:20 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2016-07-19 13:21:08 +0200 |
commit | c818408e449ea55371253bd4def1c1dc87b7bb03 (patch) | |
tree | e5724b8a8595616485ca0443c021dbf40d4d4025 /tests/qapi-schema | |
parent | 48825ca419fd9c8140d4fecb24e982d68ebca74f (diff) | |
download | qemu-c818408e449ea55371253bd4def1c1dc87b7bb03.zip qemu-c818408e449ea55371253bd4def1c1dc87b7bb03.tar.gz qemu-c818408e449ea55371253bd4def1c1dc87b7bb03.tar.bz2 |
qapi: Implement boxed types for commands/events
Turn on the ability to pass command and event arguments in
a single boxed parameter, which must name a non-empty type
(although the type can be a struct with all optional members).
For structs, it makes it possible to pass a single qapi type
instead of a breakout of all struct members (useful if the
arguments are already in a struct or if the number of members
is large); for other complex types, it is now possible to use
a union or alternate as the data for a command or event.
The empty type may be technically feasible if needed down the
road, but it's easier to forbid it now and relax things to allow
it later, than it is to allow it now and have to special case
how the generated 'q_empty' type is handled (see commit 7ce106a9
for reasons why nothing is generated for the empty type). An
alternate type is never considered empty, but now that a boxed
type can be either an object or an alternate, we have to provide
a trivial QAPISchemaAlternateType.is_empty(). The new call to
arg_type.is_empty() during QAPISchemaCommand.check() requires
that we first check the type in question; but there is no chance
of introducing a cycle since objects do not refer back to commands.
We still have a split in syntax checking between ad-hoc parsing
up front (merely validates that 'boxed' has a sane value) and
during .check() methods (if 'boxed' is set, then 'data' must name
a non-empty user-defined type).
Generated code is unchanged, as long as no client uses the
new feature.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-10-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Test files renamed to *-boxed-*]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/qapi-schema')
24 files changed, 35 insertions, 3 deletions
diff --git a/tests/qapi-schema/args-bad-boxed.err b/tests/qapi-schema/args-bad-boxed.err new file mode 100644 index 0000000..ad0d417 --- /dev/null +++ b/tests/qapi-schema/args-bad-boxed.err @@ -0,0 +1 @@ +tests/qapi-schema/args-bad-boxed.json:2: 'boxed' of command 'foo' should only use true value diff --git a/tests/qapi-schema/args-bad-boxed.exit b/tests/qapi-schema/args-bad-boxed.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/args-bad-boxed.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/args-bad-boxed.json b/tests/qapi-schema/args-bad-boxed.json new file mode 100644 index 0000000..dea0cd0 --- /dev/null +++ b/tests/qapi-schema/args-bad-boxed.json @@ -0,0 +1,2 @@ +# 'boxed' should only appear with value true +{ 'command': 'foo', 'boxed': false } diff --git a/tests/qapi-schema/args-bad-boxed.out b/tests/qapi-schema/args-bad-boxed.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/args-bad-boxed.out diff --git a/tests/qapi-schema/args-boxed-anon.err b/tests/qapi-schema/args-boxed-anon.err new file mode 100644 index 0000000..f24f345 --- /dev/null +++ b/tests/qapi-schema/args-boxed-anon.err @@ -0,0 +1 @@ +tests/qapi-schema/args-boxed-anon.json:2: 'data' for command 'foo' should be a type name diff --git a/tests/qapi-schema/args-boxed-anon.exit b/tests/qapi-schema/args-boxed-anon.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/args-boxed-anon.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/args-boxed-anon.json b/tests/qapi-schema/args-boxed-anon.json new file mode 100644 index 0000000..95f60da --- /dev/null +++ b/tests/qapi-schema/args-boxed-anon.json @@ -0,0 +1,2 @@ +# 'boxed' can only be used with named types +{ 'command': 'foo', 'boxed': true, 'data': { 'string': 'str' } } diff --git a/tests/qapi-schema/args-boxed-anon.out b/tests/qapi-schema/args-boxed-anon.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/args-boxed-anon.out diff --git a/tests/qapi-schema/args-boxed-empty.err b/tests/qapi-schema/args-boxed-empty.err new file mode 100644 index 0000000..039603e --- /dev/null +++ b/tests/qapi-schema/args-boxed-empty.err @@ -0,0 +1 @@ +tests/qapi-schema/args-boxed-empty.json:3: Cannot use 'boxed' with empty type diff --git a/tests/qapi-schema/args-boxed-empty.exit b/tests/qapi-schema/args-boxed-empty.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/args-boxed-empty.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/args-boxed-empty.json b/tests/qapi-schema/args-boxed-empty.json new file mode 100644 index 0000000..52717e0 --- /dev/null +++ b/tests/qapi-schema/args-boxed-empty.json @@ -0,0 +1,3 @@ +# 'boxed' requires a non-empty type +{ 'struct': 'Empty', 'data': {} } +{ 'command': 'foo', 'boxed': true, 'data': 'Empty' } diff --git a/tests/qapi-schema/args-boxed-empty.out b/tests/qapi-schema/args-boxed-empty.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/args-boxed-empty.out diff --git a/tests/qapi-schema/args-boxed-string.err b/tests/qapi-schema/args-boxed-string.err new file mode 100644 index 0000000..d326b48 --- /dev/null +++ b/tests/qapi-schema/args-boxed-string.err @@ -0,0 +1 @@ +tests/qapi-schema/args-boxed-string.json:2: 'data' for command 'foo' cannot use built-in type 'str' diff --git a/tests/qapi-schema/args-boxed-string.exit b/tests/qapi-schema/args-boxed-string.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/args-boxed-string.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/args-boxed-string.json b/tests/qapi-schema/args-boxed-string.json new file mode 100644 index 0000000..f91a150 --- /dev/null +++ b/tests/qapi-schema/args-boxed-string.json @@ -0,0 +1,2 @@ +# 'boxed' requires a complex (not built-in) type +{ 'command': 'foo', 'boxed': true, 'data': 'str' } diff --git a/tests/qapi-schema/args-boxed-string.out b/tests/qapi-schema/args-boxed-string.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/args-boxed-string.out diff --git a/tests/qapi-schema/args-union.err b/tests/qapi-schema/args-union.err index 1d693d7..f8ad223 100644 --- a/tests/qapi-schema/args-union.err +++ b/tests/qapi-schema/args-union.err @@ -1 +1 @@ -tests/qapi-schema/args-union.json:4: 'data' for command 'oops' cannot use union type 'Uni' +tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni' diff --git a/tests/qapi-schema/args-union.json b/tests/qapi-schema/args-union.json index 7bdcbb7..2fcaeaa 100644 --- a/tests/qapi-schema/args-union.json +++ b/tests/qapi-schema/args-union.json @@ -1,4 +1,3 @@ -# we do not allow union arguments -# TODO should we support this? +# use of union arguments requires 'boxed':true { 'union': 'Uni', 'data': { 'case1': 'int', 'case2': 'str' } } { 'command': 'oops', 'data': 'Uni' } diff --git a/tests/qapi-schema/event-boxed-empty.err b/tests/qapi-schema/event-boxed-empty.err new file mode 100644 index 0000000..68ec6f2 --- /dev/null +++ b/tests/qapi-schema/event-boxed-empty.err @@ -0,0 +1 @@ +tests/qapi-schema/event-boxed-empty.json:2: Use of 'boxed' requires 'data' diff --git a/tests/qapi-schema/event-boxed-empty.exit b/tests/qapi-schema/event-boxed-empty.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/event-boxed-empty.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/event-boxed-empty.json b/tests/qapi-schema/event-boxed-empty.json new file mode 100644 index 0000000..cb145f1 --- /dev/null +++ b/tests/qapi-schema/event-boxed-empty.json @@ -0,0 +1,2 @@ +# 'boxed' requires a non-empty type +{ 'event': 'FOO', 'boxed': true } diff --git a/tests/qapi-schema/event-boxed-empty.out b/tests/qapi-schema/event-boxed-empty.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/event-boxed-empty.out diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index f571e1b..1719463 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -127,6 +127,8 @@ { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' }, 'returns': 'int' } { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } +{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' } +{ 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': true } # For testing integer range flattening in opts-visitor. The following schema # corresponds to the option format: @@ -154,6 +156,8 @@ 'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } } { 'event': 'EVENT_D', 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } } +{ 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' } +{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' } # test that we correctly compile downstream extensions, as well as munge # ticklish names diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 1aace71..9d99c4e 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -30,6 +30,10 @@ event EVENT_C q_obj_EVENT_C-arg boxed=False event EVENT_D q_obj_EVENT_D-arg boxed=False +event EVENT_E UserDefZero + boxed=True +event EVENT_F UserDefAlternate + boxed=True object Empty1 object Empty2 base Empty1 @@ -153,6 +157,10 @@ object __org.qemu_x-Union2 case __org.qemu_x-value: __org.qemu_x-Struct2 command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> __org.qemu_x-Union1 gen=True success_response=True boxed=False +command boxed-struct UserDefZero -> None + gen=True success_response=True boxed=True +command boxed-union UserDefNativeListUnion -> None + gen=True success_response=True boxed=True command guest-get-time q_obj_guest-get-time-arg -> int gen=True success_response=True boxed=False command guest-sync q_obj_guest-sync-arg -> any |