More robust preparation for MPI tests.
authorM. Eric Irrgang <mei2n@virginia.edu>
Mon, 11 Oct 2021 09:01:10 +0000 (09:01 +0000)
committerJoe Jordan <ejjordan12@gmail.com>
Mon, 11 Oct 2021 09:01:10 +0000 (09:01 +0000)
src/testutils/CMakeLists.txt
src/testutils/TestMacros.cmake

index b5de0e007f8f8cea1771ba4ca84d17c6e2a0135a..620ee575ff2240eebf1c9b54ba07ecc0da1e5eb0 100644 (file)
@@ -119,32 +119,4 @@ target_link_libraries(testutils PUBLIC common)
 # TODO: Explicitly link specific modules with minimal exposure.
 target_link_libraries(testutils PUBLIC legacy_modules)
 
-# TODO Use gmx_add_missing_tests_notice() instead of the messages below.
-set(GMX_CAN_RUN_MPI_TESTS 1)
-if (GMX_MPI)
-    set(_an_mpi_variable_had_content 0)
-    foreach(VARNAME MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS)
-        # These variables need a valid value for the test to run
-        # and pass, but conceivably any of them might be valid
-        # with arbitrary (including empty) content. They can't be
-        # valid if they've been populated with the CMake
-        # find_package magic suffix/value "NOTFOUND", though.
-        if (${VARNAME} MATCHES ".*NOTFOUND")
-            message(STATUS "CMake variable ${VARNAME} was not detected to be a valid value. To test GROMACS correctly, check the advice in the install guide.")
-            set(GMX_CAN_RUN_MPI_TESTS 0)
-        endif()
-        if (NOT VARNAME STREQUAL MPIEXEC AND ${VARNAME})
-            set(_an_mpi_variable_had_content 1)
-        endif()
-    endforeach()
-    if(_an_mpi_variable_had_content AND NOT MPIEXEC)
-        message(STATUS "CMake variable MPIEXEC must have a valid value if one of the other related MPIEXEC variables does. To test GROMACS correctly, check the advice in the install guide.")
-        set(GMX_CAN_RUN_MPI_TESTS 0)
-    endif()
-elseif (NOT GMX_THREAD_MPI)
-    set(GMX_CAN_RUN_MPI_TESTS 0)
-endif()
-
-set(GMX_CAN_RUN_MPI_TESTS ${GMX_CAN_RUN_MPI_TESTS} PARENT_SCOPE)
-
 add_subdirectory(tests)
index 8acc6f94b7f197a8c4f1848afeece9edca5695e4..0e6bb73d611d01b28451dcafeb65d12c7536f451 100644 (file)
 include(CMakeParseArguments)
 include(gmxClangCudaUtils)
 
+set(GMX_CAN_RUN_MPI_TESTS 1)
+if (GMX_MPI)
+    set(_an_mpi_variable_had_content 0)
+    foreach(VARNAME MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS)
+        # These variables need a valid value for the test to run
+        # and pass, but conceivably any of them might be valid
+        # with arbitrary (including empty) content. They can't be
+        # valid if they've been populated with the CMake
+        # find_package magic suffix/value "NOTFOUND", though.
+        if (${VARNAME} MATCHES ".*NOTFOUND")
+            gmx_add_missing_tests_notice("CMake variable ${VARNAME} was not detected to be a valid value. "
+                                         "To test GROMACS correctly, check the advice in the install guide.")
+            set(GMX_CAN_RUN_MPI_TESTS 0)
+        endif()
+        if (NOT VARNAME STREQUAL MPIEXEC AND ${VARNAME})
+            set(_an_mpi_variable_had_content 1)
+        endif()
+    endforeach()
+    if(_an_mpi_variable_had_content AND NOT MPIEXEC)
+        gmx_add_missing_tests_notice("CMake variable MPIEXEC must have a valid value if one of the other related "
+                                     "MPIEXEC variables does. To test GROMACS correctly, check the advice in the "
+                                     "install guide.")
+        set(GMX_CAN_RUN_MPI_TESTS 0)
+    endif()
+elseif (NOT GMX_THREAD_MPI)
+    set(GMX_CAN_RUN_MPI_TESTS 0)
+endif()
+
 function (gmx_add_unit_test_library NAME)
     if (GMX_BUILD_UNITTESTS AND BUILD_TESTING)
         add_library(${NAME} STATIC ${UNITTEST_TARGET_OPTIONS} ${ARGN})
@@ -253,6 +281,7 @@ function (gmx_register_gtest_test NAME EXENAME)
         endif()
         if (ARG_MPI_RANKS)
             if (NOT GMX_CAN_RUN_MPI_TESTS)
+                gmx_add_missing_tests_notice("Skipping ${NAME} because MPI tests are not available.")
                 return()
             endif()
             list(APPEND _labels MpiTest)