Skip to content

Commit 38f84ce

Browse files
Don't actually CHECK in tests in COVERAGE mode
1 parent be2df91 commit 38f84ce

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/util.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *
2525
cb->fn(text, (void*)cb->data);
2626
}
2727

28-
#ifdef DETERMINISTIC
28+
#if defined(COVERAGE)
29+
/* Do nothing in COVERAGE mode. This will make the compiler optimize away the actual branch,
30+
and we get useful branch coverage within our test files. */
31+
#define TEST_FAILURE(msg)
32+
#elif defined(DETERMINISTIC)
2933
#define TEST_FAILURE(msg) do { \
3034
fprintf(stderr, "%s\n", msg); \
3135
abort(); \
@@ -43,7 +47,17 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *
4347
#define EXPECT(x,c) (x)
4448
#endif
4549

46-
#ifdef DETERMINISTIC
50+
/* CHECK() is like assert(). We use it only in the tests. */
51+
#if defined(COVERAGE)
52+
/* Don't abort in coverage mode.
53+
This avoids branches which are not expected to be taken.
54+
We still use cond as usual to avoid unused variable warnings. */
55+
#define CHECK(cond) do { \
56+
if (EXPECT(!(cond), 0)) { \
57+
; \
58+
} \
59+
} while (0)
60+
#elif defined(DETERMINISTIC)
4761
#define CHECK(cond) do { \
4862
if (EXPECT(!(cond), 0)) { \
4963
TEST_FAILURE("test condition failed"); \

0 commit comments

Comments
 (0)