CUnit & Coverage Larry Shi Jul 1, 2010 1 Agenda Aim CUnit Screenshots(Automated) Demo TO-DO list Jul 1, 2010 2 Aim Unit test Test C code automatically Find bugs in time to improve quality Coverage How often each line of code executes What lines of code are actually executed Suggestion CUnit for unit test GCOV, LCOV for coverage Jul 1, 2010 3 CUnit CUnit is a lightweight system for writing, administering, and running unit tests in C. Several different interfaces are provided for running tests and reporting results Type Des. Interactive ※Automated Output to xml file NO Basic Flexible programming interface NO Console Console interface (ansi C) YES Curses Graphical interface (Unix) YES Jul 1, 2010 4 Screenshots-Listing tests Jul 1, 2010 5 Screenshots-Tests result Jul 1, 2010 6 Screenshots-Coverage Jul 1, 2010 7 Screenshots-Coverage Jul 1, 2010 8 Demo ※ Please see it in the test machine Several steps below: Write test cases Compile with -ftest-coverage -fprofile-arcs Run Generated files: xx.gcda, xx.gcno for coverage LCOV Generated files: covinfo for coverage genhtml (generate html format coverage report) Confirm test report(xx.xml) Confirm coverage report (./result) Jul 1, 2010 9 TO-DO list Team discuss if CUnit & LCOV can satisfy our requirement for C code quality Framework design Unit test framework via CUnit One example about framework proposal Support for automated test Support for modular test Integrate the framework with existed source code Integrate the framework with other test frameworks Test cases Suggest that developers handle it Jul 1, 2010 10 Thank you!! Jul 1, 2010 11