Skip to content

build(cmake): honor BUILD_TESTING and run simg4ox via ctest#378

Merged
plexoos merged 2 commits into
mainfrom
ctest-simg4ox
Jun 23, 2026
Merged

build(cmake): honor BUILD_TESTING and run simg4ox via ctest#378
plexoos merged 2 commits into
mainfrom
ctest-simg4ox

Conversation

@plexoos

@plexoos plexoos commented Jun 23, 2026

Copy link
Copy Markdown
Member

This branch aligns Simphony's testing setup with standard CMake/CTest behavior and moves the
existing simg4ox integration check under ctest.

The main goals are:

  • respect BUILD_TESTING in the project tree
  • make build-tree tests discoverable and runnable through ctest
  • ensure external drivers such as Spack can enable tests and invoke ctest in a conventional way
  • remove duplicated CI execution for test_simg4ox.sh

Motivation

Before this change, test subdirectories were added unconditionally, which made the project less
friendly to standard CMake testing flows and to package-manager driven builds.

In addition, simg4ox was validated via a standalone shell script instead of a registered CTest
test. That meant CI and external tooling had to know about the script separately instead of relying
on ctest as the single test entry point.

What Changed

Top-level CMake testing behavior

  • define BUILD_TESTING using the standard CMake pattern
  • default BUILD_TESTING to PROJECT_IS_TOP_LEVEL
  • continue to include(CTest) even when BUILD_TESTING=OFF
  • gate all */tests subdirectories behind if(BUILD_TESTING)

This gives the expected behavior in both cases:

  • top-level builds get tests by default
  • subproject/package-manager builds do not force this project's tests on unless explicitly requested

Keeping CTest included even with BUILD_TESTING=OFF means external drivers can still run ctest
and see an empty test set rather than missing test configuration.

simg4ox CTest integration

  • add a dedicated top-level tests/CMakeLists.txt to register Integration.simg4ox
  • run simg4ox from CTest using $<TARGET_FILE:simg4ox>
  • use a fixed CTest working directory created from CMake
  • keep the wrapper script minimal and focused on launching the executable and comparison step

This turns the existing tests/test_simg4ox.sh flow into a normal CTest integration test instead of
an external ad hoc command.

A/B comparison script cleanup

  • move the old tests/compare_ab.py to optiphy/ana/compare_ab.py
  • remove the old tests/compare_ab.py
  • keep the script serving the same core purpose: compare A/B event outputs and validate the expected
    Geant4-version-dependent mismatch indices

Placing it under optiphy/ana makes it easier to treat as a reusable analysis/helper script rather
than a one-off test-local file.

CI cleanup

  • remove the separate tests/test_simg4ox.sh invocation from .github/workflows/build-pull-request.yaml
  • rely on the existing ctest --test-dir "$SIMPHONY_BUILD" --output-on-failure step to run Integration.simg4ox

This avoids running the same test twice in PR CI.

Copilot AI review requested due to automatic review settings June 23, 2026 00:24

Copilot AI 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.

Pull request overview

This PR aligns Simphony’s test setup with standard CMake/CTest workflows by making test subdirectories conditional on BUILD_TESTING and registering the existing simg4ox integration check as a CTest test.

Changes:

  • Gate all */tests subdirectories (and new top-level tests/) behind if(BUILD_TESTING) while keeping CTest integration present.
  • Register Integration.simg4ox via ctest, using a dedicated build-tree working directory and environment-driven wrapper script execution.
  • Relocate the A/B comparison script from tests/ into optiphy/ana/ and update the wrapper accordingly; remove duplicate CI invocation of the same integration check.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
CMakeLists.txt Introduces a BUILD_TESTING default and gates test subdirectories; keeps CTest included.
tests/CMakeLists.txt Adds a CTest-registered integration test (Integration.simg4ox) that drives test_simg4ox.sh.
tests/test_simg4ox.sh Hardens the script (pipefail, env setup) and points to the relocated compare_ab.py.
tests/compare_ab.py Removes the old test-local A/B comparison script (moved).
optiphy/ana/compare_ab.py Adds the relocated A/B comparison script with improved CLI/error handling structure.
.github/workflows/build-pull-request.yaml Removes the redundant direct execution of tests/test_simg4ox.sh in CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakeLists.txt
Comment on lines +16 to +20
# Use CMake's standard testing option, but avoid enabling this project's tests
# by default when Simphony is pulled in as a subproject.
if(NOT DEFINED BUILD_TESTING)
set(BUILD_TESTING ${PROJECT_IS_TOP_LEVEL} CACHE BOOL "Build the testing tree.")
endif()
Comment thread CMakeLists.txt
Comment on lines +33 to 35
# Keep CTest included even when BUILD_TESTING=OFF so external drivers can run
# ctest and observe an empty test set rather than a missing configuration.
include(CTest)
Comment thread tests/CMakeLists.txt
@@ -0,0 +1,20 @@
find_package(Python3 REQUIRED COMPONENTS Interpreter)
find_program(BASH_EXECUTABLE bash REQUIRED)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf4881deaa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CMakeLists.txt
# Use CMake's standard testing option, but avoid enabling this project's tests
# by default when Simphony is pulled in as a subproject.
if(NOT DEFINED BUILD_TESTING)
set(BUILD_TESTING ${PROJECT_IS_TOP_LEVEL} CACHE BOOL "Build the testing tree.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use a 3.18-compatible top-level check

cmake_minimum_required still allows CMake 3.18, but PROJECT_IS_TOP_LEVEL is only available starting in CMake 3.21 (as shown by cmake --help-variable PROJECT_IS_TOP_LEVEL). In top-level builds with CMake 3.18–3.20 and no explicit -DBUILD_TESTING, this expands empty and caches BUILD_TESTING as false, so the new if(BUILD_TESTING) block skips all test subdirectories and ctest won't discover the existing tests or Integration.simg4ox. Please either use a fallback such as comparing CMAKE_PROJECT_NAME and PROJECT_NAME, or raise the minimum CMake version.

Useful? React with 👍 / 👎.

@plexoos plexoos self-assigned this Jun 23, 2026
@plexoos plexoos force-pushed the ctest-simg4ox branch 2 times, most recently from 4e5bf1d to e0a896d Compare June 23, 2026 16:34
@plexoos plexoos requested a review from Copilot June 23, 2026 16:39

Copilot AI 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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread tests/CMakeLists.txt
Comment on lines +1 to +2
find_package(Python3 REQUIRED COMPONENTS Interpreter)
find_program(BASH_EXECUTABLE bash REQUIRED)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The official CMake 3.18 docs include [REQUIRED] in the find_program() signature and say it stops processing with an error if nothing is found.

plexoos added 2 commits June 23, 2026 13:18
- make Simphony follow CMake's standard `BUILD_TESTING` behavior
- only add `sysrap/tests`, `CSG/tests`, `qudarap/tests`, `CSGOptiX/tests`, `u4/tests`, and `g4cx/tests` when testing is enabled
- keep `include(CTest)` unconditional so external drivers can still run `ctest` and see an empty test set when `BUILD_TESTING=OFF`

The top-level build was including all test subdirectories unconditionally, so `BUILD_TESTING=OFF`
did not fully disable test configuration.

This change makes testing behavior predictable for normal CMake builds and for packaging workflows
such as Spack, where external drivers may configure with testing disabled and/or invoke `ctest`
during build or install validation.
- add a top-level tests CMake target and register Integration.simg4ox
- move compare_ab.py to optiphy/ana and remove the old tests copy
- simplify the simg4ox wrapper to run from the ctest working directory
- drop the duplicate standalone simg4ox invocation from PR CI
@plexoos plexoos merged commit 4260e06 into main Jun 23, 2026
13 checks passed
@plexoos plexoos deleted the ctest-simg4ox branch June 23, 2026 17:49
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.

2 participants