2018-02-11 10:35:54 +01:00
|
|
|
object q_empty
|
|
|
|
enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
|
|
|
|
prefix QTYPE
|
2018-02-11 10:35:55 +01:00
|
|
|
module qapi-schema-test.json
|
2018-02-11 10:35:54 +01:00
|
|
|
object TestStruct
|
|
|
|
member integer: int optional=False
|
|
|
|
member boolean: bool optional=False
|
2015-09-16 13:06:08 +02:00
|
|
|
member string: str optional=False
|
|
|
|
object NestedEnumsOne
|
|
|
|
member enum1: EnumOne optional=False
|
|
|
|
member enum2: EnumOne optional=True
|
|
|
|
member enum3: EnumOne optional=False
|
|
|
|
member enum4: EnumOne optional=True
|
2018-02-11 10:35:54 +01:00
|
|
|
enum MyEnum []
|
|
|
|
object Empty1
|
|
|
|
object Empty2
|
|
|
|
base Empty1
|
|
|
|
command user_def_cmd0 Empty2 -> Empty2
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=False oob=False
|
2015-09-16 13:06:08 +02:00
|
|
|
enum QEnumTwo ['value1', 'value2']
|
|
|
|
prefix QENUM_TWO
|
2018-02-11 10:35:54 +01:00
|
|
|
object UserDefOne
|
|
|
|
base UserDefZero
|
|
|
|
member string: str optional=False
|
|
|
|
member enum1: EnumOne optional=True
|
|
|
|
enum EnumOne ['value1', 'value2', 'value3']
|
|
|
|
object UserDefZero
|
qapi: Use generated TestStruct machinery in tests
Commit d88f5fd and friends first introduced the various test-qmp-*
tests in 2011, with duplicated hand-rolled TestStruct machinery,
to make sure the qapi visitor interface was tested. Later, commit
4f193e3 in 2013 added a .json file for further testing use by the
files, but without consolidating any of the existing hand-rolled
visitors. And with four copies, subtle differences have crept in,
between the tests themselves (mainly whitespace differences, but
also a question of whether to use NULL or "TestStruct" when
calling visit_start_struct()) and from what the generator produces
(the hand-rolled versions did not cater to partially-allocated
objects, because they did not have a deallocation usage).
Of course, just because the visitor interface is tested does not
mean it is a sane interface; and future patches will be changing
some of the visitor contracts. Rather than having to duplicate
the cleanup work in each copy of the TestStruct visitor, and keep
each hand-rolled copy in sync with what the generator supplies, we
might as well just test what the generator should give us in the
first place.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1446791754-23823-2-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-06 07:35:25 +01:00
|
|
|
member integer: int optional=False
|
2018-02-11 10:35:54 +01:00
|
|
|
object UserDefTwoDictDict
|
|
|
|
member userdef: UserDefOne optional=False
|
qapi: Use generated TestStruct machinery in tests
Commit d88f5fd and friends first introduced the various test-qmp-*
tests in 2011, with duplicated hand-rolled TestStruct machinery,
to make sure the qapi visitor interface was tested. Later, commit
4f193e3 in 2013 added a .json file for further testing use by the
files, but without consolidating any of the existing hand-rolled
visitors. And with four copies, subtle differences have crept in,
between the tests themselves (mainly whitespace differences, but
also a question of whether to use NULL or "TestStruct" when
calling visit_start_struct()) and from what the generator produces
(the hand-rolled versions did not cater to partially-allocated
objects, because they did not have a deallocation usage).
Of course, just because the visitor interface is tested does not
mean it is a sane interface; and future patches will be changing
some of the visitor contracts. Rather than having to duplicate
the cleanup work in each copy of the TestStruct visitor, and keep
each hand-rolled copy in sync with what the generator supplies, we
might as well just test what the generator should give us in the
first place.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1446791754-23823-2-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-06 07:35:25 +01:00
|
|
|
member string: str optional=False
|
2018-02-11 10:35:54 +01:00
|
|
|
object UserDefTwoDict
|
|
|
|
member string1: str optional=False
|
|
|
|
member dict2: UserDefTwoDictDict optional=False
|
|
|
|
member dict3: UserDefTwoDictDict optional=True
|
|
|
|
object UserDefTwo
|
|
|
|
member string0: str optional=False
|
|
|
|
member dict1: UserDefTwoDict optional=False
|
|
|
|
object ForceArrays
|
|
|
|
member unused1: UserDefOneList optional=False
|
|
|
|
member unused2: UserDefTwoList optional=False
|
|
|
|
member unused3: TestStructList optional=False
|
2015-09-16 13:06:08 +02:00
|
|
|
object UserDefA
|
|
|
|
member boolean: bool optional=False
|
qapi: Test for various name collisions
Expose some weaknesses in the generator: we don't always forbid
the generation of structs that contain multiple members that map
to the same C or QMP name. This has already been marked FIXME in
qapi.py in commit d90675f, but having more tests will make sure
future patches produce desired behavior; and updating existing
patches to better document things doesn't hurt, either. Some of
these collisions are already caught in the old-style parser
checks, but ultimately we want all collisions to be caught in the
new-style QAPISchema*.check() methods.
This patch focuses on C struct members, and does not consider
collisions between commands and events (affecting C function
names), or even collisions between generated C type names with
user type names (for things like automatic FOOList struct
representing array types or FOOKind for an implicit enum).
There are two types of struct collisions we want to catch:
1) Collision between two keys in a JSON object. qapi.py prevents
that within a single struct (see test duplicate-key), but it is
possible to have collisions between a type's members and its
base type's members (existing tests struct-base-clash,
struct-base-clash-deep), and its flat union variant members
(renamed test flat-union-clash-member).
2) Collision between two members of the C struct that is generated
for a given QAPI type:
a) Multiple QAPI names map to the same C name (new test
args-name-clash)
b) A QAPI name maps to a C name that is used for another purpose
(new tests flat-union-clash-branch, struct-base-clash-base,
union-clash-data). We already fixed some such cases in commit
0f61af3e and 1e6c1616, but more remain.
c) Two C names generated for other purposes clash
(updated test alternate-clash, new test union-clash-branches,
union-clash-type, flat-union-clash-type)
Ultimately, if we need to have a flat union where a tag value
clashes with a base member name, we could change the generator to
name the union (using 'foo.u.value' rather than 'foo.value') or
otherwise munge the C name corresponding to tag values. But
unless such a need arises, it will probably be easier to just
forbid these collisions.
Some of these negative tests will be deleted later, and positive
tests added to qapi-schema-test.json in their place, when the
generator code is reworked to avoid particular code generation
collisions in class 2).
[Note that viewing this patch with git rename detection enabled
may see some confusion due to renaming some tests while adding
others, but where the content is similar enough that git picks
the wrong pre- and post-patch files to associate]
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-6-git-send-email-eblake@redhat.com>
[Improve commit message and comments a bit, drop an unrelated test]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-30 00:21:03 +02:00
|
|
|
member a_b: int optional=True
|
2015-09-16 13:06:08 +02:00
|
|
|
object UserDefB
|
|
|
|
member intb: int optional=False
|
qapi: Test for various name collisions
Expose some weaknesses in the generator: we don't always forbid
the generation of structs that contain multiple members that map
to the same C or QMP name. This has already been marked FIXME in
qapi.py in commit d90675f, but having more tests will make sure
future patches produce desired behavior; and updating existing
patches to better document things doesn't hurt, either. Some of
these collisions are already caught in the old-style parser
checks, but ultimately we want all collisions to be caught in the
new-style QAPISchema*.check() methods.
This patch focuses on C struct members, and does not consider
collisions between commands and events (affecting C function
names), or even collisions between generated C type names with
user type names (for things like automatic FOOList struct
representing array types or FOOKind for an implicit enum).
There are two types of struct collisions we want to catch:
1) Collision between two keys in a JSON object. qapi.py prevents
that within a single struct (see test duplicate-key), but it is
possible to have collisions between a type's members and its
base type's members (existing tests struct-base-clash,
struct-base-clash-deep), and its flat union variant members
(renamed test flat-union-clash-member).
2) Collision between two members of the C struct that is generated
for a given QAPI type:
a) Multiple QAPI names map to the same C name (new test
args-name-clash)
b) A QAPI name maps to a C name that is used for another purpose
(new tests flat-union-clash-branch, struct-base-clash-base,
union-clash-data). We already fixed some such cases in commit
0f61af3e and 1e6c1616, but more remain.
c) Two C names generated for other purposes clash
(updated test alternate-clash, new test union-clash-branches,
union-clash-type, flat-union-clash-type)
Ultimately, if we need to have a flat union where a tag value
clashes with a base member name, we could change the generator to
name the union (using 'foo.u.value' rather than 'foo.value') or
otherwise munge the C name corresponding to tag values. But
unless such a need arises, it will probably be easier to just
forbid these collisions.
Some of these negative tests will be deleted later, and positive
tests added to qapi-schema-test.json in their place, when the
generator code is reworked to avoid particular code generation
collisions in class 2).
[Note that viewing this patch with git rename detection enabled
may see some confusion due to renaming some tests while adding
others, but where the content is similar enough that git picks
the wrong pre- and post-patch files to associate]
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-6-git-send-email-eblake@redhat.com>
[Improve commit message and comments a bit, drop an unrelated test]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-30 00:21:03 +02:00
|
|
|
member a-b: bool optional=True
|
2015-09-16 13:06:08 +02:00
|
|
|
object UserDefFlatUnion
|
|
|
|
base UserDefUnionBase
|
|
|
|
tag enum1
|
|
|
|
case value1: UserDefA
|
|
|
|
case value2: UserDefB
|
|
|
|
case value3: UserDefB
|
2018-02-11 10:35:54 +01:00
|
|
|
object UserDefUnionBase
|
|
|
|
base UserDefZero
|
|
|
|
member string: str optional=False
|
|
|
|
member enum1: EnumOne optional=False
|
|
|
|
object q_obj_UserDefFlatUnion2-base
|
|
|
|
member integer: int optional=True
|
|
|
|
member string: str optional=False
|
|
|
|
member enum1: QEnumTwo optional=False
|
2015-09-16 13:06:08 +02:00
|
|
|
object UserDefFlatUnion2
|
2016-03-17 23:48:39 +01:00
|
|
|
base q_obj_UserDefFlatUnion2-base
|
2015-09-16 13:06:08 +02:00
|
|
|
tag enum1
|
|
|
|
case value1: UserDefC
|
|
|
|
case value2: UserDefB
|
2018-02-11 10:35:54 +01:00
|
|
|
object WrapAlternate
|
|
|
|
member alt: UserDefAlternate optional=False
|
|
|
|
alternate UserDefAlternate
|
|
|
|
tag type
|
|
|
|
case udfu: UserDefFlatUnion
|
|
|
|
case e: EnumOne
|
|
|
|
case i: int
|
|
|
|
case n: null
|
|
|
|
object UserDefC
|
|
|
|
member string1: str optional=False
|
|
|
|
member string2: str optional=False
|
|
|
|
alternate AltEnumBool
|
|
|
|
tag type
|
|
|
|
case e: EnumOne
|
|
|
|
case b: bool
|
|
|
|
alternate AltEnumNum
|
|
|
|
tag type
|
|
|
|
case e: EnumOne
|
|
|
|
case n: number
|
|
|
|
alternate AltNumEnum
|
|
|
|
tag type
|
|
|
|
case n: number
|
|
|
|
case e: EnumOne
|
|
|
|
alternate AltEnumInt
|
|
|
|
tag type
|
|
|
|
case e: EnumOne
|
|
|
|
case i: int
|
|
|
|
alternate AltStrObj
|
|
|
|
tag type
|
|
|
|
case s: str
|
|
|
|
case o: TestStruct
|
|
|
|
object q_obj_intList-wrapper
|
|
|
|
member data: intList optional=False
|
|
|
|
object q_obj_int8List-wrapper
|
|
|
|
member data: int8List optional=False
|
|
|
|
object q_obj_int16List-wrapper
|
|
|
|
member data: int16List optional=False
|
|
|
|
object q_obj_int32List-wrapper
|
|
|
|
member data: int32List optional=False
|
|
|
|
object q_obj_int64List-wrapper
|
|
|
|
member data: int64List optional=False
|
|
|
|
object q_obj_uint8List-wrapper
|
|
|
|
member data: uint8List optional=False
|
|
|
|
object q_obj_uint16List-wrapper
|
|
|
|
member data: uint16List optional=False
|
|
|
|
object q_obj_uint32List-wrapper
|
|
|
|
member data: uint32List optional=False
|
|
|
|
object q_obj_uint64List-wrapper
|
|
|
|
member data: uint64List optional=False
|
|
|
|
object q_obj_numberList-wrapper
|
|
|
|
member data: numberList optional=False
|
|
|
|
object q_obj_boolList-wrapper
|
|
|
|
member data: boolList optional=False
|
|
|
|
object q_obj_strList-wrapper
|
|
|
|
member data: strList optional=False
|
|
|
|
object q_obj_sizeList-wrapper
|
|
|
|
member data: sizeList optional=False
|
|
|
|
object q_obj_anyList-wrapper
|
|
|
|
member data: anyList optional=False
|
|
|
|
enum UserDefNativeListUnionKind ['integer', 's8', 's16', 's32', 's64', 'u8', 'u16', 'u32', 'u64', 'number', 'boolean', 'string', 'sizes', 'any']
|
2015-09-16 13:06:08 +02:00
|
|
|
object UserDefNativeListUnion
|
qapi: Track simple union tag in object.local_members
We were previously creating all unions with an empty list for
local_members. However, it will make it easier to unify struct
and union generation if we include the generated tag member in
local_members. That way, we can have a common code pattern:
visit the base (if any), visit the local members (if any), visit
the variants (if any). The local_members of a flat union
remains empty (because the discriminator is already visited as
part of the base). Then, by visiting tag_member.check() during
AlternateType.check(), we no longer need to call it during
Variants.check().
The various front end entities now exist as follows:
struct: optional base, optional local_members, no variants
simple union: no base, one-element local_members, variants with tag_member
from local_members
flat union: base, no local_members, variants with tag_member from base
alternate: no base, no local_members, variants
With the new local members, we require a bit of finesse to
avoid assertions in the clients.
No change to generated code.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-2-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:36 +01:00
|
|
|
member type: UserDefNativeListUnionKind optional=False
|
2016-07-14 05:50:15 +02:00
|
|
|
tag type
|
2016-03-17 23:48:29 +01:00
|
|
|
case integer: q_obj_intList-wrapper
|
|
|
|
case s8: q_obj_int8List-wrapper
|
|
|
|
case s16: q_obj_int16List-wrapper
|
|
|
|
case s32: q_obj_int32List-wrapper
|
|
|
|
case s64: q_obj_int64List-wrapper
|
|
|
|
case u8: q_obj_uint8List-wrapper
|
|
|
|
case u16: q_obj_uint16List-wrapper
|
|
|
|
case u32: q_obj_uint32List-wrapper
|
|
|
|
case u64: q_obj_uint64List-wrapper
|
|
|
|
case number: q_obj_numberList-wrapper
|
|
|
|
case boolean: q_obj_boolList-wrapper
|
|
|
|
case string: q_obj_strList-wrapper
|
|
|
|
case sizes: q_obj_sizeList-wrapper
|
|
|
|
case any: q_obj_anyList-wrapper
|
2018-02-11 10:35:54 +01:00
|
|
|
command user_def_cmd None -> None
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=False oob=False
|
2018-02-11 10:35:54 +01:00
|
|
|
object q_obj_user_def_cmd1-arg
|
|
|
|
member ud1a: UserDefOne optional=False
|
|
|
|
command user_def_cmd1 q_obj_user_def_cmd1-arg -> None
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=False oob=False
|
2018-02-11 10:35:54 +01:00
|
|
|
object q_obj_user_def_cmd2-arg
|
|
|
|
member ud1a: UserDefOne optional=False
|
|
|
|
member ud1b: UserDefOne optional=True
|
|
|
|
command user_def_cmd2 q_obj_user_def_cmd2-arg -> UserDefTwo
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=False oob=False
|
2018-02-11 10:35:54 +01:00
|
|
|
object q_obj_guest-get-time-arg
|
|
|
|
member a: int optional=False
|
|
|
|
member b: int optional=True
|
|
|
|
command guest-get-time q_obj_guest-get-time-arg -> int
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=False oob=False
|
2018-02-11 10:35:54 +01:00
|
|
|
object q_obj_guest-sync-arg
|
|
|
|
member arg: any optional=False
|
|
|
|
command guest-sync q_obj_guest-sync-arg -> any
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=False oob=False
|
2018-02-11 10:35:54 +01:00
|
|
|
command boxed-struct UserDefZero -> None
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=True oob=False
|
2018-02-11 10:35:54 +01:00
|
|
|
command boxed-union UserDefNativeListUnion -> None
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=True oob=False
|
2018-03-26 08:38:59 +02:00
|
|
|
command an-oob-command None -> None
|
|
|
|
gen=True success_response=True boxed=False oob=True
|
2015-09-16 13:06:08 +02:00
|
|
|
object UserDefOptions
|
|
|
|
member i64: intList optional=True
|
|
|
|
member u64: uint64List optional=True
|
|
|
|
member u16: uint16List optional=True
|
|
|
|
member i64x: int optional=True
|
|
|
|
member u64x: uint64 optional=True
|
2018-02-11 10:35:54 +01:00
|
|
|
object EventStructOne
|
|
|
|
member struct1: UserDefOne optional=False
|
2015-09-16 13:06:08 +02:00
|
|
|
member string: str optional=False
|
2018-02-11 10:35:54 +01:00
|
|
|
member enum2: EnumOne optional=True
|
|
|
|
event EVENT_A None
|
2016-07-14 05:50:19 +02:00
|
|
|
boxed=False
|
2018-02-11 10:35:54 +01:00
|
|
|
event EVENT_B None
|
|
|
|
boxed=False
|
|
|
|
object q_obj_EVENT_C-arg
|
|
|
|
member a: int optional=True
|
|
|
|
member b: UserDefOne optional=True
|
|
|
|
member c: str optional=False
|
|
|
|
event EVENT_C q_obj_EVENT_C-arg
|
|
|
|
boxed=False
|
|
|
|
object q_obj_EVENT_D-arg
|
|
|
|
member a: EventStructOne optional=False
|
|
|
|
member b: str optional=False
|
|
|
|
member c: str optional=True
|
|
|
|
member enum3: EnumOne optional=True
|
|
|
|
event EVENT_D q_obj_EVENT_D-arg
|
|
|
|
boxed=False
|
|
|
|
event EVENT_E UserDefZero
|
|
|
|
boxed=True
|
|
|
|
event EVENT_F UserDefAlternate
|
|
|
|
boxed=True
|
|
|
|
enum __org.qemu_x-Enum ['__org.qemu_x-value']
|
2015-09-16 13:06:08 +02:00
|
|
|
object __org.qemu_x-Base
|
|
|
|
member __org.qemu_x-member1: __org.qemu_x-Enum optional=False
|
|
|
|
object __org.qemu_x-Struct
|
|
|
|
base __org.qemu_x-Base
|
|
|
|
member __org.qemu_x-member2: str optional=False
|
2015-11-18 09:52:52 +01:00
|
|
|
member wchar-t: int optional=True
|
2018-02-11 10:35:54 +01:00
|
|
|
object q_obj_str-wrapper
|
|
|
|
member data: str optional=False
|
|
|
|
enum __org.qemu_x-Union1Kind ['__org.qemu_x-branch']
|
2015-09-16 13:06:08 +02:00
|
|
|
object __org.qemu_x-Union1
|
qapi: Track simple union tag in object.local_members
We were previously creating all unions with an empty list for
local_members. However, it will make it easier to unify struct
and union generation if we include the generated tag member in
local_members. That way, we can have a common code pattern:
visit the base (if any), visit the local members (if any), visit
the variants (if any). The local_members of a flat union
remains empty (because the discriminator is already visited as
part of the base). Then, by visiting tag_member.check() during
AlternateType.check(), we no longer need to call it during
Variants.check().
The various front end entities now exist as follows:
struct: optional base, optional local_members, no variants
simple union: no base, one-element local_members, variants with tag_member
from local_members
flat union: base, no local_members, variants with tag_member from base
alternate: no base, no local_members, variants
With the new local members, we require a bit of finesse to
avoid assertions in the clients.
No change to generated code.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-2-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:36 +01:00
|
|
|
member type: __org.qemu_x-Union1Kind optional=False
|
2016-07-14 05:50:15 +02:00
|
|
|
tag type
|
2016-03-17 23:48:29 +01:00
|
|
|
case __org.qemu_x-branch: q_obj_str-wrapper
|
2018-02-11 10:35:54 +01:00
|
|
|
object __org.qemu_x-Struct2
|
|
|
|
member array: __org.qemu_x-Union1List optional=False
|
2015-09-16 13:06:08 +02:00
|
|
|
object __org.qemu_x-Union2
|
|
|
|
base __org.qemu_x-Base
|
|
|
|
tag __org.qemu_x-member1
|
|
|
|
case __org.qemu_x-value: __org.qemu_x-Struct2
|
2018-02-11 10:35:54 +01:00
|
|
|
alternate __org.qemu_x-Alt
|
|
|
|
tag type
|
|
|
|
case __org.qemu_x-branch: str
|
|
|
|
case b: __org.qemu_x-Base
|
|
|
|
event __ORG.QEMU_X-EVENT __org.qemu_x-Struct
|
|
|
|
boxed=False
|
2016-03-17 23:48:29 +01:00
|
|
|
object q_obj___org.qemu_x-command-arg
|
|
|
|
member a: __org.qemu_x-EnumList optional=False
|
|
|
|
member b: __org.qemu_x-StructList optional=False
|
|
|
|
member c: __org.qemu_x-Union2 optional=False
|
|
|
|
member d: __org.qemu_x-Alt optional=False
|
2018-02-11 10:35:54 +01:00
|
|
|
command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> __org.qemu_x-Union1
|
2018-03-26 08:38:58 +02:00
|
|
|
gen=True success_response=True boxed=False oob=False
|