From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XV6cV-0004Of-Bb for qemu-devel@nongnu.org; Fri, 19 Sep 2014 18:25:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XV6cO-0004YH-L1 for qemu-devel@nongnu.org; Fri, 19 Sep 2014 18:25:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28793) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XV6cO-0004W4-53 for qemu-devel@nongnu.org; Fri, 19 Sep 2014 18:25:32 -0400 From: Eric Blake Date: Fri, 19 Sep 2014 16:24:50 -0600 Message-Id: <1411165504-18198-6-git-send-email-eblake@redhat.com> In-Reply-To: <1411165504-18198-1-git-send-email-eblake@redhat.com> References: <1411165504-18198-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v4 05/19] qapi: Add some enum tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Luiz Capitulino , Fam Zheng , Markus Armbruster , wenchaoqemu@gmail.com Demonstrate that the qapi generator doesn't deal well with enums that aren't up to par. Later patches will update the expected results as the generator is made stricter. Signed-off-by: Eric Blake --- tests/Makefile | 5 ++++- tests/qapi-schema/enum-clash-member.err | 0 tests/qapi-schema/enum-clash-member.exit | 1 + tests/qapi-schema/enum-clash-member.json | 2 ++ tests/qapi-schema/enum-clash-member.out | 3 +++ tests/qapi-schema/enum-dict-member.err | 0 tests/qapi-schema/enum-dict-member.exit | 1 + tests/qapi-schema/enum-dict-member.json | 2 ++ tests/qapi-schema/enum-dict-member.out | 3 +++ tests/qapi-schema/enum-empty.err | 0 tests/qapi-schema/enum-empty.exit | 1 + tests/qapi-schema/enum-empty.json | 2 ++ tests/qapi-schema/enum-empty.out | 3 +++ tests/qapi-schema/enum-int-member.err | 1 + tests/qapi-schema/enum-int-member.exit | 1 + tests/qapi-schema/enum-int-member.json | 3 +++ tests/qapi-schema/enum-int-member.out | 0 tests/qapi-schema/enum-max-member.err | 0 tests/qapi-schema/enum-max-member.exit | 1 + tests/qapi-schema/enum-max-member.json | 3 +++ tests/qapi-schema/enum-max-member.out | 3 +++ tests/qapi-schema/enum-missing-data.err | 6 ++++++ tests/qapi-schema/enum-missing-data.exit | 1 + tests/qapi-schema/enum-missing-data.json | 2 ++ tests/qapi-schema/enum-missing-data.out | 0 tests/qapi-schema/enum-wrong-data.err | 0 tests/qapi-schema/enum-wrong-data.exit | 1 + tests/qapi-schema/enum-wrong-data.json | 2 ++ tests/qapi-schema/enum-wrong-data.out | 3 +++ 29 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/enum-clash-member.err create mode 100644 tests/qapi-schema/enum-clash-member.exit create mode 100644 tests/qapi-schema/enum-clash-member.json create mode 100644 tests/qapi-schema/enum-clash-member.out create mode 100644 tests/qapi-schema/enum-dict-member.err create mode 100644 tests/qapi-schema/enum-dict-member.exit create mode 100644 tests/qapi-schema/enum-dict-member.json create mode 100644 tests/qapi-schema/enum-dict-member.out create mode 100644 tests/qapi-schema/enum-empty.err create mode 100644 tests/qapi-schema/enum-empty.exit create mode 100644 tests/qapi-schema/enum-empty.json create mode 100644 tests/qapi-schema/enum-empty.out create mode 100644 tests/qapi-schema/enum-int-member.err create mode 100644 tests/qapi-schema/enum-int-member.exit create mode 100644 tests/qapi-schema/enum-int-member.json create mode 100644 tests/qapi-schema/enum-int-member.out create mode 100644 tests/qapi-schema/enum-max-member.err create mode 100644 tests/qapi-schema/enum-max-member.exit create mode 100644 tests/qapi-schema/enum-max-member.json create mode 100644 tests/qapi-schema/enum-max-member.out create mode 100644 tests/qapi-schema/enum-missing-data.err create mode 100644 tests/qapi-schema/enum-missing-data.exit create mode 100644 tests/qapi-schema/enum-missing-data.json create mode 100644 tests/qapi-schema/enum-missing-data.out create mode 100644 tests/qapi-schema/enum-wrong-data.err create mode 100644 tests/qapi-schema/enum-wrong-data.exit create mode 100644 tests/qapi-schema/enum-wrong-data.json create mode 100644 tests/qapi-schema/enum-wrong-data.out diff --git a/tests/Makefile b/tests/Makefile index 976388a..6a4e5a6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -195,7 +195,10 @@ $(foreach target,$(SYSEMU_TARGET_LIST), \ $(eval check-qtest-$(target)-y += tests/qom-test$(EXESUF))) check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ - comments.json empty.json funny-char.json indented-expr.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-clash-member.json enum-max-member.json \ + funny-char.json indented-expr.json \ missing-colon.json missing-comma-list.json \ missing-comma-object.json non-objects.json \ qapi-schema-test.json quoted-structural-chars.json \ diff --git a/tests/qapi-schema/enum-clash-member.err b/tests/qapi-schema/enum-clash-member.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/enum-clash-member.exit b/tests/qapi-schema/enum-clash-member.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/enum-clash-member.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/enum-clash-member.json b/tests/qapi-schema/enum-clash-member.json new file mode 100644 index 0000000..cb4b428 --- /dev/null +++ b/tests/qapi-schema/enum-clash-member.json @@ -0,0 +1,2 @@ +# FIXME: we should reject enums where members will clash in C switch +{ 'enum': 'MyEnum', 'data': [ 'one', 'ONE' ] } diff --git a/tests/qapi-schema/enum-clash-member.out b/tests/qapi-schema/enum-clash-member.out new file mode 100644 index 0000000..0814459 --- /dev/null +++ b/tests/qapi-schema/enum-clash-member.out @@ -0,0 +1,3 @@ +[OrderedDict([('enum', 'MyEnum'), ('data', ['one', 'ONE'])])] +[{'enum_name': 'MyEnum', 'enum_values': ['one', 'ONE']}] +[] diff --git a/tests/qapi-schema/enum-dict-member.err b/tests/qapi-schema/enum-dict-member.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/enum-dict-member.exit b/tests/qapi-schema/enum-dict-member.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/enum-dict-member.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/enum-dict-member.json b/tests/qapi-schema/enum-dict-member.json new file mode 100644 index 0000000..de4d6bf --- /dev/null +++ b/tests/qapi-schema/enum-dict-member.json @@ -0,0 +1,2 @@ +# FIXME: we should reject any enum member that is not a string +{ 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] } diff --git a/tests/qapi-schema/enum-dict-member.out b/tests/qapi-schema/enum-dict-member.out new file mode 100644 index 0000000..8b293f8 --- /dev/null +++ b/tests/qapi-schema/enum-dict-member.out @@ -0,0 +1,3 @@ +[OrderedDict([('enum', 'MyEnum'), ('data', [OrderedDict([('value', 'str')])])])] +[{'enum_name': 'MyEnum', 'enum_values': [OrderedDict([('value', 'str')])]}] +[] diff --git a/tests/qapi-schema/enum-empty.err b/tests/qapi-schema/enum-empty.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/enum-empty.exit b/tests/qapi-schema/enum-empty.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/enum-empty.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/enum-empty.json b/tests/qapi-schema/enum-empty.json new file mode 100644 index 0000000..40d4e85 --- /dev/null +++ b/tests/qapi-schema/enum-empty.json @@ -0,0 +1,2 @@ +# An empty enum, although unusual, is currently acceptable +{ 'enum': 'MyEnum', 'data': [ ] } diff --git a/tests/qapi-schema/enum-empty.out b/tests/qapi-schema/enum-empty.out new file mode 100644 index 0000000..3b75c16 --- /dev/null +++ b/tests/qapi-schema/enum-empty.out @@ -0,0 +1,3 @@ +[OrderedDict([('enum', 'MyEnum'), ('data', [])])] +[{'enum_name': 'MyEnum', 'enum_values': []}] +[] diff --git a/tests/qapi-schema/enum-int-member.err b/tests/qapi-schema/enum-int-member.err new file mode 100644 index 0000000..071c521 --- /dev/null +++ b/tests/qapi-schema/enum-int-member.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-int-member.json:3:31: Stray "1" diff --git a/tests/qapi-schema/enum-int-member.exit b/tests/qapi-schema/enum-int-member.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/enum-int-member.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/enum-int-member.json b/tests/qapi-schema/enum-int-member.json new file mode 100644 index 0000000..6c9c32e --- /dev/null +++ b/tests/qapi-schema/enum-int-member.json @@ -0,0 +1,3 @@ +# we reject any enum member that is not a string +# FIXME: once the parser understands integer inputs, improve the error message +{ 'enum': 'MyEnum', 'data': [ 1 ] } diff --git a/tests/qapi-schema/enum-int-member.out b/tests/qapi-schema/enum-int-member.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/enum-max-member.err b/tests/qapi-schema/enum-max-member.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/enum-max-member.exit b/tests/qapi-schema/enum-max-member.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/enum-max-member.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/enum-max-member.json b/tests/qapi-schema/enum-max-member.json new file mode 100644 index 0000000..ea854c4 --- /dev/null +++ b/tests/qapi-schema/enum-max-member.json @@ -0,0 +1,3 @@ +# FIXME: we should either reject user-supplied 'max', or munge the implicit +# max value we generate at the end of an array +{ 'enum': 'MyEnum', 'data': [ 'max' ] } diff --git a/tests/qapi-schema/enum-max-member.out b/tests/qapi-schema/enum-max-member.out new file mode 100644 index 0000000..c933044 --- /dev/null +++ b/tests/qapi-schema/enum-max-member.out @@ -0,0 +1,3 @@ +[OrderedDict([('enum', 'MyEnum'), ('data', ['max'])])] +[{'enum_name': 'MyEnum', 'enum_values': ['max']}] +[] diff --git a/tests/qapi-schema/enum-missing-data.err b/tests/qapi-schema/enum-missing-data.err new file mode 100644 index 0000000..1fec213 --- /dev/null +++ b/tests/qapi-schema/enum-missing-data.err @@ -0,0 +1,6 @@ +Traceback (most recent call last): + File "tests/qapi-schema/test-qapi.py", line 19, in + exprs = parse_schema(sys.argv[1]) + File "scripts/qapi.py", line 339, in parse_schema + add_enum(expr['enum'], expr['data']) +KeyError: 'data' diff --git a/tests/qapi-schema/enum-missing-data.exit b/tests/qapi-schema/enum-missing-data.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/enum-missing-data.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/enum-missing-data.json b/tests/qapi-schema/enum-missing-data.json new file mode 100644 index 0000000..01f3f32 --- /dev/null +++ b/tests/qapi-schema/enum-missing-data.json @@ -0,0 +1,2 @@ +# FIXME: we should require that all QAPI enums have a data array +{ 'enum': 'MyEnum' } diff --git a/tests/qapi-schema/enum-missing-data.out b/tests/qapi-schema/enum-missing-data.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/enum-wrong-data.err b/tests/qapi-schema/enum-wrong-data.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/qapi-schema/enum-wrong-data.exit b/tests/qapi-schema/enum-wrong-data.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/qapi-schema/enum-wrong-data.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/enum-wrong-data.json b/tests/qapi-schema/enum-wrong-data.json new file mode 100644 index 0000000..61d25ec --- /dev/null +++ b/tests/qapi-schema/enum-wrong-data.json @@ -0,0 +1,2 @@ +# FIXME: we should require that all qapi enums have an array for data +{ 'enum': 'MyEnum', 'data': { 'value': 'str' } } diff --git a/tests/qapi-schema/enum-wrong-data.out b/tests/qapi-schema/enum-wrong-data.out new file mode 100644 index 0000000..28d2211 --- /dev/null +++ b/tests/qapi-schema/enum-wrong-data.out @@ -0,0 +1,3 @@ +[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])] +[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}] +[] -- 1.9.3