-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile.am.coverage
84 lines (74 loc) · 3.16 KB
/
Makefile.am.coverage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Build rules for measuring coverage
COVERAGE_INFO_FILE = $(top_builddir)/coverage.info
COVERAGE_REPORT_DIR = $(top_builddir)/coverage
.PHONY: coverage-requirement-check \
coverage coverage-build coverage-check coverage-report \
clean-coverage-report clean-coverage clean-coverage-hook-for-clean-local
coverage-requirement-check:
@if test ! -e $(GCOV); then \
echo "Cannot find $(GCOV). Please install gcov."; \
exit 1; \
fi
@if test ! -e $(LCOV); then \
echo "Cannot find $(LCOV). Please install lcov."; \
exit 1; \
fi
@if test ! -e $(GENHTML); then \
echo "Cannot find $(GENHTML). Please install lcov."; \
exit 1; \
fi
coverage: coverage-requirement-check clean-coverage coverage-build coverage-check coverage-report
@echo "Please execute 'make clean' before 'make' or 'make check' to remove instrumented object files(compiled with -O0 etc.). Note that 'make clean' also remove coverage data."
coverage-build: coverage-requirement-check
@if test `find $(top_builddir) -name "*.gcno" | wc -l` -eq 0; then \
echo "Start to remove old non-instrumented object files..."; \
$(MAKE) $(AM_MAKEFLAGS) clean; \
echo "Successfully removed old non-instrumented object files."; \
fi
@echo "Start to build libraries with coverage options..."
$(MAKE) $(AM_MAKEFLAGS) \
CFLAGS="$(CFLAGS) $(COVERAGE_CFLAGS) $(COVERAGE_OPTFLAGS)" \
CXXFLAGS="$(CXXFLAGS) $(COVERAGE_CXXFLAGS) $(COVERAGE_OPTFLAGS)" \
LDFLAGS="$(LDFLAGS) $(COVERAGE_LDFLAGS)" \
LIBS="$(LIBS) $(COVERAGE_LIBS)"
@echo "Successfully built libraries with coverage options."
coverage-check: coverage-requirement-check
@echo "Start to run tests with instrumented libraries..."
$(MAKE) $(AM_MAKEFLAGS) check \
CFLAGS="$(CFLAGS) $(COVERAGE_CFLAGS) $(COVERAGE_OPTFLAGS)" \
CXXFLAGS="$(CXXFLAGS) $(COVERAGE_CXXFLAGS) $(COVERAGE_OPTFLAGS)" \
LDFLAGS="$(LDFLAGS) $(COVERAGE_LDFLAGS)" \
LIBS="$(LIBS) $(COVERAGE_LIBS)"
@echo "Successfully run tests with instrumented libraries."
coverage-report: coverage-requirement-check
@echo "Start to create coverage reports..."
$(LCOV) -c -i -d "./src/" -d "./tests" -o coverage_baseline.info
$(LCOV) --capture \
--directory "./src" \
--directory "./tests" \
--output-file coverage_test.info \
--gcov-tool $(GCOV) \
--compat-libtool --checksum
$(LCOV) -a coverage_baseline.info -a coverage_test.info -o $(COVERAGE_INFO_FILE)
$(LCOV) --extract $(COVERAGE_INFO_FILE) "*/src/*" \
--extract $(COVERAGE_INFO_FILE) "*/tests/*" \
--gcov-tool $(GCOV) \
--output-file $(COVERAGE_INFO_FILE)
$(GENHTML) --prefix "$(abs_top_srcdir)" \
--output-directory $(COVERAGE_REPORT_DIR) \
--title $(PACKAGE_NAME) \
--legend --show-details \
$(GENHTML_OPTIONS) \
$(COVERAGE_INFO_FILE)
@echo "Successfully created coverage reports into $(COVERAGE_REPORT_DIR) directory."
clean-coverage-report:
-rm -rf $(COVERAGE_INFO_FILE)
-rm -rf $(COVERAGE_REPORT_DIR)
clean-coverage: clean-coverage-report
-$(LCOV) --gcov-tool $(GCOV) --zerocounters --directory $(top_builddir)
@if xargs --version 2>/dev/null; then \
find $(top_builddir) -name "*.gcno" | xargs --no-run-if-empty rm; \
else \
find $(top_builddir) -name "*.gcno" | xargs rm; \
fi
clean-local: clean-coverage