Compare commits
1 Commits
cd66f01149
...
862ebe5fae
Author | SHA1 | Date | |
---|---|---|---|
|
862ebe5fae |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
|
coverage/
|
||||||
|
19
.vscode/tasks.json
vendored
19
.vscode/tasks.json
vendored
@ -74,7 +74,24 @@
|
|||||||
{
|
{
|
||||||
"label": "exec_unit_test",
|
"label": "exec_unit_test",
|
||||||
"type":"shell",
|
"type":"shell",
|
||||||
"command": "make exec_unit_test",
|
"command": "make exec_unit_test -j1",
|
||||||
|
"problemMatcher": {
|
||||||
|
"base": "$gcc",
|
||||||
|
"owner": "gcc",
|
||||||
|
"fileLocation": [
|
||||||
|
"relative",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "coverage",
|
||||||
|
"type":"shell",
|
||||||
|
"command": "make coverage -j1",
|
||||||
"problemMatcher": {
|
"problemMatcher": {
|
||||||
"base": "$gcc",
|
"base": "$gcc",
|
||||||
"owner": "gcc",
|
"owner": "gcc",
|
||||||
|
43
Makefile
43
Makefile
@ -5,26 +5,32 @@ 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
|
||||||
|
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)
|
||||||
|
|
||||||
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 += --coverage
|
||||||
|
L_FLAGS += --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 +48,25 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
|||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
.PHONY: coverage
|
||||||
|
coverage: _cov_genhtml
|
||||||
|
$(eval COVERAGE:=$(shell grep 'lines' .coverage.tmp | egrep -o '[0-9]+.[0-9]+%'))
|
||||||
|
@echo
|
||||||
|
@echo Line coverage: $(COVERAGE)
|
||||||
|
@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)
|
||||||
|
|
||||||
@ -51,7 +76,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)
|
||||||
@ -81,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))
|
||||||
|
Loading…
Reference in New Issue
Block a user