[Libvir] Adding test suite for sexpr<->xml conversions

Quite a critical bit of the libvirt code is that which converts between SEXPR and XML, and vica-verca. I've broken this code several times when making changes, so it is way overdue to get some unit test coverage in this area. The attached patch adds such coverage - defining two tests xml2sexprtest and sexpr2xmltest. The tests are pretty simple, in the tests/ directory I just have a bunch of xml & sexpr files - one is the fixed input, the other is the expected output. The test just runs the conversion and compares the actual output with the expected output. Currently I've added two example data files - one for paravirt & one for fully-virt. With this patch you can run tests: $ make check make check-TESTS make[1]: Entering directory `/home/berrange/src/xen/libvirt/tests' XML-2-SEXPR PV config ... OK XML-2-SEXPR FV config ... OK PASS: xml2sexprtest SEXPR-2-XML PV config ... OK SEXPR-2-XML FV config ... OK PASS: sexpr2xmltest ================== All 2 tests passed ================== make[1]: Leaving directory `/home/berrange/src/xen/libvirt/tests' I'm shortly about to start on updating the code to deal with new CDROM configuration format for HVM guests in Xen 3.0.3, and so intend to add further test files during this process (and of course make sure I don't break the existing ones :-) Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Thu, Aug 24, 2006 at 02:07:51PM +0100, Daniel P. Berrange wrote:
Quite a critical bit of the libvirt code is that which converts between SEXPR and XML, and vica-verca. I've broken this code several times when making changes, so it is way overdue to get some unit test coverage in this area.
The attached patch adds such coverage - defining two tests xml2sexprtest and sexpr2xmltest. The tests are pretty simple, in the tests/ directory I just have a bunch of xml & sexpr files - one is the fixed input, the other is the expected output. The test just runs the conversion and compares the actual output with the expected output. Currently I've added two example data files - one for paravirt & one for fully-virt. With this patch you can run tests:
$ make check make check-TESTS make[1]: Entering directory `/home/berrange/src/xen/libvirt/tests' XML-2-SEXPR PV config ... OK XML-2-SEXPR FV config ... OK PASS: xml2sexprtest SEXPR-2-XML PV config ... OK SEXPR-2-XML FV config ... OK PASS: sexpr2xmltest ================== All 2 tests passed ================== make[1]: Leaving directory `/home/berrange/src/xen/libvirt/tests'
Excellent. Small suggestions: - make tests/make check in the top level dir should also run it - adding a 'make valgrind' target running the same with valgrind -quiet thanks Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Thu, Aug 24, 2006 at 09:21:52AM -0400, Daniel Veillard wrote:
On Thu, Aug 24, 2006 at 02:07:51PM +0100, Daniel P. Berrange wrote:
Quite a critical bit of the libvirt code is that which converts between SEXPR and XML, and vica-verca. I've broken this code several times when making changes, so it is way overdue to get some unit test coverage in this area.
The attached patch adds such coverage - defining two tests xml2sexprtest and sexpr2xmltest. The tests are pretty simple, in the tests/ directory I just have a bunch of xml & sexpr files - one is the fixed input, the other is the expected output. The test just runs the conversion and compares the actual output with the expected output. Currently I've added two example data files - one for paravirt & one for fully-virt. With this patch you can run tests:
$ make check make check-TESTS make[1]: Entering directory `/home/berrange/src/xen/libvirt/tests' XML-2-SEXPR PV config ... OK XML-2-SEXPR FV config ... OK PASS: xml2sexprtest SEXPR-2-XML PV config ... OK SEXPR-2-XML FV config ... OK PASS: sexpr2xmltest ================== All 2 tests passed ================== make[1]: Leaving directory `/home/berrange/src/xen/libvirt/tests'
Excellent. Small suggestions: - make tests/make check in the top level dir should also run it
Urm - automake already hooks things up so if you type 'make check' in the top level, it runs 'make check' in all sub-directories. Why do we need to manually duplicate this with a 'make test' target ?
- adding a 'make valgrind' target running the same with valgrind -quiet
Yes, good idea. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Thu, Aug 24, 2006 at 02:28:56PM +0100, Daniel P. Berrange wrote:
On Thu, Aug 24, 2006 at 09:21:52AM -0400, Daniel Veillard wrote:
Excellent. Small suggestions: - make tests/make check in the top level dir should also run it
Urm - automake already hooks things up so if you type 'make check' in the top level, it runs 'make check' in all sub-directories. Why do we need to manually duplicate this with a 'make test' target ?
oops, I always hardwired a 'make test', don't worry I can learn to type a different command :-) Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Thu, Aug 24, 2006 at 09:21:52AM -0400, Daniel Veillard wrote:
Excellent. Small suggestions: - make tests/make check in the top level dir should also run it - adding a 'make valgrind' target running the same with valgrind -quiet
Ok, added a 'make valgrind' target now. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Thu, Aug 24, 2006 at 02:07:51PM +0100, Daniel P. Berrange wrote:
Quite a critical bit of the libvirt code is that which converts between SEXPR and XML, and vica-verca. I've broken this code several times when making changes, so it is way overdue to get some unit test coverage in this area.
Having added some unit test coverage, I was wondering just how *much* coverage... So I've attached another patch which adds a new flag to configure - --enable-test-coverage, which causes everything to be compiled & linked with -fprofile-arcs -ftest-coverage There is then a 'make cov' target in the top level directory which genrates an HTML report showing code coverage: http://people.redhat.com/berrange/libvirt-coverage/ Obviously it is mostly red - my goal is not to get 100% coverage - clearly thats impossible in unit tests, since most of the XenD interaction can only be tested through integration tests. It is however useful to be able to view how much of the XML<->SEXPR routines are covered, since they're easily unit testable. Also coverage on 'virsh' is useful since we can run it with the test backend instead of xen. The reports are generated using Perl & xsltproc - yes, this adds Perl as a dependancy, but I don't think its a worry, because this is totally a no-op unless you explicitly pass --enable-test-coverage to configure, so won't impact normal 'configure; make ; make install' cycle done by most developers. Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Thu, Aug 24, 2006 at 02:07:51PM +0100, Daniel P. Berrange wrote:
Quite a critical bit of the libvirt code is that which converts between SEXPR and XML, and vica-verca. I've broken this code several times when
This is exactly reason why I've created unit tests stuff in libvirt ;-) It's important create unit tests for all things like parsers, convertors, ...
RCS file: tests/sexpr2xml-fv.sexpr diff -N tests/sexpr2xml-fv.sexpr *** /dev/null 1 Jan 1970 00:00:00 -0000 --- tests/sexpr2xml-fv.sexpr 24 Aug 2006 13:57:37 -0000
Maybe you can create some subdirectory in tests/ for data otherwise it will be crowded. Go ahead, number of tests is unlimited :-) Karel -- Karel Zak <kzak@redhat.com>

On Thu, Aug 24, 2006 at 09:00:58PM +0200, Karel Zak wrote:
On Thu, Aug 24, 2006 at 02:07:51PM +0100, Daniel P. Berrange wrote:
Quite a critical bit of the libvirt code is that which converts between SEXPR and XML, and vica-verca. I've broken this code several times when
This is exactly reason why I've created unit tests stuff in libvirt ;-) It's important create unit tests for all things like parsers, convertors, ...
RCS file: tests/sexpr2xml-fv.sexpr diff -N tests/sexpr2xml-fv.sexpr *** /dev/null 1 Jan 1970 00:00:00 -0000 --- tests/sexpr2xml-fv.sexpr 24 Aug 2006 13:57:37 -0000
Maybe you can create some subdirectory in tests/ for data otherwise it will be crowded.
Yeah, probably a good idea - particularly as I'm about to create 30 or more test data files for 'virsh' too :-) Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Thu, Aug 24, 2006 at 08:06:26PM +0100, Daniel P. Berrange wrote:
On Thu, Aug 24, 2006 at 09:00:58PM +0200, Karel Zak wrote:
On Thu, Aug 24, 2006 at 02:07:51PM +0100, Daniel P. Berrange wrote:
Quite a critical bit of the libvirt code is that which converts between SEXPR and XML, and vica-verca. I've broken this code several times when
This is exactly reason why I've created unit tests stuff in libvirt ;-) It's important create unit tests for all things like parsers, convertors, ...
RCS file: tests/sexpr2xml-fv.sexpr diff -N tests/sexpr2xml-fv.sexpr *** /dev/null 1 Jan 1970 00:00:00 -0000 --- tests/sexpr2xml-fv.sexpr 24 Aug 2006 13:57:37 -0000
Maybe you can create some subdirectory in tests/ for data otherwise it will be crowded.
Yeah, probably a good idea - particularly as I'm about to create 30 or more test data files for 'virsh' too :-)
Sounds good, but use specialized subdirs, thanks :-) Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Karel Zak