Compare commits

..

1 Commits

Author SHA1 Message Date
Thomas Klaehn
cd66f01149 Add code coverage report generation 2019-07-16 12:13:44 +02:00
3 changed files with 13 additions and 25 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
bin/ bin/
obj/ obj/
coverage/ coverage/
test.info

4
.vscode/tasks.json vendored
View File

@ -74,7 +74,7 @@
{ {
"label": "exec_unit_test", "label": "exec_unit_test",
"type":"shell", "type":"shell",
"command": "make exec_unit_test -j1", "command": "make exec_unit_test",
"problemMatcher": { "problemMatcher": {
"base": "$gcc", "base": "$gcc",
"owner": "gcc", "owner": "gcc",
@ -91,7 +91,7 @@
{ {
"label": "coverage", "label": "coverage",
"type":"shell", "type":"shell",
"command": "make coverage -j1", "command": "make coverage",
"problemMatcher": { "problemMatcher": {
"base": "$gcc", "base": "$gcc",
"owner": "gcc", "owner": "gcc",

View File

@ -6,12 +6,10 @@ CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)cpp CPP = $(CROSS_COMPILE)cpp
CHECK = cppcheck CHECK = cppcheck
LCOV = lcov LCOV = lcov
GENHTML = genhtml
SRC_DIR = src SRC_DIR = src
OBJ_DIR = obj OBJ_DIR = obj
BIN_DIR = bin BIN_DIR = bin
COVERAGE_DIR = coverage
UNIT_TEST_SRC_DIR = test/unit UNIT_TEST_SRC_DIR = test/unit
UNIT_TEST_OBJ_DIR = $(OBJ_DIR)/$(UNIT_TEST_SRC_DIR) UNIT_TEST_OBJ_DIR = $(OBJ_DIR)/$(UNIT_TEST_SRC_DIR)
@ -20,10 +18,8 @@ INCLUDES += /usr/include/libftdi1
ifneq "$(findstring $(MAKECMDGOALS), build_unit_test exec_unit_test coverage)" "" ifneq "$(findstring $(MAKECMDGOALS), build_unit_test exec_unit_test coverage)" ""
INCLUDES += test/inc INCLUDES += test/inc
C_FLAGS += -fprofile-arcs -ftest-coverage
C_FLAGS += --coverage L_FLAGS += -fprofile-arcs -ftest-coverage
L_FLAGS += --coverage
else else
LIBS := ftdi1 LIBS := ftdi1
endif endif
@ -49,23 +45,16 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
all: $(TARGET) all: $(TARGET)
.PHONY: coverage .PHONY: coverage
coverage: _cov_genhtml coverage: $(UNIT_TEST_TARGET)
$(eval COVERAGE:=$(shell grep 'lines' .coverage.tmp | egrep -o '[0-9]+.[0-9]+%')) $(UNIT_TEST_TARGET)
@rm -f $(UNIT_TEST_OBJ_DIR)/*.gcda
@rm -f $(UNIT_TEST_OBJ_DIR)/*.gcno
$(LCOV) -c -d obj -d bin/test/unit/ -d src/ -d test/unit/ -o test.info --no-external
$(eval COVERAGE:=$(shell genhtml -o coverage/html test.info | grep 'lines' | egrep -o '[0-9]+.[0-9]+%'))
@echo @echo
@echo Line coverage: $(COVERAGE) @echo Line coverage: $(COVERAGE)
@echo @echo
@rm -f .coverage.tmp
.PHONY: _cov_lcov
_cov_lcov: exec_unit_test
@rm -f $(UNIT_TEST_OBJ_DIR)/*.gcda
@rm -f $(UNIT_TEST_OBJ_DIR)/*.gcno
@mkdir -p $(COVERAGE_DIR)
$(LCOV) -c -d $(OBJ_DIR) -o $(COVERAGE_DIR)/coverage.info
.PHONY: _cov_genhtml
_cov_genhtml: _cov_lcov
$(GENHTML) -o $(COVERAGE_DIR)/html $(COVERAGE_DIR)/coverage.info > .coverage.tmp
.PHONY: unit_test .PHONY: unit_test
build_unit_test: $(UNIT_TEST_TARGET) build_unit_test: $(UNIT_TEST_TARGET)
@ -106,10 +95,8 @@ $(UNIT_TEST_OBJ_DIR)/%.o: $(UNIT_TEST_SRC_DIR)/%.c $(UNIT_TEST_OBJ_DIR)/%.d
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET) rm -rf $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET)
rm -f $(UNIT_TEST_OBJS) $(patsubst %.o,%.d,$(UNIT_TEST_OBJS)) $(UNIT_TEST_TARGET) rm -rf $(UNIT_TEST_OBJS) $(patsubst %.o,%.d,$(UNIT_TEST_OBJS)) $(UNIT_TEST_TARGET)
rm -f $(OBJ_DIR)/*.gcda $(OBJ_DIR)/*.gcno
rm -fr $(COVERAGE_DIR)
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include $(patsubst %.o,%.d,$(OBJS)) -include $(patsubst %.o,%.d,$(OBJS))