Embedded Test Code Coverage
Coverage Tools 1. tcov 2. gcov 3. "C Test Coverage Tool" 4. "C++ Test Coverage Tool" 5. "Squish Coco" 6. "C++ Coverage Validator"
Common program
gcov gcov is a tool you can use in conjunction with GCC to test code coverage in your programs.
How it works?
gcov ● how often each line of code executes ● what lines of code are actually executed ● how much computing time each section of code uses
How to use?
$ gcc -fprofile-arcs -ftest-coverage tmp.c $ a.out $ gcov tmp.c File 'tmp.c' Lines executed:90.00% of 10 Creating 'tmp.c.gcov'
-: 0:Source:tmp.c -: 0:Graph:tmp.gcno -: 0:Data:tmp.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include <stdio.h> -: 2: -: 3:int main (void) 1: 4:{ 1: 5: int i, total; -: 6: 1: 7: total = 0; -: 8: 11: 9: for (i = 0; i < 10; i++) 10: 10: total += i; -: 11: 1: 12: if (total != 45) #####: 13: printf ("Failuren"); -: 14: else 1: 15: printf ("Successn"); 1: 16: return 0; -: 17:}
Beyond..
lcov lcov is a graphical front-end for GCC's coverage testing tool gcov.
CFLAGS += -fprofile-arcs -ftest-coverage LDFLAGS += -lgcov lcov --base-directory . --directory . --capture --output-file example.info genhtml -o /coverage/example.info
lcov result
cpputest framework CppUTest is a C /C++ based unit xUnit test framework for unit testing and for test-driving your code.
Basic Makefile
PROJECT_HOME_DIR = . CPP_PLATFORM = Gcc CPPUTEST_USE_EXTENSIONS = Y CPPUTEST_WARNINGFLAGS += -Wall CPPUTEST_WARNINGFLAGS += -Werror CPPUTEST_WARNINGFLAGS += -Wswitch-default CPPUTEST_WARNINGFLAGS += -Wswitch-enum CPPUTEST_WARNINGFLAGS += -Wno-self-assign CPPUTEST_CFLAGS += -std=c89 CPPUTEST_CFLAGS += -Wextra CPPUTEST_CFLAGS += -pedantic CPPUTEST_CFLAGS += -Wstrict-prototypes Flags
SRC_DIRS = src/* TEST_SRC_DIRS = tests tests/util tests/devices tests/HomeAutomation mocks INCLUDE_DIRS = $(CPPUTEST_HOME)/include/ include/* mocks Path
include $(CPPUTEST_HOME)/build/MakefileWorker.mk Include Framwork
CPPUTEST_HOME/build/MakefileWorker.mk CPPUTEST_USE_GCOV = Y Enable gcov
$ cd PROJECT_HOME_DIR $ make gcov Get gcov output
lcov --base-directory . --directory objs/ -c -o temp.info lcov --remove temp.info "/usr*" -o temp.info rm -rf test_coverage mkdir test_coverage genhtml -o test_coverage temp.info Generate lcov html

IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자