Skip to content

Commit a724d72

Browse files
committed
configure: add --enable-coverage to set options for coverage analysis
1 parent b595163 commit a724d72

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

Makefile.am

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ TESTS =
9393
if USE_TESTS
9494
noinst_PROGRAMS += tests
9595
tests_SOURCES = src/tests.c
96-
tests_CPPFLAGS = -DSECP256K1_BUILD -DVERIFY -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
96+
tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
97+
if !ENABLE_COVERAGE
98+
tests_CPPFLAGS += -DVERIFY
99+
endif
97100
tests_LDADD = $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
98101
tests_LDFLAGS = -static
99102
TESTS += tests
@@ -102,7 +105,10 @@ endif
102105
if USE_EXHAUSTIVE_TESTS
103106
noinst_PROGRAMS += exhaustive_tests
104107
exhaustive_tests_SOURCES = src/tests_exhaustive.c
105-
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -DVERIFY -I$(top_srcdir)/src $(SECP_INCLUDES)
108+
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES)
109+
if !ENABLE_COVERAGE
110+
exhaustive_tests_CPPFLAGS += -DVERIFY
111+
endif
106112
exhaustive_tests_LDADD = $(SECP_LIBS)
107113
exhaustive_tests_LDFLAGS = -static
108114
TESTS += exhaustive_tests

configure.ac

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ AC_PATH_TOOL(STRIP, strip)
2020
AX_PROG_CC_FOR_BUILD
2121

2222
if test "x$CFLAGS" = "x"; then
23-
CFLAGS="-O3 -g"
23+
CFLAGS="-g"
2424
fi
2525

2626
AM_PROG_CC_C_O
@@ -89,6 +89,11 @@ AC_ARG_ENABLE(benchmark,
8989
[use_benchmark=$enableval],
9090
[use_benchmark=no])
9191

92+
AC_ARG_ENABLE(coverage,
93+
AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis]),
94+
[enable_coverage=$enableval],
95+
[enable_coverage=no])
96+
9297
AC_ARG_ENABLE(tests,
9398
AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
9499
[use_tests=$enableval],
@@ -154,6 +159,14 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])],
154159
[ AC_MSG_RESULT([no])
155160
])
156161

162+
if test x"$enable_coverage" = x"yes"; then
163+
AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
164+
CFLAGS="$CFLAGS -O0 --coverage"
165+
LDFLAGS="--coverage"
166+
else
167+
CFLAGS="$CFLAGS -O3"
168+
fi
169+
157170
if test x"$use_ecmult_static_precomputation" != x"no"; then
158171
save_cross_compiling=$cross_compiling
159172
cross_compiling=no
@@ -434,6 +447,7 @@ AC_MSG_NOTICE([Using field implementation: $set_field])
434447
AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
435448
AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
436449
AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
450+
AC_MSG_NOTICE([Building for coverage analysis: $enable_coverage])
437451
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
438452
AC_MSG_NOTICE([Building ECDSA pubkey recovery module: $enable_module_recovery])
439453
AC_MSG_NOTICE([Using jni: $use_jni])
@@ -460,6 +474,7 @@ AC_SUBST(SECP_INCLUDES)
460474
AC_SUBST(SECP_LIBS)
461475
AC_SUBST(SECP_TEST_LIBS)
462476
AC_SUBST(SECP_TEST_INCLUDES)
477+
AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"])
463478
AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
464479
AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$use_exhaustive_tests" != x"no"])
465480
AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])

src/util.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *
5757
#endif
5858

5959
/* Like assert(), but when VERIFY is defined, and side-effect safe. */
60-
#ifdef VERIFY
60+
#if defined(COVERAGE)
61+
#define VERIFY_CHECK(check)
62+
#define VERIFY_SETUP(stmt)
63+
#elif defined(VERIFY)
6164
#define VERIFY_CHECK CHECK
6265
#define VERIFY_SETUP(stmt) do { stmt; } while(0)
6366
#else

0 commit comments

Comments
 (0)