Skip to content

Commit c8914b9

Browse files
committed
Have make cov optionally include branch coverage statistics
Added an option to configure to allow for branch coverage statistics gathering. Disabled logprint macro when coverage testing is on so that unnecessary branches are not analyzed.
1 parent 46311e7 commit c8914b9

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

Makefile.am

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,47 +171,47 @@ baseline.info:
171171
$(LCOV) -c -i -d $(abs_builddir)/src -o $@
172172

173173
baseline_filtered.info: baseline.info
174-
$(LCOV) -r $< "/usr/include/*" -o $@
174+
$(LCOV) -r $< "/usr/include/*" $(LCOV_OPTS) -o $@
175175

176176
leveldb_baseline.info: baseline_filtered.info
177177
$(LCOV) -c -i -d $(abs_builddir)/src/leveldb -b $(abs_builddir)/src/leveldb -o $@
178178

179179
leveldb_baseline_filtered.info: leveldb_baseline.info
180-
$(LCOV) -r $< "/usr/include/*" -o $@
180+
$(LCOV) -r $< "/usr/include/*" $(LCOV_OPTS) -o $@
181181

182182
baseline_filtered_combined.info: leveldb_baseline_filtered.info baseline_filtered.info
183-
$(LCOV) -a leveldb_baseline_filtered.info -a baseline_filtered.info -o $@
183+
$(LCOV) -a $(LCOV_OPTS) leveldb_baseline_filtered.info -a baseline_filtered.info -o $@
184184

185185
test_bitcoin.info: baseline_filtered_combined.info
186186
$(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
187+
$(LCOV) -c $(LCOV_OPTS) -d $(abs_builddir)/src -t test_bitcoin -o $@
188+
$(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src
189+
$(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src/leveldb
190190

191191
test_bitcoin_filtered.info: test_bitcoin.info
192-
$(LCOV) -r $< "/usr/include/*" -o $@
192+
$(LCOV) -r $< "/usr/include/*" $(LCOV_OPTS) -o $@
193193

194194
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
195+
-@TIMEOUT=15 test/functional/test_runner.py $(EXTENDED_FUNCTIONAL_TESTS)
196+
$(LCOV) -c $(LCOV_OPTS) -d $(abs_builddir)/src --t functional-tests -o $@
197+
$(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src
198+
$(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src/leveldb
199199

200200
functional_test_filtered.info: functional_test.info
201-
$(LCOV) -r $< "/usr/include/*" -o $@
201+
$(LCOV) -r $< "/usr/include/*" $(LCOV_OPTS) -o $@
202202

203203
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 $@
204+
$(LCOV) -a $(LCOV_OPTS) baseline_filtered.info -a leveldb_baseline_filtered.info -a test_bitcoin_filtered.info -o $@
205205

206206
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
207+
$(LCOV) -a $(LCOV_OPTS) 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
208208

209209
test_bitcoin.coverage/.dirstamp: test_bitcoin_coverage.info
210-
$(GENHTML) -s $< -o $(@D)
210+
$(GENHTML) -s $(LCOV_OPTS) $< -o $(@D)
211211
@touch $@
212212

213213
total.coverage/.dirstamp: total_coverage.info
214-
$(GENHTML) -s $< -o $(@D)
214+
$(GENHTML) -s $(LCOV_OPTS) $< -o $(@D)
215215
@touch $@
216216

217217
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],
@@ -436,6 +442,12 @@ if test x$use_lcov = xyes; then
436442
[AC_MSG_ERROR("lcov testing requested but --coverage linker flag does not work")])
437443
AX_CHECK_COMPILE_FLAG([--coverage],[CXXFLAGS="$CXXFLAGS --coverage"],
438444
[AC_MSG_ERROR("lcov testing requested but --coverage flag does not work")])
445+
AC_DEFINE(USE_COVERAGE, 1, [Define this symbol if coverage is enabled])
446+
CXXFLAGS="$CXXFLAGS -Og"
447+
fi
448+
449+
if test x$use_lcov_branch != xno; then
450+
AC_SUBST(LCOV_OPTS, "$LCOV_OPTS --rc lcov_branch_coverage=1")
439451
fi
440452

441453
dnl Check for endianness

src/util.h

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

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

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

0 commit comments

Comments
 (0)