Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
731af59
unittests: start introducing unit tests in Idefix (currently for the …
svalat Oct 5, 2026
44847c8
unittest: register ./unitests in "make test"
svalat Oct 5, 2026
831f174
unittest: Port all lookuptable tests in googletest framework
svalat Oct 7, 2026
51f2aee
unittest: Make unit tests optional at build time via Idefix_GTEST and…
svalat Oct 7, 2026
feeff77
tests: Build some examples how to simply compare some Kokkos::view an…
svalat Oct 13, 2026
96fa3f3
test: move search GTest in a function and dedicated cmake/HandleDeps.…
svalat Oct 13, 2026
d9e2db9
tests: introduce runs of the unit test in github actions
svalat Oct 13, 2026
94b23fb
tests: fix header of cmake/HandleDeps.cmake
svalat Oct 14, 2026
6cea3f8
tests: remove CPU loop to replace them by idefix_for() & parallel_for…
svalat Oct 14, 2026
9ef1ea1
test: oops fix loop order to have the right inner loop on the idefix …
svalat Oct 14, 2026
b4d79a4
test: fix GoogleTest usage with KOKKOS_LAMBDA
svalat Oct 14, 2026
eaac4e4
test: add missing fences when running on GPU
svalat Oct 14, 2026
fe0b954
test: force using downloaded v1.18.0 of googletest due to the Kokkos …
svalat Oct 14, 2026
6f57aa3
test: oops add missing Kokkos::deep_copy() when running on GPU
svalat Oct 14, 2026
87786b3
test: rename the host variable to reuse the original name + _host to …
svalat Oct 14, 2026
216d840
unittests: fix argc, argv issues
svalat Oct 20, 2026
44b3f5a
unittest: fix test dependencies
svalat Oct 20, 2026
01d0568
unittests: fix an issue in CMakeLists.txt
svalat Oct 20, 2026
af6d87e
unittest: due to weak symbol usage, setup.cpp should be build in idef…
svalat Oct 20, 2026
ba96dff
unittest: should apply suppress_fma also on libidefix-core
svalat Oct 20, 2026
0aa81b6
unittests: fix mistake in replace_idefix_source() due to idefix/idefi…
svalat Oct 26, 2026
9e0fbe7
unittest: remove utils/loopupTable which is now tests in unittests
svalat Oct 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/idefix-ci-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ env:
permissions: {}

jobs:
UnitTests:
runs-on: self-hosted
steps:
- name: Check out repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: recursive
persist-credentials: false
- name: Configure, Build Idefix and Run Unit Tests
run: scripts/ci/run-unit-tests $TESTME_OPTIONS

ShocksHydro:
runs-on: self-hosted
steps:
Expand Down
58 changes: 45 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ option(Idefix_MHD "enable MHD" OFF)
option(Idefix_MPI "enable Message Passing Interface parallelisation" OFF)
option(Idefix_HIGH_ORDER_FARGO "Force Fargo to use a PPM reconstruction scheme" OFF)
option(Idefix_DEBUG "Enable Idefix debug features (makes the code very slow)" OFF)
option(Idefix_GTEST "Enable building unittests with GoogleTest framework)" OFF)

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.

Stray ) at the end of the option help string: "Enable building unittests with GoogleTest framework)".

Comment thread
glesur marked this conversation as resolved.
Resolved
option(Idefix_RUNTIME_CHECKS "Enable runtime sanity checks" OFF)
option(Idefix_WERROR "Treat compiler warnings as errors" OFF)
option(Idefix_PYTHON "Enable python bindings (requires pybind11)" OFF)
Expand Down Expand Up @@ -70,6 +71,16 @@ include(SetIdefixProperty)
include(SetRequiredBuildSettingsForGCC8)
include(CheckHdf5ParallelSupport)
include(SuppressFMA)
include(HandleDeps)

# enable tests
if (Idefix_GTEST)
# enable supports of "make test"
enable_testing()

# it not, download it internally to the project
GoogleTestDownloadAndLink()
endif()

#Idefix requires Cuda Lambdas (experimental)
if(Kokkos_ENABLE_CUDA)
Expand Down Expand Up @@ -98,18 +109,32 @@ if(Idefix_WERROR)
endif()
endif()

# add tests
if (Idefix_GTEST)
add_executable(unittests)
target_link_libraries(unittests GTest::gtest GTest::gmock)
add_test(unittests unittests)

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.

Optional: modern signature add_test(NAME unittests COMMAND unittests) instead of the positional form.

Comment thread
glesur marked this conversation as resolved.
Resolved
endif()

# sub directories should be called after add_executable
# because the binary target "idefix" should be defined
# before adding source files via "target_sources"
# create target binary "idefix"
add_executable(idefix)
add_library(idefix-core STATIC)
add_subdirectory(src build)

# link idefix-core where it should
target_link_libraries(idefix idefix-core)
if (Idefix_GTEST)
target_link_libraries(unittests idefix-core)
endif()

# make absolute
get_filename_component(Idefix_PROBLEM_DIR_ABS ${Idefix_PROBLEM_DIR} ABSOLUTE BASE_DIR ${PROJECT_BINARY_DIR})

if(EXISTS ${Idefix_PROBLEM_DIR_ABS}/setup.cpp)
target_sources(idefix PUBLIC ${Idefix_PROBLEM_DIR_ABS}/setup.cpp)
target_sources(idefix PRIVATE ${Idefix_PROBLEM_DIR_ABS}/setup.cpp)
else()
message(WARNING "No specific setup.cpp found in the problem directory (this message can be ignored if using python to define your problem)")
endif()
Expand All @@ -130,7 +155,7 @@ endif()
if(Idefix_MPI)
add_compile_definitions("WITH_MPI")
find_package(MPI REQUIRED)
target_link_libraries(idefix MPI::MPI_CXX)
target_link_libraries(idefix-core PUBLIC MPI::MPI_CXX)
add_subdirectory(src/mpi)
endif()

Expand All @@ -143,9 +168,9 @@ if(Idefix_HDF5)
if(Idefix_MPI)
set(HDF5_PREFER_PARALLEL TRUE)
endif()
target_sources(idefix
PUBLIC src/output/xdmf.cpp
PUBLIC src/output/xdmf.hpp
target_sources(idefix-core
PRIVATE src/output/xdmf.cpp
PRIVATE src/output/xdmf.hpp
)
# Prefer imported targets (matches older working behavior), then fall back.
find_package(HDF5 QUIET COMPONENTS C)
Expand All @@ -160,9 +185,9 @@ if(Idefix_HDF5)
set(_idefix_hdf5_link_items HDF5::HDF5)
endif()

target_link_libraries(idefix ${_idefix_hdf5_link_items})
target_link_libraries(idefix-core PUBLIC ${_idefix_hdf5_link_items})
message(STATUS "Found HDF5 include directories: ${HDF5_INCLUDE_DIRS}")
target_include_directories(idefix PUBLIC "${HDF5_INCLUDE_DIRS}")
target_include_directories(idefix-core PUBLIC "${HDF5_INCLUDE_DIRS}")
if(Idefix_MPI)
CheckHdf5ParallelSupport("${_idefix_hdf5_link_items}")
if(NOT IDEFIX_HDF5_IS_PARALLEL)
Expand Down Expand Up @@ -191,8 +216,8 @@ if(Idefix_PYTHON)
endif ()
set(PYBIND11_FINDPYTHON ON CACHE BOOL "Idefix requires python" FORCE)
find_package(pybind11 REQUIRED)
target_link_libraries(idefix pybind11::embed)
target_sources(idefix
target_link_libraries(idefix-core PUBLIC pybind11::embed)
target_sources(idefix-core
PUBLIC src/pydefix.cpp
PUBLIC src/pydefix.hpp
)
Expand Down Expand Up @@ -288,10 +313,10 @@ if (${Idefix_MPI_GPU_FORCE_COPY})
add_compile_definitions("WITH_GPU_FORCE_COPY")
endif()

target_include_directories(idefix PUBLIC
target_include_directories(idefix-core PUBLIC
"${Idefix_PROBLEM_DIR_ABS}"
)
target_include_directories(idefix PUBLIC
target_include_directories(idefix-core PUBLIC
src/kokkos/core/src
src/dataBlock
src/dataBlock/planetarySystem
Expand All @@ -314,7 +339,7 @@ target_include_directories(idefix PUBLIC
src
)

target_link_libraries(idefix Kokkos::kokkos)
target_link_libraries(idefix-core PUBLIC Kokkos::kokkos)

# Generate header with compiler information (name, flags, path)
configure_file(
Expand All @@ -323,12 +348,19 @@ configure_file(
@ONLY
)
# Make sure the generated header is on the include path
target_include_directories(idefix PRIVATE ${CMAKE_BINARY_DIR}/build/generated)
target_include_directories(idefix-core PRIVATE ${CMAKE_BINARY_DIR}/build/generated)
if (Idefix_GTEST)
target_include_directories(unittests PRIVATE ${CMAKE_BINARY_DIR}/build/generated)
endif()

# disable FMA if needed
if(Idefix_SUPPRESS_FMA)
message(STATUS "FMA (fused multiply-add) contraction/codegen is disabled")
target_suppress_fma(idefix)
target_suppress_fma(idefix-core)
if (Idefix_GTEST)
target_suppress_fma(unittests)
endif()
endif()

message(STATUS "Idefix final configuration")
Expand Down
2 changes: 1 addition & 1 deletion cmake/AddIdefixSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

function(add_idefix_source _new_source)
message(STATUS " Adding problem-specific source file ${_new_source}")
target_sources(idefix PUBLIC ${_new_source})
target_sources(idefix-core PRIVATE ${_new_source})
endfunction()
30 changes: 30 additions & 0 deletions cmake/HandleDeps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
######################################################################################
# Idefix MHD astrophysical code
#
# Source file cmake/HandleDeps.cmake
#
# Last modified : 10/2026
#
# Copyright(C) by :
# - Sébastien Valat <sebastien.valat@univ-grenoble-alpes.fr> (IPAG/UGA/CNRS - 2026)
# and other code contributors
#
# Licensed under CeCILL 2.1 License, see COPYING for more information
######################################################################################

function(GoogleTestDownloadAndLink)
# CAUTION: if you change this verison, you should also check if you need to adapt

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.

Typo: "verison" -> "version". (Line 20: "# it not, download it internally" -> "# if not found on the system, download it internally".)

Comment thread
glesur marked this conversation as resolved.
Resolved
# the fix in gtest-idfx and re-import the definition of GTEST_TEST_().
set(gtest_version "1.18.0")

# it not, download it internally to the project
cmake_policy(SET CMP0135 NEW)

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.

cmake_minimum_required(VERSION 3.16) in the root CMakeLists.txt, but CMP0135 requires CMake >= 3.27 and hard-errors at configure time on older versions. Please guard with if(POLICY CMP0135) ... endif() or raise the minimum when Idefix_GTEST=ON.

Comment thread
glesur marked this conversation as resolved.
Resolved
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/releases/download/v${gtest_version}/googletest-${gtest_version}.tar.gz
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endfunction()
12 changes: 9 additions & 3 deletions cmake/ReplaceIdefixSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function(replace_idefix_source _old_source _new_source)
get_target_property(fullsource idefix SOURCES)

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.

Since the idefix-core split, this query looks at the wrong target: idefix no longer holds the core sources (only main.cpp + problem setup.cpp). Any non-main.cpp replacement now hits the spurious SEND_ERROR "no source file match" below. Fix: move the _target_name computation (lines 19-23) above this line and use get_target_property(fullsource ${_target_name} SOURCES).

Comment thread
glesur marked this conversation as resolved.
Resolved
list(FILTER fullsource INCLUDE REGEX ${_old_source})

# affected target
set(_target_name "idefix-core")
if (_old_source STREQUAL "main.cpp")
set(_target_name "idefix")
endif()

# Check that only one file matches the pattern
list(LENGTH fullsource listsize)
if(listsize GREATER 1)
Expand All @@ -27,10 +33,10 @@ function(replace_idefix_source _old_source _new_source)
message(STATUS " Replacing: ${fullsource} by ${_new_source}")

# remove the old source file from the target source list
get_target_property(mylist idefix SOURCES)
get_target_property(mylist ${_target_name} SOURCES)
list(FILTER mylist EXCLUDE REGEX ${_old_source})
# replace the source with our new source list
set_property(TARGET idefix PROPERTY SOURCES ${mylist})
set_property(TARGET ${_target_name} PROPERTY SOURCES ${mylist})
# add the new source file
target_sources(idefix PUBLIC ${_new_source})
target_sources(${_target_name} PRIVATE ${_new_source})
endfunction()
101 changes: 101 additions & 0 deletions scripts/ci/run-unit-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash
######################################################################################
# Idefix MHD astrophysical code
#
# Source file scripts/ci/run-unit-tests
#
# Last modified : 10/2026
#
# Copyright(C) by :
# - Sébastien Valat <sebastien.valat@univ-grenoble-alpes.fr> (IPAG/UGA/CNRS - 2026)
# and other code contributors
#
# Licensed under CeCILL 2.1 License, see COPYING for more information
######################################################################################

function gen_cmake_options()
{
# scan args
while [ $# != 0 ]; do
case "${1}" in
'-Werror')
echo "-DIdefix_WERROR=ON"
shift 1
;;
'-ccache')
echo "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
shift 1
;;
'-intel')
echo "-DCMAKE_CXX_COMPILER=icpx"
echo "-DCMAKE_C_COMPILER=icx"
shift 1
;;
'-cuda')
echo "-DKokkos_ENABLE_CUDA=ON"
# disable Async cuda malloc for tests performed on old UCX implementations
echo "-DKokkos_ENABLE_IMPL_CUDA_MALLOC_ASYNC=OFF"
shift 1
;;
'-hip')
echo "-DKokkos_ENABLE_HIP=ON"
shift 1
;;
*)
echo "Invalid option : ${1}" 1>&2
return 1
esac
done
}

function display_and_run()
{
echo ""
echo "======================================================================================"
echo ">> $@"
echo ""
"$@" || return 1
}

# load ICC compiler env
if [ "$IDEFIX_COMPILER" == icc ]; then
source /opt/intel/oneapi/setvars.sh
fi

# enable bash features
set -ue

# load python venv if present
if [ -d .venv ]; then
source .venv/bin/activate
fi

# to get access to idefix ./pytools/ module in python code
if [[ -v PYTHONPATH ]]; then
export PYTHONPATH="${PWD}:${PYTHONPATH}"
else
export PYTHONPATH="${PWD}"
fi

# check gen options
display_and_run gen_cmake_options "$@"

# create build dir
display_and_run mkdir -p build-unittests

# configure via cmake
display_and_run cmake . -B ./build-unittests -DIdefix_GTEST=ON -DIdefix_PROBLEM_DIR=$PWD/test/MHD/AxisFluxTube/ $(gen_cmake_options "$@") --fresh

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.

--fresh requires CMake >= 3.24, but the project declares cmake_minimum_required(VERSION 3.16). Consider dropping --fresh (the build dir is already created above) or documenting the requirement.

Comment thread
glesur marked this conversation as resolved.
Resolved

# compile
display_and_run make -C build-unittests -j8

# jump in dir to run in
display_and_run cd build-unittests

# run the unit tests
display_and_run ./unittests

# END
echo ""
echo "======================================================================================"
echo "Finished with SUCCESS"
Loading
Loading