Remove boost as a unit test runner

bitcoin/bitcoin: PR #35713

1 minor finding · 6 suggestions

Earlier concerns neither republished nor resolved: 3 minor findings · 4 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · Exception-checking macros swallow the REQUIRE abort

CHECK_THROWS, CHECK_NOTHROW, CHECK_THROWS_AS and CHECK_EXCEPTION can swallow a nested REQUIRE abort and continue a failed test; no current caller producing this nesting was found.

Location: src/test/util/framework.h:682 (head).

Details and suggested fix

If a helper evaluated inside one of these macros fails a REQUIRE, it records the failure and throws RequireFailed. The surrounding exception handler catches that sentinel instead of letting it reach the runner. CHECK_THROWS even counts the outer check as passing; the other macros normally record an additional failure. The case remains failed, but execution after the outer macro continues and can cause cascaded failures or a crash on state the fatal assertion was meant to guard. The corresponding Boost shims inherit this behavior. Add catch (const ::framework::RequireFailed&) { throw; } before the other handlers, including the typed handler, so the runner receives the abort.


Optional improvements

Link

[suggestion] · TEST_SUITE_BEGIN is missing from test discovery

No suite uses TEST_SUITE_BEGIN directly yet, but a suite declared with that advertised macro would register with the runner while receiving neither a CTest entry nor the suite-naming lint checks.

Location: src/test/util/framework.h:494 (head).

Details and suggested fix

add_boost_test scans source text for BOOST_FIXTURE_TEST_SUITE and BOOST_AUTO_TEST_SUITE, then creates the per-suite CTest entries from those matches. lint-tests.py recognizes only those same spellings. Neither tool expands the compatibility shims, so converting a suite declaration to TEST_SUITE_BEGIN removes it from discovery even though its cases remain runnable directly. Add the new spelling to CMake's matching and replacement expressions and to the lint's discovery and validation expressions.


Link

[suggestion] · Runner selection and failure paths have no self-tests

The migrated suites do not verify the new runner's filtering, option parsing or failure exit paths, so ordinary passing runs cannot establish that these mechanisms select tests and report failures correctly.

Location: src/test/util/framework.cpp:324 (head).

Details and suggested fix

There are no direct tests of matches_filter, glob_match, option abbreviation or argument parsing, and no harness checks the outcome of deliberately failing cases. A selection regression can also produce no test cases matching filter, which CTest maps to a skip. Add table-driven tests using synthetic TestCase values and argument arrays for filters, separators, abbreviations and missing values. A small separate executable linked against test_framework, driven by a harness that checks output and exit status, can verify failing CHECK, failing REQUIRE and escaped exceptions without introducing intentional failures into test_bitcoin.


Link

[suggestion] · Worker-thread REQUIRE misuse leaves the worker running

REQUIRE misuse on a worker records a failure without evaluating its precondition or stopping the worker; no current worker-thread caller was found.

Location: src/test/util/framework.h:565 (head).

Details and suggested fix

The non-owner branches of REQUIRE and REQUIRE_NO_DISPLAY only report the unsupported use and then return normally. The case will fail if execution completes, but subsequent worker code can still access state whose precondition was never checked, potentially crashing or hanging before the summary. The documentation correctly directs workers to CHECK, and avoiding an exception that cannot abort the parent test is appropriate. After reporting this misuse, call std::abort() rather than continuing. This deliberately ends the invocation, but preserves the diagnostic and prevents unchecked dependent operations.


Link

[suggestion] · Duplicate test names register without a uniqueness check

A copy-pasted case name can execute twice under the same filter and overwrite the first case's preserved -testdatadir; no existing duplicate was identified.

Location: src/test/util/framework.h:488 (head).

Details and suggested fix

FIXTURE_TEST_CASE gives each implementation a namespace derived from __LINE__ and passes #name to Registrar only as text. Two same-named cases on distinct lines therefore compile, and registration appends both without checking their identities. Both report and match the same suite/case. With -testdatadir, fixtures also derive the directory from that identity and remove its previous contents before running, so the second case replaces the first case's preserved directory. Reject duplicate (suite, name) pairs in run() before executing any cases.


Link

[suggestion] · Unit-test debugging guidance still assumes Boost.Test interception

The unit-test README says the runner intercepts faults by default and requires --catch_system_errors=no for core dumps, but the replacement does not intercept faults and accepts that option as a no-op.

Location: src/test/util/framework.cpp:303 (head).

Details and suggested fix

The segmentation-fault section explains core-dump setup in terms of disabling Boost's interception. The new parser simply accepts --catch_system_errors=no, rejects =yes, and the runner installs no fault interception. The documented command still works, but its explanation is wrong. Update this section to describe the operating-system core-dump configuration without requiring the compatibility flag, and replace the introduction's statement that the tests use Boost's unit-test framework.


Link

[suggestion] · CTest suite filters also select same-named cases elsewhere

CTest passes bare suite names to --run_test, which now also matches case names in other suites; no current suite/case-name collision was identified.

Location: src/test/util/framework.cpp:181 (head).

Details and suggested fix

For a token without /, matches_filter accepts either a matching suite name or a matching case name. Consequently, a case in suite B named like suite A would run in both suites' CTest entries. Bare-case selection is documented, so it can remain available for interactive use. Change the CTest command to --run_test=${test_suite_name}/*; the slash makes its suite-selection intent explicit and prevents unrelated case names from matching.


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

Worker-thread assertion safety was not a Boost.Test guarantee that Bitcoin Core could rely upon. Historical discussions explicitly identify BOOST_CHECK and related macros as non-thread-safe; the earlier replacement-macro proposal reports that assertions in spawned threads can compile successfully but subsequently fail under ThreadSanitizer.

The pinned replacement introduces a shared TestContext and synchronized assertion bookkeeping. This addresses a historically identified limitation rather than preserving an existing Boost guarantee. The underlying requirement remains: tests exercise indexers, validation callbacks, and other concurrent code, so assertion machinery must not itself introduce races.

Source 1 · Source 2 · Source 3 · Source 4

The musl workaround addressed test-runner setup failures caused by undersized alternate signal stacks, rather than memory exhaustion in the tested Bitcoin code. The historical issue reports Alpine test_kernel aborting during setup; the follow-up accepted disabling Boost's alternate stack because its benefit was considered questionable.

The removed macro controlled Boost.Test's signal-stack machinery. The continuing platform assumption is that a runner must start successfully on supported musl systems; there is no inspected evidence that Bitcoin tests intentionally depended on alternate-stack reporting as a required guarantee.

Source 1 · Source 2 · Source 3

Guix's reduced wide-character support was an intentional toolchain-size tradeoff. The minimal non-GUI toolchain proposal reports approximately half a megabyte saved per non-GUI binary and explicitly acknowledges that disabling wchar_t specializations produces a subset of the ISO library and can change its ABI.

This is the environmental reason the Boost.Test wchar_t formatting workaround existed. Replacing Boost.Test does not reverse the underlying minimal-toolchain decision: the remaining test framework still runs in an environment with reduced C++ wide-character support.

Source 1

The RISC-V linker-warning exception corresponded to Boost.Test execution-monitor references to feenableexcept and fedisableexcept. The upstream report reproduces warnings that those functions are unimplemented and will always fail using a minimal header-only Boost.Test program.

The Guix exception was tied to an execution-monitor dependency, not to Bitcoin test logic or a need to tolerate arbitrary linker warnings. Its historical rationale is narrower than the general warning policy that remains after the runner changes.

Source 1

Ralph's inferences

The platform workarounds have component-specific triggers, whereas supported build environments remain relevant. The inspected ancestor patch changed Boost.Test's std::wcrtomb call to the unqualified C-library name for the reduced libstdc++ configuration; the other workarounds targeted Boost's alternate stack, execution monitor, or Windows linkage configuration.

Removing the component can remove the reason for its workaround without implying that musl stack-size constraints, reduced Guix library support, RISC-V floating-point limitations, or vcpkg configuration behavior have disappeared. This separates historical rationale for retirement from any assessment of the replacement's correctness.

Source 1 · Source 2 · Source 3 · Source 4

Unresolved disagreements

The inspected earlier macro discussion contains competing preferences about fast failure: seeing all failing cases and additional debugging context versus avoiding cascaded failures and long CI logs that bury the first error. Making the behavior configurable was suggested, but the inspected passages do not establish a resolution.

This makes continuation after CHECK failure an intentional tradeoff rather than an obviously dispensable Boost behavior. It provides context for interpreting CHECK, REQUIRE, and process-level stopping without recommending a policy for this PR.

Source 1 · Source 2 · Source 3