[Qemu-devel] [PATCH RFC v2 24/47] tests/qapi-schema: Convert test harness to QAPISchemaVisitor
The old code prints the result of parsing (list of expression dictionaries), and partial results of semantic analysis (list of enum dictionaries, list of struct dictionaries). The new code prints a trace of a schema visit, i.e. what the back-ends are going to use. Built-in and array types are omitted, because they're boring. Signed-off-by: Markus Armbruster --- tests/qapi-schema/alternate-good.out| 15 +- tests/qapi-schema/comments.out | 4 +- tests/qapi-schema/data-member-array.out | 13 +- tests/qapi-schema/empty.out | 3 - tests/qapi-schema/enum-empty.out| 4 +- tests/qapi-schema/event-case.out| 4 +- tests/qapi-schema/flat-union-reverse-define.out | 21 +-- tests/qapi-schema/ident-with-escape.out | 7 +- tests/qapi-schema/include-relpath.out | 4 +- tests/qapi-schema/include-repetition.out| 4 +- tests/qapi-schema/include-simple.out| 4 +- tests/qapi-schema/indented-expr.out | 7 +- tests/qapi-schema/qapi-schema-test.out | 186 +--- tests/qapi-schema/returns-int.out | 5 +- tests/qapi-schema/test-qapi.py | 37 - tests/qapi-schema/type-bypass.out | 7 +- 16 files changed, 210 insertions(+), 115 deletions(-) diff --git a/tests/qapi-schema/alternate-good.out b/tests/qapi-schema/alternate-good.out index 99848ee..0cbdfa1 100644 --- a/tests/qapi-schema/alternate-good.out +++ b/tests/qapi-schema/alternate-good.out @@ -1,6 +1,9 @@ -[OrderedDict([('struct', 'Data'), ('data', OrderedDict([('*number', 'int'), ('*name', 'str')]))]), - OrderedDict([('enum', 'Enum'), ('data', ['hello', 'world'])]), - OrderedDict([('alternate', 'Alt'), ('data', OrderedDict([('value', 'int'), ('string', 'Enum'), ('struct', 'Data')]))])] -[{'enum_name': 'Enum', 'enum_values': ['hello', 'world']}, - {'enum_name': 'AltKind', 'enum_values': None}] -[OrderedDict([('struct', 'Data'), ('data', OrderedDict([('*number', 'int'), ('*name', 'str')]))])] +alternate Alt +case value: int flat=False +case string: Enum flat=False +case struct: Data flat=False +enum AltKind ['value', 'string', 'struct'] +object Data +member number: int optional=True +member name: str optional=True +enum Enum ['hello', 'world'] diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out index 4ce3dcf..6161b90 100644 --- a/tests/qapi-schema/comments.out +++ b/tests/qapi-schema/comments.out @@ -1,3 +1 @@ -[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])] -[{'enum_name': 'Status', 'enum_values': ['good', 'bad', 'ugly']}] -[] +enum Status ['good', 'bad', 'ugly'] diff --git a/tests/qapi-schema/data-member-array.out b/tests/qapi-schema/data-member-array.out index c39fa25..8911179 100644 --- a/tests/qapi-schema/data-member-array.out +++ b/tests/qapi-schema/data-member-array.out @@ -1,5 +1,8 @@ -[OrderedDict([('enum', 'abc'), ('data', ['a', 'b', 'c'])]), - OrderedDict([('struct', 'def'), ('data', OrderedDict([('array', ['abc'])]))]), - OrderedDict([('command', 'okay'), ('data', OrderedDict([('member1', ['int']), ('member2', ['def'])]))])] -[{'enum_name': 'abc', 'enum_values': ['a', 'b', 'c']}] -[OrderedDict([('struct', 'def'), ('data', OrderedDict([('array', ['abc'])]))])] +object :obj-okay-args +member member1: intList optional=False +member member2: defList optional=False +enum abc ['a', 'b', 'c'] +object def +member array: abcList optional=False +command okay :obj-okay-args -> None + gen=True success_response=True diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out index b7f89a4..e69de29 100644 --- a/tests/qapi-schema/empty.out +++ b/tests/qapi-schema/empty.out @@ -1,3 +0,0 @@ -[] -[] -[] diff --git a/tests/qapi-schema/enum-empty.out b/tests/qapi-schema/enum-empty.out index 3b75c16..e09b00f 100644 --- a/tests/qapi-schema/enum-empty.out +++ b/tests/qapi-schema/enum-empty.out @@ -1,3 +1 @@ -[OrderedDict([('enum', 'MyEnum'), ('data', [])])] -[{'enum_name': 'MyEnum', 'enum_values': []}] -[] +enum MyEnum [] diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-case.out index 3764bc7..b5ae4c2 100644 --- a/tests/qapi-schema/event-case.out +++ b/tests/qapi-schema/event-case.out @@ -1,3 +1 @@ -[OrderedDict([('event', 'oops')])] -[] -[] +event oops None diff --git a/tests/qapi-schema/flat-union-reverse-define.out b/tests/qapi-schema/flat-union-reverse-define.out index 1ed7b8a..e156202 100644 --- a/tests/qapi-schema/flat-union-reverse-define.out +++ b/tests/qapi-schema/flat-union-reverse-define.out @@ -1,9 +1,12 @@ -[OrderedDict([('union', 'TestUnion'), ('base', 'TestBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'TestTypeA'), ('value2', 'TestTypeB')]))]), - OrderedDict([('struct', 'TestBase'), ('data', OrderedDict([('enum1', 'TestEnum')]))]), - OrderedDict([('enum', 'TestEnum'), ('data', ['value1', 'va
Re: [Qemu-devel] [PATCH RFC v2 24/47] tests/qapi-schema: Convert test harness to QAPISchemaVisitor
Eric Blake writes: > On 07/01/2015 02:22 PM, Markus Armbruster wrote: >> The old code prints the result of parsing (list of expression >> dictionaries), and partial results of semantic analysis (list of enum >> dictionaries, list of struct dictionaries). >> >> The new code prints a trace of a schema visit, i.e. what the back-ends >> are going to use. Built-in and array types are omitted, because >> they're boring. >> >> Signed-off-by: Markus Armbruster >> --- >> tests/qapi-schema/alternate-good.out| 15 +- >> tests/qapi-schema/comments.out | 4 +- >> tests/qapi-schema/data-member-array.out | 13 +- >> tests/qapi-schema/empty.out | 3 - >> tests/qapi-schema/enum-empty.out| 4 +- >> tests/qapi-schema/event-case.out| 4 +- >> tests/qapi-schema/flat-union-reverse-define.out | 21 +-- >> tests/qapi-schema/ident-with-escape.out | 7 +- >> tests/qapi-schema/include-relpath.out | 4 +- >> tests/qapi-schema/include-repetition.out| 4 +- >> tests/qapi-schema/include-simple.out| 4 +- >> tests/qapi-schema/indented-expr.out | 7 +- >> tests/qapi-schema/qapi-schema-test.out | 186 >> +--- >> tests/qapi-schema/returns-int.out | 5 +- >> tests/qapi-schema/test-qapi.py | 37 - >> tests/qapi-schema/type-bypass.out | 7 +- >> 16 files changed, 210 insertions(+), 115 deletions(-) > > We have a lot more negative than positive tests of the parser (good > thing, because that meant fewer .out files to update to the new format). > > No change to actual qemu code, and proves that the previous three > patches have set up enough of a framework to accurately cover our testsuite. > >> >> diff --git a/tests/qapi-schema/alternate-good.out >> b/tests/qapi-schema/alternate-good.out >> index 99848ee..0cbdfa1 100644 >> --- a/tests/qapi-schema/alternate-good.out >> +++ b/tests/qapi-schema/alternate-good.out >> @@ -1,6 +1,9 @@ >> -[OrderedDict([('struct', 'Data'), ('data', OrderedDict([('*number', >> 'int'), ('*name', 'str')]))]), >> - OrderedDict([('enum', 'Enum'), ('data', ['hello', 'world'])]), >> - OrderedDict([('alternate', 'Alt'), ('data', OrderedDict([('value', >> 'int'), ('string', 'Enum'), ('struct', 'Data')]))])] >> -[{'enum_name': 'Enum', 'enum_values': ['hello', 'world']}, >> - {'enum_name': 'AltKind', 'enum_values': None}] >> -[OrderedDict([('struct', 'Data'), ('data', OrderedDict([('*number', >> 'int'), ('*name', 'str')]))])] >> +alternate Alt >> +case value: int flat=False >> +case string: Enum flat=False >> +case struct: Data flat=False > > I'm still not convinced whether we need .flat exposed through this much > detail, or if we should just normalize plain unions into flat unions > with implicit structs for each branch. Changing your design will have > obvious ripple effects here. Yes. I think it's okay as long as we keep it out of external interfaces. >> +++ b/tests/qapi-schema/data-member-array.out >> @@ -1,5 +1,8 @@ >> -[OrderedDict([('enum', 'abc'), ('data', ['a', 'b', 'c'])]), >> - OrderedDict([('struct', 'def'), ('data', OrderedDict([('array', >> ['abc'])]))]), >> - OrderedDict([('command', 'okay'), ('data', >> OrderedDict([('member1', ['int']), ('member2', ['def'])]))])] >> -[{'enum_name': 'abc', 'enum_values': ['a', 'b', 'c']}] >> -[OrderedDict([('struct', 'def'), ('data', OrderedDict([('array', >> ['abc'])]))])] >> +object :obj-okay-args >> +member member1: intList optional=False > > Took me a moment to realize the object is an implicit one (named > ':obj-okay-args') and not a typo for 'object: obj-okay-args' consistent > with members being listed 'name: type'. But not worth changing things, > as it is sufficiently unambiguous to serve as a valid test. Perhaps omitting the ':' after member names would be less confusing. >> +object UserDefFlatUnion >> +base UserDefUnionBase >> +tag enum1 >> +case value1: UserDefA flat=True >> +case value2: UserDefB flat=True >> +case value3: UserDefB flat=True >> +object UserDefFlatUnion2 >> +base UserDefUnionBase >> +tag enum1 >> +case value1: UserDefC flat=True >> +case value2: UserDefB flat=True >> +case value3: UserDefA flat=True >> +object UserDefNativeListUnion >> +case integer: intList flat=False >> +case s8: int8List flat=False >> +case s16: int16List flat=False >> +case s32: int32List flat=False >> +case s64: int64List flat=False >> +case u8: uint8List flat=False >> +case u16: uint16List flat=False >> +case u32: uint32List flat=False >> +case u64: uint64List flat=False >> +case number: numberList flat=False >> +case boolean: boolList flat=False >> +case string: strList flat=False >> +case sizes: sizeList flat=False >> +enum UserDefNativeListUnionKind ['integer', 's8', 's16', 's32', >> 's64', 'u8', 'u16', 'u32', 'u64', 'number
Re: [Qemu-devel] [PATCH RFC v2 24/47] tests/qapi-schema: Convert test harness to QAPISchemaVisitor
On 07/01/2015 02:22 PM, Markus Armbruster wrote: > The old code prints the result of parsing (list of expression > dictionaries), and partial results of semantic analysis (list of enum > dictionaries, list of struct dictionaries). > > The new code prints a trace of a schema visit, i.e. what the back-ends > are going to use. Built-in and array types are omitted, because > they're boring. > > Signed-off-by: Markus Armbruster > --- > tests/qapi-schema/alternate-good.out| 15 +- > tests/qapi-schema/comments.out | 4 +- > tests/qapi-schema/data-member-array.out | 13 +- > tests/qapi-schema/empty.out | 3 - > tests/qapi-schema/enum-empty.out| 4 +- > tests/qapi-schema/event-case.out| 4 +- > tests/qapi-schema/flat-union-reverse-define.out | 21 +-- > tests/qapi-schema/ident-with-escape.out | 7 +- > tests/qapi-schema/include-relpath.out | 4 +- > tests/qapi-schema/include-repetition.out| 4 +- > tests/qapi-schema/include-simple.out| 4 +- > tests/qapi-schema/indented-expr.out | 7 +- > tests/qapi-schema/qapi-schema-test.out | 186 > +--- > tests/qapi-schema/returns-int.out | 5 +- > tests/qapi-schema/test-qapi.py | 37 - > tests/qapi-schema/type-bypass.out | 7 +- > 16 files changed, 210 insertions(+), 115 deletions(-) We have a lot more negative than positive tests of the parser (good thing, because that meant fewer .out files to update to the new format). No change to actual qemu code, and proves that the previous three patches have set up enough of a framework to accurately cover our testsuite. > > diff --git a/tests/qapi-schema/alternate-good.out > b/tests/qapi-schema/alternate-good.out > index 99848ee..0cbdfa1 100644 > --- a/tests/qapi-schema/alternate-good.out > +++ b/tests/qapi-schema/alternate-good.out > @@ -1,6 +1,9 @@ > -[OrderedDict([('struct', 'Data'), ('data', OrderedDict([('*number', 'int'), > ('*name', 'str')]))]), > - OrderedDict([('enum', 'Enum'), ('data', ['hello', 'world'])]), > - OrderedDict([('alternate', 'Alt'), ('data', OrderedDict([('value', 'int'), > ('string', 'Enum'), ('struct', 'Data')]))])] > -[{'enum_name': 'Enum', 'enum_values': ['hello', 'world']}, > - {'enum_name': 'AltKind', 'enum_values': None}] > -[OrderedDict([('struct', 'Data'), ('data', OrderedDict([('*number', 'int'), > ('*name', 'str')]))])] > +alternate Alt > +case value: int flat=False > +case string: Enum flat=False > +case struct: Data flat=False I'm still not convinced whether we need .flat exposed through this much detail, or if we should just normalize plain unions into flat unions with implicit structs for each branch. Changing your design will have obvious ripple effects here. > +++ b/tests/qapi-schema/data-member-array.out > @@ -1,5 +1,8 @@ > -[OrderedDict([('enum', 'abc'), ('data', ['a', 'b', 'c'])]), > - OrderedDict([('struct', 'def'), ('data', OrderedDict([('array', > ['abc'])]))]), > - OrderedDict([('command', 'okay'), ('data', OrderedDict([('member1', > ['int']), ('member2', ['def'])]))])] > -[{'enum_name': 'abc', 'enum_values': ['a', 'b', 'c']}] > -[OrderedDict([('struct', 'def'), ('data', OrderedDict([('array', > ['abc'])]))])] > +object :obj-okay-args > +member member1: intList optional=False Took me a moment to realize the object is an implicit one (named ':obj-okay-args') and not a typo for 'object: obj-okay-args' consistent with members being listed 'name: type'. But not worth changing things, as it is sufficiently unambiguous to serve as a valid test. > +object UserDefFlatUnion > +base UserDefUnionBase > +tag enum1 > +case value1: UserDefA flat=True > +case value2: UserDefB flat=True > +case value3: UserDefB flat=True > +object UserDefFlatUnion2 > +base UserDefUnionBase > +tag enum1 > +case value1: UserDefC flat=True > +case value2: UserDefB flat=True > +case value3: UserDefA flat=True > +object UserDefNativeListUnion > +case integer: intList flat=False > +case s8: int8List flat=False > +case s16: int16List flat=False > +case s32: int32List flat=False > +case s64: int64List flat=False > +case u8: uint8List flat=False > +case u16: uint16List flat=False > +case u32: uint32List flat=False > +case u64: uint64List flat=False > +case number: numberList flat=False > +case boolean: boolList flat=False > +case string: strList flat=False > +case sizes: sizeList flat=False > +enum UserDefNativeListUnionKind ['integer', 's8', 's16', 's32', 's64', 'u8', > 'u16', 'u32', 'u64', 'number', 'boolean', 'string', 'sizes'] Hmm. You are dumping the tag name and type of flat unions, but not of simple unions. I would have expected: object UserDefNativeListUnion member kind: UserDefNativeListUnionKind tag kind case integer: intList flat=False