diff --git a/CMakeLists.txt b/CMakeLists.txt index e9d3928197db0117998244f5d408d78dd7d7f48e..73ee215487da31e2ca04a3858aaf253023ad5d33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ SET("CMAKE_C_FLAGS_RELWITHDEBINFO" FORCE ) # Add new build types -message("* Adding build types...") SET(CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage" CACHE STRING "Flags used by the C++ compiler during coverage builds." @@ -204,10 +203,14 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage") set(GCOVR_OPTIONS --object-directory="${PASTIS_BINARY_DIR}" -r "${PASTIS_SOURCE_DIR}/src" ${GCOVR_EXCLUDE} ${GCOVR_EXTRA}) + if(${PASTIS_HAS_MPI}) + set(MPI_UNIT_TESTS mpi_unit_tests) + endif() + add_custom_target(run_unit_tests ALL COMMAND ${CMAKE_CTEST_COMMAND} -j ${PROCESSOR_COUNT} - DEPENDS unit_tests pastis + DEPENDS unit_tests ${MPI_UNIT_TESTS} pastis COMMENT "Executing unit tests." ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 94118a24d6104092883f9e6280cfd08c5c4ba5d9..a2370f57d338656d0498053cf6c3e6d3ed584e20 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,13 @@ add_executable (unit_tests test_TinyVector.cpp ) +if (${PASTIS_HAS_MPI}) + add_executable (mpi_unit_tests + mpi_test_main.cpp + mpi_test_Messenger.cpp + ) +endif() + target_include_directories(Catch2 INTERFACE ${CATCH_INCLUDE_DIR}) target_link_libraries (unit_tests @@ -21,7 +28,24 @@ target_link_libraries (unit_tests Catch2 ) +if (${PASTIS_HAS_MPI}) + target_link_libraries (mpi_unit_tests + PastisUtils + kokkos + ${PARMETIS_LIBRARIES} + ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} + Catch2 + ) +endif() + enable_testing() #parse catch tests ParseAndAddCatchTests(unit_tests) + +if (${PASTIS_HAS_MPI}) + add_test(mpi_unit_tests ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 "--oversubscribe" + ${MPIEXEC_PREFLAGS} + ${PASTIS_BINARY_DIR}/mpi_unit_tests + ${MPIEXEC_POSTFLAGS}) +endif() diff --git a/tests/mpi_test_Messenger.cpp b/tests/mpi_test_Messenger.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d39c18c19426d88620d1a3724970845b9f904279 --- /dev/null +++ b/tests/mpi_test_Messenger.cpp @@ -0,0 +1,19 @@ +#include <catch.hpp> + +#include <Messenger.hpp> +#include <mpi.h> + +TEST_CASE("Messenger", "[mpi]") { + + SECTION("check for parallel test") { + { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + REQUIRE(rank == commRank()); + + int size; + MPI_Comm_size(MPI_COMM_WORLD, &size); + REQUIRE(size == commSize()); + } + } +} diff --git a/tests/mpi_test_main.cpp b/tests/mpi_test_main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6f2a172aa28460bfe81f8d15f8925a73b467d06 --- /dev/null +++ b/tests/mpi_test_main.cpp @@ -0,0 +1,18 @@ +#define CATCH_CONFIG_RUNNER +#include <catch.hpp> + +#include <Kokkos_Core.hpp> +#include <Messenger.hpp> + +int main( int argc, char* argv[] ) +{ + Messenger::create(argc, argv); + Kokkos::initialize({4,-1,-1,true}); + + int result = Catch::Session().run( argc, argv ); + + Kokkos::finalize(); + Messenger::destroy(); + + return result; +}