[sheepdog] [PATCH v2 0/3] Introducing unittest framework to sheepdog

Kai Zhang kyle at zelin.io
Thu Jun 6 13:19:39 CEST 2013


v2:
- fixed compile error
- add --enable-unittest to ./configure options
  don't check "check" if run ./configure without --enable-unittest or --enable-coverage
- update usage

As we all known, unittest is quite important to any project which is aimed to be used in production environment.

This series of patches is to introduce 'check', a popular unittest framework for C language.

These patches are quite initial implemented.
But it still shows the abilities of:
- adding more unittests easily
- runing unittests selectively
- showing code coverage after running unittest
- generating html report by lcov and genhtml
- integrating with other CI (continuous integration) systems like Jenkins

In addition, we can also benifit from unittest in the following ways:
- help us write more testable code
- improve the robustness of sheepdog
- new contributors can be quickly involved by writing unittest code

Usage:
- ./autogen.sh
- ./configure --enable-unittest --enable-coverage
- $make check # run all unittests
- $make check CK_RUN_SUITE=xxx_suite CK_RUN_CASE=xxx_case # run selective unittest
- $make coverage # generate coverage report in html to directory 'coverage'

There are also many things that we can improve:
- more tests of cause
- more functional mock programs (inspired by gmock)

Another thing that I wanna share with you is that, current unittests in implemented under 'check', a C unittest framework.
There is another test framework, google testing framework (including gtest and gmock), which is more popular and powerful.
However, they are written in C++.
I have tried to use gtest and gmock to write unittests in C++, but failed to compile with our code.
We need to refine our code to be compatible with C++ compiler if we wanna adopt gtest and gmock.

Kai Zhang (3):
  build: add 'make coverage' target
  unittest: add unittest for collie/common.c
  unittest: add unittest for sheep/vdi.c

 .gitignore                    |    6 +++++
 Makefile.am                   |   21 ++++++++++++++++++++
 collie/Makefile.am            |    3 ++
 configure.ac                  |   16 ++++++++++++++-
 sheep/Makefile.am             |    3 ++
 unittest/Makefile.am          |    3 ++
 unittest/collie/Makefile.am   |   21 ++++++++++++++++++++
 unittest/collie/mock_collie.c |   17 ++++++++++++++++
 unittest/collie/test_common.c |   43 +++++++++++++++++++++++++++++++++++++++++
 unittest/sheep/Makefile.am    |   20 +++++++++++++++++++
 unittest/sheep/mock_request.c |   11 ++++++++++
 unittest/sheep/mock_sheep.c   |    3 ++
 unittest/sheep/mock_store.c   |   24 ++++++++++++++++++++++
 unittest/sheep/test_vdi.c     |   38 ++++++++++++++++++++++++++++++++++++
 14 files changed, 228 insertions(+), 1 deletions(-)
 create mode 100644 unittest/Makefile.am
 create mode 100644 unittest/collie/Makefile.am
 create mode 100644 unittest/collie/mock_collie.c
 create mode 100644 unittest/collie/test_common.c
 create mode 100644 unittest/sheep/Makefile.am
 create mode 100644 unittest/sheep/mock_request.c
 create mode 100644 unittest/sheep/mock_sheep.c
 create mode 100644 unittest/sheep/mock_store.c
 create mode 100644 unittest/sheep/test_vdi.c




More information about the sheepdog mailing list