Skip to content

test: optionally run functional tests via CTest - #35762

Open
willcl-ark wants to merge 6 commits into
bitcoin:masterfrom
willcl-ark:ctest-functional-v6
Open

willcl-ark wants to merge 6 commits into
bitcoin:masterfrom
willcl-ark:ctest-functional-v6

Conversation

@willcl-ark

@willcl-ark willcl-ark commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Expose individual functional tests through the same CTest interface used for unit tests, making them easier to select, inspect, and rerun from the command line or CTest-aware IDEs.

Scheduling unit and functional tests together may improve parallel execution. It also enables per-test results and timings to be uploaded to our Bitcoin Core CDash instance, helping track failures and runtime changes across builds.

Registration is opt-in with BUILD_FUNCTIONAL_TESTS=ON and requires CMake 4.4 or newer. The existing runner remains available for RPC coverage and CSV results. The native macOS CI job exercises the combined CTest workflow and passes. See test/README.md for usage and limitations.

@DrahtBot DrahtBot added the Tests label Jul 21, 2026
@DrahtBot

DrahtBot commented Jul 21, 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 BrandonOdiwuor

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:

  • #35395 (doc: Improve test suite dependencies documentation by hebasto)

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.

@willcl-ark

Copy link
Copy Markdown
Member Author

The MacOS native CI job shows ctest orchestrating the unit and functional tests altogether: https://github.com/bitcoin/bitcoin/actions/runs/29824697919/job/88615235560?pr=35762#step:9:3919

Comment thread test/functional/test_runner.py Resolved
Comment thread test/functional/test_runner.py Resolved
Comment thread test/functional/test_runner.py Resolved
@willcl-ark
willcl-ark force-pushed the ctest-functional-v6 branch 3 times, most recently from 121c9ae to b7ad3bf Compare July 23, 2026 21:25
@maflcko maflcko removed the CI failed label Jul 30, 2026
@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task riscv32 bare metal, static libbitcoin_consensus: https://github.com/bitcoin/bitcoin/actions/runs/30046119080/job/90826618769
LLM reason (✨ experimental): CI failed because submodule cloning of newlib-cygwin.git from sourceware.org was rate-limited (HTTP 429), causing the base install step to exit with code 2.

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.

Comment thread ci/test/00_setup_env.sh Resolved
Comment thread test/functional/test_runner.py Resolved
bugfix where options such as --tmpdir can otherwise be consumed as
abbreviations of runner options.

Disable abbreviation so forwarding does not depend on which similarly
named runner options happen to exist.
Reuse the existing selection and benchmark expansion before emitting the
inventory, so exclusions and child options have one source of truth.

Pass each test specification as one quoted argument to support multiple
variant options without imposing a fixed count.

Keep the existing skip and stderr failure semantics when CTest runs one
case. Share timeout and failure-log handling with cache setup, and leave
failed test directories intact across reruns.
Native discovery makes functional cases available to CTest scheduling,
filters and dashboards alongside unit tests. Require CMake 4.4 only when
this optional registration is enabled, avoiding a second discovery
implementation while retaining the existing minimum for normal builds.

Use fixtures to prepare the shared chain cache before parallel execution.
Run cache creation through the same Python wrapper as the test cases so
its timeout and failure handling cannot drift from theirs.
Run unit and functional cases together in one native CI job to keep the
optional CTest path exercised.

Derive selection from the existing RUN_* switches and reuse the
sanitizer-wrapped invocation instead of adding another selection
interface.

Pass existing runner options through TEST_RUNNER_EXTRA, including
failure log output and the scratch directory. Exclude registered
functional cases from legacy unit-only CTest invocations to avoid
running them twice.
@DrahtBot

DrahtBot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task macOS native: https://github.com/bitcoin/bitcoin/actions/runs/37589945926/job/112688773432
LLM reason (✨ experimental): CI failed because parallel benchmark tests collided on the same temporary directory, causing bench_PrevectorDeserializeTrivial to fail with FileExistsError.

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.

Document the opt-in version requirement and standard selection commands
so developers can run individual cases or the combined suite. State the
remaining coverage and concurrent-invocation limits without implying a
replacement for every existing runner workflow.
Concurrent variants of the same script can observe the same wall-clock value
on macOS and select an identical temporary directory. The second test then
fails before framework setup completes.

Use a random UUID suffix so directory names do not depend on clock resolution.
Leave directory creation and cleanup with the test framework to preserve
failed logs and its requirement that the supplied path does not exist.
@willcl-ark
willcl-ark force-pushed the ctest-functional-v6 branch from 45a06a6 to f574198 Compare October 7, 2026 11:03
@willcl-ark

Copy link
Copy Markdown
Member Author

PR description updated with the new, more limited, scope.

Windows cross remains a limitation for now. It can be made to work without too much tinkering, but I don't think that's needed in this pull.

I also considered a commit to have the macos_native ci job (using ctest) actually push results to cdash, but I think that can also come in a separate followup pull.

@DrahtBot

Copy link
Copy Markdown
Contributor

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

@BrandonOdiwuor BrandonOdiwuor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested ACK f574198

An opt-in way to run the functional tests through CTest is valuable for developers integrating Bitcoin Core into CMake/CTest/CDash workflows, and for anyone who wants finer-grained control (filtering, parallel scheduling, fixtures, dashboard reporting) while replacing the existing test_runner.py unchanged.

Tested on Ubuntu 24.04 with CMake 4.4.2.

Build and discovery

  • Clean configure/build with -DBUILD_FUNCTIONAL_TESTS=ON.
  • Discovery: 307 base functional tests registered; 311 with TEST_RUNNER_EXTRA='--extended'.
  • Label and regex filtering (-L, -LE, -R) work as expected.

Build and discovery logs:

build-and-discovery.txt

Execution

  • Individual tests and small mixed sets run successfully under CTest.
  • Full wallet suite (76 tests) passed under -j4, with the expected skips for tests that require previous-release binaries.
  • Parallel scheduling, UUID-suffixed temporary directories, and PYTHON_GIL=1 work as intended.
  • Legacy test_runner.py path remains unaffected.
  • --rerun-failed correctly re-runs only previously failed tests and respects the fixture setup.

Execution logs:

ctest logs.txt

Cache fixture behavior

  • Fixture order is correct: functional.cache_remove_before → functional.create_cache → real tests → functional.cache_remove_after.
  • Cache directory is created under the build tree and cleaned up afterward.
  • Consecutive runs both succeed (cache is recreated each time).
  • Manual deletion of the cache mid-suite (after tests had already started) did not break the in-progress tests. The subsequent run recovered cleanly.

Cache logs;

cache-fixture-runs.txt

CDash submission

Submitted functional test runs to a local CDash instance (Experimental track) via a dashboard script. Results appear correctly with the functional label.

Image

Notes

  • The CMake ≥ 4.4 requirement is correctly enforced (needed for discover_tests()).
  • Extended tests are properly gated behind TEST_RUNNER_EXTRA='--extended' at discovery time.
  • Skip semantics (exit 77) are handled correctly by CTest.

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.

4 participants