Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics in cmake
[simgrid.git] / teshsuite / smpi / MBI / CMakeLists.txt
1 # Copyright 2021-2023. The SimGrid Team. All rights reserved.
2
3 # Integrates the MBI tests into the SimGrid build chain when asked to
4
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.
7
8 file(GLOB generator_scripts *Generator.py)
9
10 if (enable_smpi_MBI_testsuite)
11   if (NOT enable_smpi)
12     message(FATAL_ERROR "The MBI test suite cannot be enabled without SMPI. Please change either setting.")
13   endif()
14   if (NOT SIMGRID_HAVE_MC)
15     message(FATAL_ERROR "The MBI test suite cannot be enabled without the model-checker. Please change either setting.")
16   endif()
17
18   message(STATUS "Generating the MBI test cases")
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} ${script}
25                     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/MBI/tmp
26                     RESULT_VARIABLE status)
27     if (NOT status EQUAL 0)
28       message(FATAL_ERROR "Command failed with status: ${status}")
29     endif()
30   endforeach()
31
32   set(CMAKE_C_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc")
33   set(CMAKE_CXX_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpicxx")
34   include_directories(BEFORE "${CMAKE_HOME_DIRECTORY}/include/smpi")
35
36   # Connect the MBI tests to the other tests
37   add_custom_target(tests-mbi COMMENT "Recompiling the MBI tests and tools.")
38   add_dependencies(tests tests-mbi)
39   add_dependencies(tests-mbi simgrid-mc smpimain)
40
41   # Remove Concurrency tests that are out of reach because simgrid does not intercept local modifications yet
42   # An idea could be to use ASan on the verified application, along with https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning
43   # But currently, ASan is not usable at all, since the Checker dislikes this trick when it tries to read the memory of the app.
44   # We should change the checker to not read the app when verifying safty properties
45   file(GLOB cfiles ${CMAKE_BINARY_DIR}/MBI/tmp/LocalConcurrency*.c ${CMAKE_BINARY_DIR}/MBI/tmp/GlobalConcurrency*.c )
46   foreach(cfile ${cfiles})
47     file(REMOVE ${cfile})
48   endforeach()
49   list(LENGTH cfiles len)
50   message(STATUS "Removed ${len} concurrency tests that would fail because we cannot intercept modifications of local variables.")
51   unset(len)
52
53   file(GLOB cfiles RELATIVE ${CMAKE_BINARY_DIR}/MBI/tmp ${CMAKE_BINARY_DIR}/MBI/tmp/*.c )
54   foreach(cfile ${cfiles})
55     # Copy the generated files only if different (needs cmake ≥ 3.21)
56     if (CMAKE_VERSION VERSION_LESS 3.21)
57       file(COPY ${CMAKE_BINARY_DIR}/MBI/tmp/${cfile} DESTINATION ${CMAKE_BINARY_DIR}/MBI/)
58     else()
59       file(COPY_FILE ${CMAKE_BINARY_DIR}/MBI/tmp/${cfile} ${CMAKE_BINARY_DIR}/MBI/${cfile} ONLY_IF_DIFFERENT)
60     endif()
61     string(REGEX REPLACE "[.]c" "" basefile ${cfile})
62
63     # Generate an executable for each of them
64     add_executable(mbi_${basefile} EXCLUDE_FROM_ALL ${CMAKE_BINARY_DIR}/MBI/${cfile})
65     target_link_libraries(mbi_${basefile} simgrid)
66     target_compile_options(mbi_${basefile} PRIVATE "-Wno-unused-variable")
67     set_target_properties(mbi_${basefile} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/MBI)
68     add_dependencies(tests-mbi mbi_${basefile})
69
70     # Generate a test case for each source file, using the MBI runner
71     ADD_TEST(NAME mbi-${basefile}
72              COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MBI.py ${CMAKE_BINARY_DIR} ./mbi_${basefile} ${cfile}
73              WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/MBI)
74     SET_TESTS_PROPERTIES(mbi-${basefile}  PROPERTIES DEPENDS mbi-${basefile})
75     SET_TESTS_PROPERTIES(mbi-${basefile}  PROPERTIES DEPENDS simgrid-mc)
76   endforeach()
77   file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/MBI/tmp) # Clean temp files
78
79   if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
80   else()
81     file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/MBIutils.py DESTINATION ${CMAKE_BINARY_DIR}/MBI)
82   endif()
83 endif()
84
85 # Add the needed files to the distribution
86 foreach(script ${generator_scripts})
87   set(teshsuite_src ${teshsuite_src} ${script})
88 endforeach()
89
90 set(teshsuite_src ${teshsuite_src}
91                   ${CMAKE_CURRENT_SOURCE_DIR}/generator_utils.py
92                   ${CMAKE_CURRENT_SOURCE_DIR}/MBI.py
93                   ${CMAKE_CURRENT_SOURCE_DIR}/MBIutils.py
94                   ${CMAKE_CURRENT_SOURCE_DIR}/simgrid.py
95                   PARENT_SCOPE)