Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 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
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)
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)
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
# 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)
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()
2 changes: 1 addition & 1 deletion cmake/ReplaceIdefixSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ function(replace_idefix_source _old_source _new_source)
# replace the source with our new source list
set_property(TARGET idefix PROPERTY SOURCES ${mylist})
# add the new source file
target_sources(idefix PUBLIC ${_new_source})
target_sources(idefix-core 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

# 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"
62 changes: 36 additions & 26 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,43 @@ add_subdirectory(gravity)
add_subdirectory(utils)

target_sources(idefix
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/arrays.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/error.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/error.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/global.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/global.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/grid.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/grid.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/gridHost.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/gridHost.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/idefix.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/input.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/input.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/loop.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/macros.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/main.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/profiler.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/profiler.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/real_types.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/reduce.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/setup.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/setup.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/units.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/units.cpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/timeIntegrator.hpp
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/timeIntegrator.cpp
)
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/main.cpp
)

target_sources(idefix-core
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/arrays.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/error.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/error.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/global.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/global.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/grid.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/grid.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/gridHost.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/gridHost.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/idefix.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/input.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/input.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/loop.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/macros.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/profiler.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/profiler.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/real_types.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/reduce.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/setup.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/setup.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/units.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/units.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/timeIntegrator.hpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/timeIntegrator.cpp
)
# NOTE: mpi file are added by the root CMakeLists along with dependencies to the MPI library

if (Idefix_GTEST)
target_sources(unittests
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/tests/testKokkos.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/tests/testArrays.cpp
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/gtest-idfx.cpp
)
endif()

#add_subdirectory("${PROJECT_BINARY_DIR}" "${PROJECT_BINARY_DIR}/local")
Loading
Loading