Skip to content
Snippets Groups Projects
Commit c9de6bf5 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

unit tests: add coverage targets

parent 87b8669a
No related branches found
No related tags found
No related merge requests found
...@@ -6,14 +6,13 @@ TARGETS += sysctl ...@@ -6,14 +6,13 @@ TARGETS += sysctl
# Makefile to avoid test build failures when test # Makefile to avoid test build failures when test
# Makefile doesn't have explicit build rules. # Makefile doesn't have explicit build rules.
CFLAGS += -fprofile-arcs -ftest-coverage
export CFLAGS = -fprofile-arcs -ftest-coverage
export LDFLAGS = -lgcov --coverage
ifeq (1,$(MAKELEVEL)) ifeq (1,$(MAKELEVEL))
override LDFLAGS =
override MAKEFLAGS = override MAKEFLAGS =
else else
export CFLAGS
export LDFLAGS = -lgcov --coverage
endif endif
...@@ -26,9 +25,20 @@ run_tests: all ...@@ -26,9 +25,20 @@ run_tests: all
for TARGET in $(TARGETS); do \ for TARGET in $(TARGETS); do \
make -C $$TARGET run_tests; \ make -C $$TARGET run_tests; \
done; done;
clean:
coverage_tests: all
for TARGET in $(TARGETS); do \
make -C $$TARGET coverage_tests; \
done;
clean_coverage:
for TARGET in $(TARGETS); do \
make -C $$TARGET clean_coverage; \
done;
clean: clean_coverage
for TARGET in $(TARGETS); do \ for TARGET in $(TARGETS); do \
make -C $$TARGET clean; \ make -C $$TARGET clean; \
done; done;
.PHONY: install .PHONY:
...@@ -16,13 +16,24 @@ endef ...@@ -16,13 +16,24 @@ endef
run_tests: all run_tests: all
$(RUN_TESTS) $(RUN_TESTS)
define EMIT_TESTS define COVERAGE_TESTS
@for TEST in $(TEST_PROGS); do \ @for TEST in $(TEST_PROGS); do \
echo "(./$$TEST && echo \"selftests: $$TEST [PASS]\") || echo \"selftests: $$TEST [FAIL]\""; \ lcov --rc lcov_branch_coverage=1 --capture --directory ./ --output-file coverage.info; \
genhtml --branch-coverage coverage.info --output-directory out; \
done; done;
endef endef
emit_tests: coverage_tests: run_tests
$(EMIT_TESTS) $(COVERAGE_TESTS)
.PHONY: run_tests all clean emit_tests
define CLEAN_COVERAGE
@for TEST in $(TEST_PROGS); do \
$(RM) -r $$TEST $$TEST.gcno $$TEST.gcda coverage.info out/; \
done;
endef
clean_coverage:
$(CLEAN_COVERAGE)
.PHONY: run_tests all clean coverage_tests clean_coverage
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment