Explorar o código

qapi: Add some enum tests

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 <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Eric Blake %!s(int64=10) %!d(string=hai) anos
pai
achega
ad11dbb937
Modificáronse 37 ficheiros con 66 adicións e 1 borrados
  1. 5 1
      tests/Makefile
  2. 0 0
      tests/qapi-schema/enum-bad-name.err
  3. 1 0
      tests/qapi-schema/enum-bad-name.exit
  4. 2 0
      tests/qapi-schema/enum-bad-name.json
  5. 3 0
      tests/qapi-schema/enum-bad-name.out
  6. 0 0
      tests/qapi-schema/enum-clash-member.err
  7. 1 0
      tests/qapi-schema/enum-clash-member.exit
  8. 2 0
      tests/qapi-schema/enum-clash-member.json
  9. 3 0
      tests/qapi-schema/enum-clash-member.out
  10. 0 0
      tests/qapi-schema/enum-dict-member.err
  11. 1 0
      tests/qapi-schema/enum-dict-member.exit
  12. 2 0
      tests/qapi-schema/enum-dict-member.json
  13. 3 0
      tests/qapi-schema/enum-dict-member.out
  14. 0 0
      tests/qapi-schema/enum-empty.err
  15. 1 0
      tests/qapi-schema/enum-empty.exit
  16. 2 0
      tests/qapi-schema/enum-empty.json
  17. 3 0
      tests/qapi-schema/enum-empty.out
  18. 1 0
      tests/qapi-schema/enum-int-member.err
  19. 1 0
      tests/qapi-schema/enum-int-member.exit
  20. 3 0
      tests/qapi-schema/enum-int-member.json
  21. 0 0
      tests/qapi-schema/enum-int-member.out
  22. 0 0
      tests/qapi-schema/enum-max-member.err
  23. 1 0
      tests/qapi-schema/enum-max-member.exit
  24. 3 0
      tests/qapi-schema/enum-max-member.json
  25. 3 0
      tests/qapi-schema/enum-max-member.out
  26. 6 0
      tests/qapi-schema/enum-missing-data.err
  27. 1 0
      tests/qapi-schema/enum-missing-data.exit
  28. 2 0
      tests/qapi-schema/enum-missing-data.json
  29. 0 0
      tests/qapi-schema/enum-missing-data.out
  30. 0 0
      tests/qapi-schema/enum-union-clash.err
  31. 1 0
      tests/qapi-schema/enum-union-clash.exit
  32. 4 0
      tests/qapi-schema/enum-union-clash.json
  33. 5 0
      tests/qapi-schema/enum-union-clash.out
  34. 0 0
      tests/qapi-schema/enum-wrong-data.err
  35. 1 0
      tests/qapi-schema/enum-wrong-data.exit
  36. 2 0
      tests/qapi-schema/enum-wrong-data.json
  37. 3 0
      tests/qapi-schema/enum-wrong-data.out

+ 5 - 1
tests/Makefile

@@ -207,7 +207,11 @@ $(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 enum-union-clash.json \
+	enum-bad-name.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 \

+ 0 - 0
tests/qapi-schema/enum-bad-name.err


+ 1 - 0
tests/qapi-schema/enum-bad-name.exit

@@ -0,0 +1 @@
+0

+ 2 - 0
tests/qapi-schema/enum-bad-name.json

@@ -0,0 +1,2 @@
+# FIXME: we should ensure all enum names can map to C
+{ 'enum': 'MyEnum', 'data': [ 'not^possible' ] }

+ 3 - 0
tests/qapi-schema/enum-bad-name.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'MyEnum'), ('data', ['not^possible'])])]
+[{'enum_name': 'MyEnum', 'enum_values': ['not^possible']}]
+[]

+ 0 - 0
tests/qapi-schema/enum-clash-member.err


+ 1 - 0
tests/qapi-schema/enum-clash-member.exit

@@ -0,0 +1 @@
+0

+ 2 - 0
tests/qapi-schema/enum-clash-member.json

@@ -0,0 +1,2 @@
+# FIXME: we should reject enums where members will clash when mapped to C enum
+{ 'enum': 'MyEnum', 'data': [ 'one', 'ONE' ] }

+ 3 - 0
tests/qapi-schema/enum-clash-member.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'MyEnum'), ('data', ['one', 'ONE'])])]
+[{'enum_name': 'MyEnum', 'enum_values': ['one', 'ONE']}]
+[]

+ 0 - 0
tests/qapi-schema/enum-dict-member.err


+ 1 - 0
tests/qapi-schema/enum-dict-member.exit

@@ -0,0 +1 @@
+0

+ 2 - 0
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' } ] }

+ 3 - 0
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')])]}]
+[]

+ 0 - 0
tests/qapi-schema/enum-empty.err


+ 1 - 0
tests/qapi-schema/enum-empty.exit

@@ -0,0 +1 @@
+0

+ 2 - 0
tests/qapi-schema/enum-empty.json

@@ -0,0 +1,2 @@
+# An empty enum, although unusual, is currently acceptable
+{ 'enum': 'MyEnum', 'data': [ ] }

+ 3 - 0
tests/qapi-schema/enum-empty.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'MyEnum'), ('data', [])])]
+[{'enum_name': 'MyEnum', 'enum_values': []}]
+[]

+ 1 - 0
tests/qapi-schema/enum-int-member.err

@@ -0,0 +1 @@
+tests/qapi-schema/enum-int-member.json:3:31: Stray "1"

+ 1 - 0
tests/qapi-schema/enum-int-member.exit

@@ -0,0 +1 @@
+1

+ 3 - 0
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 ] }

+ 0 - 0
tests/qapi-schema/enum-int-member.out


+ 0 - 0
tests/qapi-schema/enum-max-member.err


+ 1 - 0
tests/qapi-schema/enum-max-member.exit

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/qapi-schema/enum-max-member.json

@@ -0,0 +1,3 @@
+# FIXME: we should reject user-supplied 'max' for clashing with implicit enum end
+# TODO: should we instead munge the implicit value to avoid the clash?
+{ 'enum': 'MyEnum', 'data': [ 'max' ] }

+ 3 - 0
tests/qapi-schema/enum-max-member.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'MyEnum'), ('data', ['max'])])]
+[{'enum_name': 'MyEnum', 'enum_values': ['max']}]
+[]

+ 6 - 0
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 <module>
+    exprs = parse_schema(sys.argv[1])
+  File "scripts/qapi.py", line 334, in parse_schema
+    add_enum(expr['enum'], expr['data'])
+KeyError: 'data'

+ 1 - 0
tests/qapi-schema/enum-missing-data.exit

@@ -0,0 +1 @@
+1

+ 2 - 0
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' }

+ 0 - 0
tests/qapi-schema/enum-missing-data.out


+ 0 - 0
tests/qapi-schema/enum-union-clash.err


+ 1 - 0
tests/qapi-schema/enum-union-clash.exit

@@ -0,0 +1 @@
+0

+ 4 - 0
tests/qapi-schema/enum-union-clash.json

@@ -0,0 +1,4 @@
+# FIXME: we should reject types that would conflict with implicit union enum
+{ 'enum': 'UnionKind', 'data': [ 'oops' ] }
+{ 'union': 'Union',
+  'data': { 'a': 'int' } }

+ 5 - 0
tests/qapi-schema/enum-union-clash.out

@@ -0,0 +1,5 @@
+[OrderedDict([('enum', 'UnionKind'), ('data', ['oops'])]),
+ OrderedDict([('union', 'Union'), ('data', OrderedDict([('a', 'int')]))])]
+[{'enum_name': 'UnionKind', 'enum_values': ['oops']},
+ {'enum_name': 'UnionKind', 'enum_values': None}]
+[]

+ 0 - 0
tests/qapi-schema/enum-wrong-data.err


+ 1 - 0
tests/qapi-schema/enum-wrong-data.exit

@@ -0,0 +1 @@
+0

+ 2 - 0
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' } }

+ 3 - 0
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')])}]
+[]