qapi: Add some expr tests
Demonstrate that the qapi generator doesn't deal well with expressions that aren't up to par. Later patches will improve the expected results as the generator is made stricter. Only a few of the the added tests actually behave sanely at rejecting obvious problems or demonstrating success. Note that in some cases, we reject bad QAPI merely because our pseudo-JSON parser does not yet know how to parse numbers. This series does not address that, but when a later series adds support for numeric defaults of integer fields, the testsuite will ensure that we don't lose the error (and hopefully that the error message quality is improved). Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
		
							parent
							
								
									ab916faddd
								
							
						
					
					
						commit
						9050c65b71
					
				@ -210,8 +210,10 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 | 
				
			|||||||
	comments.json empty.json enum-empty.json enum-missing-data.json \
 | 
						comments.json empty.json enum-empty.json enum-missing-data.json \
 | 
				
			||||||
	enum-wrong-data.json enum-int-member.json enum-dict-member.json \
 | 
						enum-wrong-data.json enum-int-member.json enum-dict-member.json \
 | 
				
			||||||
	enum-clash-member.json enum-max-member.json enum-union-clash.json \
 | 
						enum-clash-member.json enum-max-member.json enum-union-clash.json \
 | 
				
			||||||
	enum-bad-name.json \
 | 
						enum-bad-name.json funny-char.json indented-expr.json \
 | 
				
			||||||
	funny-char.json indented-expr.json \
 | 
						missing-type.json bad-ident.json ident-with-escape.json \
 | 
				
			||||||
 | 
						double-type.json bad-base.json bad-type-bool.json bad-type-int.json \
 | 
				
			||||||
 | 
						bad-type-dict.json double-data.json unknown-expr-key.json \
 | 
				
			||||||
	missing-colon.json missing-comma-list.json \
 | 
						missing-colon.json missing-comma-list.json \
 | 
				
			||||||
	missing-comma-object.json non-objects.json \
 | 
						missing-comma-object.json non-objects.json \
 | 
				
			||||||
	qapi-schema-test.json quoted-structural-chars.json \
 | 
						qapi-schema-test.json quoted-structural-chars.json \
 | 
				
			||||||
@ -232,7 +234,7 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 | 
				
			|||||||
	include-simple.json include-relpath.json include-format-err.json \
 | 
						include-simple.json include-relpath.json include-format-err.json \
 | 
				
			||||||
	include-non-file.json include-no-file.json include-before-err.json \
 | 
						include-non-file.json include-no-file.json include-before-err.json \
 | 
				
			||||||
	include-nested-err.json include-self-cycle.json include-cycle.json \
 | 
						include-nested-err.json include-self-cycle.json include-cycle.json \
 | 
				
			||||||
	include-repetition.json event-nest-struct.json)
 | 
						include-repetition.json event-nest-struct.json event-case.json)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \
 | 
					GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \
 | 
				
			||||||
		     tests/test-qmp-commands.h tests/test-qapi-event.h
 | 
							     tests/test-qmp-commands.h tests/test-qapi-event.h
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/bad-base.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/bad-base.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/bad-base.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/bad-base.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/bad-base.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/bad-base.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					# FIXME: we should reject a base that is not a struct
 | 
				
			||||||
 | 
					{ 'union': 'Union', 'data': { 'a': 'int', 'b': 'str' } }
 | 
				
			||||||
 | 
					{ 'type': 'MyType', 'base': 'Union', 'data': { 'c': 'int' } }
 | 
				
			||||||
							
								
								
									
										4
									
								
								tests/qapi-schema/bad-base.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/qapi-schema/bad-base.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('union', 'Union'), ('data', OrderedDict([('a', 'int'), ('b', 'str')]))]),
 | 
				
			||||||
 | 
					 OrderedDict([('type', 'MyType'), ('base', 'Union'), ('data', OrderedDict([('c', 'int')]))])]
 | 
				
			||||||
 | 
					[{'enum_name': 'UnionKind', 'enum_values': None}]
 | 
				
			||||||
 | 
					[OrderedDict([('type', 'MyType'), ('base', 'Union'), ('data', OrderedDict([('c', 'int')]))])]
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/bad-ident.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/bad-ident.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/bad-ident.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/bad-ident.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										2
									
								
								tests/qapi-schema/bad-ident.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								tests/qapi-schema/bad-ident.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# FIXME: we should reject creating a type name with bad name
 | 
				
			||||||
 | 
					{ 'type': '*oops', 'data': { 'i': 'int' } }
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/bad-ident.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/bad-ident.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('type', '*oops'), ('data', OrderedDict([('i', 'int')]))])]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
 | 
					[OrderedDict([('type', '*oops'), ('data', OrderedDict([('i', 'int')]))])]
 | 
				
			||||||
							
								
								
									
										1
									
								
								tests/qapi-schema/bad-type-bool.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/bad-type-bool.err
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					tests/qapi-schema/bad-type-bool.json:3:11: Stray "t"
 | 
				
			||||||
							
								
								
									
										1
									
								
								tests/qapi-schema/bad-type-bool.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/bad-type-bool.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					1
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/bad-type-bool.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/bad-type-bool.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					# we reject an expression with a metatype that is not a string
 | 
				
			||||||
 | 
					# FIXME: once the parser understands bool inputs, improve the error message
 | 
				
			||||||
 | 
					{ 'type': true, 'data': { } }
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/bad-type-bool.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/bad-type-bool.out
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								tests/qapi-schema/bad-type-dict.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/bad-type-dict.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/bad-type-dict.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/bad-type-dict.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										2
									
								
								tests/qapi-schema/bad-type-dict.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								tests/qapi-schema/bad-type-dict.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# FIXME: we should reject an expression with a metatype that is not a string
 | 
				
			||||||
 | 
					{ 'command': { } }
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/bad-type-dict.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/bad-type-dict.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('command', OrderedDict())])]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
							
								
								
									
										1
									
								
								tests/qapi-schema/bad-type-int.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/bad-type-int.err
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					tests/qapi-schema/bad-type-int.json:3:11: Stray "1"
 | 
				
			||||||
							
								
								
									
										1
									
								
								tests/qapi-schema/bad-type-int.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/bad-type-int.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					1
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/bad-type-int.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/bad-type-int.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					# we reject an expression with a metatype that is not a string
 | 
				
			||||||
 | 
					# FIXME: once the parser understands integer inputs, improve the error message
 | 
				
			||||||
 | 
					{ 'type': 1, 'data': { } }
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/bad-type-int.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/bad-type-int.out
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/double-data.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/double-data.err
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					tests/qapi-schema/double-data.json:2:39: Duplicate key "data"
 | 
				
			||||||
							
								
								
									
										1
									
								
								tests/qapi-schema/double-data.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/double-data.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					1
 | 
				
			||||||
							
								
								
									
										2
									
								
								tests/qapi-schema/double-data.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								tests/qapi-schema/double-data.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# we reject an expression with duplicate top-level keys
 | 
				
			||||||
 | 
					{ 'type': 'bar', 'data': { }, 'data': { 'string': 'str'} }
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/double-data.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/double-data.out
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								tests/qapi-schema/double-type.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/double-type.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/double-type.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/double-type.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										2
									
								
								tests/qapi-schema/double-type.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								tests/qapi-schema/double-type.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# FIXME: we should reject an expression with ambiguous metatype
 | 
				
			||||||
 | 
					{ 'command': 'foo', 'type': 'bar', 'data': { } }
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/double-type.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/double-type.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
 | 
					[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/event-case.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/event-case.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/event-case.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/event-case.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/event-case.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/event-case.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					# TODO: might be nice to enforce naming conventions; but until then this works
 | 
				
			||||||
 | 
					# even though events should usually be ALL_CAPS
 | 
				
			||||||
 | 
					{ 'event': 'oops' }
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/event-case.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/event-case.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('event', 'oops')])]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/ident-with-escape.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/ident-with-escape.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/ident-with-escape.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/ident-with-escape.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										4
									
								
								tests/qapi-schema/ident-with-escape.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/qapi-schema/ident-with-escape.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					# FIXME: we should allow escape sequences in strings, if they map back to ASCII
 | 
				
			||||||
 | 
					# { 'command': 'fooA', 'data': { 'bar1': 'str' } }
 | 
				
			||||||
 | 
					{ 'c\u006fmmand': '\u0066\u006f\u006FA',
 | 
				
			||||||
 | 
					  'd\u0061ta': { '\u0062\u0061\u00721': '\u0073\u0074\u0072' } }
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/ident-with-escape.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/ident-with-escape.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('cu006fmmand', 'u0066u006fu006FA'), ('du0061ta', OrderedDict([('u0062u0061u00721', 'u0073u0074u0072')]))])]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/missing-type.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/missing-type.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/missing-type.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/missing-type.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										2
									
								
								tests/qapi-schema/missing-type.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								tests/qapi-schema/missing-type.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# FIXME: we should reject an expression with missing metatype
 | 
				
			||||||
 | 
					{ 'data': { } }
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/missing-type.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/missing-type.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('data', OrderedDict())])]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
							
								
								
									
										0
									
								
								tests/qapi-schema/unknown-expr-key.err
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/qapi-schema/unknown-expr-key.err
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								tests/qapi-schema/unknown-expr-key.exit
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/qapi-schema/unknown-expr-key.exit
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					0
 | 
				
			||||||
							
								
								
									
										2
									
								
								tests/qapi-schema/unknown-expr-key.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								tests/qapi-schema/unknown-expr-key.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# FIXME: we should reject an expression with unknown top-level keys
 | 
				
			||||||
 | 
					{ 'type': 'bar', 'data': { 'string': 'str'}, 'bogus': { } }
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/qapi-schema/unknown-expr-key.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/qapi-schema/unknown-expr-key.out
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[OrderedDict([('type', 'bar'), ('data', OrderedDict([('string', 'str')])), ('bogus', OrderedDict())])]
 | 
				
			||||||
 | 
					[]
 | 
				
			||||||
 | 
					[OrderedDict([('type', 'bar'), ('data', OrderedDict([('string', 'str')])), ('bogus', OrderedDict())])]
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user