Repository navigation
Conversation
… download GoogleTest if not found on the system
…d IdefixXDArray 1D,2D,3D,4D
…cmake + add a missing test file
…() + remove some useless redundant tests
…mem representation
…ix target not in libidefix-core
There was a problem hiding this comment.
Already addressed in this branch: the UnitTests job in .github/workflows/idefix-ci-jobs.yml was inserted as the first job; it is now moved back to the end of the jobs: list, restoring the previous ordering (per the PR TODO).
Change requests
cmake/ReplaceIdefixSource.cmake:16— broken for non-main.cppreplacements since the core split. The match/uniqueness check queriesget_target_property(fullsource idefix SOURCES), but core sources now live inidefix-core(theidefixtarget only holdsmain.cpp+ the problemsetup.cpp). Any non-main.cppreplacement now trips the spuriousSEND_ERROR "no source file match". Fix: compute_target_namefirst and useget_target_property(fullsource ${_target_name} SOURCES). (Onlytest/skeletonuses this today, withmain.cpp, which is why CI is green.)- CMake minimum vs. the GTEST path.
CMakeLists.txt:19declarescmake_minimum_required(VERSION 3.16), but the GTEST path usescmake_policy(SET CMP0135 NEW)(cmake/HandleDeps.cmake:21, requires CMake ≥ 3.27 — hard configure error on older versions) andcmake --fresh(scripts/ci/run-unit-tests:87, requires ≥ 3.24). Please guard withif(POLICY CMP0135)/ drop--fresh, or raise the minimum whenIdefix_GTEST=ON. doc/source/programmingguide.rst:733— stale pointer. "Usage examples are provided intest/utils/lookupTable" — that directory is deleted by this PR. Point tosrc/utils/tests/testLookupTable.cppinstead.
Nits
CMakeLists.txt:34: stray)in theIdefix_GTESToption help string.CMakeLists.txt:116: optional modernization —add_test(NAME unittests COMMAND unittests).cmake/HandleDeps.cmake:16,20: typos — "verison" → "version"; "# it not, download it internally" → "# if not found on the system, download it internally".- Wrong
Source fileheader paths:src/gtest-idfx.hpp:4andsrc/gtest-idfx.cpp:4saysrc/utils/gtest-idfx.hpp(files live insrc/);src/tests/testKokkos.cpp:4andsrc/tests/testArrays.cpp:4say.hpp(they are.cpp);src/utils/tests/testLookupTable.cpp:4sayssrc/utils/testLookupTable.hpp;src/utils/tests/data/gendata.py:4still saystest/utils/lookupTable/testmelib.pyafter the move/rename. src/gtest-idfx.hpp:388: "GEST_TEST_" → "GTEST_TEST_"; doc comments say "patcher matcher" (×12) and "recieve" (×6);src/gtest-idfx.cppsays "environnement" (×3).src/utils/tests/testLookupTable.cpp: leftover commented-out//idfx::coutdebug lines (200, 222, 235, 249, 302, 332, 502, 509, 547, 569) — remove them, or keep deliberately as debugging aids.
| @@ -16,6 +16,12 @@ function(replace_idefix_source _old_source _new_source) | |||
| get_target_property(fullsource idefix SOURCES) | |||
There was a problem hiding this comment.
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).
| set(gtest_version "1.18.0") | ||
|
|
||
| # it not, download it internally to the project | ||
| cmake_policy(SET CMP0135 NEW) |
There was a problem hiding this comment.
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.
| ###################################################################################### | ||
|
|
||
| function(GoogleTestDownloadAndLink) | ||
| # CAUTION: if you change this verison, you should also check if you need to adapt |
There was a problem hiding this comment.
Typo: "verison" -> "version". (Line 20: "# it not, download it internally" -> "# if not found on the system, download it internally".)
| 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 |
There was a problem hiding this comment.
--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.
| 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) |
There was a problem hiding this comment.
Stray ) at the end of the option help string: "Enable building unittests with GoogleTest framework)".
| if (Idefix_GTEST) | ||
| add_executable(unittests) | ||
| target_link_libraries(unittests GTest::gtest GTest::gmock) | ||
| add_test(unittests unittests) |
There was a problem hiding this comment.
Optional: modern signature add_test(NAME unittests COMMAND unittests) instead of the positional form.
| // *********************************************************************************** | ||
| // Idefix MHD astrophysical code | ||
| // | ||
| // Source file src/utils/gtest-idfx.hpp |
There was a problem hiding this comment.
Header says Source file src/utils/gtest-idfx.hpp but the file lives in src/. Same in src/gtest-idfx.cpp:4. Also line 388: "GEST_TEST_" -> "GTEST_TEST_"; "patcher matcher"/"recieve" wording in the matcher doc comments.
| int dataIdx[2]; | ||
| csv1D.GetNeighboursHost(xq, xN, dataN); | ||
| csv1D.GetNeighboursIndxHost(xq, idx, dataIdx); | ||
| //idfx::cout << "1D: x=" << xN[0] << "," << xN[1] << " data=" << dataN[0] << "," << dataN[1] |
There was a problem hiding this comment.
Leftover commented-out //idfx::cout debug lines throughout this file (200, 222, 235, 249, 302, 332, 502, 509, 547, 569) - remove them or keep deliberately. Header line 4 also has a wrong path (src/utils/testLookupTable.hpp).
|
Duplicated review (made offline), so marked as resolved the second one :-) |
This PR introduces the usage of GoogleTest in the Idefix sources via the first use case about the
LookupTable.In the build system
GoogleTest is automatically downloaded by the CMake script in version 1.18.0 via the function
GoogleTestDownloadAndLink()implemented incmake/HandleDeps.cmake.Due to the limitation discussed in next part I cannot safely use the system GoogleTest because I don't know the version on which I fall on form the sources.
The core functions of Idefix has been moved into
libidefix-coreto be linked toidefixas for the newunittestsexacultable.GTest limitation with KOKKOS_LAMBDA
When building a unit test defined via
TEST(..., ...)with aKOKKOS_LAMDAinside we cannot compile withNVCC because it complains about the fact the the function generated by
TEST()isprivate.A fix has been proposed to Google in 2022 but they rejected it due to non standard
behavior of the compiler : google/googletest#4104
I currently override inside Idefix the
GTEST_TEST_macro applying theprivate->publicchange but to be safeit makes the code sticked to a specific version of GoogleTest.
With this fix everything is working as long as we
#include "gtest-idfx.hpp"in each test file.Idefix & MPI & Kokkos init
A new
main()has been defined ingtest-idfx.cppto be used to launch the unit tests with Kokkos and MPI initialized.Extra assertions
When we will progress in unit testing Idefix we will need to validation some
IdefixXDArrays. I already defined some dedicated macrosto get a simple semantic reusing all the matchers provided by
GoogleTest & GoogleMock.
There is a full example of use in
src/test/testArrays.hpp.First ported tests
The
LoopkupTabletest has been translated to GoogeTest and is first realtest in Idefix.
Building and launching
You need to activate
-DIdefix_GTEST=ONto build the unit tests.Intégration in github actions
I patched the github action scripts so they first build & run the unittests
for each mode (CUDA / Intel / gcc).
It currently run first the unit tests then run the integration tests the time
to validate. I will revert that behavior before doing the final merge.
TODO