mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 15:11:38 +00:00
WIP: test: [NOMERGE,SKETCH] Add thread-safe fast-failing test macros #35139
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35139
Loading…
Reference in a new issue
No description provided.
Delete branch "2604-test-fail-fast-thread-safe-macros"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently, the unit tests use different boost check macros. However, this is problematic:
BOOST_CHECK_GT(-10, 10U);compiles and passes fine, even though it is obviously wrong.assert, but it would be better if the macros just worked under tsan.assertandAssert, and evenCHECK_NONFATALunder 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 asASSERT_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, andAssert). While it may confusing to have three unaryassertmacros that do roughly the same, it should be harmless and any macro that compiles is fine to use. (There is a special edge case toAssert, which allows to be turned into an exception as part ofg_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
assertorAssert, 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.
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.
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:
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.
To test the Tsan error, one can use this diff:
Tsan passes with
ASSSERTorassert, orAssert, but fails withBOOST_CHECKwhen running this test.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
I have noted
<typeindex>appears to be unused here. I checked for any usage ofstd::type_indexbut didn’t find any.Since
typeid(e).name()relies on<typeinfo>, can this include likely be removed to reduce compile run timeThx, according to iwyu:
Pushed the diff.
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?
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.
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?
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:
Concept ACK
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.
🐙 This pull request conflicts with the target branch and needs rebase.
Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🟠 Minor ·
ASSERT_EQ_COLLECTIONScan pass for unequal mixed-sign integersUnlike scalar checks,
ASSERT_EQ_COLLECTIONScan 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
chararrayFormatting 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_EQcompares two C strings by addressEqual C strings at different addresses fail
ASSERT_EQand 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_COLLECTIONSaccepts constraints that itsconstparameters cannot satisfySource inspection shows that
ASSERT_EQ_COLLECTIONSaccepts afilter_viewconstraint but cannot iterate the view through itsconstparameters; 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_usagestill continue after failureThe migration leaves two non-fatal
BOOST_CHECK_GTassertions instreams_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 reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/44688592584/job/136128723071LLM reason (✨ experimental): CI failed because the include linter detected a duplicate
#include <utility>insrc/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.