From 7363390e8e0f75ab766311d81acc0e963e2e414d Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 9 Apr 2024 09:36:48 +0200 Subject: [PATCH] Use ctest to run unit tests --- .github/workflows/pack-debian.yml | 1 + .github/workflows/pack-rpm.yml | 1 + .github/workflows/run-unit-tests.yml | 87 ++++++++++--------- CMakePresets.json | 2 +- test/UnitTests/Parallel-mpi/CMakeLists.txt | 9 ++ test/UnitTests/Parallel/PLSerializer_test.cpp | 2 +- 6 files changed, 58 insertions(+), 44 deletions(-) diff --git a/.github/workflows/pack-debian.yml b/.github/workflows/pack-debian.yml index 78728625e..0863ea147 100644 --- a/.github/workflows/pack-debian.yml +++ b/.github/workflows/pack-debian.yml @@ -6,6 +6,7 @@ on: mpi_implementation: description: mpi implementation type: choice + default: openmpi options: - mpich - openmpi diff --git a/.github/workflows/pack-rpm.yml b/.github/workflows/pack-rpm.yml index dae0e85b4..ffd2094ad 100644 --- a/.github/workflows/pack-rpm.yml +++ b/.github/workflows/pack-rpm.yml @@ -6,6 +6,7 @@ on: mpi_implementation: description: mpi implementation type: choice + default: openmpi options: [mpich, openmpi] pull_request: paths: ['**CMakeLists.txt', '**.cmake', .github/workflows/pack-rpm.yml] diff --git a/.github/workflows/run-unit-tests.yml b/.github/workflows/run-unit-tests.yml index 0e5981df1..5726add53 100644 --- a/.github/workflows/run-unit-tests.yml +++ b/.github/workflows/run-unit-tests.yml @@ -45,46 +45,49 @@ jobs: preset-name: ${{ matrix.build-setup.cmake-preset }} targets: norm_test parallel_test parallel_mpi_test learning_test KNITest override-flags: -DTESTING=ON - - name: Run Unit Tests for the Norm Module + - name: Run Unit Tests run: | - build/${{ matrix.build-setup.cmake-preset }}/bin/norm_test \ - --gtest_output="xml:reports/report-norm.xml" - - name: Run Unit Tests for the Parallel Module - if: always() - run: | - build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_test \ - --gtest_output="xml:reports/report-parallel.xml" - - name: Run Unit Tests for the Parallel MPI Module in serial - if: always() - run: | - build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_mpi_test \ - --gtest_output="xml:reports/report-parallel-mpi-serial.xml" - - name: Run Unit Tests for the Parallel MPI Module in parallel (Linux) - if: ${{ always() && runner.os == 'Linux' }} - run: | - mpirun --oversubscribe --use-hwthread-cpus -n 4 build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_mpi_test \ - --gtest_output="xml:reports/report-parallel-mpi-parallel.xml" - - name: Run Unit Tests for the Parallel MPI Module in parallel (Windows and - macOS) - if: ${{ always() && runner.os != 'Linux' }} - run: | - mpiexec -n 4 build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_mpi_test \ - --gtest_output="xml:reports/report-parallel-mpi-parallel.xml" - - name: Run Unit Tests for the Learning Module - if: always() - run: | - build/${{ matrix.build-setup.cmake-preset }}/bin/learning_test \ - --gtest_output="xml:reports/report-learning.xml" - - name: Run Unit Tests for the KNI Module - if: always() - run: | - build/${{ matrix.build-setup.cmake-preset }}/bin/KNITest \ - --gtest_output="xml:reports/report-kni.xml" - - name: Create Unit Test Reports Dashboards - uses: phoenix-actions/test-reporting@v12 - if: always() - with: - name: Unit Tests Reports (${{ matrix.build-setup.os }}) - reporter: jest-junit - path: reports/report-*.xml - path-replace-backslashes: 'true' # Necessary for windows paths + ctest --preset ${{ matrix.build-setup.cmake-preset }} --output-junit junit.xml + # - name: Run Unit Tests for the Norm Module + # run: | + # build/${{ matrix.build-setup.cmake-preset }}/bin/norm_test \ + # --gtest_output="xml:reports/report-norm.xml" + # - name: Run Unit Tests for the Parallel Module + # if: always() + # run: | + # build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_test \ + # --gtest_output="xml:reports/report-parallel.xml" + # - name: Run Unit Tests for the Parallel MPI Module in serial + # if: always() + # run: | + # build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_mpi_test \ + # --gtest_output="xml:reports/report-parallel-mpi-serial.xml" + # - name: Run Unit Tests for the Parallel MPI Module in parallel (Linux) + # if: ${{ always() && runner.os == 'Linux' }} + # run: | + # mpirun --oversubscribe --use-hwthread-cpus -n 4 build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_mpi_test \ + # --gtest_output="xml:reports/report-parallel-mpi-parallel.xml" + # - name: Run Unit Tests for the Parallel MPI Module in parallel (Windows and + # macOS) + # if: ${{ always() && runner.os != 'Linux' }} + # run: | + # mpiexec -n 4 build/${{ matrix.build-setup.cmake-preset }}/bin/parallel_mpi_test \ + # --gtest_output="xml:reports/report-parallel-mpi-parallel.xml" + # - name: Run Unit Tests for the Learning Module + # if: always() + # run: | + # build/${{ matrix.build-setup.cmake-preset }}/bin/learning_test \ + # --gtest_output="xml:reports/report-learning.xml" + # - name: Run Unit Tests for the KNI Module + # if: always() + # run: | + # build/${{ matrix.build-setup.cmake-preset }}/bin/KNITest \ + # --gtest_output="xml:reports/report-kni.xml" + # - name: Create Unit Test Reports Dashboards + # uses: phoenix-actions/test-reporting@v14 + # if: always() + # with: + # name: Unit Tests Reports (${{ matrix.build-setup.os }}) + # reporter: jest-junit + # path: build/${{ matrix.build-setup.cmake-preset }}/junit.xml + # path-replace-backslashes: 'true' # Necessary for windows paths diff --git a/CMakePresets.json b/CMakePresets.json index 32bbe6a2a..44b190c95 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -13,7 +13,7 @@ "generator": "Ninja", "cacheVariables": { "MPI": "ON", - "TESTING": "OFF", + "TESTING": "ON", "BUILD_JARS": "OFF", "BUILD_LEX_YACC": "OFF", "C11": "ON" diff --git a/test/UnitTests/Parallel-mpi/CMakeLists.txt b/test/UnitTests/Parallel-mpi/CMakeLists.txt index 87a26991b..11533a1a3 100644 --- a/test/UnitTests/Parallel-mpi/CMakeLists.txt +++ b/test/UnitTests/Parallel-mpi/CMakeLists.txt @@ -12,3 +12,12 @@ target_include_directories(parallel_mpi_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_options(parallel_mpi_test PUBLIC ${GTEST_CFLAGS}) include(GoogleTest) gtest_discover_tests(parallel_mpi_test) + +# Add the same test in CTest framework. It allows to run the test directly with the right mpi command. The command +# "ctest --preset linux-gcc-release -L mpi" will run (depending on the mpi implementation and the core number): mpiexec +# -n 8 build/linux-gcc-release/parallel_mpi_test +add_test(NAME ctest_parallel_mpi_test COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} + ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + +# Add "mpi" label to the test +set_tests_properties(ctest_parallel_mpi_test PROPERTIES LABELS "mpi") diff --git a/test/UnitTests/Parallel/PLSerializer_test.cpp b/test/UnitTests/Parallel/PLSerializer_test.cpp index 0007cf46a..af10c73f3 100644 --- a/test/UnitTests/Parallel/PLSerializer_test.cpp +++ b/test/UnitTests/Parallel/PLSerializer_test.cpp @@ -21,7 +21,7 @@ TEST(PLSerializer, int) nOut = serializer.GetInt(); serializer.Close(); - ASSERT_EQ(nIn, nOut); + ASSERT_NE(nIn, nOut); } KHIOPS_TEST(PLSerializer, full, PLSerializer::Test);