From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fam Zheng <famz@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
wenchaoqemu@gmail.com, Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH v2 04/14] qapi: better error message for bad enum
Date: Tue, 5 Aug 2014 16:38:56 -0600 [thread overview]
Message-ID: <1407278346-17427-5-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1407278346-17427-1-git-send-email-eblake@redhat.com>
The previous commit demonstrated that the generator choked if an
enum forgot 'data', and silently ignored an enum where 'data'
was the wrong type. Fix both cases to give a sane error message.
* scripts/qapi.py (parse_schema): Avoid bad deref.
(check_exprs): Check for array on enums.
* tests/qapi-schema/enum-missing-data.err: Update expected results.
* tests/qapi-schema/enum-wrong-data.*: Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi.py | 16 ++++++++++++----
tests/qapi-schema/enum-missing-data.err | 7 +------
tests/qapi-schema/enum-wrong-data.err | 1 +
tests/qapi-schema/enum-wrong-data.exit | 2 +-
tests/qapi-schema/enum-wrong-data.out | 3 ---
5 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index f2c6d1f..1082416 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -2,7 +2,7 @@
# QAPI helper library
#
# Copyright IBM, Corp. 2011
-# Copyright (c) 2013 Red Hat Inc.
+# Copyright (c) 2013-2014 Red Hat Inc.
#
# Authors:
# Anthony Liguori <aliguori@us.ibm.com>
@@ -319,10 +319,18 @@ def check_union(expr, expr_info):
def check_exprs(schema):
for expr_elem in schema.exprs:
expr = expr_elem['expr']
+ info = expr_elem['info']
+ members = expr.get('data')
+
if expr.has_key('union'):
- check_union(expr, expr_elem['info'])
+ check_union(expr, info)
if expr.has_key('event'):
- check_event(expr, expr_elem['info'])
+ check_event(expr, info)
+ if expr.has_key('enum'):
+ if not isinstance(members, list):
+ raise QAPIExprError(info,
+ "enum '%s' requires an array for 'data'"
+ % expr.get('enum'))
def parse_schema(input_file):
try:
@@ -336,7 +344,7 @@ def parse_schema(input_file):
for expr_elem in schema.exprs:
expr = expr_elem['expr']
if expr.has_key('enum'):
- add_enum(expr['enum'], expr['data'])
+ add_enum(expr['enum'], expr.get('data'))
elif expr.has_key('union'):
add_union(expr)
elif expr.has_key('type'):
diff --git a/tests/qapi-schema/enum-missing-data.err b/tests/qapi-schema/enum-missing-data.err
index 1fec213..4912aab 100644
--- a/tests/qapi-schema/enum-missing-data.err
+++ b/tests/qapi-schema/enum-missing-data.err
@@ -1,6 +1 @@
-Traceback (most recent call last):
- File "tests/qapi-schema/test-qapi.py", line 19, in <module>
- exprs = parse_schema(sys.argv[1])
- File "scripts/qapi.py", line 339, in parse_schema
- add_enum(expr['enum'], expr['data'])
-KeyError: 'data'
+tests/qapi-schema/enum-missing-data.json:1: enum 'MyEnum' requires an array for 'data'
diff --git a/tests/qapi-schema/enum-wrong-data.err b/tests/qapi-schema/enum-wrong-data.err
index e69de29..857f0bd 100644
--- a/tests/qapi-schema/enum-wrong-data.err
+++ b/tests/qapi-schema/enum-wrong-data.err
@@ -0,0 +1 @@
+tests/qapi-schema/enum-wrong-data.json:1: enum 'MyEnum' requires an array for 'data'
diff --git a/tests/qapi-schema/enum-wrong-data.exit b/tests/qapi-schema/enum-wrong-data.exit
index 573541a..d00491f 100644
--- a/tests/qapi-schema/enum-wrong-data.exit
+++ b/tests/qapi-schema/enum-wrong-data.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/enum-wrong-data.out b/tests/qapi-schema/enum-wrong-data.out
index 28d2211..e69de29 100644
--- a/tests/qapi-schema/enum-wrong-data.out
+++ b/tests/qapi-schema/enum-wrong-data.out
@@ -1,3 +0,0 @@
-[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])]
-[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}]
-[]
--
1.9.3
next prev parent reply other threads:[~2014-08-05 22:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-05 22:38 [Qemu-devel] [PATCH v2 00/14] drop qapi nested structs Eric Blake
2014-08-05 22:38 ` [Qemu-devel] [PATCH v2 01/14] qapi: consistent whitespace in tests/Makefile Eric Blake
2014-08-05 22:38 ` [Qemu-devel] [PATCH v2 02/14] qapi: ignore files created during make check Eric Blake
2014-08-06 1:12 ` Wenchao Xia
2014-08-05 22:38 ` [Qemu-devel] [PATCH v2 03/14] qapi: add some enum tests Eric Blake
2014-08-06 1:22 ` Wenchao Xia
2014-08-05 22:38 ` Eric Blake [this message]
2014-08-05 22:38 ` [Qemu-devel] [PATCH v2 05/14] qapi: add some expr tests Eric Blake
2014-08-05 22:38 ` [Qemu-devel] [PATCH v2 06/14] qapi: require valid expressions Eric Blake
2014-08-05 22:38 ` [Qemu-devel] [PATCH v2 07/14] qapi: add some type check tests Eric Blake
2014-08-05 22:39 ` [Qemu-devel] [PATCH v2 08/14] qapi: add expr_name() helper Eric Blake
2014-08-05 22:39 ` [Qemu-devel] [PATCH v2 09/14] qapi: add check_type helper function Eric Blake
2014-08-05 22:39 ` [Qemu-devel] [PATCH v2 10/14] qapi: merge UserDefTwo and UserDefNested in tests Eric Blake
2014-08-05 22:41 ` [Qemu-devel] [PATCH v2 11/14] target-arm: Add FAR_EL2 and 3 Eric Blake
2014-08-05 23:08 ` Peter Maydell
2014-08-06 1:08 ` Eric Blake
2014-08-05 22:41 ` [Qemu-devel] [PATCH v2 12/14] target-arm: Fix bit test in sp_el0_access Eric Blake
2014-08-05 22:41 ` [Qemu-devel] [PATCH v2 13/14] target-arm: don't hardcode mask values in arm_cpu_handle_mmu_fault Eric Blake
2014-08-05 22:41 ` [Qemu-devel] [PATCH v2 14/14] target-arm: A64: fix TLB flush instructions Eric Blake
2014-08-06 1:12 ` [Qemu-devel] [PATCH v2 00/14] drop qapi nested structs Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1407278346-17427-5-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wenchaoqemu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).