Skip to contentSkip to conversation

drop qapi nested structs

PATCH Superseded Eric Blake 3 participants 20 messages Aug 5, 2014 – Aug 6, 2014

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

v2 cover drop qapi nested structs

According to this email:
https://lists.gnu.org/archive/html/qemu-devel/2014-05/msg00708.html
we want to repurpose 'data': { 'name': {dict...} } in qapi files for future use of designating default values of optional parameters. But to do that, we must first nuke existing use of that syntax for declaring nested structs. Enhancing the testsuite while at it never hurts.

v2:
New patches: 1-2, 5-9
consistent TAB usage in Makefile [Fam]
catch more bad coding constructs, and test them
avoid code duplication in type validity checks (patch 14 [former 7] is simpler because of patch 9)

Eric Blake (14):
qapi: consistent whitespace in tests/Makefile
qapi: ignore files created during make check
qapi: add some enum tests
qapi: better error message for bad enum
qapi: add some expr tests
qapi: require valid expressions
qapi: add some type check tests
qapi: add expr_name() helper
qapi: add check_type helper function
qapi: merge UserDefTwo and UserDefNested in tests
qapi: drop tests for inline subtypes
qapi: drop inline subtype in query-version
qapi: drop inline subtype in query-pci
qapi: drop support for inline subtypes

 hmp.c                                        | 28 ++++----
 hw/pci/pci.c                                 | 42 ++++++------
 qapi-schema.json                             | 90 ++++++++++++++++++--------
 qapi/common.json                             | 26 ++++++--
 qmp.c                                        |  9 +--
 scripts/qapi-commands.py                     |  8 +--
 scripts/qapi-event.py                        |  4 +-
 scripts/qapi-types.py                        |  9 +--
 scripts/qapi-visit.py                        | 37 ++---------
 scripts/qapi.py                              | 96 ++++++++++++++++++++++------
 tests/.gitignore                             |  3 +
 tests/Makefile                               | 37 ++++++-----
 tests/qapi-schema/data-array-empty.err       |  0
 tests/qapi-schema/data-array-empty.exit      |  1 +
 tests/qapi-schema/data-array-empty.json      |  1 +
 tests/qapi-schema/data-array-empty.out       |  3 +
 tests/qapi-schema/data-array-unknown.err     |  1 +
 tests/qapi-schema/data-array-unknown.exit    |  1 +
 tests/qapi-schema/data-array-unknown.json    |  1 +
 tests/qapi-schema/data-array-unknown.out     |  0
 tests/qapi-schema/data-int.err               |  1 +
 tests/qapi-schema/data-int.exit              |  1 +
 tests/qapi-schema/data-int.json              |  1 +
 tests/qapi-schema/data-int.out               |  0
 tests/qapi-schema/data-unknown.err           |  1 +
 tests/qapi-schema/data-unknown.exit          |  1 +
 tests/qapi-schema/data-unknown.json          |  1 +
 tests/qapi-schema/data-unknown.out           |  0
 tests/qapi-schema/double-type.err            |  1 +
 tests/qapi-schema/double-type.exit           |  1 +
 tests/qapi-schema/double-type.json           |  1 +
 tests/qapi-schema/double-type.out            |  0
 tests/qapi-schema/enum-empty.err             |  0
 tests/qapi-schema/enum-empty.exit            |  1 +
 tests/qapi-schema/enum-empty.json            |  1 +
 tests/qapi-schema/enum-empty.out             |  3 +
 tests/qapi-schema/enum-missing-data.err      |  1 +
 tests/qapi-schema/enum-missing-data.exit     |  1 +
 tests/qapi-schema/enum-missing-data.json     |  1 +
 tests/qapi-schema/enum-missing-data.out      |  0
 tests/qapi-schema/enum-wrong-data.err        |  1 +
 tests/qapi-schema/enum-wrong-data.exit       |  1 +
 tests/qapi-schema/enum-wrong-data.json       |  1 +
 tests/qapi-schema/enum-wrong-data.out        |  0
 tests/qapi-schema/event-nest-struct.err      |  2 +-
 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          |  1 +
 tests/qapi-schema/missing-type.json          |  1 +
 tests/qapi-schema/missing-type.out           |  0
 tests/qapi-schema/nested-struct-data.err     |  1 +
 tests/qapi-schema/nested-struct-data.exit    |  1 +
 tests/qapi-schema/nested-struct-data.json    |  3 +
 tests/qapi-schema/nested-struct-data.out     |  0
 tests/qapi-schema/nested-struct-returns.err  |  1 +
 tests/qapi-schema/nested-struct-returns.exit |  1 +
 tests/qapi-schema/nested-struct-returns.json |  2 +
 tests/qapi-schema/nested-struct-returns.out  |  0
 tests/qapi-schema/qapi-schema-test.json      | 18 +++---
 tests/qapi-schema/qapi-schema-test.out       | 10 +--
 tests/qapi-schema/returns-array-bad.err      |  1 +
 tests/qapi-schema/returns-array-bad.exit     |  1 +
 tests/qapi-schema/returns-array-bad.json     |  1 +
 tests/qapi-schema/returns-array-bad.out      |  0
 tests/qapi-schema/returns-int.err            |  0
 tests/qapi-schema/returns-int.exit           |  1 +
 tests/qapi-schema/returns-int.json           |  1 +
 tests/qapi-schema/returns-int.out            |  3 +
 tests/qapi-schema/returns-unknown.err        |  1 +
 tests/qapi-schema/returns-unknown.exit       |  1 +
 tests/qapi-schema/returns-unknown.json       |  1 +
 tests/qapi-schema/returns-unknown.out        |  0
 tests/test-qmp-commands.c                    | 35 +++++-----
 tests/test-qmp-input-strict.c                | 19 +++---
 tests/test-qmp-input-visitor.c               | 25 +++++---
 tests/test-qmp-output-visitor.c              | 64 ++++++++++---------
 tests/test-visitor-serialization.c           | 84 +++++++++++++-----------
 78 files changed, 433 insertions(+), 270 deletions(-)
 create mode 100644 tests/qapi-schema/data-array-empty.err
 create mode 100644 tests/qapi-schema/data-array-empty.exit
 create mode 100644 tests/qapi-schema/data-array-empty.json
 create mode 100644 tests/qapi-schema/data-array-empty.out
 create mode 100644 tests/qapi-schema/data-array-unknown.err
 create mode 100644 tests/qapi-schema/data-array-unknown.exit
 create mode 100644 tests/qapi-schema/data-array-unknown.json
 create mode 100644 tests/qapi-schema/data-array-unknown.out
 create mode 100644 tests/qapi-schema/data-int.err
 create mode 100644 tests/qapi-schema/data-int.exit
 create mode 100644 tests/qapi-schema/data-int.json
 create mode 100644 tests/qapi-schema/data-int.out
 create mode 100644 tests/qapi-schema/data-unknown.err
 create mode 100644 tests/qapi-schema/data-unknown.exit
 create mode 100644 tests/qapi-schema/data-unknown.json
 create mode 100644 tests/qapi-schema/data-unknown.out
 create mode 100644 tests/qapi-schema/double-type.err
 create mode 100644 tests/qapi-schema/double-type.exit
 create mode 100644 tests/qapi-schema/double-type.json
 create mode 100644 tests/qapi-schema/double-type.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-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
 create mode 100644 tests/qapi-schema/missing-type.err
 create mode 100644 tests/qapi-schema/missing-type.exit
 create mode 100644 tests/qapi-schema/missing-type.json
 create mode 100644 tests/qapi-schema/missing-type.out
 create mode 100644 tests/qapi-schema/nested-struct-data.err
 create mode 100644 tests/qapi-schema/nested-struct-data.exit
 create mode 100644 tests/qapi-schema/nested-struct-data.json
 create mode 100644 tests/qapi-schema/nested-struct-data.out
 create mode 100644 tests/qapi-schema/nested-struct-returns.err
 create mode 100644 tests/qapi-schema/nested-struct-returns.exit
 create mode 100644 tests/qapi-schema/nested-struct-returns.json
 create mode 100644 tests/qapi-schema/nested-struct-returns.out
 create mode 100644 tests/qapi-schema/returns-array-bad.err
 create mode 100644 tests/qapi-schema/returns-array-bad.exit
 create mode 100644 tests/qapi-schema/returns-array-bad.json
 create mode 100644 tests/qapi-schema/returns-array-bad.out
 create mode 100644 tests/qapi-schema/returns-int.err
 create mode 100644 tests/qapi-schema/returns-int.exit
 create mode 100644 tests/qapi-schema/returns-int.json
 create mode 100644 tests/qapi-schema/returns-int.out
 create mode 100644 tests/qapi-schema/returns-unknown.err
 create mode 100644 tests/qapi-schema/returns-unknown.exit
 create mode 100644 tests/qapi-schema/returns-unknown.json
 create mode 100644 tests/qapi-schema/returns-unknown.out
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH v2 1/14 qapi: consistent whitespace in tests/Makefile

This file had a mix of TAB vs. 8-space indentation; given that it is a Makefile, TAB is more idiomatic even though in these particular cases the choice of whitespace didn't matter.

* tests/Makefile (check-qapi-schema-y, GENERATED_HEADERS) (test-qapi-obj-y): Consistent tab indentation.

---
 tests/Makefile | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
tests/Makefile +16 -16
index 4b2e1bb..aa17e44 100644
@@ -190,23 +190,23 @@ $(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 \
-        missing-colon.json missing-comma-list.json \
-        missing-comma-object.json non-objects.json \
-        qapi-schema-test.json quoted-structural-chars.json \
-        trailing-comma-list.json trailing-comma-object.json \
-        unclosed-list.json unclosed-object.json unclosed-string.json \
-        duplicate-key.json union-invalid-base.json flat-union-no-base.json \
-        flat-union-invalid-discriminator.json \
-        flat-union-invalid-branch-key.json flat-union-reverse-define.json \
-        flat-union-string-discriminator.json \
-        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)
+	comments.json empty.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 \
+	trailing-comma-list.json trailing-comma-object.json \
+	unclosed-list.json unclosed-object.json unclosed-string.json \
+	duplicate-key.json union-invalid-base.json flat-union-no-base.json \
+	flat-union-invalid-discriminator.json \
+	flat-union-invalid-branch-key.json flat-union-reverse-define.json \
+	flat-union-string-discriminator.json \
+	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)
 
 GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \
-                     tests/test-qmp-commands.h tests/test-qapi-event.h
+		     tests/test-qmp-commands.h tests/test-qapi-event.h
 
 test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
 	tests/check-qlist.o tests/check-qfloat.o tests/check-qjson.o \
@@ -218,7 +218,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
 	tests/test-opts-visitor.o tests/test-qmp-event.o
 
 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
-                  tests/test-qapi-event.o
+		  tests/test-qapi-event.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
Signature · 1 line
1.9.3
author
#2 lore raw

PATCH v2 2/14 qapi: ignore files created during make check

In reply to Eric Blake

After an in-tree build and run of 'make check-{qapi-schema,unit}', I noticed some leftover files.

* tests/.gitignore: Ignore more testsuite droppings.

---
 tests/.gitignore | 3 +++
 1 file changed, 3 insertions(+)
tests/.gitignore +3 -0
index c71c110..e2e4957 100644
@@ -14,11 +14,14 @@ test-int128
 test-iov
 test-mul64
 test-opts-visitor
+test-qapi-event.[ch]
 test-qapi-types.[ch]
 test-qapi-visit.[ch]
 test-qdev-global-props
+test-qemu-opts
 test-qmp-commands
 test-qmp-commands.h
+test-qmp-event
 test-qmp-input-strict
 test-qmp-input-visitor
 test-qmp-marshal.c
Signature · 1 line
1.9.3
Reviewed-by on v2 2/14
#3 lore raw

Re: [Qemu-devel] [PATCH v2 02/14] qapi: ignore files created during make check

Quoted 30 lines · Eric Blake

After an in-tree build and run of 'make check-{qapi-schema,unit}', I noticed some leftover files.

* tests/.gitignore: Ignore more testsuite droppings.

---
  tests/.gitignore | 3 +++
  1 file changed, 3 insertions(+)
tests/.gitignore +3 -0
index c71c110..e2e4957 100644
@@ -14,11 +14,14 @@ test-int128
  test-iov
  test-mul64
  test-opts-visitor
+test-qapi-event.[ch]
  test-qapi-types.[ch]
  test-qapi-visit.[ch]
  test-qdev-global-props
+test-qemu-opts
  test-qmp-commands
  test-qmp-commands.h
+test-qmp-event
  test-qmp-input-strict
  test-qmp-input-visitor
  test-qmp-marshal.c
author
#4 lore raw

PATCH v2 3/14 qapi: add some enum tests

In reply to Eric Blake

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.

* tests/qapi-schema/enum-empty.*: New files.
* tests/qapi-schema/enum-missing-data.*: Likewise.
* tests/qapi-schema/enum-wrong-data.*: Likewise.
* tests/Makefile (check-qapi-schema-y): Run them.

---
 tests/Makefile                           | 3 ++-
 tests/qapi-schema/enum-empty.err         | 0
 tests/qapi-schema/enum-empty.exit        | 1 +
 tests/qapi-schema/enum-empty.json        | 1 +
 tests/qapi-schema/enum-empty.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 | 1 +
 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   | 1 +
 tests/qapi-schema/enum-wrong-data.out    | 3 +++
 13 files changed, 20 insertions(+), 1 deletion(-)
 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-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
tests/Makefile +2 -1
index aa17e44..fbf6909 100644
@@ -190,7 +190,8 @@ $(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 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 \
tests/qapi-schema/enum-empty.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/enum-empty.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/enum-empty.json new file +1 -0
new file mode 100644
index 0000000..f550aa0
@@ -0,0 +1 @@
+{ 'enum': 'MyEnum', 'data': [ ] }
tests/qapi-schema/enum-empty.out new file +3 -0
new file mode 100644
index 0000000..3b75c16
@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'MyEnum'), ('data', [])])]
+[{'enum_name': 'MyEnum', 'enum_values': []}]
+[]
tests/qapi-schema/enum-missing-data.err new file +6 -0
new file mode 100644
index 0000000..1fec213
@@ -0,0 +1,6 @@
+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.exit new file +1 -0
new file mode 100644
index 0000000..d00491f
@@ -0,0 +1 @@
+1
tests/qapi-schema/enum-missing-data.json new file +1 -0
new file mode 100644
index 0000000..6e2acd8
@@ -0,0 +1 @@
+{ 'enum': 'MyEnum' }
tests/qapi-schema/enum-missing-data.out new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/enum-wrong-data.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/enum-wrong-data.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/enum-wrong-data.json new file +1 -0
new file mode 100644
index 0000000..4b7e90c
@@ -0,0 +1 @@
+{ 'enum': 'MyEnum', 'data': { 'value': 'str' } }
tests/qapi-schema/enum-wrong-data.out new file +3 -0
new file mode 100644
index 0000000..28d2211
@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])]
+[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}]
+[]
Signature · 1 line
1.9.3
author
#6 lore raw

PATCH v2 4/14 qapi: better error message for bad enum

In reply to Eric Blake

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.

---
 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(-)
scripts/qapi.py +12 -4
index f2c6d1f..1082416 100644
@@ -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 <[email protected]>
@@ -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'):
tests/qapi-schema/enum-missing-data.err +1 -6
index 1fec213..4912aab 100644
@@ -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'
tests/qapi-schema/enum-wrong-data.err +1 -0
index e69de29..857f0bd 100644
@@ -0,0 +1 @@
+tests/qapi-schema/enum-wrong-data.json:1: enum 'MyEnum' requires an array for 'data'
tests/qapi-schema/enum-wrong-data.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/enum-wrong-data.out +0 -3
index 28d2211..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])]
-[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}]
-[]
Signature · 1 line
1.9.3
author
#7 lore raw

PATCH v2 5/14 qapi: add some expr tests

In reply to Eric Blake

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.

* tests/qapi-schema/missing-type.*: New files.
* tests/qapi-schema/double-type.*: Likewise.
* tests/Makefile (check-qapi-schema-y): Run them.

---
 tests/Makefile                      | 1 +
 tests/qapi-schema/double-type.err   | 0
 tests/qapi-schema/double-type.exit  | 1 +
 tests/qapi-schema/double-type.json  | 1 +
 tests/qapi-schema/double-type.out   | 3 +++
 tests/qapi-schema/missing-type.err  | 0
 tests/qapi-schema/missing-type.exit | 1 +
 tests/qapi-schema/missing-type.json | 1 +
 tests/qapi-schema/missing-type.out  | 3 +++
 9 files changed, 11 insertions(+)
 create mode 100644 tests/qapi-schema/double-type.err
 create mode 100644 tests/qapi-schema/double-type.exit
 create mode 100644 tests/qapi-schema/double-type.json
 create mode 100644 tests/qapi-schema/double-type.out
 create mode 100644 tests/qapi-schema/missing-type.err
 create mode 100644 tests/qapi-schema/missing-type.exit
 create mode 100644 tests/qapi-schema/missing-type.json
 create mode 100644 tests/qapi-schema/missing-type.out
tests/Makefile +1 -0
index fbf6909..1b0c96f 100644
@@ -192,6 +192,7 @@ $(foreach target,$(SYSEMU_TARGET_LIST), \
 check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 	comments.json empty.json enum-empty.json enum-missing-data.json \
 	enum-wrong-data.json funny-char.json indented-expr.json \
+	missing-type.json double-type.json \
 	missing-colon.json missing-comma-list.json \
 	missing-comma-object.json non-objects.json \
 	qapi-schema-test.json quoted-structural-chars.json \
tests/qapi-schema/double-type.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/double-type.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/double-type.json new file +1 -0
new file mode 100644
index 0000000..2d4d97d
@@ -0,0 +1 @@
+{ 'command': 'foo', 'type': 'bar', 'data': { } }
tests/qapi-schema/double-type.out new file +3 -0
new file mode 100644
index 0000000..3e244f5
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
+[]
+[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
tests/qapi-schema/missing-type.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/missing-type.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/missing-type.json new file +1 -0
new file mode 100644
index 0000000..9043aa4
@@ -0,0 +1 @@
+{ 'data': { } }
tests/qapi-schema/missing-type.out new file +3 -0
new file mode 100644
index 0000000..67fd4fa
@@ -0,0 +1,3 @@
+[OrderedDict([('data', OrderedDict())])]
+[]
+[]
Signature · 1 line
1.9.3
author
#8 lore raw

PATCH v2 6/14 qapi: require valid expressions

In reply to Eric Blake

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.

---
 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(-)
scripts/qapi.py +12 -0
index 1082416..910e422 100644
@@ -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'):
tests/qapi-schema/double-type.err +1 -0
index e69de29..2df4a12 100644
@@ -0,0 +1 @@
+tests/qapi-schema/double-type.json:1: Conflicting expression meta-types
tests/qapi-schema/double-type.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/double-type.out +0 -3
index 3e244f5..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
-[]
-[OrderedDict([('command', 'foo'), ('type', 'bar'), ('data', OrderedDict())])]
tests/qapi-schema/indented-expr.json +2 -2
index d80af60..7115d31 100644
@@ -1,2 +1,2 @@
-{ 'id' : 'eins' }
- { 'id' : 'zwei' }
+{ 'command' : 'eins' }
+ { 'command' : 'zwei' }
tests/qapi-schema/indented-expr.out +1 -1
index 98af89a..b5ce915 100644
@@ -1,3 +1,3 @@
-[OrderedDict([('id', 'eins')]), OrderedDict([('id', 'zwei')])]
+[OrderedDict([('command', 'eins')]), OrderedDict([('command', 'zwei')])]
 []
 []
tests/qapi-schema/missing-type.err +1 -0
index e69de29..af650e0 100644
@@ -0,0 +1 @@
+tests/qapi-schema/missing-type.json:1: Missing expression meta-type
tests/qapi-schema/missing-type.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/missing-type.out +0 -3
index 67fd4fa..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('data', OrderedDict())])]
-[]
-[]
Signature · 1 line
1.9.3
author
#9 lore raw

PATCH v2 7/14 qapi: add some type check tests

In reply to Eric Blake

Demonstrate that the qapi generator silently parses confusing types, which may cause other errors later on. Later patches will update the expected results as the generator is made stricter.

* tests/qapi-schema/data-array-empty.*: New files.
* tests/qapi-schema/data-array-unknown.*: Likewise.
* tests/qapi-schema/data-unknown.*: Likewise.
* tests/qapi-schema/data-int.*: Likewise.
* tests/qapi-schema/returns-unknown.*: Likewise.
* tests/qapi-schema/returns-int.*: Likewise.
* tests/qapi-schema/returns-array-bad.*: Likewise.
* tests/Makefile (check-qapi-schema-y): Run them.

---
 tests/Makefile                            | 4 +++-
 tests/qapi-schema/data-array-empty.err    | 0
 tests/qapi-schema/data-array-empty.exit   | 1 +
 tests/qapi-schema/data-array-empty.json   | 1 +
 tests/qapi-schema/data-array-empty.out    | 3 +++
 tests/qapi-schema/data-array-unknown.err  | 0
 tests/qapi-schema/data-array-unknown.exit | 1 +
 tests/qapi-schema/data-array-unknown.json | 1 +
 tests/qapi-schema/data-array-unknown.out  | 3 +++
 tests/qapi-schema/data-int.err            | 0
 tests/qapi-schema/data-int.exit           | 1 +
 tests/qapi-schema/data-int.json           | 1 +
 tests/qapi-schema/data-int.out            | 3 +++
 tests/qapi-schema/data-unknown.err        | 0
 tests/qapi-schema/data-unknown.exit       | 1 +
 tests/qapi-schema/data-unknown.json       | 1 +
 tests/qapi-schema/data-unknown.out        | 3 +++
 tests/qapi-schema/returns-array-bad.err   | 0
 tests/qapi-schema/returns-array-bad.exit  | 1 +
 tests/qapi-schema/returns-array-bad.json  | 1 +
 tests/qapi-schema/returns-array-bad.out   | 3 +++
 tests/qapi-schema/returns-int.err         | 0
 tests/qapi-schema/returns-int.exit        | 1 +
 tests/qapi-schema/returns-int.json        | 1 +
 tests/qapi-schema/returns-int.out         | 3 +++
 tests/qapi-schema/returns-unknown.err     | 0
 tests/qapi-schema/returns-unknown.exit    | 1 +
 tests/qapi-schema/returns-unknown.json    | 1 +
 tests/qapi-schema/returns-unknown.out     | 3 +++
 29 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 tests/qapi-schema/data-array-empty.err
 create mode 100644 tests/qapi-schema/data-array-empty.exit
 create mode 100644 tests/qapi-schema/data-array-empty.json
 create mode 100644 tests/qapi-schema/data-array-empty.out
 create mode 100644 tests/qapi-schema/data-array-unknown.err
 create mode 100644 tests/qapi-schema/data-array-unknown.exit
 create mode 100644 tests/qapi-schema/data-array-unknown.json
 create mode 100644 tests/qapi-schema/data-array-unknown.out
 create mode 100644 tests/qapi-schema/data-int.err
 create mode 100644 tests/qapi-schema/data-int.exit
 create mode 100644 tests/qapi-schema/data-int.json
 create mode 100644 tests/qapi-schema/data-int.out
 create mode 100644 tests/qapi-schema/data-unknown.err
 create mode 100644 tests/qapi-schema/data-unknown.exit
 create mode 100644 tests/qapi-schema/data-unknown.json
 create mode 100644 tests/qapi-schema/data-unknown.out
 create mode 100644 tests/qapi-schema/returns-array-bad.err
 create mode 100644 tests/qapi-schema/returns-array-bad.exit
 create mode 100644 tests/qapi-schema/returns-array-bad.json
 create mode 100644 tests/qapi-schema/returns-array-bad.out
 create mode 100644 tests/qapi-schema/returns-int.err
 create mode 100644 tests/qapi-schema/returns-int.exit
 create mode 100644 tests/qapi-schema/returns-int.json
 create mode 100644 tests/qapi-schema/returns-int.out
 create mode 100644 tests/qapi-schema/returns-unknown.err
 create mode 100644 tests/qapi-schema/returns-unknown.exit
 create mode 100644 tests/qapi-schema/returns-unknown.json
 create mode 100644 tests/qapi-schema/returns-unknown.out
tests/Makefile +3 -1
index 1b0c96f..c36faca 100644
@@ -192,7 +192,9 @@ $(foreach target,$(SYSEMU_TARGET_LIST), \
 check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 	comments.json empty.json enum-empty.json enum-missing-data.json \
 	enum-wrong-data.json funny-char.json indented-expr.json \
-	missing-type.json double-type.json \
+	missing-type.json double-type.json data-array-empty.json \
+	data-array-unknown.json data-unknown.json data-int.json \
+	returns-unknown.json returns-int.json returns-array-bad.json \
 	missing-colon.json missing-comma-list.json \
 	missing-comma-object.json non-objects.json \
 	qapi-schema-test.json quoted-structural-chars.json \
tests/qapi-schema/data-array-empty.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/data-array-empty.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/data-array-empty.json new file +1 -0
new file mode 100644
index 0000000..00352ac
@@ -0,0 +1 @@
+{ 'command': 'oops', 'data': [ ] }
tests/qapi-schema/data-array-empty.out new file +3 -0
new file mode 100644
index 0000000..67802be
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'oops'), ('data', [])])]
+[]
+[]
tests/qapi-schema/data-array-unknown.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/data-array-unknown.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/data-array-unknown.json new file +1 -0
new file mode 100644
index 0000000..03ef321
@@ -0,0 +1 @@
+{ 'command': 'oops', 'data': [ 'NoSuchType' ] }
tests/qapi-schema/data-array-unknown.out new file +3 -0
new file mode 100644
index 0000000..c3bc05e
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'oops'), ('data', ['NoSuchType'])])]
+[]
+[]
tests/qapi-schema/data-int.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/data-int.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/data-int.json new file +1 -0
new file mode 100644
index 0000000..926c75e
@@ -0,0 +1 @@
+{ 'command': 'oops', 'data': 'int' }
tests/qapi-schema/data-int.out new file +3 -0
new file mode 100644
index 0000000..e589a4f
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'oops'), ('data', 'int')])]
+[]
+[]
tests/qapi-schema/data-unknown.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/data-unknown.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/data-unknown.json new file +1 -0
new file mode 100644
index 0000000..4415584
@@ -0,0 +1 @@
+{ 'command': 'oops', 'data': 'NoSuchType' }
tests/qapi-schema/data-unknown.out new file +3 -0
new file mode 100644
index 0000000..2c60726
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'oops'), ('data', 'NoSuchType')])]
+[]
+[]
tests/qapi-schema/returns-array-bad.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/returns-array-bad.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/returns-array-bad.json new file +1 -0
new file mode 100644
index 0000000..76bf6df
@@ -0,0 +1 @@
+{ 'command': 'oops', 'data': [ 'str', 'str' ] }
tests/qapi-schema/returns-array-bad.out new file +3 -0
new file mode 100644
index 0000000..cfc474e
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'oops'), ('data', ['str', 'str'])])]
+[]
+[]
tests/qapi-schema/returns-int.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/returns-int.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/returns-int.json new file +1 -0
new file mode 100644
index 0000000..0884968
@@ -0,0 +1 @@
+{ 'command': 'okay', 'returns': 'int' }
tests/qapi-schema/returns-int.out new file +3 -0
new file mode 100644
index 0000000..36b00a9
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'okay'), ('returns', 'int')])]
+[]
+[]
tests/qapi-schema/returns-unknown.err new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/returns-unknown.exit new file +1 -0
new file mode 100644
index 0000000..573541a
@@ -0,0 +1 @@
+0
tests/qapi-schema/returns-unknown.json new file +1 -0
new file mode 100644
index 0000000..508df3e
@@ -0,0 +1 @@
+{ 'command': 'oops', 'returns': 'NoSuchType' }
tests/qapi-schema/returns-unknown.out new file +3 -0
new file mode 100644
index 0000000..a482c83
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'oops'), ('returns', 'NoSuchType')])]
+[]
+[]
Signature · 1 line
1.9.3
author
#10 lore raw

PATCH v2 8/14 qapi: add expr_name() helper

In reply to Eric Blake

Now that we know every expression has a known meta-type, we can add a helper function that retrieves the name of an arbitrary expression, for use in future error messages.

* scripts/qapi.py (expr_name): New function.

---
 scripts/qapi.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
scripts/qapi.py +13 -0
index 910e422..e02fa0b 100644
@@ -248,6 +248,19 @@ def discriminator_find_enum_define(expr):
 
     return find_enum(discriminator_type)
 
+def expr_name(expr):
+    if expr.has_key('union'):
+        return expr['union']
+    if expr.has_key('type'):
+        return expr['type']
+    if expr.has_key('enum'):
+        return expr['enum']
+    if expr.has_key('command'):
+        return expr['command']
+    if expr.has_key('event'):
+        return expr['event']
+    return None
+
 def check_event(expr, expr_info):
     params = expr.get('data')
     if params:
Signature · 1 line
1.9.3
author
#11 lore raw

PATCH v2 9/14 qapi: add check_type helper function

In reply to Eric Blake

Add a helper function for use in a later patch that will validate that a 'data':... or 'returns':... member of an expression evaluates to a valid type.

* scripts/qapi.py (check_type): New function.
(check_exprs): Use it.

---
 scripts/qapi.py                           | 30 ++++++++++++++++++++++++++++++
 tests/qapi-schema/data-array-unknown.err  |  1 +
 tests/qapi-schema/data-array-unknown.exit |  2 +-
 tests/qapi-schema/data-array-unknown.out  |  3 ---
 tests/qapi-schema/data-int.err            |  1 +
 tests/qapi-schema/data-int.exit           |  2 +-
 tests/qapi-schema/data-int.out            |  3 ---
 tests/qapi-schema/data-unknown.err        |  1 +
 tests/qapi-schema/data-unknown.exit       |  2 +-
 tests/qapi-schema/data-unknown.out        |  3 ---
 tests/qapi-schema/returns-array-bad.err   |  1 +
 tests/qapi-schema/returns-array-bad.exit  |  2 +-
 tests/qapi-schema/returns-array-bad.out   |  3 ---
 tests/qapi-schema/returns-unknown.err     |  1 +
 tests/qapi-schema/returns-unknown.exit    |  2 +-
 tests/qapi-schema/returns-unknown.out     |  3 ---
 16 files changed, 40 insertions(+), 20 deletions(-)
scripts/qapi.py +30 -0
index e02fa0b..e4d27d6 100644
@@ -329,6 +329,32 @@ def check_union(expr, expr_info):
         # Todo: add checking for values. Key is checked as above, value can be
         # also checked here, but we need more functions to handle array case.
 
+def check_type(expr_info, name, data, allow_native = False):
+    if not data:
+        return
+    if isinstance(data, list):
+        if len(data) != 1 or not isinstance(data[0], basestring):
+            raise QAPIExprError(expr_info,
+                                "Use of array type in '%s' must contain "
+                                "single element type name" % name)
+        data = data[0]
+
+    if isinstance(data, basestring):
+        if find_struct(data) or find_enum(data) or find_union(data):
+            return
+        if data == 'str' or data == 'int' or data == 'visitor':
+            if allow_native:
+                return
+            raise QAPIExprError(expr_info,
+                                "Primitive type '%s' not allowed as data "
+                                "of '%s'" % (data, name))
+        raise QAPIExprError(expr_info,
+                            "Unknown type '%s' as data of '%s'"
+                            % (data, name))
+    elif not isinstance(data, OrderedDict):
+        raise QAPIExprError(expr_info,
+                            "Expecting dictionary for data of '%s'" % name)
+
 def check_exprs(schema):
     for expr_elem in schema.exprs:
         expr = expr_elem['expr']
@@ -356,6 +382,10 @@ def check_exprs(schema):
                 raise QAPIExprError(info,
                                     "enum '%s' requires an array for 'data'"
                                     % expr.get('enum'))
+        else:
+            check_type(info, expr_name(expr), members)
+            if expr.has_key('command') and expr.has_key('returns'):
+                check_type(info, expr['command'], expr['returns'], True)
 
 def parse_schema(input_file):
     try:
tests/qapi-schema/data-array-unknown.err +1 -0
index e69de29..e0433b8 100644
@@ -0,0 +1 @@
+tests/qapi-schema/data-array-unknown.json:1: Unknown type 'NoSuchType' as data of 'oops'
tests/qapi-schema/data-array-unknown.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/data-array-unknown.out +0 -3
index c3bc05e..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'oops'), ('data', ['NoSuchType'])])]
-[]
-[]
tests/qapi-schema/data-int.err +1 -0
index e69de29..30bbffc 100644
@@ -0,0 +1 @@
+tests/qapi-schema/data-int.json:1: Primitive type 'int' not allowed as data of 'oops'
tests/qapi-schema/data-int.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/data-int.out +0 -3
index e589a4f..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'oops'), ('data', 'int')])]
-[]
-[]
tests/qapi-schema/data-unknown.err +1 -0
index e69de29..f7fd635 100644
@@ -0,0 +1 @@
+tests/qapi-schema/data-unknown.json:1: Unknown type 'NoSuchType' as data of 'oops'
tests/qapi-schema/data-unknown.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/data-unknown.out +0 -3
index 2c60726..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'oops'), ('data', 'NoSuchType')])]
-[]
-[]
tests/qapi-schema/returns-array-bad.err +1 -0
index e69de29..d2a216f 100644
@@ -0,0 +1 @@
+tests/qapi-schema/returns-array-bad.json:1: Use of array type in 'oops' must contain single element type name
tests/qapi-schema/returns-array-bad.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/returns-array-bad.out +0 -3
index cfc474e..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'oops'), ('data', ['str', 'str'])])]
-[]
-[]
tests/qapi-schema/returns-unknown.err +1 -0
index e69de29..d09fb92 100644
@@ -0,0 +1 @@
+tests/qapi-schema/returns-unknown.json:1: Unknown type 'NoSuchType' as data of 'oops'
tests/qapi-schema/returns-unknown.exit +1 -1
index 573541a..d00491f 100644
@@ -1 +1 @@
-0
+1
tests/qapi-schema/returns-unknown.out +0 -3
index a482c83..e69de29 100644
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'oops'), ('returns', 'NoSuchType')])]
-[]
-[]
Signature · 1 line
1.9.3
author
#12 lore raw

PATCH v2 10/14 qapi: merge UserDefTwo and UserDefNested in tests

In reply to Eric Blake

In the testsuite, UserDefTwo and UserDefNested were identical types other than the member names. Reduce code duplication by having just one type, and choose names that also favor reuse. This will also make it easier for a later patch to get rid of nested inline subtypes in QAPI.

Ensure that 'make check-qapi-schema check-unit' still passes.

* tests/qapi-schema/qapi-schema-test.json (UserDefNested): Drop. (UserDefTwo): Rename element members for clarity.
* tests/qapi-schema/qapi-schema-test.out: Update expected output.
* tests/test-qmp-output-visitor.c (test_visitor_out_struct_nested, test_visitor_out_list_qapi_free):
Update clients.
* tests/test-qmp-input-visitor.c (test_visitor_in_struct_nested):
Likewise.
* tests/test-qmp-input-strict.c (test_validate_struct_nested) (test_validate_fail_struct_nested): Likewise.
* tests/test-qmp-commands.c (qmp_user_def_cmd2) (test_dealloc_partial, test_dispatch_cmd_io): Likewise.
* tests/test-visitor-serialization.c (nested_struct_create) (nested_struct_compare, nested_struct_cleanup) (visit_nested_struct, visit_nested_struct_list) (test_nested_struct, test_nested_struct_list): Likewise.

---
 tests/qapi-schema/qapi-schema-test.json | 10 +----
 tests/qapi-schema/qapi-schema-test.out  |  6 +--
 tests/test-qmp-commands.c               | 32 +++++++--------
 tests/test-qmp-input-strict.c           | 19 +++++----
 tests/test-qmp-input-visitor.c          | 19 +++++----
 tests/test-qmp-output-visitor.c         | 50 +++++++++++------------
 tests/test-visitor-serialization.c      | 71 +++++++++++++++++----------------
 7 files changed, 103 insertions(+), 104 deletions(-)
tests/qapi-schema/qapi-schema-test.json +2 -8
index ab4d3d9..2e13f09 100644
@@ -15,16 +15,10 @@
   'data': { 'string': 'str', '*enum1': 'EnumOne' } }
 
 { 'type': 'UserDefTwo',
-  'data': { 'string': 'str',
-            'dict': { 'string': 'str',
-                      'dict': { 'userdef': 'UserDefOne', 'string': 'str' },
-                      '*dict2': { 'userdef': 'UserDefOne', 'string': 'str' } } } }
-
-{ 'type': 'UserDefNested',
   'data': { 'string0': 'str',
             'dict1': { 'string1': 'str',
-                       'dict2': { 'userdef1': 'UserDefOne', 'string2': 'str' },
-                       '*dict3': { 'userdef2': 'UserDefOne', 'string3': 'str' } } } }
+                       'dict2': { 'userdef': 'UserDefOne', 'string': 'str' },
+                       '*dict3': { 'userdef': 'UserDefOne', 'string': 'str' } } } }
 
 # for testing unions
 { 'type': 'UserDefA',
tests/qapi-schema/qapi-schema-test.out +2 -4
index 95e9899..f94bbcc 100644
@@ -2,8 +2,7 @@
  OrderedDict([('type', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]),
  OrderedDict([('type', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]),
  OrderedDict([('type', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]),
- OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]),
- OrderedDict([('type', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]),
+ OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]),
  OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]),
  OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]),
  OrderedDict([('union', 'UserDefUnion'), ('base', 'UserDefZero'), ('data', OrderedDict([('a', 'UserDefA'), ('b', 'UserDefB')]))]),
@@ -28,8 +27,7 @@
 [OrderedDict([('type', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]),
  OrderedDict([('type', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]),
  OrderedDict([('type', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]),
- OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]),
- OrderedDict([('type', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]),
+ OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]),
  OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]),
  OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]),
  OrderedDict([('type', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]),
tests/test-qmp-commands.c +16 -16
index 554e222..9189cd2 100644
@@ -32,13 +32,13 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a,
     ud1d->base->integer = has_udb1 ? ud1b->base->integer : 0;
 
     ret = g_malloc0(sizeof(UserDefTwo));
-    ret->string = strdup("blah1");
-    ret->dict.string = strdup("blah2");
-    ret->dict.dict.userdef = ud1c;
-    ret->dict.dict.string = strdup("blah3");
-    ret->dict.has_dict2 = true;
-    ret->dict.dict2.userdef = ud1d;
-    ret->dict.dict2.string = strdup("blah4");
+    ret->string0 = strdup("blah1");
+    ret->dict1.string1 = strdup("blah2");
+    ret->dict1.dict2.userdef = ud1c;
+    ret->dict1.dict2.string = strdup("blah3");
+    ret->dict1.has_dict3 = true;
+    ret->dict1.dict3.userdef = ud1d;
+    ret->dict1.dict3.string = strdup("blah4");
 
     return ret;
 }
@@ -120,15 +120,15 @@ static void test_dispatch_cmd_io(void)
 
     ret = qobject_to_qdict(test_qmp_dispatch(req));
 
-    assert(!strcmp(qdict_get_str(ret, "string"), "blah1"));
-    ret_dict = qdict_get_qdict(ret, "dict");
-    assert(!strcmp(qdict_get_str(ret_dict, "string"), "blah2"));
-    ret_dict_dict = qdict_get_qdict(ret_dict, "dict");
+    assert(!strcmp(qdict_get_str(ret, "string0"), "blah1"));
+    ret_dict = qdict_get_qdict(ret, "dict1");
+    assert(!strcmp(qdict_get_str(ret_dict, "string1"), "blah2"));
+    ret_dict_dict = qdict_get_qdict(ret_dict, "dict2");
     ret_dict_dict_userdef = qdict_get_qdict(ret_dict_dict, "userdef");
     assert(qdict_get_int(ret_dict_dict_userdef, "integer") == 42);
     assert(!strcmp(qdict_get_str(ret_dict_dict_userdef, "string"), "hello"));
     assert(!strcmp(qdict_get_str(ret_dict_dict, "string"), "blah3"));
-    ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict2");
+    ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict3");
     ret_dict_dict2_userdef = qdict_get_qdict(ret_dict_dict2, "userdef");
     assert(qdict_get_int(ret_dict_dict2_userdef, "integer") == 422);
     assert(!strcmp(qdict_get_str(ret_dict_dict2_userdef, "string"), "hello2"));
@@ -192,7 +192,7 @@ static void test_dealloc_partial(void)
         QmpInputVisitor *qiv;
 
         ud2_dict = qdict_new();
-        qdict_put_obj(ud2_dict, "string", QOBJECT(qstring_from_str(text)));
+        qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));
 
         qiv = qmp_input_visitor_new(QOBJECT(ud2_dict));
         visit_type_UserDefTwo(qmp_input_get_visitor(qiv), &ud2, NULL, &err);
@@ -202,9 +202,9 @@ static void test_dealloc_partial(void)
 
     /* verify partial success */
     assert(ud2 != NULL);
-    assert(ud2->string != NULL);
-    assert(strcmp(ud2->string, text) == 0);
-    assert(ud2->dict.dict.userdef == NULL);
+    assert(ud2->string0 != NULL);
+    assert(strcmp(ud2->string0, text) == 0);
+    assert(ud2->dict1.dict2.userdef == NULL);
 
     /* confirm & release construction error */
     assert(err != NULL);
tests/test-qmp-input-strict.c +11 -8
index 0f77003..29d4f82 100644
@@ -1,7 +1,7 @@
 /*
  * QMP Input Visitor unit-tests (strict mode).
  *
- * Copyright (C) 2011-2012 Red Hat Inc.
+ * Copyright (C) 2011-2012, 2014 Red Hat Inc.
  *
  * Authors:
  *  Luiz Capitulino <[email protected]>
@@ -116,15 +116,18 @@ static void test_validate_struct(TestInputVisitorData *data,
 static void test_validate_struct_nested(TestInputVisitorData *data,
                                          const void *unused)
 {
-    UserDefNested *udp = NULL;
+    UserDefTwo *udp = NULL;
     Error *err = NULL;
     Visitor *v;
 
-    v = validate_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string' }, 'string2': 'string2'}}}");
+    v = validate_test_init(data, "{ 'string0': 'string0', "
+                           "'dict1': { 'string1': 'string1', "
+                           "'dict2': { 'userdef': { 'integer': 42, "
+                           "'string': 'string' }, 'string': 'string2'}}}");
 
-    visit_type_UserDefNested(v, &udp, NULL, &err);
+    visit_type_UserDefTwo(v, &udp, NULL, &err);
     g_assert(!err);
-    qapi_free_UserDefNested(udp);
+    qapi_free_UserDefTwo(udp);
 }
 
 static void test_validate_list(TestInputVisitorData *data,
@@ -207,15 +210,15 @@ static void test_validate_fail_struct(TestInputVisitorData *data,
 static void test_validate_fail_struct_nested(TestInputVisitorData *data,
                                               const void *unused)
 {
-    UserDefNested *udp = NULL;
+    UserDefTwo *udp = NULL;
     Error *err = NULL;
     Visitor *v;
 
     v = validate_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string', 'extra': [42, 23, {'foo':'bar'}] }, 'string2': 'string2'}}}");
 
-    visit_type_UserDefNested(v, &udp, NULL, &err);
+    visit_type_UserDefTwo(v, &udp, NULL, &err);
     g_assert(err);
-    qapi_free_UserDefNested(udp);
+    qapi_free_UserDefTwo(udp);
 }
 
 static void test_validate_fail_list(TestInputVisitorData *data,
tests/test-qmp-input-visitor.c +11 -8
index 1c8e872..3e1da9d 100644
@@ -1,7 +1,7 @@
 /*
  * QMP Input Visitor unit-tests.
  *
- * Copyright (C) 2011 Red Hat Inc.
+ * Copyright (C) 2011, 2014 Red Hat Inc.
  *
  * Authors:
  *  Luiz Capitulino <[email protected]>
@@ -248,23 +248,26 @@ static void check_and_free_str(char *str, const char *cmp)
 static void test_visitor_in_struct_nested(TestInputVisitorData *data,
                                           const void *unused)
 {
-    UserDefNested *udp = NULL;
+    UserDefTwo *udp = NULL;
     Error *err = NULL;
     Visitor *v;
 
-    v = visitor_input_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string' }, 'string2': 'string2'}}}");
+    v = visitor_input_test_init(data, "{ 'string0': 'string0', "
+                                "'dict1': { 'string1': 'string1', "
+                                "'dict2': { 'userdef': { 'integer': 42, "
+                                "'string': 'string' }, 'string': 'string2'}}}");
 
-    visit_type_UserDefNested(v, &udp, NULL, &err);
+    visit_type_UserDefTwo(v, &udp, NULL, &err);
     g_assert(!err);
 
     check_and_free_str(udp->string0, "string0");
     check_and_free_str(udp->dict1.string1, "string1");
-    g_assert_cmpint(udp->dict1.dict2.userdef1->base->integer, ==, 42);
-    check_and_free_str(udp->dict1.dict2.userdef1->string, "string");
-    check_and_free_str(udp->dict1.dict2.string2, "string2");
+    g_assert_cmpint(udp->dict1.dict2.userdef->base->integer, ==, 42);
+    check_and_free_str(udp->dict1.dict2.userdef->string, "string");
+    check_and_free_str(udp->dict1.dict2.string, "string2");
     g_assert(udp->dict1.has_dict3 == false);
 
-    g_free(udp->dict1.dict2.userdef1);
+    g_free(udp->dict1.dict2.userdef);
     g_free(udp);
 }
 
tests/test-qmp-output-visitor.c +25 -25

106 lines not on this page · raw message

tests/test-visitor-serialization.c +36 -35

127 lines not on this page · raw message

Signature · 1 line
1.9.3
author
#13 lore raw

PATCH v2 11/14 target-arm: Add FAR_EL2 and 3

In reply to Eric Blake

From: "Edgar E. Iglesias" <[email protected]>

Message-id: [email protected]

---
 target-arm/cpu.h    | 2 +-
 target-arm/helper.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
target-arm/cpu.h +1 -1
index 3d9cf57..79205ba 100644
@@ -187,7 +187,7 @@ typedef struct CPUARMState {
         uint32_t ifsr_el2; /* Fault status registers.  */
         uint64_t esr_el[4];
         uint32_t c6_region[8]; /* MPU base/size registers.  */
-        uint64_t far_el[2]; /* Fault address registers.  */
+        uint64_t far_el[4]; /* Fault address registers.  */
         uint64_t par_el1;  /* Translation result. */
         uint32_t c9_insn; /* Cache lockdown registers.  */
         uint32_t c9_data;
target-arm/helper.c +6 -0
index f4845b0..a7f82f3 100644
@@ -2131,6 +2131,9 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = {
       .type = ARM_CP_NO_MIGRATE,
       .opc0 = 3, .opc1 = 4, .crn = 5, .crm = 2, .opc2 = 0,
       .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[2]) },
+    { .name = "FAR_EL2", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 4, .crn = 6, .crm = 0, .opc2 = 0,
+      .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[2]) },
     { .name = "SPSR_EL2", .state = ARM_CP_STATE_AA64,
       .type = ARM_CP_NO_MIGRATE,
       .opc0 = 3, .opc1 = 4, .crn = 4, .crm = 0, .opc2 = 0,
@@ -2153,6 +2156,9 @@ static const ARMCPRegInfo v8_el3_cp_reginfo[] = {
       .type = ARM_CP_NO_MIGRATE,
       .opc0 = 3, .opc1 = 6, .crn = 5, .crm = 2, .opc2 = 0,
       .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[3]) },
+    { .name = "FAR_EL3", .state = ARM_CP_STATE_AA64,
+      .opc0 = 3, .opc1 = 6, .crn = 6, .crm = 0, .opc2 = 0,
+      .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[3]) },
     { .name = "SPSR_EL3", .state = ARM_CP_STATE_AA64,
       .type = ARM_CP_NO_MIGRATE,
       .opc0 = 3, .opc1 = 6, .crn = 4, .crm = 0, .opc2 = 0,
Signature · 1 line
1.9.3
#14 lore raw

Re: [Qemu-devel] [PATCH v2 11/14] target-arm: Add FAR_EL2 and 3

Quoted 7 lines · Eric Blake

From: "Edgar E. Iglesias" <[email protected]>

Message-id: [email protected]

Hi Eric; why are you retransmitting these target-arm patches? They don't seem to match up with your cover letter...

thanks
-- PMM

author
#15 lore raw

Re: [Qemu-devel] [PATCH v2 11/14] target-arm: Add FAR_EL2 and 3

Quoted 11 lines · Peter Maydell
Quoted 7 lines · Eric Blake

From: "Edgar E. Iglesias" <[email protected]>

Message-id: [email protected]

Hi Eric; why are you retransmitting these target-arm patches? They don't seem to match up with your cover letter...

Shoot, 'git send-email' misbehaved on me after the first try died mid-send. Looks like 11-14 is bogus. I'll resend the correct series shortly :(

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#16 lore raw

PATCH v2 12/14 target-arm: Fix bit test in sp_el0_access

In reply to Eric Blake

From: Stefan Weil <[email protected]>

Static code analyzers complain about a dubious & operation used for a boolean value. The code does not test the PSTATE_SP bit as it should.

Message-id: [email protected]

---
 target-arm/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-arm/helper.c +1 -1
index a7f82f3..d709285 100644
@@ -1853,7 +1853,7 @@ static uint64_t aa64_dczid_read(CPUARMState *env, const ARMCPRegInfo *ri)
 
 static CPAccessResult sp_el0_access(CPUARMState *env, const ARMCPRegInfo *ri)
 {
-    if (!env->pstate & PSTATE_SP) {
+    if (!(env->pstate & PSTATE_SP)) {
         /* Access to SP_EL0 is undefined if it's being used as
          * the stack pointer.
          */
Signature · 1 line
1.9.3
author
#17 lore raw

PATCH v2 13/14 target-arm: don't hardcode mask values in arm_cpu_handle_mmu_fault

In reply to Eric Blake

From: Alex Bennée <[email protected]>

Otherwise we break quickly when we change TARGET_PAGE_SIZE.

Message-id: [email protected]

---
 target-arm/helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target-arm/helper.c +2 -2
index d709285..35c11e7 100644
@@ -4156,8 +4156,8 @@ int arm_cpu_handle_mmu_fault(CPUState *cs, vaddr address,
                         &page_size);
     if (ret == 0) {
         /* Map a single [sub]page.  */
-        phys_addr &= ~(hwaddr)0x3ff;
-        address &= ~(target_ulong)0x3ff;
+        phys_addr &= TARGET_PAGE_MASK;
+        address &= TARGET_PAGE_MASK;
         tlb_set_page(cs, address, phys_addr, prot, mmu_idx, page_size);
         return 0;
     }
Signature · 1 line
1.9.3
author
#18 lore raw

PATCH v2 14/14 target-arm: A64: fix TLB flush instructions

In reply to Eric Blake

From: Alex Bennée <[email protected]>

According to the ARM ARM we weren't correctly flushing the TLB entries where bits 63:56 didn't match bit 55 of the virtual address. This exposed a problem when we switched QEMU's internal TARGET_PAGE_BITS to 12 for aarch64.

Message-id: [email protected]

---
 target-arm/helper.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
target-arm/helper.c +8 -2
index 35c11e7..f630d96 100644
@@ -1801,12 +1801,17 @@ static CPAccessResult aa64_cacheop_access(CPUARMState *env,
     return CP_ACCESS_OK;
 }
 
+/* See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
+ * Page D4-1736 (DDI0487A.b)
+ */
+
 static void tlbi_aa64_va_write(CPUARMState *env, const ARMCPRegInfo *ri,
                                uint64_t value)
 {
     /* Invalidate by VA (AArch64 version) */
     ARMCPU *cpu = arm_env_get_cpu(env);
-    uint64_t pageaddr = value << 12;
+    uint64_t pageaddr = sextract64(value << 12, 0, 56);
+
     tlb_flush_page(CPU(cpu), pageaddr);
 }
 
@@ -1815,7 +1820,8 @@ static void tlbi_aa64_vaa_write(CPUARMState *env, const ARMCPRegInfo *ri,
 {
     /* Invalidate by VA, all ASIDs (AArch64 version) */
     ARMCPU *cpu = arm_env_get_cpu(env);
-    uint64_t pageaddr = value << 12;
+    uint64_t pageaddr = sextract64(value << 12, 0, 56);
+
     tlb_flush_page(CPU(cpu), pageaddr);
 }
 
Signature · 1 line
1.9.3
author
#19 lore raw
In reply to Eric Blake
Quoted 14 lines · Eric Blake

According to this email:
https://lists.gnu.org/archive/html/qemu-devel/2014-05/msg00708.html
we want to repurpose 'data': { 'name': {dict...} } in qapi files for future use of designating default values of optional parameters. But to do that, we must first nuke existing use of that syntax for declaring nested structs. Enhancing the testsuite while at it never hurts.

v2:
New patches: 1-2, 5-9
consistent TAB usage in Makefile [Fam]
catch more bad coding constructs, and test them
avoid code duplication in type validity checks (patch 14 [former 7] is simpler because of patch 9)

Quoted 15 lines

Eric Blake (14):
qapi: consistent whitespace in tests/Makefile
qapi: ignore files created during make check
qapi: add some enum tests
qapi: better error message for bad enum
qapi: add some expr tests
qapi: require valid expressions
qapi: add some type check tests
qapi: add expr_name() helper
qapi: add check_type helper function
qapi: merge UserDefTwo and UserDefNested in tests
qapi: drop tests for inline subtypes
qapi: drop inline subtype in query-version
qapi: drop inline subtype in query-pci
qapi: drop support for inline subtypes

Blah; I messed up the attempt to resume after a failed git send-email. Better to just send a v3 than risk confusion with two different patches at v2 for 11-14.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org