Skip to content

Remove boost as a unit test runner - #35587

Closed
rustaceanrob wants to merge 19 commits into
bitcoin:masterfrom
rustaceanrob:remove-boost-test
Closed

rustaceanrob wants to merge 19 commits into
bitcoin:masterfrom
rustaceanrob:remove-boost-test

Conversation

@rustaceanrob

@rustaceanrob rustaceanrob commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

tl;dr: Make an equivalent test runner to boost with simpler macros and tighter coupling to bitcoin-specific code.

Motivation

There are a number of problems with using dependencies in general. Bugs must either be promptly upstreamed or patched, projects may be abandoned, and they are not tailored to a particular use case. This PR removes boost for writing and running unit tests. In the case of Boost.Test, there are a number of issues which are listed below.

My problems with Boost.Test

Macros

When using boost, there are 3 ways of writing the same thing, each with different outcomes

  • BOOST_CHECK(expr1 == expr2): failures show the expression, but no values for expr1 and expr2
  • BOOST_CHECK_EQUAL(expr1, expr2): failures show the expression and values, but requires developers remember CHECK_EQUAL and does not use usual operands
  • BOOST_TEST(expr1 == expr2): failures show the expression and values, and developers may use familiar operands (==, !=)

All three are preserved to maintain backwards compatibility - presumably, but this results in all 3 being used throughout the repository. As a bonus there is a 4th way, with added context

  • BOOST_CHECK_MESSAGE(expr1 == expr2, "the context"): failures show the expression and message, but no values for expr1 and expr2

To make debugging and review easier, all of these should be unified to a single macro. Test sites use operands, print helpful messages - values are always included, and do not vary in approach (deciding between BOOST_TEST, CHECK, and BOOST_CHECK_EQUAL is unintuitive)

Example boost outputs
BOOST_AUTO_TEST_CASE(mustfail)
{
    auto a{1};
    auto b{2};
    BOOST_CHECK(a == b);
    BOOST_CHECK_EQUAL(a, b);
    BOOST_TEST(a == b);
    COutPoint outpoint_1{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 0};
    COutPoint outpoint_2{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 1};
    BOOST_CHECK(outpoint_1 == outpoint_2);
    // Doesn't even compile
    // BOOST_TEST(outpoint_1 == outpoint_2);
    // BOOST_CHECK_EQUAL(outpoint_1, outpoint_2);
}
Running 1 test case...
test/argsman_tests.cpp(31): error: in "argsman_tests/mustfail": check a == b has failed
test/argsman_tests.cpp(32): error: in "argsman_tests/mustfail": check a == b has failed [1 != 2]
test/argsman_tests.cpp(33): error: in "argsman_tests/mustfail": check a == b has failed [1 != 2]
test/argsman_tests.cpp(36): error: in "argsman_tests/mustfail": check outpoint_1 == outpoint_2 has failed
New outputs
TEST_CASE(mustfail)
{
    auto a{1};
    auto b{2};
    CHECK(a == b);
    COutPoint outpoint_1{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 0};
    COutPoint outpoint_2{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 1};
    CHECK(outpoint_1 == outpoint_2);
}
Running 1 test cases...
[FAIL]: test/argsman_tests.cpp:30: CHECK(a == b)
1 == 2

[FAIL]: test/argsman_tests.cpp:33: CHECK(outpoint_1 == outpoint_2)
COutPoint(0000000000, 0) == COutPoint(0000000000, 1)

[FAIL] mustfail (2/2 checks failed)

No repository context

Many types implement ToString, but boost has no way of meaningfully using these representations (will change w/ future std::format). With a repository-specific test runner we can use these today. See example above.

Not extensible

With the test runner in this repository we can add things such as #35139, implement string representations for more types, and implement ideas from #8670.

Other issues

More issues with boost are raised in #34666, #8670. This PR does not resolve all of them, but one it does address immediately is banning comparisons of integers with different signs, previously allowed by boost. Using a test runner within the source also makes IWYU easier to work with.

High level changes

For those running tests, not a tremendous amount has changed in this PR. For instance, the doc page remains valid. Changes to the runner options include anything that is not help, run_test, log_level, list_content. This includes catch_system_errors which is always no. The log_levels have been reduced to 5 levels.

Changes in writing tests

  • CHECK to compare two values with any ==, !=, >, etc
  • CHECK(a == b, "my message") to append a message
  • REQUIRE, same as CHECK, but will fail the test immediately
  • CHECK_EQUAL_RANGES(it1, it2) to compare two ranges
  • TEST_CASE(name) to add a test
  • FIXTURE_TEST_CASE(name, Fixture) to add a test with a fixture
  • TEST_SUITE_BEGIN/END to declare a suite, optionally with fixture for each test in the suite

Migration

Boost.Test is removed in this PR, but the macros are aliased by BOOST_* counterparts so there are no merge conflicts. The idea would be to migrate test files to the new macros when there are no/low number of conflicts on that file.

Commits

The addition of the framework:

  • test: Add header-only framework to util

Migration script (majority of the file changes):

  • scripted-diff: Migrate tests to header-only framework

Low usage count macro removals:

  • test: Remove use of BOOST_FAIL
  • test: Remove use of BOOST_TEST_INFO_*
  • test: Remove use of BOOST_CHECK_CLOSE

Required for expression decomposition:

  • crypto: Use constexpr to define output size
  • util: Use constexpr in LockedPool definitions
  • net: Make AddressPosition comparitor const
  • test: Unroll && conditions in macros
  • test: Wrap || expressions in macros
  • test: Wrap bitwise & expressions in macros

To pass CI

  • test: Use lambda for CRecipient to avoid gcc12 uninitialized warning
  • test: Include memory in result_tests for IWYU
  • test: Initialize variables in dbwrapper_tests

Build and config

  • depends: drop test from Boost libraries
  • cmake: drop vcpkg Boost Test check
  • vcpkg: drop boost-test dependency

@DrahtBot

DrahtBot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35587.

Reviews

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

Type Reviewers
Concept ACK purpleKarrot, josibake, janb84, w0xlt, optout21

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:

  • #35662 (script: make txdata non-default-constructible by l0rinc)
  • #35531 (txindex: hash keys and pack positions to reduce disk usage by andrewtoth)
  • #35511 (RFC: consensus: Make CAmount a class by hodlinator)
  • #35195 (coins: cache UTXO outpoint hash codes by l0rinc)
  • #34864 (coins: tighten cache entry state invariants by l0rinc)
  • #34075 (fees: Introduce Mempool Based Fee Estimation to reduce overestimation by ismaelsadeeq)
  • #33540 (argsman, cli: GNU-style command-line option parsing (allows options after non-option arguments) by pablomartin4btc)
  • #31682 ([IBD] specialize CheckBlock's input & coinbase checks by l0rinc)
  • #29278 (Wallet: Add maxfeerate wallet startup option by ismaelsadeeq)
  • #17783 (common: Disallow calling IsArgSet() on ALLOW_LIST options by ryanofsky)
  • #17581 (refactor: Remove settings merge reverse precedence code by ryanofsky)
  • #17580 (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
  • #17493 (util: Forbid ambiguous multiple assignments in config file by ryanofsky)

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.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • Path that the test binary -> Path to the test binary [the comment is incomplete as written]
  • evalution -> evaluation [misspelling in the comment about operator precedence]

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • [TaprootBuilder::Add(…, …, 0xc0)] in src/test/script_standard_tests.cpp
  • [Lookup(..., 1, false)] in src/test/pcp_tests.cpp
  • [close_to(double, double, double)] in src/test/validation_chainstatemanager_tests.cpp

2026-07-13 09:40:05

@purpleKarrot

Copy link
Copy Markdown
Contributor

Strong Concept ACK

My problems with boost

Boost may have multiple problems on its own, but the problems that you list are specific to Boost.Test. You should not conflate the two.

CHECK_EQUAL_RANGES(it1, it2) to compare two iterators

Iterators or Ranges?

TEST_SUITE_BEGIN/END to declare a suite

Boost.Test allows arbitrary deep nesting of test suites. When integrating Boost.Test into CTest, this causes headaches for little benefit. I hope we can follow-up on this and restrict the test hierarchy to exactly one test suite (no more and no less) using something along the TEST(TestSuiteName, TestName) macro from GoogleTest.

Why no concurrency?

In my opinion, concurrency does not belong in a testing framework. Many testing frameworks have a test driver built-in. But separating test framework and test driver into two orthogonal components allows much more powerful composition. I would even go so far and claim that a test framework should not provide a way to run more than one test; neither concurrently, nor sequentially.

What a test framework needs to be able to provide, is a way to launch a single test and a way to tell the test driver about the list of tests that are available. The test driver can then orchestrate tests from different testing frameworks from potentially different programming languages and invoke tests individually, sequentially, concurrently, or even distributed across multiple hosts.

This kind of integration is exactly the reason why I implemented discover_tests, which will be available in CMake 4.4.

The Boost.Test framework is notoriously bad at this. When selecting a single test, it spams out information about all tests that are not selected. While it can provide information about what tests are available, that output is optimized for human readability and very hard to parse by a test driver. We can definitely do better with a custom test framework!

@fjahr

fjahr commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

There are a number of problems with using dependencies in general. Bugs must either be promptly upstreamed or patched, projects may be abandoned, and they are not tailored to a particular use case. bitcoind has a small number of dependencies and will have fewer very soon (#34411). One of the final remaining dependencies is boost, which is responsible for the unit tests and multi-index. This PR removes boost for writing and running unit tests.

Boost.Test is not a dependency of bitcoind, only of test_bitcoin so this is not comparable to the libevent removal. Also boost::multi_index removal was rejected very recently: #34586.

@rustaceanrob

rustaceanrob commented Jun 23, 2026 •

Copy link
Copy Markdown
Member Author

only of test_bitcoin

Correct me if I'm wrong but it appears the config here still builds test_bitcoin: https://github.com/bitcoin/bitcoin/blob/master/contrib/guix/libexec/build.sh#L125

Also boost::multi_index removal was rejected very recently: #34586

That approach used STL containers. An actual replacement would need to use something like this: https://www.mail-archive.com/[email protected]/msg33920.html

@fjahr

fjahr commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Correct me if I'm wrong but it appears the config here still builds test_bitcoin

Yes, but what does that have to with my comment? I just said that it's a dependency of test_bitcoin not bitcoind. Reducing the dependencies of bitcoind is a lot more interesting than those of test_bitcoin for obvious security reasons. I don't think the fact that test_bitcoin is built in a release and installed changes much of that. Maybe it does for other people but I think your motivation should be more clear on this if this is what you are after. Particularly this part:

bitcoind has a small number of dependencies and will have fewer very soon (#34411). One of the final remaining dependencies is boost, which is responsible for the unit tests and multi-index.

I would read this very clearly as boost (including Boost.Test) is a dependency of bitcoind if I didn't know better.

That approach used STL containers.

The pull was rejected on conceptual basis, not approach, so I don't think this matters.

@rustaceanrob

rustaceanrob commented Jun 23, 2026 •

Copy link
Copy Markdown
Member Author

I would read this very clearly as boost (including Boost.Test) is a dependency of bitcoind if I didn't know better.

Sure, PR description updated.

Reducing the dependencies of bitcoind is a lot more interesting than those of test_bitcoin for obvious security reasons

I find this less obvious then the comment implies. A repository going stale is far more likely than some backdoor or high severity CVE, so "a lot more interesting" feels subjective.

@josibake

Copy link
Copy Markdown
Member

Yes, but what does that have to with my comment?

A lot. @rustaceanrob correctly points out that even though Boost.Test is not strictly a dependency of bitcoind, it is included in the release flow that creates and packages bitcoind, along with test_bitcoin. It is correct to say that Boost.Test is a dependency of our release process.

@josibake

Copy link
Copy Markdown
Member

A repository going stale is far more likely than some backdoor or high severity CVE, so "a lot more interesting" feels subjective.

Precisely. It's also worth remembering the xzutils backdoor was introduced through test code.

@josibake

Copy link
Copy Markdown
Member

Strong Concept ACK!

Love to see it. While I broadly agree with the author's reasons stated in the PR, the ones I'll highlight specifically are:

  • No repository context
  • Not extensible

Having our own simple, in house test framework gives us the ability to customise it for exactly our needs. I believe we should do everything in our power to make testing an easy, intuitive, and feature rich experience as this helps to remove barriers to people writing and interpreting tests.

In particular, as a longer term project I am looking at ways to improve concurrency in our testing to help speed up CI. As @purpleKarrot points out:

The Boost.Test framework is notoriously bad at this. When selecting a single test, it spams out information about all tests that are not selected. While it can provide information about what tests are available, that output is optimized for human readability and very hard to parse by a test driver. We can definitely do better with a custom test framework!

Makes the output size of each hash known at compile time for other TU.
When using expression decomposition, like in `BOOST_TEST` or the
framework introduced later, expressions are captured as `const T&`
function arguments whose values must be known at compile time.
Makes the size of the pool known at compile time for other TU.
When using expression decomposition, like in `BOOST_TEST` or the
framework introduced later, expressions are captured as `const T&`
function arguments whose values must be known at compile time.
Needed to use `==` operator in tests.
This is being brought in transitively by boost
libboost_unit_test_framework is prebuilt without MSan/UBSan,
so these uninitialized reads were not flagged. The test framework
introduced in later commits is compiled with the sanitizers.
There is only a single case of this macro and the if conditional that
triggers it may simply be used in a `BOOST_REQUIRE`
In the case of `descriptor_tests.cpp`, the info is only used to get the
diagonsics of `BOOST_CHECK_EQUAL` along with the human readable form of
the descriptor. This is irrelevant if the test framework implements
expression decomposition, which will print the string representation on
failure (e.g. `BOOST_TEST`).

Removing `BOOST_TEST_INFO_SCOPE` requires a few duplications, but these are
very little cost compared to a port of this macro, which does not appear
very useful.
This is only used in a single test and would be a low-motivation add to
porting the test framework. A lambda is sufficient to enforce the check.
rustaceanrob and others added 11 commits July 13, 2026 10:31
gcc12 warns with uninitialized when boost is not used for this test.
This side-steps the warning.
`EraseTx` already returns a `bool`, so these implicit casts within the
comparisons are not necessary.
Using `&&` in `BOOST_CHECK` is problematic as failures will not indicate
which condition failed. By unrolling these checks, the user knows
exactly which expression is the failing case.

This is also required when using test macros that support value
decomposition, which requires `&&` and `||` are `delete`. Examples
include `BOOST_TEST`, doctest, Catch2, etc.

ref: https://fekir.info/post/decomposing-an-expression/
The `||` is not usable with `BOOST_TEST` and other modern test
frameworks like Catch2. This is due to operator precedence used in such
macros. Here is an additional opinion from Catch2:

> There is no simple rewrite rule for ||, but I generally believe
that if you have || in your test expression, you should rethink your tests.

ref: https://catch2-temp.readthedocs.io/en/latest/assertions.html#other-limitations
ref: https://fekir.info/post/decomposing-an-expression/
-BEGIN VERIFY SCRIPT-
mv src/test/new_main.cpp src/test/main.cpp
git grep -l '<boost/test/unit_test.hpp>' | xargs sed -i 's|<boost/test/unit_test.hpp>|<test/util/framework.h>|'
sed -i 's|BOOST_TEST_MODULE Bitcoin Kernel Test Suite|BITCOIN_TEST_MAIN|; s|<boost/test/included/unit_test.hpp>|<test/util/framework.h>|' src/test/kernel/test_kernel.cpp
sed -i 's|boost::unit_test::framework::master_test_suite().argv\[0\]|framework::executable_path()|' src/test/system_tests.cpp
sed -i '/boost\/test\/\(included\/\)\?unit_test.hpp/d' test/lint/lint-includes.py
sed -i 's| --catch_system_error=no||' src/test/CMakeLists.txt
-END VERIFY SCRIPT-
@rustaceanrob

Copy link
Copy Markdown
Member Author

Closing and reopening to remove the github UI items

@sedited sedited reopened this Jul 13, 2026
@rustaceanrob

Copy link
Copy Markdown
Member Author
Screenshot 2026-07-13 at 3 38 22 PM

is this a UI bug or was this reopened @sedited

@yancyribbens

Copy link
Copy Markdown
Contributor

is this a UI bug or was this reopened @sedited

Yeah I thought that was curious too. My email said you closed it and then two minutes later @sedited re-opened. I figured you had pinged him to re-open it for some reason.

@sedited

sedited commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Oh, I completely misunderstood what you wanted to do here. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.