[sheepdog] [PATCH v4 0/4] Introducing unittest framework to sheepdog

Kai Zhang kyle at zelin.io
Mon Jun 17 15:32:41 CEST 2013


v4:
- modified directory structure
  moved previous tests to tests/functional
  moved unittest to tests/unit

v3:
- fixed compile error on ubuntu 12.04

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:
- $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 (4):
  tests: move tests to tests/functional
  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 +++
 tests/{ => functional}/001           |    0
 tests/{ => functional}/001.out       |    0
 tests/{ => functional}/002           |    0
 tests/{ => functional}/002.out       |    0
 tests/{ => functional}/003           |    0
 tests/{ => functional}/003.out       |    0
 tests/{ => functional}/004           |    0
 tests/{ => functional}/004.out       |    0
 tests/{ => functional}/005           |    0
 tests/{ => functional}/005.out       |    0
 tests/{ => functional}/006           |    0
 tests/{ => functional}/006.out       |    0
 tests/{ => functional}/007           |    0
 tests/{ => functional}/007.out       |    0
 tests/{ => functional}/008           |    0
 tests/{ => functional}/008.out       |    0
 tests/{ => functional}/009           |    0
 tests/{ => functional}/009.out       |    0
 tests/{ => functional}/010           |    0
 tests/{ => functional}/010.out       |    0
 tests/{ => functional}/011           |    0
 tests/{ => functional}/011.out       |    0
 tests/{ => functional}/012           |    0
 tests/{ => functional}/012.out       |    0
 tests/{ => functional}/013           |    0
 tests/{ => functional}/013.out       |    0
 tests/{ => functional}/014           |    0
 tests/{ => functional}/014.out       |    0
 tests/{ => functional}/015           |    0
 tests/{ => functional}/015.out       |    0
 tests/{ => functional}/016           |    0
 tests/{ => functional}/016.out       |    0
 tests/{ => functional}/017           |    0
 tests/{ => functional}/017.out       |    0
 tests/{ => functional}/018           |    0
 tests/{ => functional}/018.out       |    0
 tests/{ => functional}/019           |    0
 tests/{ => functional}/019.out       |    0
 tests/{ => functional}/020           |    0
 tests/{ => functional}/020.out       |    0
 tests/{ => functional}/021           |    0
 tests/{ => functional}/021.out       |    0
 tests/{ => functional}/022           |    0
 tests/{ => functional}/022.out       |    0
 tests/{ => functional}/023           |    0
 tests/{ => functional}/023.out       |    0
 tests/{ => functional}/024           |    0
 tests/{ => functional}/024.out       |    0
 tests/{ => functional}/025           |    0
 tests/{ => functional}/025.out       |    0
 tests/{ => functional}/026           |    0
 tests/{ => functional}/026.out       |    0
 tests/{ => functional}/027           |    0
 tests/{ => functional}/027.out       |    0
 tests/{ => functional}/028           |    0
 tests/{ => functional}/028.out       |    0
 tests/{ => functional}/029           |    0
 tests/{ => functional}/029.out       |    0
 tests/{ => functional}/030           |    0
 tests/{ => functional}/030.out       |    0
 tests/{ => functional}/031           |    0
 tests/{ => functional}/031.out       |    0
 tests/{ => functional}/032           |    0
 tests/{ => functional}/032.out       |    0
 tests/{ => functional}/033           |    0
 tests/{ => functional}/033.out       |    0
 tests/{ => functional}/034           |    0
 tests/{ => functional}/034.out       |    0
 tests/{ => functional}/035           |    0
 tests/{ => functional}/035.out       |    0
 tests/{ => functional}/036           |    0
 tests/{ => functional}/036.out       |    0
 tests/{ => functional}/037           |    0
 tests/{ => functional}/037.out       |    0
 tests/{ => functional}/038           |    0
 tests/{ => functional}/038.out       |    0
 tests/{ => functional}/039           |    0
 tests/{ => functional}/039.out       |    0
 tests/{ => functional}/040           |    0
 tests/{ => functional}/040.out       |    0
 tests/{ => functional}/041           |    0
 tests/{ => functional}/041.out       |    0
 tests/{ => functional}/042           |    0
 tests/{ => functional}/042.out       |    0
 tests/{ => functional}/043           |    0
 tests/{ => functional}/043.out       |    0
 tests/{ => functional}/044           |    0
 tests/{ => functional}/044.out       |    0
 tests/{ => functional}/045           |    0
 tests/{ => functional}/045.out       |    0
 tests/{ => functional}/046           |    0
 tests/{ => functional}/046.out       |    0
 tests/{ => functional}/047           |    0
 tests/{ => functional}/047.out       |    0
 tests/{ => functional}/048           |    0
 tests/{ => functional}/048.out       |    0
 tests/{ => functional}/049           |    0
 tests/{ => functional}/049.out       |    0
 tests/{ => functional}/050           |    0
 tests/{ => functional}/050.out       |    0
 tests/{ => functional}/051           |    0
 tests/{ => functional}/051.out       |    0
 tests/{ => functional}/052           |    0
 tests/{ => functional}/052.out       |    0
 tests/{ => functional}/053           |    0
 tests/{ => functional}/053.out       |    0
 tests/{ => functional}/054           |    0
 tests/{ => functional}/054.out       |    0
 tests/{ => functional}/055           |    0
 tests/{ => functional}/055.out       |    0
 tests/{ => functional}/056           |    0
 tests/{ => functional}/056.out       |    0
 tests/{ => functional}/057           |    0
 tests/{ => functional}/057.out       |    0
 tests/{ => functional}/058           |    0
 tests/{ => functional}/058.out       |    0
 tests/{ => functional}/059           |    0
 tests/{ => functional}/059.out       |    0
 tests/{ => functional}/060           |    0
 tests/{ => functional}/060.out       |    0
 tests/{ => functional}/061           |    0
 tests/{ => functional}/061.out       |    0
 tests/{ => functional}/062           |    0
 tests/{ => functional}/062.out       |    0
 tests/{ => functional}/063           |    0
 tests/{ => functional}/063.out       |    0
 tests/{ => functional}/064           |    0
 tests/{ => functional}/064.out       |    0
 tests/{ => functional}/HOWTO         |    0
 tests/{ => functional}/check         |    0
 tests/{ => functional}/common.config |    4 ++--
 tests/{ => functional}/common.filter |    0
 tests/{ => functional}/common.rc     |    0
 tests/{ => functional}/foo           |    0
 tests/{ => functional}/group         |    0
 tests/{ => functional}/valgrind.supp |    0
 tests/unit/Makefile.am               |    3 +++
 tests/unit/collie/Makefile.am        |   22 +++++++++++++++++
 tests/unit/collie/mock_collie.c      |   18 ++++++++++++++
 tests/unit/collie/test_common.c      |   43 ++++++++++++++++++++++++++++++++++
 tests/unit/sheep/Makefile.am         |   21 +++++++++++++++++
 tests/unit/sheep/mock_request.c      |   11 +++++++++
 tests/unit/sheep/mock_sheep.c        |    3 +++
 tests/unit/sheep/mock_store.c        |   24 +++++++++++++++++++
 tests/unit/sheep/test_vdi.c          |   38 ++++++++++++++++++++++++++++++
 150 files changed, 233 insertions(+), 3 deletions(-)
 rename tests/{ => functional}/001 (100%)
 rename tests/{ => functional}/001.out (100%)
 rename tests/{ => functional}/002 (100%)
 rename tests/{ => functional}/002.out (100%)
 rename tests/{ => functional}/003 (100%)
 rename tests/{ => functional}/003.out (100%)
 rename tests/{ => functional}/004 (100%)
 rename tests/{ => functional}/004.out (100%)
 rename tests/{ => functional}/005 (100%)
 rename tests/{ => functional}/005.out (100%)
 rename tests/{ => functional}/006 (100%)
 rename tests/{ => functional}/006.out (100%)
 rename tests/{ => functional}/007 (100%)
 rename tests/{ => functional}/007.out (100%)
 rename tests/{ => functional}/008 (100%)
 rename tests/{ => functional}/008.out (100%)
 rename tests/{ => functional}/009 (100%)
 rename tests/{ => functional}/009.out (100%)
 rename tests/{ => functional}/010 (100%)
 rename tests/{ => functional}/010.out (100%)
 rename tests/{ => functional}/011 (100%)
 rename tests/{ => functional}/011.out (100%)
 rename tests/{ => functional}/012 (100%)
 rename tests/{ => functional}/012.out (100%)
 rename tests/{ => functional}/013 (100%)
 rename tests/{ => functional}/013.out (100%)
 rename tests/{ => functional}/014 (100%)
 rename tests/{ => functional}/014.out (100%)
 rename tests/{ => functional}/015 (100%)
 rename tests/{ => functional}/015.out (100%)
 rename tests/{ => functional}/016 (100%)
 rename tests/{ => functional}/016.out (100%)
 rename tests/{ => functional}/017 (100%)
 rename tests/{ => functional}/017.out (100%)
 rename tests/{ => functional}/018 (100%)
 rename tests/{ => functional}/018.out (100%)
 rename tests/{ => functional}/019 (100%)
 rename tests/{ => functional}/019.out (100%)
 rename tests/{ => functional}/020 (100%)
 rename tests/{ => functional}/020.out (100%)
 rename tests/{ => functional}/021 (100%)
 rename tests/{ => functional}/021.out (100%)
 rename tests/{ => functional}/022 (100%)
 rename tests/{ => functional}/022.out (100%)
 rename tests/{ => functional}/023 (100%)
 rename tests/{ => functional}/023.out (100%)
 rename tests/{ => functional}/024 (100%)
 rename tests/{ => functional}/024.out (100%)
 rename tests/{ => functional}/025 (100%)
 rename tests/{ => functional}/025.out (100%)
 rename tests/{ => functional}/026 (100%)
 rename tests/{ => functional}/026.out (100%)
 rename tests/{ => functional}/027 (100%)
 rename tests/{ => functional}/027.out (100%)
 rename tests/{ => functional}/028 (100%)
 rename tests/{ => functional}/028.out (100%)
 rename tests/{ => functional}/029 (100%)
 rename tests/{ => functional}/029.out (100%)
 rename tests/{ => functional}/030 (100%)
 rename tests/{ => functional}/030.out (100%)
 rename tests/{ => functional}/031 (100%)
 rename tests/{ => functional}/031.out (100%)
 rename tests/{ => functional}/032 (100%)
 rename tests/{ => functional}/032.out (100%)
 rename tests/{ => functional}/033 (100%)
 rename tests/{ => functional}/033.out (100%)
 rename tests/{ => functional}/034 (100%)
 rename tests/{ => functional}/034.out (100%)
 rename tests/{ => functional}/035 (100%)
 rename tests/{ => functional}/035.out (100%)
 rename tests/{ => functional}/036 (100%)
 rename tests/{ => functional}/036.out (100%)
 rename tests/{ => functional}/037 (100%)
 rename tests/{ => functional}/037.out (100%)
 rename tests/{ => functional}/038 (100%)
 rename tests/{ => functional}/038.out (100%)
 rename tests/{ => functional}/039 (100%)
 rename tests/{ => functional}/039.out (100%)
 rename tests/{ => functional}/040 (100%)
 rename tests/{ => functional}/040.out (100%)
 rename tests/{ => functional}/041 (100%)
 rename tests/{ => functional}/041.out (100%)
 rename tests/{ => functional}/042 (100%)
 rename tests/{ => functional}/042.out (100%)
 rename tests/{ => functional}/043 (100%)
 rename tests/{ => functional}/043.out (100%)
 rename tests/{ => functional}/044 (100%)
 rename tests/{ => functional}/044.out (100%)
 rename tests/{ => functional}/045 (100%)
 rename tests/{ => functional}/045.out (100%)
 rename tests/{ => functional}/046 (100%)
 rename tests/{ => functional}/046.out (100%)
 rename tests/{ => functional}/047 (100%)
 rename tests/{ => functional}/047.out (100%)
 rename tests/{ => functional}/048 (100%)
 rename tests/{ => functional}/048.out (100%)
 rename tests/{ => functional}/049 (100%)
 rename tests/{ => functional}/049.out (100%)
 rename tests/{ => functional}/050 (100%)
 rename tests/{ => functional}/050.out (100%)
 rename tests/{ => functional}/051 (100%)
 rename tests/{ => functional}/051.out (100%)
 rename tests/{ => functional}/052 (100%)
 rename tests/{ => functional}/052.out (100%)
 rename tests/{ => functional}/053 (100%)
 rename tests/{ => functional}/053.out (100%)
 rename tests/{ => functional}/054 (100%)
 rename tests/{ => functional}/054.out (100%)
 rename tests/{ => functional}/055 (100%)
 rename tests/{ => functional}/055.out (100%)
 rename tests/{ => functional}/056 (100%)
 rename tests/{ => functional}/056.out (100%)
 rename tests/{ => functional}/057 (100%)
 rename tests/{ => functional}/057.out (100%)
 rename tests/{ => functional}/058 (100%)
 rename tests/{ => functional}/058.out (100%)
 rename tests/{ => functional}/059 (100%)
 rename tests/{ => functional}/059.out (100%)
 rename tests/{ => functional}/060 (100%)
 rename tests/{ => functional}/060.out (100%)
 rename tests/{ => functional}/061 (100%)
 rename tests/{ => functional}/061.out (100%)
 rename tests/{ => functional}/062 (100%)
 rename tests/{ => functional}/062.out (100%)
 rename tests/{ => functional}/063 (100%)
 rename tests/{ => functional}/063.out (100%)
 rename tests/{ => functional}/064 (100%)
 rename tests/{ => functional}/064.out (100%)
 rename tests/{ => functional}/HOWTO (100%)
 rename tests/{ => functional}/check (100%)
 rename tests/{ => functional}/common.config (94%)
 rename tests/{ => functional}/common.filter (100%)
 rename tests/{ => functional}/common.rc (100%)
 rename tests/{ => functional}/foo (100%)
 rename tests/{ => functional}/group (100%)
 rename tests/{ => functional}/valgrind.supp (100%)
 create mode 100644 tests/unit/Makefile.am
 create mode 100644 tests/unit/collie/Makefile.am
 create mode 100644 tests/unit/collie/mock_collie.c
 create mode 100644 tests/unit/collie/test_common.c
 create mode 100644 tests/unit/sheep/Makefile.am
 create mode 100644 tests/unit/sheep/mock_request.c
 create mode 100644 tests/unit/sheep/mock_sheep.c
 create mode 100644 tests/unit/sheep/mock_store.c
 create mode 100644 tests/unit/sheep/test_vdi.c

--
1.7.9.5




More information about the sheepdog mailing list