Skip to content

Commit 14fec63

Browse files
committedMar 18, 2025
Merge bitcoin#32059: test: Update coverage.cpp to drop linux restriction
54e6eac test: Enable ResetCoverageCounters beyond Linux (janb84) Pull request description: In PR [bitcoin#31901](bitcoin#31901), Coverage.cpp was introduced as a separate utility file, based on existing code. However, the macro defined in Coverage.cpp was limited to Clang and Linux, which caused issues for users on macOS when using the newly introduced deterministic test tooling. This change adds fallback functions which are used when building without code coverage on non linux env. This adds support for macOS to ResetCoverageCounters. ResetCoverageCounters is used by the unit tests in `g_rng_temp_path_init` to support the deterministic unit test tooling. It is also used in fuzz tests to completely suppress coverage from anything init-related. See [Readme](https://github.com/bitcoin/bitcoin/blob/master/contrib/devtools/README.md) on how to test this for deterministic unit & fuzz test. Suggestion for test files: - for unit test: `util_string_tests` - for fuzz test: `addition_overflow ` These files should give deterministic results ACKs for top commit: maflcko: review-only ACK 54e6eac hodlinator: re-ACK 54e6eac Tree-SHA512: dd71da6f76d4fc9e64bf521bbfe5e7483d77c2ca0380f9e692502e64b529068ea33f21b19399481feb7c6780a23d893d8b7f733cef641a2db18a13397c98deea
2 parents ece0b41 + 54e6eac commit 14fec63

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed
 

‎src/test/util/coverage.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44

55
#include <test/util/coverage.h>
66

7-
#if defined(__clang__) && defined(__linux__)
8-
extern "C" void __llvm_profile_reset_counters(void) __attribute__((weak));
9-
extern "C" void __gcov_reset(void) __attribute__((weak));
7+
#if defined(__clang__)
8+
extern "C" __attribute__((weak)) void __llvm_profile_reset_counters(void);
9+
extern "C" __attribute__((weak)) void __gcov_reset(void);
1010

11-
void ResetCoverageCounters()
12-
{
13-
if (__llvm_profile_reset_counters) {
14-
__llvm_profile_reset_counters();
15-
}
11+
// Fallback implementations
12+
extern "C" __attribute__((weak)) void __llvm_profile_reset_counters(void) {}
13+
extern "C" __attribute__((weak)) void __gcov_reset(void) {}
1614

17-
if (__gcov_reset) {
18-
__gcov_reset();
19-
}
15+
void ResetCoverageCounters() {
16+
// These will call the real ones if available, or our dummies if not
17+
__llvm_profile_reset_counters();
18+
__gcov_reset();
2019
}
2120
#else
2221
void ResetCoverageCounters() {}

0 commit comments

Comments
 (0)