1 # Copyright 2021-2022. The SimGrid Team. All rights reserved.
3 # Integrates the MBI tests into the SimGrid build chain when asked to
5 # Only the python scripts are embeeded in the archive, and the C test files are generated at config time using these scripts.
6 # These python scripts are copied over from the MBI repository with as little changes as possible.
8 set(generator_scripts CollMatchingGenerator.py ResleakGenerator.py) # More generators to come
10 if (enable_smpi_MBI_testsuite)
12 message(FATAL_ERROR "MBI test suite cannot be enabled without SMPI. Please change either setting.")
14 if (NOT enable_model-checking)
15 message(FATAL_ERROR "MBI test suite cannot be enabled without the Mc SimGrid model-checker. Please change either setting.")
18 message(STATUS "Generating the MBI scripts")
19 file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/MBI/tmp)
20 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/MBI/tmp)
21 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/generator_utils.py DESTINATION ${CMAKE_BINARY_DIR}/MBI/tmp)
22 foreach (script ${generator_scripts})
23 message(STATUS " $ ${CMAKE_CURRENT_SOURCE_DIR}/${script}")
24 execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${script}
25 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/MBI/tmp)
28 set(CMAKE_C_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc")
29 set(CMAKE_CXX_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpicxx")
30 include_directories(BEFORE "${CMAKE_HOME_DIRECTORY}/include/smpi")
32 # Connect the MBI tests to the other tests
33 add_custom_target(tests-mbi COMMENT "Recompiling the MBI tests and tools.")
34 add_dependencies(tests tests-mbi)
36 file(GLOB cfiles RELATIVE ${CMAKE_BINARY_DIR}/MBI/tmp ${CMAKE_BINARY_DIR}/MBI/tmp/*.c )
37 foreach(cfile ${cfiles})
38 # Copy the generated files only if different (needs cmake ≥ 3.21)
39 if (CMAKE_VERSION VERSION_LESS 3.21)
40 file(COPY ${CMAKE_BINARY_DIR}/MBI/tmp/${cfile} DESTINATION ${CMAKE_BINARY_DIR}/MBI/)
42 file(COPY_FILE ${CMAKE_BINARY_DIR}/MBI/tmp/${cfile} ${CMAKE_BINARY_DIR}/MBI/${cfile} ONLY_IF_DIFFERENT)
44 string(REGEX REPLACE "[.]c" "" basefile ${cfile})
46 # Generate an executable for each of them
47 add_executable(mbi_${basefile} EXCLUDE_FROM_ALL ${CMAKE_BINARY_DIR}/MBI/${cfile})
48 target_link_libraries(mbi_${basefile} simgrid)
49 target_compile_options(mbi_${basefile} PRIVATE "-Wno-error")
50 set_target_properties(mbi_${basefile} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/MBI)
51 add_dependencies(tests-mbi mbi_${basefile})
53 # Generate a test case for each source file, using the MBI runner
54 ADD_TEST(NAME mbi-${basefile}
55 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MBI.py ${CMAKE_BINARY_DIR} ./mbi_${basefile} ${cfile}
56 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/MBI)
57 SET_TESTS_PROPERTIES(mbi-${basefile} PROPERTIES DEPENDS mbi-${basefile})
58 SET_TESTS_PROPERTIES(mbi-${basefile} PROPERTIES DEPENDS simgrid-mc)
60 file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/MBI/tmp) # Clean temp files
62 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
64 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/MBIutils.py DESTINATION ${CMAKE_BINARY_DIR}/MBI)
68 # Add the needed files to the distribution
69 foreach(script ${generator_scripts})
70 set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${script})
73 set(teshsuite_src ${teshsuite_src}
74 ${CMAKE_CURRENT_SOURCE_DIR}/generator_utils.py
75 ${CMAKE_CURRENT_SOURCE_DIR}/MBI.py
76 ${CMAKE_CURRENT_SOURCE_DIR}/MBIutils.py
77 ${CMAKE_CURRENT_SOURCE_DIR}/simgrid.py