Compare commits

..

1 Commits

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

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
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", "command": "make exec_unit_test -j1",
"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", "command": "make coverage -j1",
"problemMatcher": { "problemMatcher": {
"base": "$gcc", "base": "$gcc",
"owner": "gcc", "owner": "gcc",

View File

@ -6,10 +6,12 @@ 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)
@ -18,8 +20,10 @@ 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
L_FLAGS += -fprofile-arcs -ftest-coverage C_FLAGS += --coverage
L_FLAGS += --coverage
else else
LIBS := ftdi1 LIBS := ftdi1
endif endif
@ -45,16 +49,23 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
all: $(TARGET) all: $(TARGET)
.PHONY: coverage .PHONY: coverage
coverage: $(UNIT_TEST_TARGET) coverage: _cov_genhtml
$(UNIT_TEST_TARGET) $(eval COVERAGE:=$(shell grep 'lines' .coverage.tmp | egrep -o '[0-9]+.[0-9]+%'))
@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)
@ -95,8 +106,10 @@ $(UNIT_TEST_OBJ_DIR)/%.o: $(UNIT_TEST_SRC_DIR)/%.c $(UNIT_TEST_OBJ_DIR)/%.d
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET) rm -f $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET)
rm -rf $(UNIT_TEST_OBJS) $(patsubst %.o,%.d,$(UNIT_TEST_OBJS)) $(UNIT_TEST_TARGET) rm -f $(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))