Skip to contentSkip to conversation

: Improve QMP visitor unit-tests

PATCH Superseded Luiz Capitulino 3 participants 8 messages Nov 21, 2011 – Nov 22, 2011 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

An important to do item I plan to work next is to measure test coverage.

PS: The first patch is a fix unrelated to the QAPI.

 Makefile                  |   11 +-
 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, 710 insertions(+), 343 deletions(-)
#1 lore raw

PATCH 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).

Untagle 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
index 6c77fbb..ac0fbd9 100755
@@ -2685,8 +2685,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
 
@@ -3175,7 +3176,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.rc3.17.gf56ef1.dirty
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] configure: Don't mix glib and libcheck tests

Am 21.11.2011 18:09, schrieb Luiz Capitulino:

Quoted 10 lines

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).

Untagle test-coroutine from the libcheck tests by introducing the

Untangle

Quoted 4 lines

'test_progs' variable and using it to generate the test list used by 'make check'.

Andreas

Quoted 28 lines
---
 configure |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
configure +3 -2
index 6c77fbb..ac0fbd9 100755
@@ -2685,8 +2685,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
 
@@ -3175,7 +3176,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 · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] configure: Don't mix glib and libcheck tests

Quoted 6 lines · On Mon, 21 Nov 2011 19:08:41 +0100 Andreas Färber <[email protected]> wrote:

Am 21.11.2011 18:09, schrieb Luiz Capitulino:

Quoted 5 lines

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).

Quoted 7 lines
Quoted 5 lines

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).

Untagle test-coroutine from the libcheck tests by introducing the

Untangle

Fixed, thanks. This series is going to need a respin anyway.

Quoted 40 lines
Quoted 5 lines

'test_progs' variable and using it to generate the test list used by 'make check'.

Andreas

Quoted 28 lines
---
 configure |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
configure +3 -2
index 6c77fbb..ac0fbd9 100755
@@ -2685,8 +2685,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
 
@@ -3175,7 +3176,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
#4 lore raw

Re: [Qemu-devel] [PATCH 1/4] configure: Don't mix glib and libcheck tests

In reply to Luiz Capitulino
Quoted 9 lines · Luiz Capitulino

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).

Quoted 5 lines

Untagle test-coroutine from the libcheck tests by introducing the 'test_progs' variable and using it to generate the test list used by 'make check'.

This should be ok for 1.0 too.

Paolo

#5 lore raw

PATCH 2/4 Introduce test-qmp-output-visitor

In reply to Luiz Capitulino

Contains unit-tests for the QMP output visitor implementation.

---
 Makefile                  |    4 +
 configure                 |    2 +-
 qapi-schema-test.json     |    6 +
 test-qmp-output-visitor.c |  423 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 434 insertions(+), 1 deletions(-)
 create mode 100644 test-qmp-output-visitor.c
Makefile +4 -0
index 168093c..9013dc1 100644
@@ -169,6 +169,7 @@ test-coroutine: test-coroutine.o qemu-timer-common.o async.o $(coroutine-obj-y)
 $(qapi-obj-y): $(GENERATED_HEADERS)
 qapi-dir := qapi-generated
 test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
+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
@@ -204,6 +205,9 @@ qmp-marshal.c: $(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
index ac0fbd9..037fa12 100755
@@ -2687,7 +2687,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
index 3acedad..2b38919 100644
@@ -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.rc3.17.gf56ef1.dirty
#6 lore raw

PATCH 3/4 Introduce test-qmp-input-visitor

In reply to Luiz Capitulino

Contains unit-tests for the QMP input visitor implementation.

---
 Makefile                 |    4 +
 configure                |    2 +-
 test-qmp-input-visitor.c |  270 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+), 1 deletions(-)
 create mode 100644 test-qmp-input-visitor.c
Makefile +4 -0
index 9013dc1..1beab28 100644
@@ -170,6 +170,7 @@ $(qapi-obj-y): $(GENERATED_HEADERS)
 qapi-dir := qapi-generated
 test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
 test-qmp-output-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
+test-qmp-input-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 +209,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
index 037fa12..5012f95 100755
@@ -2687,7 +2687,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.rc3.17.gf56ef1.dirty
#7 lore raw

PATCH 4/4 Drop test-visitor

In reply to Luiz Capitulino

It 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
index 1beab28..6ca299c 100644
@@ -168,7 +168,7 @@ test-coroutine: test-coroutine.o qemu-timer-common.o async.o $(coroutine-obj-y)
 
 $(qapi-obj-y): $(GENERATED_HEADERS)
 qapi-dir := qapi-generated
-test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
+test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
 test-qmp-output-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
 test-qmp-input-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
 qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
@@ -203,9 +203,6 @@ qmp-commands.h: qmp-marshal.c
 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.rc3.17.gf56ef1.dirty