From d2f7201a10362c5d17a86cf54a46bdad643a9186 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Mon, 15 Jul 2019 23:55:17 +0200 Subject: [PATCH] Add code coverage report generation --- .gitignore | 2 ++ Makefile | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cd42ee3..caab209 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ bin/ obj/ +coverage/ +test.info diff --git a/Makefile b/Makefile index 5cb3790..d5c4fdb 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ TARGET_FILE ?= ftdi_gpio CC = $(CROSS_COMPILE)gcc CPP = $(CROSS_COMPILE)cpp CHECK = cppcheck +LCOV = lcov +GENHTML = genhtml SRC_DIR = src OBJ_DIR = obj @@ -15,16 +17,17 @@ UNIT_TEST_OBJ_DIR = $(OBJ_DIR)/$(UNIT_TEST_SRC_DIR) INCLUDES := inc 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 +C_FLAGS += -fprofile-arcs -ftest-coverage +L_FLAGS += -fprofile-arcs -ftest-coverage else LIBS := ftdi1 endif -LD_FLAGS := -C_FLAGS := -O0 -g -Wall -Wextra -Werror -CPP_FLAGS := $(addprefix -I, $(INCLUDES)) -CHECK_CLAGS := --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem +C_FLAGS += -O0 -g -Wall -Wextra -Werror +CPP_FLAGS += $(addprefix -I, $(INCLUDES)) +CHECK_FLAGS = --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem C_SRCS = $(wildcard $(SRC_DIR)/*.c) C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS))) @@ -42,6 +45,14 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) .PHONY: all 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 + $(GENHTML) -o coverage/html test.info + .PHONY: unit_test build_unit_test: $(UNIT_TEST_TARGET) @@ -51,7 +62,7 @@ exec_unit_test: $(UNIT_TEST_TARGET) .PHONY: check 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) @mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR)