Skip to content

scripted-diff: [fuzz] Add util/check.h includes for assertions - #36074

Merged
fanquake merged 2 commits into
bitcoin:masterfrom
maflcko:2608-test-assert
Nov 10, 2026
Merged

fanquake merged 2 commits into
bitcoin:masterfrom
maflcko:2608-test-assert

Conversation

@maflcko

@maflcko maflcko commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

In test code, assert is used. This is perfectly fine, but sometimes confusion arises, when it is unclear whether NDEBUG can disable the assertions, or whether to use assert or Assert.

Avoid that confusion in test code with a scripted replacement to add the util/check.h include. The changes here will also make it easier to run IWYU.

Scope: This change is only about test code (fuzz), other code can be done later, if there is need to.

@DrahtBot DrahtBot changed the title scripted-diff: [test] replace assert with Assert scripted-diff: [test] replace assert with Assert Aug 25, 2026
@DrahtBot

DrahtBot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

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
ACK hebasto
Concept ACK l0rinc

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:

  • #36817 (ipc: remove pre-v14 libmultiprocess compat definitions by fanquake)
  • #36809 (rpc, wallet: Support BIP322 simple message signing by jaromil)
  • #36808 (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)
  • #36786 (fuzz: report more events, and check more invariants in connman target by darosior)
  • #36635 (fuzz: Add a target that feeds arbitrary bytes to V2Transport by fametrano)
  • #36548 (net: serve MSG_BLOCK by stripping witnesses in place by l0rinc)
  • #36068 (fuzz: reuse one fuzzed wallet across inputs by brunoerg)
  • #35916 (fuzz: improve ipc fuzz coverage by enirox001)

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.

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task i686, no IPC: https://github.com/bitcoin/bitcoin/actions/runs/32832295932/job/97753466551
LLM reason (✨ experimental): CI failed due to a C++ build error treated as fatal (-Werror=return-type) in bench/sign_transaction.cpp where an Assert(false) lambda triggers “control reaches end of non-void function.”

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.

@maflcko
maflcko marked this pull request as draft August 25, 2026 12:08
@maflcko

maflcko commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Hmm, I guess Assert(0/false) being a function trips GCC into thinking it can return? Though, the optimized codegen is unaffected on GCC. Funnily clang doesn't warn, but pessimises codegen: https://godbolt.org/z/h79K1scWK

I guess that means we could add an explicit #define AssertUnreachable() assertion_fail(std::source_location::current(), "Unreachable code")

Comment thread src/test/fuzz/mini_miner.cpp Resolved
Comment thread test/lint/test_runner/src/lint_cpp.rs Resolved
MarcoFalke added 2 commits November 9, 2026 17:16
The project has a compile error when compiled without assertions in
util/check.h. Thus, util/check.h should be included for all assertions.

So do that with a scripted-diff to use util/check.h.

-BEGIN VERIFY SCRIPT-

 # Select all fuzz files
 paths=(
   'src/ipc/test/fuzz'
   'src/test/fuzz'
   'src/wallet/test/fuzz'
 )

 # Add the util/check.h includes
 for f in $(git grep -l --extended-regexp "\<(a|A)ssert\(" -- "${paths[@]}"); do
   if ! grep --quiet "util/check.h" "$f"; then
     line=$(grep --line-number --max-count=1 '^#include' "$f" | cut --delimiter=: --fields=1)
     sed --in-place "${line}i#include <util/check.h>" "$f"
   fi
 done

 # Remove cassert includes
 for f in $(git grep -l '<cassert>' -- "${paths[@]}"); do
   sed --in-place '/^#include <cassert>$/d' "$f"
 done

-END VERIFY SCRIPT-
-BEGIN VERIFY SCRIPT-
 git show -U0 HEAD~0 | ./contrib/devtools/clang-format-diff.py -p1 -i -v
-END VERIFY SCRIPT-
@maflcko

maflcko commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Rebased and limited to fuzz to limit conflicts.

@DrahtBot DrahtBot removed the CI failed label Nov 9, 2026

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa6c603.

This somewhat overlaps with #36808. However, this PR is focused and scripted, whereas #36808 is not ready for review yet. In any case, this PR will make the diff in #36808 smaller and easier to review.

@DrahtBot
DrahtBot requested a review from l0rinc November 9, 2026 19:07
@maflcko maflcko changed the title scripted-diff: [test] Add util/check.h includes for assertions scripted-diff: [fuzz] Add util/check.h includes for assertions Nov 10, 2026
@fanquake
fanquake merged commit 232cb54 into bitcoin:master Nov 10, 2026
27 checks passed
@maflcko
maflcko deleted the 2608-test-assert branch November 10, 2026 13:55
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.

6 participants