qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 06/14] qapi: require valid expressions
Date: Tue,  5 Aug 2014 16:38:58 -0600	[thread overview]
Message-ID: <1407278346-17427-7-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1407278346-17427-1-git-send-email-eblake@redhat.com>

The previous patch demonstrated that the generator could get
confused if an expression had conflicting meta-types, and
silently ignored expressions that lacked a known meta-type.
Fix both cases to give a sane error message.

* scripts/qapi.py (check_exprs): Require a valid meta-type for
every expression.
* tests/qapi-schema/indented-expr.*: Use valid types.
* tests/qapi-schema/missing-type.*: Update expected output.
* tests/qapi-schema/double-type.*: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi.py                      | 12 ++++++++++++
 tests/qapi-schema/double-type.err    |  1 +
 tests/qapi-schema/double-type.exit   |  2 +-
 tests/qapi-schema/double-type.out    |  3 ---
 tests/qapi-schema/indented-expr.json |  4 ++--
 tests/qapi-schema/indented-expr.out  |  2 +-
 tests/qapi-schema/missing-type.err   |  1 +
 tests/qapi-schema/missing-type.exit  |  2 +-
 tests/qapi-schema/missing-type.out   |  3 ---
 9 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 1082416..910e422 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -322,6 +322,18 @@ def check_exprs(schema):
         info = expr_elem['info']
         members = expr.get('data')

+        # 'include' has already been flattened; at this point, all exprs
+        # should have one of the remaining keys
+        keys = (expr.has_key('enum') + expr.has_key('union') +
+                expr.has_key('type') + expr.has_key('command') +
+                expr.has_key('event'))
+        if keys < 1:
+            raise QAPIExprError(info,
+                                "Missing expression meta-type")
+        if keys > 1:
+            raise QAPIExprError(info,
+                                "Conflicting expression meta-types")
+
         if expr.has_key('union'):
             check_union(expr, info)
         if expr.has_key('event'):
diff --git a/tests/qapi-schema/double-type.err b/tests/qapi-schema/double-type.err
index e69de29..2df4a12 100644
--- a/tests/qapi-schema/double-type.err
+++ b/tests/qapi-schema/double-type.err
@@ -0,0 +1 @@
+tests/qapi-schema/double-type.json:1: Conflicting expression meta-types
diff --git a/tests/qapi-schema/double-type.exit b/tests/qapi-schema/double-type.exit
index 573541a..d00491f 100644
--- a/tests/qapi-schema/double-type.exit
+++ b/tests/qapi-schema/double-type.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/double-type.out b/tests/qapi-schema/double-type.out
index 3e244f5..e69de29 100644
--- a/tests/qapi-schema/double-type.out
+++ b/tests/qapi-schema/double-type.out
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
-[]
-[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
diff --git a/tests/qapi-schema/indented-expr.json b/tests/qapi-schema/indented-expr.json
index d80af60..7115d31 100644
--- a/tests/qapi-schema/indented-expr.json
+++ b/tests/qapi-schema/indented-expr.json
@@ -1,2 +1,2 @@
-{ 'id' : 'eins' }
- { 'id' : 'zwei' }
+{ 'command' : 'eins' }
+ { 'command' : 'zwei' }
diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indented-expr.out
index 98af89a..b5ce915 100644
--- a/tests/qapi-schema/indented-expr.out
+++ b/tests/qapi-schema/indented-expr.out
@@ -1,3 +1,3 @@
-[OrderedDict([('id', 'eins')]), OrderedDict([('id', 'zwei')])]
+[OrderedDict([('command', 'eins')]), OrderedDict([('command', 'zwei')])]
 []
 []
diff --git a/tests/qapi-schema/missing-type.err b/tests/qapi-schema/missing-type.err
index e69de29..af650e0 100644
--- a/tests/qapi-schema/missing-type.err
+++ b/tests/qapi-schema/missing-type.err
@@ -0,0 +1 @@
+tests/qapi-schema/missing-type.json:1: Missing expression meta-type
diff --git a/tests/qapi-schema/missing-type.exit b/tests/qapi-schema/missing-type.exit
index 573541a..d00491f 100644
--- a/tests/qapi-schema/missing-type.exit
+++ b/tests/qapi-schema/missing-type.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/missing-type.out b/tests/qapi-schema/missing-type.out
index 67fd4fa..e69de29 100644
--- a/tests/qapi-schema/missing-type.out
+++ b/tests/qapi-schema/missing-type.out
@@ -1,3 +0,0 @@
-[OrderedDict([('data', OrderedDict())])]
-[]
-[]
-- 
1.9.3

  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 ` [Qemu-devel] [PATCH v2 04/14] qapi: better error message for bad enum Eric Blake
2014-08-05 22:38 ` [Qemu-devel] [PATCH v2 05/14] qapi: add some expr tests Eric Blake
2014-08-05 22:38 ` Eric Blake [this message]
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-7-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).