-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve precision of code coverage and add report to CI #954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
af0b3e6
be2df91
38f84ce
249cdee
6b8dd8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,11 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback * | |
cb->fn(text, (void*)cb->data); | ||
} | ||
|
||
#ifdef DETERMINISTIC | ||
#if defined(COVERAGE) | ||
/* Do nothing in COVERAGE mode. This will make the compiler optimize away the actual branch, | ||
and we get useful branch coverage within our test files. */ | ||
#define TEST_FAILURE(msg) | ||
#elif defined(DETERMINISTIC) | ||
#define TEST_FAILURE(msg) do { \ | ||
fprintf(stderr, "%s\n", msg); \ | ||
abort(); \ | ||
|
@@ -43,7 +47,17 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback * | |
#define EXPECT(x,c) (x) | ||
#endif | ||
|
||
#ifdef DETERMINISTIC | ||
/* CHECK() is like assert(). We use it only in the tests. */ | ||
#if defined(COVERAGE) | ||
/* Don't abort in coverage mode. | ||
This avoids branches which are not expected to be taken. | ||
We still use cond as usual to avoid unused variable warnings. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/unused variable/unused return values/ (or actually both, but the "unused variables" can be suppressed by casting to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps also note that this works because an if statement with an empty consequent is not treated as a branch. |
||
#define CHECK(cond) do { \ | ||
if (EXPECT(!(cond), 0)) { \ | ||
; \ | ||
} \ | ||
} while (0) | ||
#elif defined(DETERMINISTIC) | ||
#define CHECK(cond) do { \ | ||
if (EXPECT(!(cond), 0)) { \ | ||
TEST_FAILURE("test condition failed"); \ | ||
|
@@ -59,7 +73,11 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback * | |
|
||
/* Like assert(), but when VERIFY is defined, and side-effect safe. */ | ||
#if defined(COVERAGE) | ||
#define VERIFY_CHECK(check) | ||
/* Do nothing in coverage mode but try to stay syntactically correct. | ||
This suppresses a lot of implicit branches introduced by shortcutting | ||
operators at the cost of not being side-effect safe in coverage mode. | ||
We rely on the compiler to eliminate the if (0) statement entirely. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what GCC does. I can't really test with clang because the coverage report is empty, even though it should work with clang too when passing |
||
#define VERIFY_CHECK(cond) do { if (0) (void)(cond); } while(0) | ||
#define VERIFY_SETUP(stmt) | ||
#elif defined(VERIFY) | ||
#define VERIFY_CHECK CHECK | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be unnecessary now that the definition of CHECK is changed.