Skip to content

unittests: start introducing unit tests in Idefix (currently for the lookupTable) - #419

Open
svalat wants to merge 20 commits into
idefix-code:developfrom
svalat:feature/introduce-gtest-usage-valid-lookup-table
Open

svalat wants to merge 20 commits into
idefix-code:developfrom
svalat:feature/introduce-gtest-usage-valid-lookup-table

Conversation

@svalat

@svalat svalat commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

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 in cmake/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-core to be linked to idefix as for the new unittests exacultable.

GTest limitation with KOKKOS_LAMBDA

When building a unit test defined via TEST(..., ...) with a KOKKOS_LAMDA inside we cannot compile with
NVCC because it complains about the fact the the function generated by TEST() is private.

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 the private -> public change but to be safe
it 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 in gtest-idfx.cpp to 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 macros
to get a simple semantic reusing all the matchers provided by
GoogleTest & GoogleMock.

#include "gtest-idfx.hpp"

//check all 5 static
ASSERT_THAT_1D_ARRAY(a, testing::Eq, 6);

//compare both array
ASSERT_THAT_1D_ARRAYS(a, testing::Eq, b);

//compare with near
ASSERT_THAT_1D_ARRAYS_ARGS(a, testing::DoubleNear, b, 0.001);

There is a full example of use in src/test/testArrays.hpp.

First ported tests

The LoopkupTable test has been translated to GoogeTest and is first real
test in Idefix.

Building and launching

You need to activate -DIdefix_GTEST=ON to build the unit tests.

# configure
mkdir build-unittests
cd build-unittests
cmake .. -DIdefix_GTEST=ON -DIdefix_PROBLEM_DIR=../test/MHD/AxisFluxTube/

# build
make

# run all
./unittest

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

  • Revert the unittest priority in github action before merging.

svalat added 20 commits October 5, 2026 16:30
… download GoogleTest if not found on the system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant