Repository navigation
unittests: start introducing unit tests in Idefix (currently for the lookupTable) #419
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
base: develop
Are you sure you want to change the base?
Changes from all commits
731af59
44847c8
831f174
51f2aee
feeff77
96fa3f3
d9e2db9
94b23fb
6cea3f8
9ef1ea1
b4d79a4
eaac4e4
fe0b954
6f57aa3
87786b3
216d840
44b3f5a
01d0568
af6d87e
ba96dff
0aa81b6
9e0fbe7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
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) | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: modern signature
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() | ||
|
|
@@ -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() | ||
|
|
||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
| ) | ||
|
|
@@ -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 | ||
|
|
@@ -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( | ||
|
|
@@ -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") | ||
|
|
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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".)
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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,12 @@ function(replace_idefix_source _old_source _new_source) | |
| get_target_property(fullsource idefix SOURCES) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the
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) | ||
|
|
@@ -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() | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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" | ||
There was a problem hiding this comment.
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)".