Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Avoid including CTest if not top level project #161

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

ryanofsky
Copy link
Collaborator

Avoid including CTest in if this is not a top-level cmake project because as reported #145 (comment) this adds a BUILD_TESTING option could be confused for Bitcoin core's BUILD_TESTS option.

Reported
bitcoin-core#145 (comment)
this creates confusion in the bitoin core project because it adds a
BUILD_TESTING variable which is confusing because bitcoin core uses a different
BUILD_TESTS variable.
@ryanofsky
Copy link
Collaborator Author

Marking as a draft for now because this change seems to result in mptest not being found by ctest in Bitcoin core project. I assume some other change is needed there to be compatible with this, but I'm not sure what that would be.

@hebasto
Copy link
Member

hebasto commented Feb 10, 2025

Marking as a draft for now because this change seems to result in mptest not being found by ctest in Bitcoin core project. I assume some other change is needed there to be compatible with this, but I'm not sure what that would be.

Maybe set(BUILD_TESTING ON) in bitcoin/src/ipc/CMakeLists.txt before calling add_subdirectory(libmultiprocess)?

This will satisfy the following condition: https://github.com/chaincodelabs/libmultiprocess/blob/26b9f3dda42110a8ffa5e81b0ea78ba1e30ae659/test/CMakeLists.txt#L22

@ryanofsky
Copy link
Collaborator Author

Thanks will experiment, but do you think set(BUILD_TESTING ${BUILD_TESTS}) make sense? Or should BUILD_TESTS not be followed?

In general I'm pretty confused about this situation. I don't understand why bitcoin is using a different variable name and not including ctest when both bitcoin and libmultiprocess cmake projects appear to be using ctest. Is bitcoin using ctest in a different way than libmultiprocess is using ctest?

@hebasto
Copy link
Member

hebasto commented Feb 10, 2025

Thanks will experiment, but do you think set(BUILD_TESTING ${BUILD_TESTS}) make sense?

Yes, it does. We do the same for the secp256k1 subtree.

In general I'm pretty confused about this situation. I don't understand why bitcoin is using a different variable name and not including ctest when both bitcoin and libmultiprocess cmake projects appear to be using ctest. Is bitcoin using ctest in a different way than libmultiprocess is using ctest?

For Bitcoin Core's test suite, different executables and commands are used, including test_bitcoin, test_bitcoin-qt, bench_bitcoin and a few of Python scripts. Using CTest's BUILD_TESTING variable to control the configuration of these targets seems confusing. Additionally, the BUILD_TESTS and BUILD_BENCH variables inherit the corresponding Autotools' options—namely, --disable-tests and --disable-bench.

@ryanofsky
Copy link
Collaborator Author

Using CTest's BUILD_TESTING variable to control the configuration of these targets seems confusing.

This is the part I don't understand. We are using ctest so why would it be confusing to use the ctest variable and less confusing to have our own similarly named variable?

@hebasto
Copy link
Member

hebasto commented Feb 10, 2025

Using CTest's BUILD_TESTING variable to control the configuration of these targets seems confusing.

This is the part I don't understand. We are using ctest so why would it be confusing to use the ctest variable and less confusing to have our own similarly named variable?

Hmm, I was going to respond with the following example:

$ cmake -B build -DBUILD_TESTS=OFF -DBUILD_BENCH=ON
$ cmake --build build -j $(nproc)
$ ctest --test-dir build
Internal ctest changing into directory: /home/hebasto/git/bitcoin/build
Test project /home/hebasto/git/bitcoin/build
    Start 1: util_rpcauth_test
1/2 Test #1: util_rpcauth_test ..................   Passed    0.12 sec
    Start 2: bench_sanity_check_high_priority
2/2 Test #2: bench_sanity_check_high_priority ...   Passed    5.73 sec

100% tests passed, 0 tests failed out of 2

Total Test time (real) =   5.85 sec

However, due to the following (buggy?) code:

if(BUILD_TESTS)
  enable_testing()
endif()

my example is broken, and the semantics of BUILD_TESTS are indistinguishable from those of BUILD_TESTING.

UPD. Bitcoin Core's code should have enable_testing() unconditionally.

@ryanofsky
Copy link
Collaborator Author

I see, so the idea that you want BUILD_TESTS to specifically control whether or not test_bitcoin executable is built, and want BUILD_TESTING as an option for whether to require ctest to simply not exist and always be forced on? That seems reasonable and consistent.

I will say this is not the approach I would take if I were designing the cmake build. IMO, it makes more sense to have options to control whether dependencies are used, not whether targets are built. So having a BUILD_TESTING option to control whether ctest is used seems useful, and having a BUILD_TEST option to control whether test_bitcoin is built seems less useful. But your approach is consistent and I think it should work.

I think I will merge this PR, and then in bitcoin/bitcoin#31741 I can decide what to do to support it. I could do set(BUILD_TESTING ON) and add a comment about how bitcoin build always requires ctest so this option is forced on. I could set(BUILD_TESTING ${BUILD_TESTS}) and let BUILD_TESTS control whether unit tests are built in general. Or I could add a separate option to control whether libmultiprocess unit tests are built.

@ryanofsky ryanofsky merged commit 011fc53 into bitcoin-core:master Feb 10, 2025
Sjors pushed a commit to Sjors/bitcoin that referenced this pull request Feb 10, 2025
Bring in a few cmake changes to improve cmake support and fix compile/lint/tidy warnings.

bitcoin-core/libmultiprocess#140 build: don't clobber user/superproject c++ version
bitcoin-core/libmultiprocess#142 build: add option for external mpgen binary
bitcoin-core/libmultiprocess#143 cleanup: initialize vars in the EventLoop constructor in the correct order
bitcoin-core/libmultiprocess#146 cmake: Suppress compiler warnings from capnproto headers
bitcoin-core/libmultiprocess#147 cmake: EXTERNAL_MPGEN cleanups
bitcoin-core/libmultiprocess#148 util: fix -Wpessimizing-move warning
bitcoin-core/libmultiprocess#145 CTest: Module must be included at the top level
bitcoin-core/libmultiprocess#149 Avoid `-Wundef` compiler warnings
bitcoin-core/libmultiprocess#152 refactor: Fix compiler and clang-tidy warnings
bitcoin-core/libmultiprocess#155 scripted-diff: s/Libmultiprocess_EXTERNAL_MPGEN/MPGEN_EXECUTABLE/g
bitcoin-core/libmultiprocess#156 refactor: Remove locale-dependent function calls
bitcoin-core/libmultiprocess#157 refactor: Avoid using std::format
bitcoin-core/libmultiprocess#159 bugfix: Do not lock EventLoop::mutex after EventLoop is done
bitcoin-core/libmultiprocess#161 cmake: Avoid including CTest if not top level project
Sjors pushed a commit to Sjors/bitcoin that referenced this pull request Feb 13, 2025
Bring in a few cmake changes to improve cmake support and fix compile/lint/tidy warnings.

bitcoin-core/libmultiprocess#140 build: don't clobber user/superproject c++ version
bitcoin-core/libmultiprocess#142 build: add option for external mpgen binary
bitcoin-core/libmultiprocess#143 cleanup: initialize vars in the EventLoop constructor in the correct order
bitcoin-core/libmultiprocess#146 cmake: Suppress compiler warnings from capnproto headers
bitcoin-core/libmultiprocess#147 cmake: EXTERNAL_MPGEN cleanups
bitcoin-core/libmultiprocess#148 util: fix -Wpessimizing-move warning
bitcoin-core/libmultiprocess#145 CTest: Module must be included at the top level
bitcoin-core/libmultiprocess#149 Avoid `-Wundef` compiler warnings
bitcoin-core/libmultiprocess#152 refactor: Fix compiler and clang-tidy warnings
bitcoin-core/libmultiprocess#155 scripted-diff: s/Libmultiprocess_EXTERNAL_MPGEN/MPGEN_EXECUTABLE/g
bitcoin-core/libmultiprocess#156 refactor: Remove locale-dependent function calls
bitcoin-core/libmultiprocess#157 refactor: Avoid using std::format
bitcoin-core/libmultiprocess#159 bugfix: Do not lock EventLoop::mutex after EventLoop is done
bitcoin-core/libmultiprocess#161 cmake: Avoid including CTest if not top level project
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 24, 2025
Bump libmultiprocess library to include bugfix
bitcoin-core/libmultiprocess#159 which should fix
intermittent CI failure reported
bitcoin#31921

This change is bumping the libmultiprocess version instead of cherry picking
the bugfix. It could cherry-pick the bugfix instead, but there are reasons to
prefer just bumping the version:

- Bugfix might interact with earlier PRs, and the latest version is better
  tested with testing done in many CI configurations in bitcoin#30975 and bitcoin#31802

- Even though we are in feature freeze for a release, the MULTIPROCESS=1 option
  is currently not enabled for release, so this PR only affect CI builds and
  local builds, not the release build.

bitcoin-core/libmultiprocess#140 build: don't clobber user/superproject c++ version
bitcoin-core/libmultiprocess#142 build: add option for external mpgen binary
bitcoin-core/libmultiprocess#143 cleanup: initialize vars in the EventLoop constructor in the correct order
bitcoin-core/libmultiprocess#146 cmake: Suppress compiler warnings from capnproto headers
bitcoin-core/libmultiprocess#147 cmake: EXTERNAL_MPGEN cleanups
bitcoin-core/libmultiprocess#148 util: fix -Wpessimizing-move warning
bitcoin-core/libmultiprocess#145 CTest: Module must be included at the top level
bitcoin-core/libmultiprocess#149 Avoid `-Wundef` compiler warnings
bitcoin-core/libmultiprocess#152 refactor: Fix compiler and clang-tidy warnings
bitcoin-core/libmultiprocess#155 scripted-diff: s/Libmultiprocess_EXTERNAL_MPGEN/MPGEN_EXECUTABLE/g
bitcoin-core/libmultiprocess#156 refactor: Remove locale-dependent function calls
bitcoin-core/libmultiprocess#157 refactor: Avoid using std::format
bitcoin-core/libmultiprocess#159 bugfix: Do not lock EventLoop::mutex after EventLoop is done
bitcoin-core/libmultiprocess#161 cmake: Avoid including CTest if not top level project
bitcoin-core/libmultiprocess#164 Bump minimum required cmake to 3.12
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 24, 2025
Bump libmultiprocess library to include bugfix
bitcoin-core/libmultiprocess#159 which should fix
intermittent CI failures reported in
bitcoin#31921

This change is bumping the libmultiprocess version instead of cherry picking
the bugfix. It could cherry-pick the bugfix instead, but there are reasons to
prefer bumping the version:

- Bugfix might interact with earlier PRs, and the latest version is better
  tested with testing done in many CI configurations in bitcoin#30975 and bitcoin#31802

- Even though we are in feature freeze for a release, the MULTIPROCESS=1 option
  is currently not enabled for release, so this PR only affect CI builds and
  local builds, not the release build.

This update brings in the following changes:

bitcoin-core/libmultiprocess#140 build: don't clobber user/superproject c++ version
bitcoin-core/libmultiprocess#142 build: add option for external mpgen binary
bitcoin-core/libmultiprocess#143 cleanup: initialize vars in the EventLoop constructor in the correct order
bitcoin-core/libmultiprocess#146 cmake: Suppress compiler warnings from capnproto headers
bitcoin-core/libmultiprocess#147 cmake: EXTERNAL_MPGEN cleanups
bitcoin-core/libmultiprocess#148 util: fix -Wpessimizing-move warning
bitcoin-core/libmultiprocess#145 CTest: Module must be included at the top level
bitcoin-core/libmultiprocess#149 Avoid `-Wundef` compiler warnings
bitcoin-core/libmultiprocess#152 refactor: Fix compiler and clang-tidy warnings
bitcoin-core/libmultiprocess#155 scripted-diff: s/Libmultiprocess_EXTERNAL_MPGEN/MPGEN_EXECUTABLE/g
bitcoin-core/libmultiprocess#156 refactor: Remove locale-dependent function calls
bitcoin-core/libmultiprocess#157 refactor: Avoid using std::format
bitcoin-core/libmultiprocess#159 bugfix: Do not lock EventLoop::mutex after EventLoop is done
bitcoin-core/libmultiprocess#161 cmake: Avoid including CTest if not top level project
bitcoin-core/libmultiprocess#164 Bump minimum required cmake to 3.12
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 24, 2025
Bump libmultiprocess library to include bugfix
bitcoin-core/libmultiprocess#159 which should fix
intermittent CI failures reported in
bitcoin#31921

This change is bumping the libmultiprocess version instead of cherry picking
the bugfix. It could cherry-pick the bugfix instead, but there are reasons to
prefer bumping the version:

- Bugfix might interact with earlier PRs, and the latest version is better
  tested with testing done in many CI configurations in bitcoin#30975 and bitcoin#31802

- Even though we are in feature freeze for a release, the MULTIPROCESS=1 option
  is currently not enabled for release, so this PR only affect CI builds and
  local builds, not the release build.

This update brings in the following changes:

bitcoin-core/libmultiprocess#140 build: don't clobber user/superproject c++ version
bitcoin-core/libmultiprocess#142 build: add option for external mpgen binary
bitcoin-core/libmultiprocess#143 cleanup: initialize vars in the EventLoop constructor in the correct order
bitcoin-core/libmultiprocess#146 cmake: Suppress compiler warnings from capnproto headers
bitcoin-core/libmultiprocess#147 cmake: EXTERNAL_MPGEN cleanups
bitcoin-core/libmultiprocess#148 util: fix -Wpessimizing-move warning
bitcoin-core/libmultiprocess#145 CTest: Module must be included at the top level
bitcoin-core/libmultiprocess#149 Avoid `-Wundef` compiler warnings
bitcoin-core/libmultiprocess#152 refactor: Fix compiler and clang-tidy warnings
bitcoin-core/libmultiprocess#155 scripted-diff: s/Libmultiprocess_EXTERNAL_MPGEN/MPGEN_EXECUTABLE/g
bitcoin-core/libmultiprocess#156 refactor: Remove locale-dependent function calls
bitcoin-core/libmultiprocess#157 refactor: Avoid using std::format
bitcoin-core/libmultiprocess#159 bugfix: Do not lock EventLoop::mutex after EventLoop is done
bitcoin-core/libmultiprocess#161 cmake: Avoid including CTest if not top level project
bitcoin-core/libmultiprocess#164 Bump minimum required cmake to 3.12
fanquake pushed a commit to bitcoin/bitcoin that referenced this pull request Feb 25, 2025
Bump libmultiprocess library to include bugfix
bitcoin-core/libmultiprocess#159 which should fix
intermittent CI failures reported in
#31921

This change is bumping the libmultiprocess version instead of cherry picking
the bugfix. It could cherry-pick the bugfix instead, but there are reasons to
prefer bumping the version:

- Bugfix might interact with earlier PRs, and the latest version is better
  tested with testing done in many CI configurations in #30975 and #31802

- Even though we are in feature freeze for a release, the MULTIPROCESS=1 option
  is currently not enabled for release, so this PR only affect CI builds and
  local builds, not the release build.

This update brings in the following changes:

bitcoin-core/libmultiprocess#140 build: don't clobber user/superproject c++ version
bitcoin-core/libmultiprocess#142 build: add option for external mpgen binary
bitcoin-core/libmultiprocess#143 cleanup: initialize vars in the EventLoop constructor in the correct order
bitcoin-core/libmultiprocess#146 cmake: Suppress compiler warnings from capnproto headers
bitcoin-core/libmultiprocess#147 cmake: EXTERNAL_MPGEN cleanups
bitcoin-core/libmultiprocess#148 util: fix -Wpessimizing-move warning
bitcoin-core/libmultiprocess#145 CTest: Module must be included at the top level
bitcoin-core/libmultiprocess#149 Avoid `-Wundef` compiler warnings
bitcoin-core/libmultiprocess#152 refactor: Fix compiler and clang-tidy warnings
bitcoin-core/libmultiprocess#155 scripted-diff: s/Libmultiprocess_EXTERNAL_MPGEN/MPGEN_EXECUTABLE/g
bitcoin-core/libmultiprocess#156 refactor: Remove locale-dependent function calls
bitcoin-core/libmultiprocess#157 refactor: Avoid using std::format
bitcoin-core/libmultiprocess#159 bugfix: Do not lock EventLoop::mutex after EventLoop is done
bitcoin-core/libmultiprocess#161 cmake: Avoid including CTest if not top level project
bitcoin-core/libmultiprocess#164 Bump minimum required cmake to 3.12
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Feb 25, 2025
01f7715 depends: Update libmultiprocess library to fix CI failure (Ryan Ofsky)

Pull request description:

  Bump libmultiprocess library to include bugfix bitcoin-core/libmultiprocess#159 which should fix intermittent CI failures reported in #31921

  This change is bumping the libmultiprocess version instead of cherry picking the bugfix. It could cherry-pick the bugfix instead, but there are reasons to prefer bumping the version:

  - Bugfix might interact with earlier PRs, and the latest version is better tested with testing done in many CI configurations in [#30975](#30975) and [#31802](#31802)

  - Even though we are in feature freeze for a release, the MULTIPROCESS=1 option is currently not enabled for release, so this PR only affect CI builds and local builds, not the release build.

  This update brings in the following changes:

  bitcoin-core/libmultiprocess#140 build: don't clobber user/superproject c++ version
  bitcoin-core/libmultiprocess#142 build: add option for external mpgen binary
  bitcoin-core/libmultiprocess#143 cleanup: initialize vars in the EventLoop constructor in the correct order
  bitcoin-core/libmultiprocess#146 cmake: Suppress compiler warnings from capnproto headers
  bitcoin-core/libmultiprocess#147 cmake: EXTERNAL_MPGEN cleanups
  bitcoin-core/libmultiprocess#148 util: fix -Wpessimizing-move warning
  bitcoin-core/libmultiprocess#145 CTest: Module must be included at the top level
  bitcoin-core/libmultiprocess#149 Avoid `-Wundef` compiler warnings
  bitcoin-core/libmultiprocess#152 refactor: Fix compiler and clang-tidy warnings
  bitcoin-core/libmultiprocess#155 scripted-diff: s/Libmultiprocess_EXTERNAL_MPGEN/MPGEN_EXECUTABLE/g
  bitcoin-core/libmultiprocess#156 refactor: Remove locale-dependent function calls
  bitcoin-core/libmultiprocess#157 refactor: Avoid using std::format
  bitcoin-core/libmultiprocess#159 bugfix: Do not lock EventLoop::mutex after EventLoop is done
  bitcoin-core/libmultiprocess#161 cmake: Avoid including CTest if not top level project
  bitcoin-core/libmultiprocess#164 Bump minimum required cmake to 3.12

  ---

  This PR is part of the [process separation project](#28722).

ACKs for top commit:
  fanquake:
    ACK 01f7715

Tree-SHA512: a6a795e4d4e13e9d35c9346f3c83d5da817f1452bdc4a9412aeadc4c652ad6e5047f4c77756570594a70ec9095cc786772a0469e306dc19bb5a508fd515c37f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants