@@ -105,10 +105,6 @@ set( INSTALL_HEADERS "${prefix}/include" CACHE PATH
105105 "Installation path for header files" )
106106message ( STATUS "Installation directory prefix is ${prefix} " )
107107
108- # C++ standard
109- set (CMAKE_CXX_STANDARD 17)
110- set (CMAKE_CXX_STANDARD_REQUIRED YES )
111-
112108# Dependencies
113109set (ENGINES)
114110find_library ( LIB_POSIX_THREADS
@@ -165,9 +161,6 @@ if ( MPI_FOUND )
165161 if ( NOT MPI_IS_THREAD_COMPAT OR NOT MPI_IS_NOT_OPENMPI1 )
166162 message ( WARNING "MPI implementation does not tolerate any threading. Hybrid implementation will not be built" )
167163 endif ()
168- if ( NOT MPI_OPEN_PORT )
169- message ( WARNING "MPI implementation does not support dynamically connecting separate MPI processes. Hence, lpf_mpi_initialize_over_tcp will always fail." )
170- endif ()
171164 if ( NOT MPI_IBARRIER )
172165 message ( WARNING "MPI implementation does not have MPI_Ibarrier, which is required to use the dense all-to-all algorithm on large (> 2 GB) meta-data exchanges" )
173166 endif ()
@@ -181,17 +174,16 @@ if ( LIB_MATH AND LIB_DL AND MPI_FOUND )
181174 list (APPEND ENGINES "mpirma" )
182175 endif ()
183176
184- if (LIB_IBVERBS )
177+ if (ENABLE_IBVERBS )
185178 list (APPEND ENGINES "ibverbs" )
186- list (APPEND ENGINES "zero" )
187179 endif ()
188180
189181endif ()
190182
191183#enable the hybrid engine
192184if ( LIB_POSIX_THREADS AND LIB_MATH AND LIB_DL AND MPI_FOUND
193185 AND MPI_IS_THREAD_COMPAT AND MPI_IS_NOT_OPENMPI1
194- AND LIB_IBVERBS )
186+ AND ENABLE_IBVERBS )
195187 list (APPEND ENGINES "hybrid" )
196188 set (HYBRID_ENGINE_ENABLED on )
197189endif ()
@@ -239,6 +231,19 @@ add_definitions(-DBSPLIB_DLL=1)
239231option (LPF_ENABLE_TESTS
240232 "Enable unit and API tests. This uses Google Testing and Mocking Framework"
241233 OFF )
234+ option (GTEST_AGREE_TO_LICENSE
235+ "Does the user agree to the GoogleTest license"
236+ OFF )
237+
238+ # C++ standard -- Google tests require newer C++ standard than C++11
239+ if (LPF_ENABLE_TESTS)
240+ set (CMAKE_CXX_STANDARD 17)
241+ set (CMAKE_CXX_STANDARD_REQUIRED YES )
242+ else ()
243+ set (CMAKE_CXX_STANDARD 11)
244+ set (CMAKE_CXX_STANDARD_REQUIRED YES )
245+ endif ()
246+
242247
243248# Handling of compiler flags
244249function (target_add_compilation_flags target visibility)
@@ -336,9 +341,13 @@ endfunction()
336341if (LPF_ENABLE_TESTS)
337342 message (STATUS "Unit and API tests will be built. This requires CMake version 3.29 or higher, since we use recent features of the GoogleTest package in CMake." )
338343
344+ if (NOT GTEST_AGREE_TO_LICENSE)
345+ message (FATAL_ERROR "The user needs to agree with the GoogleTest license to use tests (option GTEST_AGREE_TO_LICENSE=TRUE)" )
346+ endif ()
339347 # Enable testing in CMake
340348 enable_testing ()
341349 find_package (GTest)
350+ include (GoogleTest)
342351 if (NOT GTest_FOUND) # if not found, download it and pull it in
343352 include (FetchContent)
344353 FetchContent_Declare(
@@ -357,104 +366,73 @@ if (LPF_ENABLE_TESTS)
357366 file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR} /junit)
358367 set (test_output "${CMAKE_BINARY_DIR} /junit" )
359368
360- # Have a macro to add a unit test
361- function (add_gtest testName engines debug testSource)
362- include (GoogleTest)
363- add_executable (${testName} ${testSource} )
364- if (debug)
365- target_include_directories ( ${testName} BEFORE PRIVATE ${CMAKE_SOURCE_DIR} /include /debug )
366- target_link_libraries (${testName} lpf_debug lpf_hl_debug GTest::gtest GTest::gtest_main)
367- else (debug)
368- target_link_libraries (${testName} GTest::gtest GTest::gtest_main)
369- endif (debug)
370- target_link_exe_with_core(${testName} ${engines} )
371- foreach (LPF_IMPL_ID ${engines} )
372- target_compile_definitions (${testName} PUBLIC LPF_CORE_IMPL_ID=${LPF_IMPL_ID} )
373- endforeach (LPF_IMPL_ID)
374- gtest_add_tests(TARGET ${testName}
375- EXTRA_ARGS --gtest_output=xml:${test_output} /${testName}
376- TEST_LIST seqTests
377- )
378- endfunction (add_gtest)
379-
380-
381-
382369 set (MY_TEST_LAUNCHER ${CMAKE_BINARY_DIR} /test_launcher.py)
383- configure_file ( ${CMAKE_SOURCE_DIR} /test_launcher.py ${MY_TEST_LAUNCHER} @ONLY )
370+ configure_file ( ${CMAKE_SOURCE_DIR} /test_launcher.py ${MY_TEST_LAUNCHER} @ONLY FILE_PERMISSIONS WORLD_EXECUTE OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ )
384371 if ( NOT Python3_FOUND )
385- find_package ( Python3 )
372+ find_package ( Python3 REQUIRED )
386373 endif ()
387- # Proposed optimisation by Albert
388- #execute_process( COMMAND ${Python3_EXECUTABLE} -OO -m py_compile ${MY_TEST_LAUNCHER}
389- # OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE python_opt
390- #)
391- #if ( NOT python_opt EQUAL "0" )
392- # message( FATAL_ERROR "cannot compile test runner" )
393- #else()
394- # message( "compilation of test runner successful" )
395- #endif()
396-
397- set (MY_DT_LAUNCHER ${Python3_EXECUTABLE} ${MY_TEST_LAUNCHER} )
398- # Have a macro to add a unit test that should run with MPI
399- if (MPI_FOUND)
400-
401- function (add_gtest_mpi testName ENGINE debug deathTest testSource )
402- if ("{$ENGINE}" STREQUAL "" )
403- message (FATAL_ERROR "engine cannot be empty, ever!" )
404- endif ()
405- include (GoogleTest)
406- add_executable (${testName} ${testSource} ${ARGN} )
407- target_compile_definitions (${testName} PUBLIC LPF_CORE_IMPL_ID=${ENGINE} )
408- target_compile_definitions (${testName} PUBLIC LPF_CORE_MPI_USES_${ENGINE} )
409- if (debug)
410- target_include_directories ( ${testName} BEFORE PRIVATE ${CMAKE_SOURCE_DIR} /include /debug )
411- target_link_libraries (${testName} lpf_debug lpf_hl_debug GTest::gtest GTest::gtest_main)
412- else (debug)
413- target_link_libraries (${testName} GTest::gtest GTest::gtest_main)
414- endif (debug)
415-
416-
417- execute_process (COMMAND bash -c "grep -m 1 \" Exit code\" ${testSource} | awk 'NF>1{print $NF}' | tr -d '[:cntrl:]'" OUTPUT_VARIABLE retCode)
418- execute_process (COMMAND bash -c "grep -m 1 \" P >=\" ${testSource} | awk 'NF>1{print $NF}' | tr -d '[:cntrl:]'" OUTPUT_VARIABLE minProcs)
419- execute_process (COMMAND bash -c "grep -m 1 \" P <=\" ${testSource} | awk 'NF>1{print $NF}' | tr -d '[:cntrl:]'" OUTPUT_VARIABLE maxProcs)
420- execute_process (COMMAND bash -c "grep -m 1 \"\\ -probe\" ${testSource} | awk 'NF>1{print $NF}' | tr -d '[:cntrl:]'" OUTPUT_VARIABLE lpfProbeSecs)
421-
422- target_link_exe_with_core(${testName} ${ENGINE} )
423-
424-
425- gtest_add_tests(TARGET ${testName}
426- TEST_PREFIX ${ENGINE} _
427- EXTRA_ARGS --gtest_output=xml:${test_output} /${ENGINE} _${testName}
428- )
429-
430-
431- if ("${minProcs} " STREQUAL "" )
432- set (minProcs "1" )
433- endif ()
434- if ("${maxProcs} " STREQUAL "" )
435- set (maxProcs "5" )
436- endif ()
437- if ("${lpfProbeSecs} " STREQUAL "" )
438- set (lpfProbeSecs "0.0" )
439- endif ()
440- if ("${retCode} " STREQUAL "" )
441- set (retCode "0" )
442- endif ()
443-
444- set_property (TARGET ${testName} PROPERTY TEST_LAUNCHER ${MY_DT_LAUNCHER} ;-e;${ENGINE} ;-L;${CMAKE_BINARY_DIR} /lpfrun_build;-p;${minProcs} ;-P;${maxProcs} ;-t;${lpfProbeSecs} ;-R;${retCode} )
445-
446- endfunction (add_gtest_mpi)
447- endif (MPI_FOUND)
374+
375+ # Macro for adding a new GoogleTest test
376+ function (add_gtest testName ENGINE debug testSource )
377+ if ("{$ENGINE}" STREQUAL "" )
378+ message (FATAL_ERROR "engine cannot be empty, ever!" )
379+ endif ()
380+ add_executable (${testName} ${testSource} ${ARGN} )
381+ target_compile_definitions (${testName} PUBLIC LPF_CORE_IMPL_ID=${ENGINE} )
382+ target_compile_definitions (${testName} PUBLIC LPF_CORE_MPI_USES_${ENGINE} )
383+ if (debug)
384+ target_include_directories ( ${testName} BEFORE PRIVATE ${CMAKE_SOURCE_DIR} /include /debug )
385+ target_link_libraries (${testName} lpf_debug lpf_hl_debug GTest::gtest GTest::gtest_main)
386+ else (debug)
387+ target_link_libraries (${testName} GTest::gtest GTest::gtest_main)
388+ endif (debug)
389+
390+
391+ # Extract test-specific information from comments of tests
392+ file (READ ${testSource} fileContents)
393+ string (REGEX MATCH "Exit code: ([0-9]+)" _ ${fileContents} )
394+ set (retCode ${CMAKE_MATCH_1} )
395+ string (REGEX MATCH "pre P >= ([0-9]+)" _ ${fileContents} )
396+ set (minProcs ${CMAKE_MATCH_1} )
397+ string (REGEX MATCH "pre P <= ([0-9]+)" _ ${fileContents} )
398+ set (maxProcs ${CMAKE_MATCH_1} )
399+ string (REGEX MATCH "-probe ([0-9]+.[0-9]+)" _ ${fileContents} )
400+ set (lpfProbeSecs ${CMAKE_MATCH_1} )
401+
402+ target_link_exe_with_core(${testName} ${ENGINE} )
403+
404+
405+ if ("${minProcs} " STREQUAL "" )
406+ set (minProcs "1" )
407+ endif ()
408+ if ("${maxProcs} " STREQUAL "" )
409+ set (maxProcs "5" )
410+ endif ()
411+ if ("${lpfProbeSecs} " STREQUAL "" )
412+ set (lpfProbeSecs "0.0" )
413+ endif ()
414+ if ("${retCode} " STREQUAL "" )
415+ set (retCode "0" )
416+ endif ()
417+
418+ # Most recent approach to Gtests, recommended!
419+ set_property (TARGET ${testName} PROPERTY TEST_LAUNCHER ${MY_TEST_LAUNCHER} ;-e;${ENGINE} ;-L;${CMAKE_BINARY_DIR} /lpfrun_build;-p;${minProcs} ;-P;${maxProcs} ;-t;${lpfProbeSecs} ;-R;${retCode} )
420+ gtest_discover_tests(${testName}
421+ TEST_PREFIX ${ENGINE} _
422+ EXTRA_ARGS --gtest_output=xml:${test_output} /${ENGINE} _${testName}
423+ DISCOVERY_MODE POST_BUILD
424+ DISCOVERY_TIMEOUT 15
425+ )
426+
427+
428+ endfunction (add_gtest)
448429
449430else (LPF_ENABLE_TESTS)
450431 message (STATUS "Unit and API tests will *not* be built" )
451- function (add_gtest testName)
432+ function (add_gtest testName ENGINE debug testSource )
452433 # Do nothing because tests are disabled
453434 endfunction (add_gtest)
454435
455- function (add_gtest_mpi testName ENGINE debug deathTest testSource )
456- # DO nothing because tests are disabled
457- endfunction (add_gtest_mpi)
458436endif (LPF_ENABLE_TESTS)
459437
460438include_directories (include )
@@ -531,5 +509,5 @@ install(DIRECTORY "include/bsp" DESTINATION ${INSTALL_HEADERS})
531509install (DIRECTORY "include/debug" DESTINATION ${INSTALL_HEADERS} /lpf )
532510
533511# Post install actions
534- # add_subdirectory(post-install)
512+ add_subdirectory (post-install )
535513
0 commit comments