WIP: test: [NOMERGE,SKETCH] Add thread-safe fast-failing test macros #35139

Draft
maflcko wants to merge 3 commits from 2604-test-fail-fast-thread-safe-macros into master AGit
maflcko commented 2026-04-22 14:04:15 +00:00 (Migrated from github.com)

Currently, the unit tests use different boost check macros. However, this is problematic:

  • The check macros are tied to the boost test framework and can not be used in other tests, such as the fuzz tests.
  • The check macros are not overflow-safe. For example BOOST_CHECK_GT(-10, 10U); compiles and passes fine, even though it is obviously wrong.
  • The check macros are not thread-safe. Using them in a thread will compile fine, but then fail tsan later on. Usually it is trivial to replace them by a plain assert, but it would be better if the macros just worked under tsan.
  • The check macros are not fast-failing. This is confusing, as the test continues to run and will print more logs, making it harder to spot the first failure. Also, it is contrary to the internal check macros assert and Assert, and even CHECK_NONFATAL under debug mode, which all lead to an immediate abort.

Fix all issues by adding new check macros: ASSERT, ASSERT_EQ (and friends), ASSERT_EQ_COLLECTIONS (C++20 range-based), as well as ASSERT_EXCEPTION. They can be used as a drop-in replacement for the corresponding boost macro.

The implementation for all macros is only ~150 LOC, so it should be preferable to any external dependency addressing the above issues (which I couldn't find anyway).

(Tracking issue: https://github.com/bitcoin/bitcoin/issues/34666)

Note on naming (why ASSERT?)

The test macros follow the naming and semantics of the internal Bitcoin Core macros (assert, and Assert). While it may confusing to have three unary assert macros that do roughly the same, it should be harmless and any macro that compiles is fine to use. (There is a special edge case to Assert, which allows to be turned into an exception as part of g_detail_test_only_CheckFailuresAreExceptionsNotAborts, but this shouldn't matter much).

In theory, if devs didn't care about nice diagnostic messages on a failure (printing the left and right side), the macros could even be a direct alias of assert or Assert, reducing the LOC even more. Though, I think it is fine and preferable to have slightly better failure messages in tests.

Also, the naming and semantics follow the Bitcoin Core functional test macros, which also start with assert_.

Later optimizations

The macros are currently sitting in the header, but once they are applied to the whole codebase, the pretty-printing implementation can move to a cpp file, which reduces the weight of the header and makes it possible to change or add pretty-printing features without a whole re-compilation of all tests.

Currently, the unit tests use different boost check macros. However, this is problematic: * The check macros are tied to the boost test framework and can not be used in other tests, such as the fuzz tests. * The check macros are not overflow-safe. For example `BOOST_CHECK_GT(-10, 10U);` compiles and passes fine, even though it is obviously wrong. * The check macros are not thread-safe. Using them in a thread will compile fine, but then fail tsan later on. Usually it is trivial to replace them by a plain `assert`, but it would be better if the macros just worked under tsan. * The check macros are not fast-failing. This is confusing, as the test continues to run and will print more logs, making it harder to spot the first failure. Also, it is contrary to the internal check macros `assert` and `Assert`, and even `CHECK_NONFATAL` under debug mode, which all lead to an immediate abort. Fix all issues by adding new check macros: `ASSERT`, `ASSERT_EQ` (and friends), `ASSERT_EQ_COLLECTIONS` (C++20 range-based), as well as `ASSERT_EXCEPTION`. They can be used as a drop-in replacement for the corresponding boost macro. The implementation for all macros is only ~150 LOC, so it should be preferable to any external dependency addressing the above issues (which I couldn't find anyway). (Tracking issue: https://github.com/bitcoin/bitcoin/issues/34666) ### Note on naming (why `ASSERT`?) The test macros follow the naming and semantics of the internal Bitcoin Core macros (`assert`, and `Assert`). While it may confusing to have three unary `assert` macros that do *roughly* the same, it should be harmless and any macro that compiles is fine to use. (There is a special edge case to `Assert`, which allows to be turned into an exception as part of `g_detail_test_only_CheckFailuresAreExceptionsNotAborts`, but this shouldn't matter much). In theory, if devs didn't care about nice diagnostic messages on a failure (printing the left and right side), the macros could even be a direct alias of `assert` or `Assert`, reducing the LOC even more. Though, I think it is fine and preferable to have slightly better failure messages in tests. Also, the naming and semantics follow the Bitcoin Core functional test macros, which also start with `assert_`. ### Later optimizations The macros are currently sitting in the header, but once they are applied to the whole codebase, the pretty-printing implementation can move to a cpp file, which reduces the weight of the header and makes it possible to change or add pretty-printing features without a whole re-compilation of all tests.
DrahtBot commented 2026-04-22 14:04:52 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK sedited

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35003 (validation: improve block data I/O error handling in P2P paths by furszy)
  • #33324 (blocks: add resumable reobfuscation for existing block files by l0rinc)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35139 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35139.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35139#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [sedited](https://github.com/bitcoin/bitcoin/pull/35139#issuecomment-4904579293) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35003](https://github.com/bitcoin/bitcoin/pull/35003) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35003.svg"></sub> (validation: improve block data I/O error handling in P2P paths by furszy) * [#33324](https://github.com/bitcoin/bitcoin/pull/33324) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33324.svg"></sub> (blocks: add resumable reobfuscation for existing block files by l0rinc) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
maflcko commented 2026-04-22 15:42:33 +00:00 (Migrated from github.com)

To test the Tsan error, one can use this diff:

diff --git a/src/test/btcsignals_tests.cpp b/src/test/btcsignals_tests.cpp
index b3203ebeb2..43a68607a3 100644
--- a/src/test/btcsignals_tests.cpp
+++ b/src/test/btcsignals_tests.cpp
@@ -5,2 +5,3 @@
 #include <btcsignals.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
@@ -162,3 +163,3 @@ BOOST_AUTO_TEST_CASE(thread_safety)
         // a race inside of BOOST_CHECK itself (writing to the log).
-        assert(!sig0.empty());
+        ASSERT(!sig0.empty());
         assert(conn0.connected());

Tsan passes with ASSSERT or assert, or Assert, but fails with BOOST_CHECK when running this test.

To test the Tsan error, one can use this diff: ```diff diff --git a/src/test/btcsignals_tests.cpp b/src/test/btcsignals_tests.cpp index b3203ebeb2..43a68607a3 100644 --- a/src/test/btcsignals_tests.cpp +++ b/src/test/btcsignals_tests.cpp @@ -5,2 +5,3 @@ #include <btcsignals.h> +#include <test/util/common.h> #include <test/util/setup_common.h> @@ -162,3 +163,3 @@ BOOST_AUTO_TEST_CASE(thread_safety) // a race inside of BOOST_CHECK itself (writing to the log). - assert(!sig0.empty()); + ASSERT(!sig0.empty()); assert(conn0.connected()); ``` Tsan passes with `ASSSERT` or `assert`, or `Assert`, but fails with `BOOST_CHECK` when running this test. <!-- # Insert the required header sed --in-place '5i#include <test/util/common.h>' src/test/streams_tests.cpp # - Use range-based collection equality check sed --in-place --regexp-extended 's/BOOST_CHECK_EQUAL_COLLECTIONS\(([^.]+)\.begin\(\), \1\.end\(\), ([^.]+)\.begin\(\), \2\.end\(\)\)/ASSERT_EQ_COLLECTIONS(\1, \2)/g' src/test/streams_tests.cpp
maflcko commented 2026-04-22 20:11:44 +00:00 (Migrated from github.com)

To test the overall behavior, and compare it with the boost behavior, one can use this diff (it includes recommended instructions to run)

a diff to trigger different failures
diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp
index 9bf7f6f6fd..e6a4049328 100644
--- a/src/test/streams_tests.cpp
+++ b/src/test/streams_tests.cpp
@@ -17,6 +17,154 @@
 using namespace std::string_literals;
 using namespace util::hex_literals;
 
+// All suites below will fail
+// For testing, run them via Bash:
+// clang-format off
+// cmake --build ./bld-cmake --parallel && for s in Suite_Bool Suite_Equality Suite_Null Suite_Null2 Suite_Inequality Suite_LessThan Suite_GreaterThan Suite_LessEqual Suite_GreaterEqual Suite_Collections Suite_CollectionsEnd Suite_Exceptions Suite_ExceptionsWrongCatch Suite_ExceptionsWrongThrow; do valgrind ./bld-cmake/bin/test_bitcoin --catch_system_error=no -t $s; echo "Exit code: $?"; done
+// clang-format on
+BOOST_AUTO_TEST_SUITE(Suite_Bool)
+BOOST_AUTO_TEST_CASE(Test_Assert)
+{
+    short* condition{};
+    BOOST_CHECK(condition);
+    ASSERT(condition);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_Equality)
+BOOST_AUTO_TEST_CASE(Test_AssertEq)
+{
+    const char* a{"hi"};
+    std::cout << "Passes on both:\n";
+    BOOST_CHECK_EQUAL(a, "hi");
+    ASSERT_EQ(a, "hi");
+
+    std::cout << "Fails on the new macro (This check is stricter and will do pointer-compare)\n";
+    char b[3] = {'h', 'i', '\0'};
+    BOOST_CHECK_EQUAL(b, "hi");
+    using namespace std::literals;
+    ASSERT_EQ(b, "hi"); // Use "hi"sv or "hi"s instead
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_Null)
+BOOST_AUTO_TEST_CASE(Test_AssertNull)
+{
+    const char* a{"hi"};
+    BOOST_CHECK_EQUAL(a, nullptr);
+    ASSERT_EQ(a, nullptr);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_Null2)
+BOOST_AUTO_TEST_CASE(Test_AssertNull2)
+{
+    const char* a{};
+    BOOST_CHECK_EQUAL(a, "hi");
+    ASSERT_EQ(a, "hi");
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_Inequality)
+BOOST_AUTO_TEST_CASE(Test_AssertNe)
+{
+    bool a{true};
+    BOOST_CHECK_NE(a, true);
+    ASSERT_NE(a, true);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_LessThan)
+BOOST_AUTO_TEST_CASE(Test_AssertLt)
+{
+    BOOST_CHECK_LT(10, 5U);
+    ASSERT_LT(10U, 5U); // Checks at compile time that the same signdness is provided!
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_GreaterThan)
+BOOST_AUTO_TEST_CASE(Test_AssertGt)
+{
+    std::cout << "This should obviously fail, but boost passes!\n";
+    BOOST_CHECK_GT(-10, 10U);
+    // ASSERT_GT(-10, 10U); // does not compile
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_LessEqual)
+BOOST_AUTO_TEST_CASE(Test_AssertLe)
+{
+    BOOST_CHECK_LE(10.1, 5.1);
+    ASSERT_LE(10.1, 5.1);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_GreaterEqual)
+BOOST_AUTO_TEST_CASE(Test_AssertGe)
+{
+    BOOST_CHECK_GE(char{12}, 'a');
+    ASSERT_GE(char{12}, 'a');
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_Collections)
+BOOST_AUTO_TEST_CASE(Test_AssertCollections)
+{
+    std::vector<int> v1{1, 2, 3}, v2{1, 99, 3};
+    BOOST_CHECK_EQUAL_COLLECTIONS(v1.begin(), v1.end(), v2.begin(), v2.end());
+    ASSERT_EQ_COLLECTIONS(v1, v2);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_CollectionsEnd)
+BOOST_AUTO_TEST_CASE(Test_AssertCollectionsEnd)
+{
+    std::vector<NodeSeconds> v1{
+        NodeSeconds{1s},
+    },
+        v2{};
+    BOOST_CHECK_EQUAL_COLLECTIONS(v1.begin(), v1.end(), v2.begin(), v2.end());
+    ASSERT_EQ_COLLECTIONS(v1, v2);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_Exceptions)
+BOOST_AUTO_TEST_CASE(Test_AssertException)
+{
+    auto thrower = []() { throw std::runtime_error("test error"); };
+    auto predicate = [](const std::runtime_error&) { return false; };
+
+    BOOST_CHECK_EXCEPTION(thrower(), std::runtime_error, predicate);
+    ASSERT_EXCEPTION(thrower(), std::runtime_error, predicate);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_ExceptionsWrongCatch)
+BOOST_AUTO_TEST_CASE(Test_AssertExceptionWrongCatch)
+{
+    auto thrower = []() { throw std::runtime_error("test error"); };
+    auto predicate = [](const int&) { return false; };
+
+    try {
+        BOOST_CHECK_EXCEPTION(thrower(), int, predicate);
+    } catch (...) {
+        std::cout << "boost lets the exception through\n";
+    }
+    ASSERT_EXCEPTION(thrower(), int, predicate);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(Suite_ExceptionsWrongThrow)
+BOOST_AUTO_TEST_CASE(Test_AssertExceptionWrongThrow)
+{
+    auto thrower = []() {};
+    auto predicate = [](const int&) { return false; };
+
+    BOOST_CHECK_EXCEPTION(thrower(), int, predicate);
+    ASSERT_EXCEPTION(thrower(), int, predicate);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
 BOOST_FIXTURE_TEST_SUITE(streams_tests, BasicTestingSetup)
 
 // Check optimized obfuscation with random offsets and sizes to ensure proper

To test the overall behavior, and compare it with the boost behavior, one can use this diff (it includes recommended instructions to run) <details><summary>a diff to trigger different failures</summary> ```diff diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index 9bf7f6f6fd..e6a4049328 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -17,6 +17,154 @@ using namespace std::string_literals; using namespace util::hex_literals; +// All suites below will fail +// For testing, run them via Bash: +// clang-format off +// cmake --build ./bld-cmake --parallel && for s in Suite_Bool Suite_Equality Suite_Null Suite_Null2 Suite_Inequality Suite_LessThan Suite_GreaterThan Suite_LessEqual Suite_GreaterEqual Suite_Collections Suite_CollectionsEnd Suite_Exceptions Suite_ExceptionsWrongCatch Suite_ExceptionsWrongThrow; do valgrind ./bld-cmake/bin/test_bitcoin --catch_system_error=no -t $s; echo "Exit code: $?"; done +// clang-format on +BOOST_AUTO_TEST_SUITE(Suite_Bool) +BOOST_AUTO_TEST_CASE(Test_Assert) +{ + short* condition{}; + BOOST_CHECK(condition); + ASSERT(condition); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_Equality) +BOOST_AUTO_TEST_CASE(Test_AssertEq) +{ + const char* a{"hi"}; + std::cout << "Passes on both:\n"; + BOOST_CHECK_EQUAL(a, "hi"); + ASSERT_EQ(a, "hi"); + + std::cout << "Fails on the new macro (This check is stricter and will do pointer-compare)\n"; + char b[3] = {'h', 'i', '\0'}; + BOOST_CHECK_EQUAL(b, "hi"); + using namespace std::literals; + ASSERT_EQ(b, "hi"); // Use "hi"sv or "hi"s instead +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_Null) +BOOST_AUTO_TEST_CASE(Test_AssertNull) +{ + const char* a{"hi"}; + BOOST_CHECK_EQUAL(a, nullptr); + ASSERT_EQ(a, nullptr); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_Null2) +BOOST_AUTO_TEST_CASE(Test_AssertNull2) +{ + const char* a{}; + BOOST_CHECK_EQUAL(a, "hi"); + ASSERT_EQ(a, "hi"); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_Inequality) +BOOST_AUTO_TEST_CASE(Test_AssertNe) +{ + bool a{true}; + BOOST_CHECK_NE(a, true); + ASSERT_NE(a, true); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_LessThan) +BOOST_AUTO_TEST_CASE(Test_AssertLt) +{ + BOOST_CHECK_LT(10, 5U); + ASSERT_LT(10U, 5U); // Checks at compile time that the same signdness is provided! +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_GreaterThan) +BOOST_AUTO_TEST_CASE(Test_AssertGt) +{ + std::cout << "This should obviously fail, but boost passes!\n"; + BOOST_CHECK_GT(-10, 10U); + // ASSERT_GT(-10, 10U); // does not compile +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_LessEqual) +BOOST_AUTO_TEST_CASE(Test_AssertLe) +{ + BOOST_CHECK_LE(10.1, 5.1); + ASSERT_LE(10.1, 5.1); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_GreaterEqual) +BOOST_AUTO_TEST_CASE(Test_AssertGe) +{ + BOOST_CHECK_GE(char{12}, 'a'); + ASSERT_GE(char{12}, 'a'); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_Collections) +BOOST_AUTO_TEST_CASE(Test_AssertCollections) +{ + std::vector<int> v1{1, 2, 3}, v2{1, 99, 3}; + BOOST_CHECK_EQUAL_COLLECTIONS(v1.begin(), v1.end(), v2.begin(), v2.end()); + ASSERT_EQ_COLLECTIONS(v1, v2); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_CollectionsEnd) +BOOST_AUTO_TEST_CASE(Test_AssertCollectionsEnd) +{ + std::vector<NodeSeconds> v1{ + NodeSeconds{1s}, + }, + v2{}; + BOOST_CHECK_EQUAL_COLLECTIONS(v1.begin(), v1.end(), v2.begin(), v2.end()); + ASSERT_EQ_COLLECTIONS(v1, v2); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_Exceptions) +BOOST_AUTO_TEST_CASE(Test_AssertException) +{ + auto thrower = []() { throw std::runtime_error("test error"); }; + auto predicate = [](const std::runtime_error&) { return false; }; + + BOOST_CHECK_EXCEPTION(thrower(), std::runtime_error, predicate); + ASSERT_EXCEPTION(thrower(), std::runtime_error, predicate); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_ExceptionsWrongCatch) +BOOST_AUTO_TEST_CASE(Test_AssertExceptionWrongCatch) +{ + auto thrower = []() { throw std::runtime_error("test error"); }; + auto predicate = [](const int&) { return false; }; + + try { + BOOST_CHECK_EXCEPTION(thrower(), int, predicate); + } catch (...) { + std::cout << "boost lets the exception through\n"; + } + ASSERT_EXCEPTION(thrower(), int, predicate); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Suite_ExceptionsWrongThrow) +BOOST_AUTO_TEST_CASE(Test_AssertExceptionWrongThrow) +{ + auto thrower = []() {}; + auto predicate = [](const int&) { return false; }; + + BOOST_CHECK_EXCEPTION(thrower(), int, predicate); + ASSERT_EXCEPTION(thrower(), int, predicate); +} +BOOST_AUTO_TEST_SUITE_END() + BOOST_FIXTURE_TEST_SUITE(streams_tests, BasicTestingSetup) // Check optimized obfuscation with random offsets and sizes to ensure proper ``` </details>
mercie-ux (Migrated from github.com) reviewed 2026-04-27 02:40:03 +00:00
mercie-ux (Migrated from github.com) commented 2026-04-27 02:40:03 +00:00

I have noted <typeindex> appears to be unused here. I checked for any usage of std::type_index but didn’t find any.
Since typeid(e).name() relies on <typeinfo>, can this include likely be removed to reduce compile run time

I have noted `<typeindex>` appears to be unused here. I checked for any usage of `std::type_index` but didn’t find any. Since `typeid(e).name()` relies on `<typeinfo>`, can this include likely be removed to reduce compile run time
maflcko (Migrated from github.com) reviewed 2026-05-11 07:31:33 +00:00
maflcko (Migrated from github.com) commented 2026-05-11 07:31:33 +00:00

Thx, according to iwyu:


---


/home/admin/actions-runner/_work/_temp/src/test/util/common.h should add these lines:
#include <iterator>         // for distance
#include <typeinfo>         // for type_info
#include <utility>          // for declval

/home/admin/actions-runner/_work/_temp/src/test/util/common.h should remove these lines:
- #include <cstdio>  // lines 13-13
- #include <functional>  // lines 16-16
- #include <ostream>  // lines 19-19
- #include <typeindex>  // lines 26-26

The full include-list for /home/admin/actions-runner/_work/_temp/src/test/util/common.h:
#include <tinyformat.h>     // for format, tfm
#include <algorithm>        // for mismatch
#include <chrono>           // for time_point
#include <concepts>         // for same_as
#include <cstdlib>          // for abort
#include <exception>        // for exception_ptr, exception, current_exception, rethrow_exception
#include <iostream>         // for operator<<, ostream, basic_ostream, cerr, endl, ostringstream
#include <iterator>         // for distance
#include <optional>         // for optional
#include <ranges>           // for end, forward_range, begin
#include <source_location>  // for source_location
#include <sstream>          // for basic_ostringstream
#include <string>           // for basic_string, string, char_traits, operator<<
#include <string_view>      // for string_view, operator<<
#include <type_traits>      // for is_signed_v, is_integral_v, is_array_v, is_bounded_array_v, is_enum_v, is_pointer_v, remove_all_extents_t, underlying_type_t
#include <typeinfo>         // for type_info
#include <utility>          // for declval
---

Pushed the diff.

Thx, according to iwyu: ``` --- /home/admin/actions-runner/_work/_temp/src/test/util/common.h should add these lines: #include <iterator> // for distance #include <typeinfo> // for type_info #include <utility> // for declval /home/admin/actions-runner/_work/_temp/src/test/util/common.h should remove these lines: - #include <cstdio> // lines 13-13 - #include <functional> // lines 16-16 - #include <ostream> // lines 19-19 - #include <typeindex> // lines 26-26 The full include-list for /home/admin/actions-runner/_work/_temp/src/test/util/common.h: #include <tinyformat.h> // for format, tfm #include <algorithm> // for mismatch #include <chrono> // for time_point #include <concepts> // for same_as #include <cstdlib> // for abort #include <exception> // for exception_ptr, exception, current_exception, rethrow_exception #include <iostream> // for operator<<, ostream, basic_ostream, cerr, endl, ostringstream #include <iterator> // for distance #include <optional> // for optional #include <ranges> // for end, forward_range, begin #include <source_location> // for source_location #include <sstream> // for basic_ostringstream #include <string> // for basic_string, string, char_traits, operator<< #include <string_view> // for string_view, operator<< #include <type_traits> // for is_signed_v, is_integral_v, is_array_v, is_bounded_array_v, is_enum_v, is_pointer_v, remove_all_extents_t, underlying_type_t #include <typeinfo> // for type_info #include <utility> // for declval --- ``` Pushed the diff.
sedited commented 2026-05-26 09:56:48 +00:00 (Migrated from github.com)

Not sure about these changes. I've found it useful in the past that the tests are not failing fast. Both to have more context when debugging, and to see all failing cases at once when patching them. Judged by the lack of engagement here, I'm also not sure if others would find that valuable too. The value I could see is in the shared utilities between the fuzz and unit tests, but even there we could just use plain asserts, since they are not actual test cases?

Not sure about these changes. I've found it useful in the past that the tests are not failing fast. Both to have more context when debugging, and to see all failing cases at once when patching them. Judged by the lack of engagement here, I'm also not sure if others would find that valuable too. The value I could see is in the shared utilities between the fuzz and unit tests, but even there we could just use plain asserts, since they are not actual test cases?
maflcko commented 2026-05-28 17:13:45 +00:00 (Migrated from github.com)

Not sure about these changes. I've found it useful in the past that the tests are not failing fast. Both to have more context when debugging, and to see all failing cases at once when patching them.

I guess this may be subjective. The context before a failure is certainly useful, but the context after a failure is often counter-productive (think about a 10'000 line github log, where the failure happens in the first 1000 lines, or think about a test failure that sets off an avalanche of other failures, where only the first one is the relevant one to fix). Again, this may be subjective (I've heard preferences either way), so I am happy to add an env var to control the behavior here.

Judged by the lack of engagement here, I'm also not sure if others would find that valuable too.

Yeah, I think the main issue is that all the annoyances are not worth it when looked at in a vacuum. However, while the boost test framework was the right choice in 2011, I am not sure it is the right choice in a modern C++ codebase:

I understand the review bottleneck, and I don't want to force this on anyone, but I want to highlight the issues and ask if we want to address them here, not at all, or upstream?

> Not sure about these changes. I've found it useful in the past that the tests are not failing fast. Both to have more context when debugging, and to see all failing cases at once when patching them. I guess this may be subjective. The context before a failure is certainly useful, but the context after a failure is often counter-productive (think about a 10'000 line github log, where the failure happens in the first 1000 lines, or think about a test failure that sets off an avalanche of other failures, where only the first one is the relevant one to fix). Again, this may be subjective (I've heard preferences either way), so I am happy to add an env var to control the behavior here. > Judged by the lack of engagement here, I'm also not sure if others would find that valuable too. Yeah, I think the main issue is that all the annoyances are not worth it when looked at in a vacuum. However, while the boost test framework was the right choice in 2011, I am not sure it is the right choice in a modern C++ codebase: * It doesn't work with tsan out of the box when a check macro is called outside the main thread * It doesn't work with clang-tidy out of the box when a std::move is done in a check macro (I ran into this, but other seem to be running into it as well: https://bitcoin-irc.chaincode.com/bitcoin-core-dev/2026-05-21#1221768) * It silences compiler errors that would normally happen for integer compares of different signs * It doesn't work well with iwyu (https://github.com/kevkevinpal/bitcoin/issues/385) * Probably more stuff I missed ...? I understand the review bottleneck, and I don't want to force this on anyone, but I want to highlight the issues and ask if we want to address them here, not at all, or upstream?
maflcko commented 2026-07-07 13:28:13 +00:00 (Migrated from github.com)

The context before a failure is certainly useful, but the context after a failure is often counter-productive (think about a 10'000 line github log

I keep running into this, and it is annoying. E.g. try to find the failure in https://github.com/bitcoin/bitcoin/actions/runs/28867247659/job/85623740486?pr=35676#step:9:2171. The full log doesn't show the failure in the tail of the log:

https://gist.github.com/maflcko/4b2b6c7e1a0d23841cbe7d962ed61525

edit:

> The context before a failure is certainly useful, but the context after a failure is often counter-productive (think about a 10'000 line github log I keep running into this, and it is annoying. E.g. try to find the failure in https://github.com/bitcoin/bitcoin/actions/runs/28867247659/job/85623740486?pr=35676#step:9:2171. The full log doesn't show the failure in the tail of the log: https://gist.github.com/maflcko/4b2b6c7e1a0d23841cbe7d962ed61525 edit: * https://github.com/bitcoin/bitcoin/pull/35716#issuecomment-7190180582
sedited commented 2026-07-07 13:54:27 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
maflcko commented 2026-07-07 14:01:16 +00:00 (Migrated from github.com)

Reviewers, this pull request conflicts with the following ones:

* [#35587](https://github.com/bitcoin/bitcoin/pull/35587) (Remove boost as a unit test runner by rustaceanrob)

Turned to draft into now, as a conflicting pull was opened in the meantime. Probably good to keep the number of non-draft pulls to a minimum.

> Reviewers, this pull request conflicts with the following ones: > > * [#35587](https://github.com/bitcoin/bitcoin/pull/35587) (Remove boost as a unit test runner by rustaceanrob) Turned to draft into now, as a conflicting pull was opened in the meantime. Probably good to keep the number of non-draft pulls to a minimum.
DrahtBot commented 2026-08-20 10:23:36 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
First-time contributor

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

🟠 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).

🟠 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).

🟠 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).

🔵 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).

🔵 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).

Review coverage was incomplete.


Reviewed: 687af6db87a0 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3705f06c6a27c475c77f2533c4d016ac03c829c839b7b538bba5e4768ccf54f1:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:079437cca7a8e2997a6dcd83ad38350014352544 --> <!-- ralph-head:687af6db87a0ace04def094204316d91e524194e --> <!-- ralph-case:9e19b94ba81c0bb376cf081f79e8261d00a58e432cd696331ba61e3b6040c627 --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. **🟠 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/687af6db87a0ace04def094204316d91e524194e/src/test/util/common.h#L221>) (head). **🟠 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/687af6db87a0ace04def094204316d91e524194e/src/test/util/common.h#L169>) (head). **🟠 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/687af6db87a0ace04def094204316d91e524194e/src/test/util/common.h#L276>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/687af6db87a0ace04def094204316d91e524194e/src/test/util/common.h#L218>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/687af6db87a0ace04def094204316d91e524194e/src/test/streams_tests.cpp#L99>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`687af6db87a0`](<https://git.fish.foo/bitcoin/bitcoin/commit/687af6db87a0ace04def094204316d91e524194e>) · [Review report](<https://review.fish.foo/report/35139-687af6db87a0ace04def094204316d91e524194e-2870-3.html>) · [Previous reports](<https://review.fish.foo/traces/35139/>) [permalink](<https://review.fish.foo/report/35139-687af6db87a0ace04def094204316d91e524194e-2870-3.html>)
DrahtBot commented 2026-11-02 23:03:22 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-11-20 07:22:07 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/44688592584/job/136128723071
LLM reason (✨ experimental): CI failed because the include linter detected a duplicate #include <utility> in src/test/util/common.h.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/44688592584/job/136128723071</sub> <sub>LLM reason (✨ experimental): CI failed because the include linter detected a duplicate `#include <utility>` in `src/test/util/common.h`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35139
No description provided.