: Improve QMP visitor unit-tests
v2 cover : Improve QMP visitor unit-tests
This series introduces two new test programs: test-qmp-output-visitor and test-qmp-input-visitor.
As their names suggest, they contain unit-tests to check QMP's Visitor implementation. They supersede the test-visitor program (which is dropped by this series).
Besides adding new unit-tests, I've _tried_ to follow these principles:
- The tests don't print test result data to be manually checked by humans. Instead, all results are checked with g_assert()s and printed results are only OK or FAILED
- Each test-case checks a single functionality
- A test-case is only allowed to use a QAPI functionality after it has been tested
- setup and teardown functions are used as much as possible to avoid duplication
PS: The first patch is a fix unrelated to the QAPI.
changelog
---------
v2
o Rebase against Makefile changes in master
o Typo fix in patch 1/4
Makefile | 9 +- configure | 5 +- qapi-schema-test.json | 6 + test-qmp-input-visitor.c | 270 +++++++++++++++++++++++++++++ test-qmp-output-visitor.c | 423 +++++++++++++++++++++++++++++++++++++++++++++ test-visitor.c | 338 ------------------------------------ 6 files changed, 708 insertions(+), 343 deletions(-)
PATCH v2 1/4 configure: Don't mix glib and libcheck tests
test-coroutine is listed as a libcheck test in the 'checks' variable. This is not right because 'make check' won't run test-coroutine if libcheck tests are not enabled (either because libcheck isn't detected or because --disable-check-utests is passed).
Tests using the glib test framework are independent from libcheck and afaik are always present (although having a configure switch to disable them is probably worth it).
Untangle test-coroutine from the libcheck tests by introducing the 'test_progs' variable and using it to generate the test list used by 'make check'.
--- configure | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
configure +3 -2
@@ -2742,8 +2742,9 @@ if test "$softmmu" = yes ; then fi if [ "$check_utests" = "yes" ]; then checks="check-qint check-qstring check-qdict check-qlist" - checks="check-qfloat check-qjson test-coroutine $checks" + checks="check-qfloat check-qjson $checks" fi + test_progs="$checks test-coroutine" fi fi
@@ -3232,7 +3233,7 @@ if test "$trace_default" = "yes"; then fi echo "TOOLS=$tools" >> $config_host_mak -echo "CHECKS=$checks" >> $config_host_mak +echo "CHECKS=$test_progs" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak echo "INSTALL=$install" >> $config_host_mak
Signature · 1 line
1.7.8.dirty
PATCH v2 2/4 Introduce test-qmp-output-visitor
In reply to Luiz CapitulinoContains unit-tests for the QMP output visitor implementation.
--- Makefile | 5 +- configure | 2 +- qapi-schema-test.json | 6 + test-qmp-output-visitor.c | 423 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 434 insertions(+), 2 deletions(-) create mode 100644 test-qmp-output-visitor.c
Makefile +4 -1
@@ -169,7 +169,7 @@ test-coroutine: test-coroutine.o qemu-timer-common.o async.o $(coroutine-obj-y) $(qapi-obj-y): $(GENERATED_HEADERS) qapi-dir := $(BUILD_DIR)/qapi-generated -test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) +test-qmp-output-visitor.o test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) $(qapi-dir)/test-qapi-types.c $(qapi-dir)/test-qapi-types.h :\
@@ -205,6 +205,9 @@ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) test-visitor: test-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o +test-qmp-output-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) +test-qmp-output-visitor: test-qmp-output-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o + test-qmp-commands.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h test-qmp-marshal.c test-qmp-commands.h) $(qapi-obj-y) test-qmp-commands: test-qmp-commands.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o $(qapi-dir)/test-qmp-marshal.o module.o
configure +1 -1
@@ -2744,7 +2744,7 @@ if test "$softmmu" = yes ; then checks="check-qint check-qstring check-qdict check-qlist" checks="check-qfloat check-qjson $checks" fi - test_progs="$checks test-coroutine" + test_progs="$checks test-coroutine test-qmp-output-visitor" fi fi
qapi-schema-test.json +6 -0
@@ -16,6 +16,12 @@ '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' } } } } + # testing commands { 'command': 'user_def_cmd', 'data': {} } { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
test-qmp-output-visitor.c new file +423 -0
423 lines not on this page · raw message
Signature · 1 line
1.7.8.dirty
PATCH v2 3/4 Introduce test-qmp-input-visitor
In reply to Luiz CapitulinoContains unit-tests for the QMP input visitor implementation.
--- Makefile | 5 +- configure | 2 +- test-qmp-input-visitor.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+), 2 deletions(-) create mode 100644 test-qmp-input-visitor.c
Makefile +4 -1
@@ -169,7 +169,7 @@ test-coroutine: test-coroutine.o qemu-timer-common.o async.o $(coroutine-obj-y) $(qapi-obj-y): $(GENERATED_HEADERS) qapi-dir := $(BUILD_DIR)/qapi-generated -test-qmp-output-visitor.o test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) +test-qmp-input-visitor.o test-qmp-output-visitor.o test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) $(qapi-dir)/test-qapi-types.c $(qapi-dir)/test-qapi-types.h :\
@@ -208,6 +208,9 @@ test-visitor: test-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qap test-qmp-output-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) test-qmp-output-visitor: test-qmp-output-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o +test-qmp-input-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) +test-qmp-input-visitor: test-qmp-input-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o + test-qmp-commands.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h test-qmp-marshal.c test-qmp-commands.h) $(qapi-obj-y) test-qmp-commands: test-qmp-commands.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o $(qapi-dir)/test-qmp-marshal.o module.o
configure +1 -1
@@ -2744,7 +2744,7 @@ if test "$softmmu" = yes ; then checks="check-qint check-qstring check-qdict check-qlist" checks="check-qfloat check-qjson $checks" fi - test_progs="$checks test-coroutine test-qmp-output-visitor" + test_progs="$checks test-coroutine test-qmp-output-visitor test-qmp-input-visitor" fi fi
test-qmp-input-visitor.c new file +270 -0
270 lines not on this page · raw message
Signature · 1 line
1.7.8.dirty
PATCH v2 4/4 Drop test-visitor
In reply to Luiz CapitulinoIt has been superseded by the two previous commits, which introduced the test-qmp-output-visitor and test-qmp-input-visitor tests.
--- Makefile | 5 +- test-visitor.c | 338 -------------------------------------------------------- 2 files changed, 1 insertions(+), 342 deletions(-) delete mode 100644 test-visitor.c
Makefile +1 -4
@@ -169,7 +169,7 @@ test-coroutine: test-coroutine.o qemu-timer-common.o async.o $(coroutine-obj-y) $(qapi-obj-y): $(GENERATED_HEADERS) qapi-dir := $(BUILD_DIR)/qapi-generated -test-qmp-input-visitor.o test-qmp-output-visitor.o test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) +test-qmp-input-visitor.o test-qmp-output-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) $(qapi-dir)/test-qapi-types.c $(qapi-dir)/test-qapi-types.h :\
@@ -202,9 +202,6 @@ qmp-commands.h qmp-marshal.c :\ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, " GEN $@") -test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) -test-visitor: test-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o - test-qmp-output-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) test-qmp-output-visitor: test-qmp-output-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o
test-visitor.c deleted +0 -338
338 lines not on this page · raw message
Signature · 1 line
1.7.8.dirty