Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar fixes and little cleanups
[simgrid.git] / teshsuite / smpi / MBI / CMakeLists.txt
1 # Copyright 2021-2022. 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 set(generator_scripts CollMatchingGenerator.py ResleakGenerator.py) # More generators to come
9
10 if (enable_smpi_MBI_testsuite)
11   if (NOT enable_smpi)
12     message(FATAL_ERROR "MBI test suite cannot be enabled without SMPI. Please change either setting.")
13   endif()
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.")
16   endif()
17
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)
26   endforeach()
27
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")
31
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)
35
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/)
41     else()
42       file(COPY_FILE ${CMAKE_BINARY_DIR}/MBI/tmp/${cfile} ${CMAKE_BINARY_DIR}/MBI/${cfile} ONLY_IF_DIFFERENT)
43     endif()
44     string(REGEX REPLACE "[.]c" "" basefile ${cfile})
45     
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})
52
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)
59   endforeach()
60   file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/MBI/tmp) # Clean temp files
61
62   if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
63   else()
64     file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/MBIutils.py DESTINATION ${CMAKE_BINARY_DIR}/MBI) 
65   endif()
66 endif()
67
68 # Add the needed files to the distribution
69 foreach(script ${generator_scripts})
70   set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${script})
71 endforeach()
72
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
78                   PARENT_SCOPE)