WIP: test: Add thread-safe fast-failing test macros

bitcoin/bitcoin: PR #35139

3 minor findings · 2 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · ASSERT_EQ_COLLECTIONS can pass for unequal mixed-sign integers

Unlike scalar checks, ASSERT_EQ_COLLECTIONS can accept unequal mixed-sign integer elements; no current caller with mixed-sign element types was found.

Location: src/test/util/common.h:221 (head).

Details and suggested fix

check_eq_collections calls std::ranges::mismatch(lhs, rhs) with default equality, bypassing the signedness guard in check_op. Consequently, comparing std::vector<int>{-1} with std::vector<unsigned>{UINT_MAX} compiles and passes: the element comparison converts -1 to UINT_MAX. The current collection callers use matching byte-element types and are unaffected. Apply the same post-promotion signedness guard to std::ranges::range_value_t<L> and std::ranges::range_value_t<R> before calling mismatch.


Link

[minor] · Failed-assertion formatting can read past a non-terminated char array

Formatting a failed test assertion can read beyond a non-terminated char[N]; no current caller supplying such an array was found, and no failure was observed.

Location: src/test/util/common.h:169 (head).

Details and suggested fix

The bounded char-array branch passes value to make_printable(std::string_view). That conversion measures a null-terminated string rather than using the array extent. For example, ASSERT_EQ on two distinct non-terminated character arrays compares their addresses, then scans beyond an array while formatting the failure instead of safely producing the diagnostic. Deduction through const T& admits mutable arrays too. Bound the terminator search by std::extent_v<T> and construct the view with that bounded length.


Link

[minor] · ASSERT_EQ compares two C strings by address

Equal C strings at different addresses fail ASSERT_EQ and abort the test; no current caller comparing two C-string operands was found, so no such failure has been observed.

Location: src/test/util/common.h:276 (head).

Details and suggested fix

ASSERT_EQ applies std::equal_to<> directly, so two const char* operands or character arrays compare by address, not content. Two separate arrays initialized with the same text therefore fail, even though the formatter explicitly tolerates these types “to compare strings.” Comparisons involving std::string or std::string_view, including the migrated HexStr(raw) comparison, are unaffected. Reject the two-C-string combination with a static_assert directing callers to use std::string_view, rather than silently accepting address equality as a string check.


Optional improvements

Link

[suggestion] · ASSERT_EQ_COLLECTIONS accepts constraints that its const parameters cannot satisfy

Source inspection shows that ASSERT_EQ_COLLECTIONS accepts a filter_view constraint but cannot iterate the view through its const parameters; no current caller uses such a view, and no compilation failure was observed.

Location: src/test/util/common.h:218 (head).

Details and suggested fix

check_eq_collections constrains L and R as forward ranges, then takes const L& and const R&. A std::ranges::filter_view has no const begin(), so a natural call such as ASSERT_EQ_COLLECTIONS(v | std::views::filter(pred), expected) fails inside std::ranges::mismatch despite satisfying the declared constraint. Take the ranges as forwarding references, L&& and R&&, so these views work without making the existing container callers copy or change behavior.


Link

[suggestion] · Two checks in streams_scoped_data_stream_usage still continue after failure

The migration leaves two non-fatal BOOST_CHECK_GT assertions in streams_tests.cpp, so these checks retain different failure behavior from the converted assertions.

Location: src/test/streams_tests.cpp:99 (head).

Details and suggested fix

Both BOOST_CHECK_GT(stream.size(), 0U) calls remain unchanged because the word-bounded ren BOOST_CHECK ASSERT rule does not match BOOST_CHECK_GT. Add ren BOOST_CHECK_GT ASSERT_GT to the verify script to complete this conversion. ASSERT_GT is already available, and both operands are unsigned, so its mixed-signedness guard permits these calls.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Exception-based check handling was explicitly introduced so tests could intentionally trigger failures without aborting, consistently across build configurations.

The May 2025 commit introducing test_only_CheckFailuresAreExceptionsNotAborts states this purpose and uses it to test Assume(false), Assert(false), and CHECK_NONFATAL(false). This establishes a deliberate testability requirement for failures in the code under test. It does not establish that an unsuccessful test assertion must itself remain recoverable.

Source 1

When CHECK_NONFATAL gained abort behavior in debug builds, the accompanying changes preserved intentional-failure tests rather than treating their aborts as ordinary fuzz discoveries.

The historical change forced exceptions for RPC unit tests and for the fuzz target's test-only echo RPC, explicitly to avoid aborting fuzzing on an intentional trigger_internal_bug. A separate functional test accepted either a checked process crash or an RPC exception. The rationale therefore distinguishes expected failures being exercised from unexpected failures detected by a test.

Source 1