Skip to content

Commit 96f6d87

Browse files
committed
makefiles: add gcov
1 parent 39c7b98 commit 96f6d87

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

makefiles/arch/native.inc.mk

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ else
1010
DEBUGGER ?= gdb
1111
endif
1212

13+
GCOV_DIR := $(BINDIR)/gcov_files
1314

1415
export VALGRIND ?= valgrind
1516
export CGANNOTATE ?= cg_annotate
1617
export GPROF ?= gprof
18+
export GCOV ?= gcov
19+
export GCOVR ?= gcovr
1720

1821
# basic cflags:
1922
CFLAGS += -Wall -Wextra $(CFLAGS_DBG) $(CFLAGS_OPT)
@@ -110,11 +113,14 @@ debug-valgrind-server: export VALGRIND_FLAGS ?= --vgdb=yes --vgdb-error=0 -v \
110113
term-cachegrind: export CACHEGRIND_FLAGS += --tool=cachegrind
111114
term-gprof: TERMPROG = $(ELFFILE)
112115
term-gprof: TERMENV += GMON_OUT_PREFIX=gmon.out
116+
term-gcov: TERMPROG = $(ELFFILE)
113117

114118
all-valgrind: CFLAGS += -DHAVE_VALGRIND_H
115119
all-valgrind: NATIVEINCLUDES += $(shell pkg-config valgrind --cflags)
116120
all-gprof: CFLAGS += -pg
117121
all-gprof: LINKFLAGS += -pg
122+
all-gcov: CFLAGS += --coverage -fprofile-arcs
123+
all-gcov: LINKFLAGS += --coverage -fprofile-arcs
118124

119125
CFLAGS_ASAN += -fsanitize=address -fno-omit-frame-pointer -DNATIVE_MEMORY
120126
LINKFLAGS_ASAN += -fsanitize=address -fno-omit-frame-pointer
@@ -143,6 +149,8 @@ all: # do not override first target
143149

144150
all-gprof: all
145151

152+
all-gcov: all
153+
146154
all-asan: all
147155

148156
all-valgrind: all
@@ -165,8 +173,33 @@ term-cachegrind:
165173

166174
term-gprof: term
167175

176+
term-gcov: term
177+
168178
eval-gprof:
169179
$(GPROF) $(ELFFILE) $(shell ls -rt gmon.out* | tail -1)
170180

181+
# gcov needs the source file and the .gcno file
182+
# It is not easy to know the source file by the object file.
183+
# The trick is to extract the source file by the .d file
184+
eval-gcov: $(GCOV_DIR)
185+
@find $(BINDIR) -name '*.gcno' | while read gcno; do \
186+
dep=$$(echo $$gcno | sed 's/\.gcno$$/.d/'); \
187+
src=$$(grep '\.c \\' $$dep); \
188+
src=$$(echo $$src | sed 's/.* \///; s/\\$$//'); \
189+
cd -P $(GCOV_DIR) && $(GCOV) -abcdfHkp $$src $$gcno; \
190+
done
191+
192+
$(GCOV_DIR)/gcovr.cfg: $(GCOV_DIR)
193+
@echo "root = $(RIOTBASE)" > $@
194+
@echo "object-directory = $(BINDIR)" >> $@
195+
196+
eval-gcovr: $(GCOV_DIR)/gcovr.cfg
197+
$(GCOVR) --config $(GCOV_DIR)/gcovr.cfg \
198+
--html-details --html $(GCOV_DIR)/index.html
199+
xdg-open $(GCOV_DIR)/index.html
200+
201+
$(GCOV_DIR):
202+
$(Q)mkdir -p $(GCOV_DIR)
203+
171204
eval-cachegrind:
172205
$(CGANNOTATE) $(shell ls -rt cachegrind.out* | tail -1)

0 commit comments

Comments
 (0)