Browse Source

tests: QAPI schema parser tests

The parser handles erroneous input badly.  To be improved shortly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1374939721-7876-2-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Markus Armbruster 12 years ago
parent
commit
98626572f1
59 changed files with 121 additions and 3 deletions
  1. 1 1
      configure
  2. 22 2
      tests/Makefile
  3. 0 0
      tests/qapi-schema/comments.err
  4. 1 0
      tests/qapi-schema/comments.exit
  5. 4 0
      tests/qapi-schema/comments.json
  6. 3 0
      tests/qapi-schema/comments.out
  7. 0 0
      tests/qapi-schema/empty.err
  8. 1 0
      tests/qapi-schema/empty.exit
  9. 0 0
      tests/qapi-schema/empty.json
  10. 3 0
      tests/qapi-schema/empty.out
  11. 0 0
      tests/qapi-schema/funny-char.err
  12. 1 0
      tests/qapi-schema/funny-char.exit
  13. 2 0
      tests/qapi-schema/funny-char.json
  14. 3 0
      tests/qapi-schema/funny-char.out
  15. 0 0
      tests/qapi-schema/indented-expr.err
  16. 1 0
      tests/qapi-schema/indented-expr.exit
  17. 2 0
      tests/qapi-schema/indented-expr.json
  18. 3 0
      tests/qapi-schema/indented-expr.out
  19. 0 0
      tests/qapi-schema/missing-colon.err
  20. 1 0
      tests/qapi-schema/missing-colon.exit
  21. 2 0
      tests/qapi-schema/missing-colon.json
  22. 3 0
      tests/qapi-schema/missing-colon.out
  23. 0 0
      tests/qapi-schema/missing-comma-list.err
  24. 1 0
      tests/qapi-schema/missing-comma-list.exit
  25. 2 0
      tests/qapi-schema/missing-comma-list.json
  26. 3 0
      tests/qapi-schema/missing-comma-list.out
  27. 0 0
      tests/qapi-schema/missing-comma-object.err
  28. 1 0
      tests/qapi-schema/missing-comma-object.exit
  29. 2 0
      tests/qapi-schema/missing-comma-object.json
  30. 3 0
      tests/qapi-schema/missing-comma-object.out
  31. 1 0
      tests/qapi-schema/non-objects.err
  32. 1 0
      tests/qapi-schema/non-objects.exit
  33. 2 0
      tests/qapi-schema/non-objects.json
  34. 0 0
      tests/qapi-schema/non-objects.out
  35. 0 0
      tests/qapi-schema/quoted-structural-chars.err
  36. 1 0
      tests/qapi-schema/quoted-structural-chars.exit
  37. 1 0
      tests/qapi-schema/quoted-structural-chars.json
  38. 3 0
      tests/qapi-schema/quoted-structural-chars.out
  39. 25 0
      tests/qapi-schema/test-qapi.py
  40. 0 0
      tests/qapi-schema/trailing-comma-list.err
  41. 1 0
      tests/qapi-schema/trailing-comma-list.exit
  42. 2 0
      tests/qapi-schema/trailing-comma-list.json
  43. 3 0
      tests/qapi-schema/trailing-comma-list.out
  44. 0 0
      tests/qapi-schema/trailing-comma-object.err
  45. 1 0
      tests/qapi-schema/trailing-comma-object.exit
  46. 2 0
      tests/qapi-schema/trailing-comma-object.json
  47. 3 0
      tests/qapi-schema/trailing-comma-object.out
  48. 1 0
      tests/qapi-schema/unclosed-list.err
  49. 1 0
      tests/qapi-schema/unclosed-list.exit
  50. 1 0
      tests/qapi-schema/unclosed-list.json
  51. 0 0
      tests/qapi-schema/unclosed-list.out
  52. 1 0
      tests/qapi-schema/unclosed-object.err
  53. 1 0
      tests/qapi-schema/unclosed-object.exit
  54. 1 0
      tests/qapi-schema/unclosed-object.json
  55. 0 0
      tests/qapi-schema/unclosed-object.out
  56. 1 0
      tests/qapi-schema/unclosed-string.err
  57. 1 0
      tests/qapi-schema/unclosed-string.exit
  58. 2 0
      tests/qapi-schema/unclosed-string.json
  59. 0 0
      tests/qapi-schema/unclosed-string.out

+ 1 - 1
configure

@@ -4502,7 +4502,7 @@ if [ "$dtc_internal" = "yes" ]; then
 fi
 
 # build tree in object directory in case the source is not in the current directory
-DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos"
+DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema"
 DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw"
 DIRS="$DIRS roms/seabios roms/vgabios"
 DIRS="$DIRS qapi-generated"

+ 22 - 2
tests/Makefile

@@ -83,6 +83,14 @@ gcov-files-arm-y += hw/tmp105.c
 check-qtest-ppc-y += tests/boot-order-test$(EXESUF)
 check-qtest-ppc64-y += tests/boot-order-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 \
+        quoted-structural-chars.json \
+        trailing-comma-list.json trailing-comma-object.json \
+        unclosed-list.json unclosed-object.json unclosed-string.json)
+
 GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
 
 test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
@@ -171,6 +179,7 @@ check-help:
 	@echo " make check-qtest-TARGET   Run qtest tests for given target"
 	@echo " make check-qtest          Run qtest tests"
 	@echo " make check-unit           Run qobject tests"
+	@echo " make check-qapi-schema    Run QAPI schema tests"
 	@echo " make check-block          Run block tests"
 	@echo " make check-report.html    Generates an HTML test report"
 	@echo
@@ -233,13 +242,24 @@ check-report.html: check-report.xml
 check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF) qemu-io$(EXESUF)
 	$<
 
+.PHONY: check-tests/test-qapi.py
+check-tests/test-qapi.py: tests/test-qapi.py
+
+.PHONY: $(patsubst %, check-%, $(check-qapi-schema-y))
+$(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json
+	$(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts $(PYTHON) $(SRC_PATH)/tests/qapi-schema/test-qapi.py <$^ >$*.out 2>$*.err; echo $$? >$*.exit, "  TEST  $*.out")
+	@diff -q $(SRC_PATH)/$*.out $*.out
+	@diff -q $(SRC_PATH)/$*.err $*.err
+	@diff -q $(SRC_PATH)/$*.exit $*.exit
+
 # Consolidated targets
 
-.PHONY: check-qtest check-unit check
+.PHONY: check-qapi-schema check-qtest check-unit check
+check-qapi-schema: $(patsubst %,check-%, $(check-qapi-schema-y))
 check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS))
 check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
-check: check-unit check-qtest
+check: check-qapi-schema check-unit check-qtest
 
 -include $(wildcard tests/*.d)
 -include $(wildcard tests/libqos/*.d)

+ 0 - 0
tests/qapi-schema/comments.err


+ 1 - 0
tests/qapi-schema/comments.exit

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

+ 4 - 0
tests/qapi-schema/comments.json

@@ -0,0 +1,4 @@
+# Unindented comment
+{ 'enum': 'Status',             # Comment to the right of code
+  # Indented comment
+  'data': [ 'good', 'bad', 'ugly' ] }

+ 3 - 0
tests/qapi-schema/comments.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
+['Status']
+[]

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


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

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

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


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

@@ -0,0 +1,3 @@
+[]
+[]
+[]

+ 0 - 0
tests/qapi-schema/funny-char.err


+ 1 - 0
tests/qapi-schema/funny-char.exit

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

+ 2 - 0
tests/qapi-schema/funny-char.json

@@ -0,0 +1,2 @@
+{ 'enum': 'Status',
+  'data': [ 'good', 'bad', 'ugly' ]; }

+ 3 - 0
tests/qapi-schema/funny-char.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
+['Status']
+[]

+ 0 - 0
tests/qapi-schema/indented-expr.err


+ 1 - 0
tests/qapi-schema/indented-expr.exit

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

+ 2 - 0
tests/qapi-schema/indented-expr.json

@@ -0,0 +1,2 @@
+{ 'id' : 'eins' }
+ { 'id' : 'zwei' }

+ 3 - 0
tests/qapi-schema/indented-expr.out

@@ -0,0 +1,3 @@
+[OrderedDict([('id', 'eins')])]
+[]
+[]

+ 0 - 0
tests/qapi-schema/missing-colon.err


+ 1 - 0
tests/qapi-schema/missing-colon.exit

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

+ 2 - 0
tests/qapi-schema/missing-colon.json

@@ -0,0 +1,2 @@
+{ 'enum' 'Status',
+  'data': [ 'good', 'bad', 'ugly' ] }

+ 3 - 0
tests/qapi-schema/missing-colon.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', ','), ('data', ['good', 'bad', 'ugly'])])]
+[',']
+[]

+ 0 - 0
tests/qapi-schema/missing-comma-list.err


+ 1 - 0
tests/qapi-schema/missing-comma-list.exit

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

+ 2 - 0
tests/qapi-schema/missing-comma-list.json

@@ -0,0 +1,2 @@
+{ 'enum': 'Status',
+  'data': [ 'good' 'bad', 'ugly' ] }

+ 3 - 0
tests/qapi-schema/missing-comma-list.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
+['Status']
+[]

+ 0 - 0
tests/qapi-schema/missing-comma-object.err


+ 1 - 0
tests/qapi-schema/missing-comma-object.exit

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

+ 2 - 0
tests/qapi-schema/missing-comma-object.json

@@ -0,0 +1,2 @@
+{ 'enum': 'Status'
+  'data': [ 'good', 'bad', 'ugly' ] }

+ 3 - 0
tests/qapi-schema/missing-comma-object.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
+['Status']
+[]

+ 1 - 0
tests/qapi-schema/non-objects.err

@@ -0,0 +1 @@
+Crashed: <type 'exceptions.AttributeError'>

+ 1 - 0
tests/qapi-schema/non-objects.exit

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

+ 2 - 0
tests/qapi-schema/non-objects.json

@@ -0,0 +1,2 @@
+'string'
+[ ]

+ 0 - 0
tests/qapi-schema/non-objects.out


+ 0 - 0
tests/qapi-schema/quoted-structural-chars.err


+ 1 - 0
tests/qapi-schema/quoted-structural-chars.exit

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

+ 1 - 0
tests/qapi-schema/quoted-structural-chars.json

@@ -0,0 +1 @@
+'{' 'key1' ':' 'value1' ',' 'key2' ':' '[' ']' '}'

+ 3 - 0
tests/qapi-schema/quoted-structural-chars.out

@@ -0,0 +1,3 @@
+[OrderedDict([('key1', 'value1'), ('key2', [])])]
+[]
+[]

+ 25 - 0
tests/qapi-schema/test-qapi.py

@@ -0,0 +1,25 @@
+#
+# QAPI parser test harness
+#
+# Copyright (c) 2013 Red Hat Inc.
+#
+# Authors:
+#  Markus Armbruster <armbru@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+
+from qapi import *
+from pprint import pprint
+import sys
+
+try:
+    exprs = parse_schema(sys.stdin)
+except:
+    print >>sys.stderr, "Crashed:", sys.exc_info()[0]
+    exit(1)
+
+pprint(exprs)
+pprint(enum_types)
+pprint(struct_types)

+ 0 - 0
tests/qapi-schema/trailing-comma-list.err


+ 1 - 0
tests/qapi-schema/trailing-comma-list.exit

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

+ 2 - 0
tests/qapi-schema/trailing-comma-list.json

@@ -0,0 +1,2 @@
+{ 'enum': 'Status',
+  'data': [ 'good', 'bad', 'ugly', ] }

+ 3 - 0
tests/qapi-schema/trailing-comma-list.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
+['Status']
+[]

+ 0 - 0
tests/qapi-schema/trailing-comma-object.err


+ 1 - 0
tests/qapi-schema/trailing-comma-object.exit

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

+ 2 - 0
tests/qapi-schema/trailing-comma-object.json

@@ -0,0 +1,2 @@
+{ 'enum': 'Status',
+  'data': [ 'good', 'bad', 'ugly' ], }

+ 3 - 0
tests/qapi-schema/trailing-comma-object.out

@@ -0,0 +1,3 @@
+[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
+['Status']
+[]

+ 1 - 0
tests/qapi-schema/unclosed-list.err

@@ -0,0 +1 @@
+Crashed: <type 'exceptions.IndexError'>

+ 1 - 0
tests/qapi-schema/unclosed-list.exit

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

+ 1 - 0
tests/qapi-schema/unclosed-list.json

@@ -0,0 +1 @@
+{ 'key': [ 'value' }

+ 0 - 0
tests/qapi-schema/unclosed-list.out


+ 1 - 0
tests/qapi-schema/unclosed-object.err

@@ -0,0 +1 @@
+Crashed: <type 'exceptions.IndexError'>

+ 1 - 0
tests/qapi-schema/unclosed-object.exit

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

+ 1 - 0
tests/qapi-schema/unclosed-object.json

@@ -0,0 +1 @@
+{ 'key': [ 'value' ]

+ 0 - 0
tests/qapi-schema/unclosed-object.out


+ 1 - 0
tests/qapi-schema/unclosed-string.err

@@ -0,0 +1 @@
+Crashed: <type 'exceptions.Exception'>

+ 1 - 0
tests/qapi-schema/unclosed-string.exit

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

+ 2 - 0
tests/qapi-schema/unclosed-string.json

@@ -0,0 +1,2 @@
+{ 'text': 'lorem ips
+}

+ 0 - 0
tests/qapi-schema/unclosed-string.out