From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: famz@redhat.com, Markus Armbruster <armbru@redhat.com>,
wenchaoqemu@gmail.com, Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH 2/7] qapi: better error message for bad enum
Date: Mon, 4 Aug 2014 22:36:06 -0600 [thread overview]
Message-ID: <1407213371-7408-3-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1407213371-7408-1-git-send-email-eblake@redhat.com>
The previous test 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..11f70db 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:
@@ -335,7 +343,7 @@ def parse_schema(input_file):
for expr_elem in schema.exprs:
expr = expr_elem['expr']
- if expr.has_key('enum'):
+ if expr.has_key('enum') and expr.has_key('data'):
add_enum(expr['enum'], expr['data'])
elif expr.has_key('union'):
add_union(expr)
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 4:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-05 4:36 [Qemu-devel] [PATCH 0/7] drop qapi nested structs Eric Blake
2014-08-05 4:36 ` [Qemu-devel] [PATCH 1/7] qapi: add some enum tests Eric Blake
2014-08-05 5:31 ` Fam Zheng
2014-08-05 4:36 ` Eric Blake [this message]
2014-08-05 4:36 ` [Qemu-devel] [PATCH 3/7] qapi: merge UserDefTwo and UserDefNested in tests Eric Blake
2014-08-05 4:36 ` [Qemu-devel] [PATCH 4/7] qapi: drop tests for inline subtypes Eric Blake
2014-08-05 4:36 ` [Qemu-devel] [PATCH 5/7] qapi: drop inline subtype in query-version Eric Blake
2014-08-05 4:36 ` [Qemu-devel] [PATCH 6/7] qapi: drop inline subtype in query-pci Eric Blake
2014-08-05 4:36 ` [Qemu-devel] [PATCH 7/7] qapi: drop support for inline subtypes Eric Blake
2014-08-05 6:04 ` Fam Zheng
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=1407213371-7408-3-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).