Add code coverage report generation

This commit is contained in:
Thomas Klaehn 2019-07-15 23:55:17 +02:00
parent 66be59c7ee
commit cd66f01149
3 changed files with 39 additions and 6 deletions

2
.gitignore vendored
View File

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

17
.vscode/tasks.json vendored
View File

@ -87,6 +87,23 @@
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
} }
},
{
"label": "coverage",
"type":"shell",
"command": "make coverage",
"problemMatcher": {
"base": "$gcc",
"owner": "gcc",
"fileLocation": [
"relative",
"${workspaceFolder}"
]
},
"group": {
"kind": "build",
"isDefault": true
}
} }
], ],
"presentation": { "presentation": {

View File

@ -5,6 +5,7 @@ TARGET_FILE ?= ftdi_gpio
CC = $(CROSS_COMPILE)gcc CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)cpp CPP = $(CROSS_COMPILE)cpp
CHECK = cppcheck CHECK = cppcheck
LCOV = lcov
SRC_DIR = src SRC_DIR = src
OBJ_DIR = obj OBJ_DIR = obj
@ -15,16 +16,17 @@ UNIT_TEST_OBJ_DIR = $(OBJ_DIR)/$(UNIT_TEST_SRC_DIR)
INCLUDES := inc INCLUDES := inc
INCLUDES += /usr/include/libftdi1 INCLUDES += /usr/include/libftdi1
ifneq "$(findstring $(MAKECMDGOALS), build_unit_test exec_unit_test)" "" 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
else else
LIBS := ftdi1 LIBS := ftdi1
endif endif
LD_FLAGS := C_FLAGS += -O0 -g -Wall -Wextra -Werror
C_FLAGS := -O0 -g -Wall -Wextra -Werror CPP_FLAGS += $(addprefix -I, $(INCLUDES))
CPP_FLAGS := $(addprefix -I, $(INCLUDES)) CHECK_FLAGS = --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem
CHECK_CLAGS := --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem
C_SRCS = $(wildcard $(SRC_DIR)/*.c) C_SRCS = $(wildcard $(SRC_DIR)/*.c)
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS))) C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS)))
@ -42,6 +44,18 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)
.PHONY: coverage
coverage: $(UNIT_TEST_TARGET)
$(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 Line coverage: $(COVERAGE)
@echo
.PHONY: unit_test .PHONY: unit_test
build_unit_test: $(UNIT_TEST_TARGET) build_unit_test: $(UNIT_TEST_TARGET)
@ -51,7 +65,7 @@ exec_unit_test: $(UNIT_TEST_TARGET)
.PHONY: check .PHONY: check
check: $(C_SRCS) check: $(C_SRCS)
$(CHECK) $(CPP_FLAGS) $(CHECK_CLAGS) $(C_SRCS) $(CHECK) $(CPP_FLAGS) $(CHECK_FLAGS) $(C_SRCS)
$(UNIT_TEST_TARGET): $(UNIT_TEST_OBJS) $(THIS_MAKEFILE) $(UNIT_TEST_TARGET): $(UNIT_TEST_OBJS) $(THIS_MAKEFILE)
@mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR) @mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR)