Skip to content

Commit 8c2098a

Browse files
committed
Merge #10565: [coverage] Remove subtrees and benchmarks from coverage report
d5711f4 Filter subtrees and and benchmarks from coverage report (Andrew Chow) 405b86a Replace lcov -r commands with faster way (Andrew Chow) c8914b9 Have `make cov` optionally include branch coverage statistics (Andrew Chow) Tree-SHA512: 9c349a7baeb7430ea586617c52f91177df58e3546d6dc573e26815ddb79e30ab1873542d85ac1daca5e1fb2c6d6c8965824b42d027b6b0496a744af57b095852
2 parents 6bef7ca + d5711f4 commit 8c2098a

File tree

4 files changed

+71
-29
lines changed

4 files changed

+71
-29
lines changed

Makefile.am

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ OSX_PACKAGING = $(OSX_DEPLOY_SCRIPT) $(OSX_FANCY_PLIST) $(OSX_INSTALLER_ICONS) \
5959
$(top_srcdir)/contrib/macdeploy/detached-sig-apply.sh \
6060
$(top_srcdir)/contrib/macdeploy/detached-sig-create.sh
6161

62-
COVERAGE_INFO = baseline_filtered_combined.info baseline.info \
63-
leveldb_baseline.info test_bitcoin_filtered.info total_coverage.info \
62+
COVERAGE_INFO = baseline.info \
63+
test_bitcoin_filtered.info total_coverage.info \
6464
baseline_filtered.info functional_test.info functional_test_filtered.info \
65-
leveldb_baseline_filtered.info test_bitcoin_coverage.info test_bitcoin.info
65+
test_bitcoin_coverage.info test_bitcoin.info
6666

6767
dist-hook:
6868
-$(GIT) archive --format=tar HEAD -- src/clientversion.cpp | $(AMTAR) -C $(top_distdir) -xf -
@@ -166,52 +166,45 @@ $(BITCOIN_CLI_BIN): FORCE
166166
$(MAKE) -C src $(@F)
167167

168168
if USE_LCOV
169+
LCOV_FILTER_PATTERN=-p "/usr/include/" -p "src/leveldb/" -p "src/bench/" -p "src/univalue" -p "src/crypto/ctaes" -p "src/secp256k1"
169170

170171
baseline.info:
171172
$(LCOV) -c -i -d $(abs_builddir)/src -o $@
172173

173174
baseline_filtered.info: baseline.info
174-
$(LCOV) -r $< "/usr/include/*" -o $@
175+
$(abs_builddir)/contrib/filter-lcov.py $(LCOV_FILTER_PATTERN) $< $@
176+
$(LCOV) -a $@ $(LCOV_OPTS) -o $@
175177

176-
leveldb_baseline.info: baseline_filtered.info
177-
$(LCOV) -c -i -d $(abs_builddir)/src/leveldb -b $(abs_builddir)/src/leveldb -o $@
178-
179-
leveldb_baseline_filtered.info: leveldb_baseline.info
180-
$(LCOV) -r $< "/usr/include/*" -o $@
181-
182-
baseline_filtered_combined.info: leveldb_baseline_filtered.info baseline_filtered.info
183-
$(LCOV) -a leveldb_baseline_filtered.info -a baseline_filtered.info -o $@
184-
185-
test_bitcoin.info: baseline_filtered_combined.info
178+
test_bitcoin.info: baseline_filtered.info
186179
$(MAKE) -C src/ check
187-
$(LCOV) -c -d $(abs_builddir)/src -t test_bitcoin -o $@
188-
$(LCOV) -z -d $(abs_builddir)/src
189-
$(LCOV) -z -d $(abs_builddir)/src/leveldb
180+
$(LCOV) -c $(LCOV_OPTS) -d $(abs_builddir)/src -t test_bitcoin -o $@
181+
$(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src
190182

191183
test_bitcoin_filtered.info: test_bitcoin.info
192-
$(LCOV) -r $< "/usr/include/*" -o $@
184+
$(abs_builddir)/contrib/filter-lcov.py $(LCOV_FILTER_PATTERN) $< $@
185+
$(LCOV) -a $@ $(LCOV_OPTS) -o $@
193186

194187
functional_test.info: test_bitcoin_filtered.info
195-
-@TIMEOUT=15 python test/functional/test_runner.py $(EXTENDED_FUNCTIONAL_TESTS)
196-
$(LCOV) -c -d $(abs_builddir)/src --t functional-tests -o $@
197-
$(LCOV) -z -d $(abs_builddir)/src
198-
$(LCOV) -z -d $(abs_builddir)/src/leveldb
188+
-@TIMEOUT=15 test/functional/test_runner.py $(EXTENDED_FUNCTIONAL_TESTS)
189+
$(LCOV) -c $(LCOV_OPTS) -d $(abs_builddir)/src --t functional-tests -o $@
190+
$(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src
199191

200192
functional_test_filtered.info: functional_test.info
201-
$(LCOV) -r $< "/usr/include/*" -o $@
193+
$(abs_builddir)/contrib/filter-lcov.py $(LCOV_FILTER_PATTERN) $< $@
194+
$(LCOV) -a $@ $(LCOV_OPTS) -o $@
202195

203-
test_bitcoin_coverage.info: baseline_filtered_combined.info test_bitcoin_filtered.info
204-
$(LCOV) -a baseline_filtered.info -a leveldb_baseline_filtered.info -a test_bitcoin_filtered.info -o $@
196+
test_bitcoin_coverage.info: baseline_filtered.info test_bitcoin_filtered.info
197+
$(LCOV) -a $(LCOV_OPTS) baseline_filtered.info -a test_bitcoin_filtered.info -o $@
205198

206-
total_coverage.info: baseline_filtered_combined.info test_bitcoin_filtered.info functional_test_filtered.info
207-
$(LCOV) -a baseline_filtered.info -a leveldb_baseline_filtered.info -a test_bitcoin_filtered.info -a functional_test_filtered.info -o $@ | $(GREP) "\%" | $(AWK) '{ print substr($$3,2,50) "/" $$5 }' > coverage_percent.txt
199+
total_coverage.info: test_bitcoin_filtered.info functional_test_filtered.info
200+
$(LCOV) -a $(LCOV_OPTS) baseline_filtered.info -a test_bitcoin_filtered.info -a functional_test_filtered.info -o $@ | $(GREP) "\%" | $(AWK) '{ print substr($$3,2,50) "/" $$5 }' > coverage_percent.txt
208201

209202
test_bitcoin.coverage/.dirstamp: test_bitcoin_coverage.info
210-
$(GENHTML) -s $< -o $(@D)
203+
$(GENHTML) -s $(LCOV_OPTS) $< -o $(@D)
211204
@touch $@
212205

213206
total.coverage/.dirstamp: total_coverage.info
214-
$(GENHTML) -s $< -o $(@D)
207+
$(GENHTML) -s $(LCOV_OPTS) $< -o $(@D)
215208
@touch $@
216209

217210
cov: test_bitcoin.coverage/.dirstamp total.coverage/.dirstamp

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ AC_ARG_ENABLE([lcov],
158158
[enable lcov testing (default is no)])],
159159
[use_lcov=yes],
160160
[use_lcov=no])
161+
162+
AC_ARG_ENABLE([lcov-branch-coverage],
163+
[AS_HELP_STRING([--enable-lcov-branch-coverage],
164+
[enable lcov testing branch coverage (default is no)])],
165+
[use_lcov_branch=yes],
166+
[use_lcov_branch=no])
161167

162168
AC_ARG_ENABLE([glibc-back-compat],
163169
[AS_HELP_STRING([--enable-glibc-back-compat],
@@ -442,6 +448,12 @@ if test x$use_lcov = xyes; then
442448
[AC_MSG_ERROR("lcov testing requested but --coverage linker flag does not work")])
443449
AX_CHECK_COMPILE_FLAG([--coverage],[CXXFLAGS="$CXXFLAGS --coverage"],
444450
[AC_MSG_ERROR("lcov testing requested but --coverage flag does not work")])
451+
AC_DEFINE(USE_COVERAGE, 1, [Define this symbol if coverage is enabled])
452+
CXXFLAGS="$CXXFLAGS -Og"
453+
fi
454+
455+
if test x$use_lcov_branch != xno; then
456+
AC_SUBST(LCOV_OPTS, "$LCOV_OPTS --rc lcov_branch_coverage=1")
445457
fi
446458

447459
dnl Check for endianness

contrib/filter-lcov.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
5+
parser = argparse.ArgumentParser(description='Remove the coverage data from a tracefile for all files matching the pattern.')
6+
parser.add_argument('--pattern', '-p', action='append', help='the pattern of files to remove', required=True)
7+
parser.add_argument('tracefile', help='the tracefile to remove the coverage data from')
8+
parser.add_argument('outfile', help='filename for the output to be written to')
9+
10+
args = parser.parse_args()
11+
tracefile = args.tracefile
12+
pattern = args.pattern
13+
outfile = args.outfile
14+
15+
in_remove = False
16+
with open(tracefile, 'r') as f:
17+
with open(outfile, 'w') as wf:
18+
for line in f:
19+
for p in pattern:
20+
if line.startswith("SF:") and p in line:
21+
in_remove = True
22+
if not in_remove:
23+
wf.write(line)
24+
if line == 'end_of_record\n':
25+
in_remove = False

src/util.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ int LogPrintStr(const std::string &str);
122122
/** Get format string from VA_ARGS for error reporting */
123123
template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt, const Args&... args) { return fmt; }
124124

125+
static inline void MarkUsed() {}
126+
template<typename T, typename... Args> static inline void MarkUsed(const T& t, const Args&... args)
127+
{
128+
(void)t;
129+
MarkUsed(args...);
130+
}
131+
132+
#ifdef USE_COVERAGE
133+
#define LogPrintf(...) do { MarkUsed(__VA_ARGS__); } while(0)
134+
#define LogPrint(category, ...) do { MarkUsed(__VA_ARGS__); } while(0)
135+
#else
125136
#define LogPrintf(...) do { \
126137
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
127138
try { \
@@ -138,6 +149,7 @@ template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt,
138149
LogPrintf(__VA_ARGS__); \
139150
} \
140151
} while(0)
152+
#endif
141153

142154
template<typename... Args>
143155
bool error(const char* fmt, const Args&... args)

0 commit comments

Comments
 (0)