From: Eric Blake Date: Mon, 4 May 2015 15:05:14 +0000 (-0600) Subject: qapi: Add some expr tests X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9050c65b71ac1d197330e6db221f63189e21bad5;p=people%2Fliuw%2Flibxenctrl-split%2Fqemu-xen.git 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 Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- diff --git a/tests/Makefile b/tests/Makefile index 3978c3d30..835ec9cb4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -210,8 +210,10 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ comments.json empty.json enum-empty.json enum-missing-data.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-bad-name.json \ - funny-char.json indented-expr.json \ + enum-bad-name.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-comma-object.json non-objects.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-non-file.json include-no-file.json include-before-err.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 \ tests/test-qmp-commands.h tests/test-qapi-event.h diff --git a/tests/qapi-schema/bad-base.err b/tests/qapi-schema/bad-base.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/bad-base.exit b/tests/qapi-schema/bad-base.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/bad-base.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/bad-base.json b/tests/qapi-schema/bad-base.json new file mode 100644 index 000000000..de964a0e8 --- /dev/null +++ b/tests/qapi-schema/bad-base.json @@ -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' } } diff --git a/tests/qapi-schema/bad-base.out b/tests/qapi-schema/bad-base.out new file mode 100644 index 000000000..91d12fcf6 --- /dev/null +++ b/tests/qapi-schema/bad-base.out @@ -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')]))])] diff --git a/tests/qapi-schema/bad-ident.err b/tests/qapi-schema/bad-ident.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/bad-ident.exit b/tests/qapi-schema/bad-ident.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/bad-ident.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/bad-ident.json b/tests/qapi-schema/bad-ident.json new file mode 100644 index 000000000..f139110e8 --- /dev/null +++ b/tests/qapi-schema/bad-ident.json @@ -0,0 +1,2 @@ +# FIXME: we should reject creating a type name with bad name +{ 'type': '*oops', 'data': { 'i': 'int' } } diff --git a/tests/qapi-schema/bad-ident.out b/tests/qapi-schema/bad-ident.out new file mode 100644 index 000000000..165e34645 --- /dev/null +++ b/tests/qapi-schema/bad-ident.out @@ -0,0 +1,3 @@ +[OrderedDict([('type', '*oops'), ('data', OrderedDict([('i', 'int')]))])] +[] +[OrderedDict([('type', '*oops'), ('data', OrderedDict([('i', 'int')]))])] diff --git a/tests/qapi-schema/bad-type-bool.err b/tests/qapi-schema/bad-type-bool.err new file mode 100644 index 000000000..badb7c284 --- /dev/null +++ b/tests/qapi-schema/bad-type-bool.err @@ -0,0 +1 @@ +tests/qapi-schema/bad-type-bool.json:3:11: Stray "t" diff --git a/tests/qapi-schema/bad-type-bool.exit b/tests/qapi-schema/bad-type-bool.exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/tests/qapi-schema/bad-type-bool.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/bad-type-bool.json b/tests/qapi-schema/bad-type-bool.json new file mode 100644 index 000000000..22d6369ef --- /dev/null +++ b/tests/qapi-schema/bad-type-bool.json @@ -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': { } } diff --git a/tests/qapi-schema/bad-type-bool.out b/tests/qapi-schema/bad-type-bool.out new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/bad-type-dict.err b/tests/qapi-schema/bad-type-dict.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/bad-type-dict.exit b/tests/qapi-schema/bad-type-dict.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/bad-type-dict.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/bad-type-dict.json b/tests/qapi-schema/bad-type-dict.json new file mode 100644 index 000000000..3c392a7cb --- /dev/null +++ b/tests/qapi-schema/bad-type-dict.json @@ -0,0 +1,2 @@ +# FIXME: we should reject an expression with a metatype that is not a string +{ 'command': { } } diff --git a/tests/qapi-schema/bad-type-dict.out b/tests/qapi-schema/bad-type-dict.out new file mode 100644 index 000000000..c62f1edb7 --- /dev/null +++ b/tests/qapi-schema/bad-type-dict.out @@ -0,0 +1,3 @@ +[OrderedDict([('command', OrderedDict())])] +[] +[] diff --git a/tests/qapi-schema/bad-type-int.err b/tests/qapi-schema/bad-type-int.err new file mode 100644 index 000000000..980855000 --- /dev/null +++ b/tests/qapi-schema/bad-type-int.err @@ -0,0 +1 @@ +tests/qapi-schema/bad-type-int.json:3:11: Stray "1" diff --git a/tests/qapi-schema/bad-type-int.exit b/tests/qapi-schema/bad-type-int.exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/tests/qapi-schema/bad-type-int.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/bad-type-int.json b/tests/qapi-schema/bad-type-int.json new file mode 100644 index 000000000..398879df9 --- /dev/null +++ b/tests/qapi-schema/bad-type-int.json @@ -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': { } } diff --git a/tests/qapi-schema/bad-type-int.out b/tests/qapi-schema/bad-type-int.out new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/double-data.err b/tests/qapi-schema/double-data.err new file mode 100644 index 000000000..6f1a67b90 --- /dev/null +++ b/tests/qapi-schema/double-data.err @@ -0,0 +1 @@ +tests/qapi-schema/double-data.json:2:39: Duplicate key "data" diff --git a/tests/qapi-schema/double-data.exit b/tests/qapi-schema/double-data.exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/tests/qapi-schema/double-data.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/double-data.json b/tests/qapi-schema/double-data.json new file mode 100644 index 000000000..a94b7dfe2 --- /dev/null +++ b/tests/qapi-schema/double-data.json @@ -0,0 +1,2 @@ +# we reject an expression with duplicate top-level keys +{ 'type': 'bar', 'data': { }, 'data': { 'string': 'str'} } diff --git a/tests/qapi-schema/double-data.out b/tests/qapi-schema/double-data.out new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/double-type.err b/tests/qapi-schema/double-type.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/double-type.exit b/tests/qapi-schema/double-type.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/double-type.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/double-type.json b/tests/qapi-schema/double-type.json new file mode 100644 index 000000000..6ca96b97c --- /dev/null +++ b/tests/qapi-schema/double-type.json @@ -0,0 +1,2 @@ +# FIXME: we should reject an expression with ambiguous metatype +{ 'command': 'foo', 'type': 'bar', 'data': { } } diff --git a/tests/qapi-schema/double-type.out b/tests/qapi-schema/double-type.out new file mode 100644 index 000000000..3e244f578 --- /dev/null +++ b/tests/qapi-schema/double-type.out @@ -0,0 +1,3 @@ +[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])] +[] +[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])] diff --git a/tests/qapi-schema/event-case.err b/tests/qapi-schema/event-case.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/event-case.exit b/tests/qapi-schema/event-case.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/event-case.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/event-case.json b/tests/qapi-schema/event-case.json new file mode 100644 index 000000000..3a92d8b61 --- /dev/null +++ b/tests/qapi-schema/event-case.json @@ -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' } diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-case.out new file mode 100644 index 000000000..3764bc781 --- /dev/null +++ b/tests/qapi-schema/event-case.out @@ -0,0 +1,3 @@ +[OrderedDict([('event', 'oops')])] +[] +[] diff --git a/tests/qapi-schema/ident-with-escape.err b/tests/qapi-schema/ident-with-escape.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/ident-with-escape.exit b/tests/qapi-schema/ident-with-escape.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/ident-with-escape.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/ident-with-escape.json b/tests/qapi-schema/ident-with-escape.json new file mode 100644 index 000000000..cfb205052 --- /dev/null +++ b/tests/qapi-schema/ident-with-escape.json @@ -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' } } diff --git a/tests/qapi-schema/ident-with-escape.out b/tests/qapi-schema/ident-with-escape.out new file mode 100644 index 000000000..a44623fa4 --- /dev/null +++ b/tests/qapi-schema/ident-with-escape.out @@ -0,0 +1,3 @@ +[OrderedDict([('cu006fmmand', 'u0066u006fu006FA'), ('du0061ta', OrderedDict([('u0062u0061u00721', 'u0073u0074u0072')]))])] +[] +[] diff --git a/tests/qapi-schema/missing-type.err b/tests/qapi-schema/missing-type.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/missing-type.exit b/tests/qapi-schema/missing-type.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/missing-type.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/missing-type.json b/tests/qapi-schema/missing-type.json new file mode 100644 index 000000000..1696f5c13 --- /dev/null +++ b/tests/qapi-schema/missing-type.json @@ -0,0 +1,2 @@ +# FIXME: we should reject an expression with missing metatype +{ 'data': { } } diff --git a/tests/qapi-schema/missing-type.out b/tests/qapi-schema/missing-type.out new file mode 100644 index 000000000..67fd4fa67 --- /dev/null +++ b/tests/qapi-schema/missing-type.out @@ -0,0 +1,3 @@ +[OrderedDict([('data', OrderedDict())])] +[] +[] diff --git a/tests/qapi-schema/unknown-expr-key.err b/tests/qapi-schema/unknown-expr-key.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qapi-schema/unknown-expr-key.exit b/tests/qapi-schema/unknown-expr-key.exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/qapi-schema/unknown-expr-key.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/unknown-expr-key.json b/tests/qapi-schema/unknown-expr-key.json new file mode 100644 index 000000000..1e9282d8e --- /dev/null +++ b/tests/qapi-schema/unknown-expr-key.json @@ -0,0 +1,2 @@ +# FIXME: we should reject an expression with unknown top-level keys +{ 'type': 'bar', 'data': { 'string': 'str'}, 'bogus': { } } diff --git a/tests/qapi-schema/unknown-expr-key.out b/tests/qapi-schema/unknown-expr-key.out new file mode 100644 index 000000000..c93f020ae --- /dev/null +++ b/tests/qapi-schema/unknown-expr-key.out @@ -0,0 +1,3 @@ +[OrderedDict([('type', 'bar'), ('data', OrderedDict([('string', 'str')])), ('bogus', OrderedDict())])] +[] +[OrderedDict([('type', 'bar'), ('data', OrderedDict([('string', 'str')])), ('bogus', OrderedDict())])]