Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a target to recompile all ns3 tests (and only them)
[simgrid.git] / examples / cpp / CMakeLists.txt
1 # Regular examples: with only one source and tested with all factories by default
2 #################################################################################
3 ### Define the examples' specificities
4
5 set(_app-bittorrent_sources app-bittorrent/s4u-bittorrent.cpp app-bittorrent/s4u-bittorrent.hpp
6                             app-bittorrent/s4u-peer.cpp app-bittorrent/s4u-peer.hpp
7                             app-bittorrent/s4u-tracker.cpp app-bittorrent/s4u-tracker.hpp)
8 set(_dht-chord_sources    dht-chord/s4u-dht-chord.cpp dht-chord/s4u-dht-chord.hpp dht-chord/s4u-dht-chord-node.cpp)
9 set(_dht-kademlia_sources dht-kademlia/s4u-dht-kademlia.cpp dht-kademlia/s4u-dht-kademlia.hpp
10                           dht-kademlia/node.cpp dht-kademlia/node.hpp
11                           dht-kademlia/routing_table.cpp dht-kademlia/routing_table.hpp
12                           dht-kademlia/answer.cpp dht-kademlia/answer.hpp dht-kademlia/message.hpp)
13
14 set(_actor-stacksize_factories "^thread") # Threads ignore modifications of the stack size
15
16 # The maestro-set example only works for threads
17 set(_maestro-set_factories "thread")
18
19 if(SIMGRID_HAVE_MC)
20   # These tests timeout with threads, not sure why
21   foreach(example mc-bugged1 mc-bugged2 mc-failing-assert mc-electric-fence)
22     set(_${example}_factories "^thread") # Timeout
23     add_dependencies(tests-mc s4u-${example})
24   endforeach()
25
26   if(enable_coverage)
27     foreach (example mc-bugged1 mc-bugged2 mc-electric-fence mc-failing-assert)
28       ADD_TEST(cover-${example} ${CMAKE_CURRENT_BINARY_DIR}/${example}/s4u-${example} ${CMAKE_HOME_DIRECTORY}/examples/platforms/model_checker_platform.xml)
29     endforeach()
30   endif()
31 else()
32   foreach (example mc-bugged1 mc-bugged2  mc-centralized-mutex mc-failing-assert mc-electric-fence)
33     set(_${example}_disable 1)
34   endforeach()
35 endif()
36
37 if(SIMGRID_HAVE_STATEFUL_MC)
38   if(HAVE_C_STACK_CLEANER)
39     add_executable       (s4u-mc-bugged1-liveness-cleaner-on  EXCLUDE_FROM_ALL s4u-mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp)
40     target_link_libraries(s4u-mc-bugged1-liveness-cleaner-on  simgrid)
41     set_target_properties(s4u-mc-bugged1-liveness-cleaner-on  PROPERTIES COMPILE_FLAGS "-DGARBAGE_STACK -fstack-cleaner")
42     add_dependencies(tests-mc s4u-mc-bugged1-liveness-cleaner-on)
43
44     add_executable       (s4u-mc-bugged1-liveness-cleaner-off EXCLUDE_FROM_ALL s4u-mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp)
45     target_link_libraries(s4u-mc-bugged1-liveness-cleaner-off simgrid)
46     set_target_properties(s4u-mc-bugged1-liveness-cleaner-off PROPERTIES COMPILE_FLAGS "-DGARBAGE_STACK -fno-stack-cleaner")
47     add_dependencies(tests-mc s4u-mc-bugged1-liveness-cleaner-off)
48   endif()
49
50   # Model-checking liveness
51   if(HAVE_UCONTEXT_CONTEXTS AND SIMGRID_PROCESSOR_x86_64)
52     # liveness model-checking works only on 64bits (for now ...)
53     set(_mc-bugged1-liveness_factories "ucontext")
54     add_dependencies(tests-mc s4u-mc-bugged1-liveness)
55     set(_mc-bugged2-liveness_factories "ucontext")
56
57     # This example never ends, disable it for now
58     set(_mc-bugged2-liveness_disable 1)
59
60     ADD_TESH(s4u-mc-bugged1-liveness-visited-ucontext --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/mc-bugged1-liveness
61                                                       --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
62                                                       --cd ${CMAKE_CURRENT_SOURCE_DIR}/mc-bugged1-liveness
63                                                        ${CMAKE_HOME_DIRECTORY}/examples/cpp/mc-bugged1-liveness/s4u-mc-bugged1-liveness-visited.tesh)
64     IF(HAVE_C_STACK_CLEANER)
65       add_dependencies(tests-mc s4u-mc-bugged1-liveness-stack-cleaner)
66       # This test checks if the stack cleaner is making a difference:
67       ADD_TEST(s4u-mc-bugged1-liveness-stack-cleaner ${CMAKE_HOME_DIRECTORY}/examples/cpp/mc-bugged1-liveness/s4u-mc-bugged1-liveness-stack-cleaner
68                                                      ${CMAKE_HOME_DIRECTORY}/examples/cpp/mc-bugged1-liveness/
69                                                      ${CMAKE_CURRENT_BINARY_DIR}/mc-bugged1-liveness/)
70     ENDIF()
71   else()
72     set(_mc-bugged1-liveness_disable 1)
73     set(_mc-bugged2-liveness_disable 1)
74   endif()
75
76   if(enable_coverage)
77     ADD_TEST(cover-mc-bugged1-liveness ${CMAKE_CURRENT_BINARY_DIR}/mc-bugged1-liveness/s4u-mc-bugged1-liveness ${CMAKE_HOME_DIRECTORY}/examples/platforms/small_platform.xml 1 1001)
78   endif()
79
80 else()
81   foreach (example mc-bugged1-liveness mc-bugged2-liveness)
82     set(_${example}_disable 1)
83   endforeach()
84 endif()
85
86 # Hijack some regular tests to run them on top of the MC
87 foreach (example synchro-barrier synchro-mutex synchro-semaphore)
88   set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u-mc-${example}.tesh)
89
90   if (SIMGRID_HAVE_MC)
91     ADD_TESH(s4u-mc-${example}
92               --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example}
93               --setenv libdir=${CMAKE_BINARY_DIR}/lib
94               --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
95               --setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR}/${example}
96               --cd ${CMAKE_CURRENT_SOURCE_DIR}/${example}
97               ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-mc-${example}.tesh)
98
99     add_dependencies(tests-mc s4u-${example})
100   endif()
101 endforeach()
102
103 if (SIMGRID_HAVE_MC)
104   # Dependency on the regular tests
105   foreach(example mc-centralized-mutex)
106     add_dependencies(tests-mc s4u-${example})
107   endforeach()
108 endif()
109
110 if(NOT HAVE_GRAPHVIZ)
111   set(_dag-from-dot_disable 1)
112   set(_dag-from-dot-simple_disable 1)
113 endif()
114
115 if (NOT SIMGRID_HAVE_JSON)
116   set(_dag-from-json-simple_disable 1)
117 endif()
118
119 if(SIMGRID_HAVE_NS3)
120   if(NS3_VERSION VERSION_GREATER_EQUAL 3.37)
121     set(_network-ns3_teshfile         ${CMAKE_HOME_DIRECTORY}/examples/cpp/network-ns3/s4u-network-ns3-timed.tesh)
122     set(tesh_files    ${tesh_files}   ${CMAKE_HOME_DIRECTORY}/examples/cpp/network-ns3/s4u-network-ns3-notime.tesh)
123   else()
124     set(_network-ns3_teshfile         ${CMAKE_HOME_DIRECTORY}/examples/cpp/network-ns3/s4u-network-ns3-notime.tesh)
125     set(tesh_files    ${tesh_files}   ${CMAKE_HOME_DIRECTORY}/examples/cpp/network-ns3/s4u-network-ns3-timed.tesh)
126   endif()
127
128 foreach (example network-ns3 network-ns3-wifi)
129   add_dependencies(tests-ns3 s4u-${example})
130 endforeach()
131
132 else()
133   # Even if ns3 is not found, we need to override the teshfile name and make sure that everything gets included in the archive
134   set(_network-ns3_teshfile         ${CMAKE_HOME_DIRECTORY}/examples/cpp/network-ns3/s4u-network-ns3-notime.tesh)
135   set(tesh_files    ${tesh_files}   ${CMAKE_HOME_DIRECTORY}/examples/cpp/network-ns3/s4u-network-ns3-timed.tesh)
136
137   foreach (example network-ns3 network-ns3-wifi)
138     set(_${example}_disable 1)
139   endforeach()
140 endif()
141
142 # Deal with each example
143
144 foreach (example activity-testany activity-waitany
145                  actor-create actor-daemon actor-exiting actor-join actor-kill
146                  actor-lifetime actor-migrate actor-suspend actor-yield actor-stacksize
147                  app-bittorrent app-chainsend app-token-ring
148                  battery-degradation battery-simple battery-energy
149                  comm-pingpong comm-ready comm-suspend comm-testany comm-wait comm-waitany comm-waitall comm-waituntil
150                  comm-dependent comm-host2host comm-failure comm-throttling
151                  cloud-capping cloud-migration cloud-simple
152                  dag-comm dag-from-json-simple dag-from-dax-simple dag-from-dax dag-from-dot-simple dag-from-dot dag-failure dag-io dag-scheduling dag-simple dag-tuto
153                  dht-chord dht-kademlia
154                  energy-exec energy-boot energy-link energy-vm energy-exec-ptask energy-wifi
155                  engine-filtering engine-run-partial
156                  exec-async exec-basic exec-dvfs exec-remote exec-waitany exec-waitfor exec-dependent exec-unassigned
157                  exec-ptask-multicore exec-ptask-multicore-latency exec-cpu-nonlinear exec-cpu-factors exec-failure exec-threads
158                  maestro-set
159                  mc-bugged1 mc-bugged1-liveness mc-bugged2 mc-bugged2-liveness mc-centralized-mutex mc-electric-fence mc-failing-assert
160                  network-ns3 network-ns3-wifi network-wifi
161                  io-async io-priority io-degradation io-file-system io-file-remote io-disk-raw io-dependent
162                  platform-comm-serialize platform-failures platform-profile platform-properties
163                  plugin-host-load plugin-link-load plugin-prodcons
164                  replay-comm replay-io
165                  routing-get-clusters
166                  synchro-barrier synchro-condition-variable synchro-condition-variable-waituntil synchro-mutex synchro-semaphore
167                  clusters-multicpu network-factors network-nonlinear)
168
169   # Use default source file unless specified otherwise
170   if(NOT DEFINED _${example}_sources)
171     set(_${example}_sources ${example}/s4u-${example}.cpp)
172   endif()
173
174   # Use default tesh file unless specified otherwise
175   if(NOT DEFINED _${example}_teshfile)
176     set(_${example}_teshfile ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}.tesh)
177   endif()
178
179   if(NOT DEFINED _${example}_disable)
180     add_executable       (s4u-${example} EXCLUDE_FROM_ALL ${_${example}_sources})
181     add_dependencies     (tests s4u-${example})
182     add_dependencies     (s4u-${example} platf_cpp)
183     target_link_libraries(s4u-${example} simgrid)
184     set_target_properties(s4u-${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
185
186     # Use default factories unless specified otherwise
187     if(NOT DEFINED _${example}_factories)
188       set(_${example}_factories "*")
189     endif()
190 #    message("Factories of ${example}: ${_${example}_factories}")
191
192     ADD_TESH_FACTORIES(s4u-${example} "${_${example}_factories}"
193                                       --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example}
194                                       --setenv libdir=${CMAKE_BINARY_DIR}/lib
195                                       --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
196                                       --setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR}/${example}
197                                       --cd ${CMAKE_CURRENT_SOURCE_DIR}/${example}
198                                       ${_${example}_teshfile})
199   else()
200     message(STATUS "Example ${example} disabled, thus not compiled.")
201     unset(_${example}_disable)
202   endif()
203
204   set(tesh_files    ${tesh_files}    ${_${example}_teshfile})
205   foreach(file ${_${example}_sources})
206     set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${file})
207   endforeach()
208
209   unset(_${example}_factories)
210   unset(_${example}_sources)
211   unset(_${example}_teshfile)
212 endforeach()
213
214
215 # Specific examples
216 ###################
217
218 # MASTERWORKERS EXAMPLE
219 foreach(variant fun class)
220   add_executable       (s4u-app-masterworkers-${variant} EXCLUDE_FROM_ALL app-masterworkers/s4u-app-masterworkers-${variant}.cpp)
221   target_link_libraries(s4u-app-masterworkers-${variant} simgrid)
222   set_target_properties(s4u-app-masterworkers-${variant} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/app-masterworkers)
223   add_dependencies(tests s4u-app-masterworkers-${variant})
224
225   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworkers/s4u-app-masterworkers-${variant}.cpp)
226 endforeach()
227 set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworkers/s4u-app-masterworkers.tesh)
228
229 # The tests the parallel variant of of DHTs
230
231 if(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
232   # Thread-local storage (TLS) is needed for parallel execution, but it doesn't
233   # play well with Ucontexts on 64bit SunOS (at least on x86_64).
234   set(parallel-factories "^ucontext")
235 else()
236   set(parallel-factories "*")
237 endif()
238
239 foreach(example app-bittorrent app-masterworkers
240                 dht-chord dht-kademlia
241                 )
242   ADD_TESH_FACTORIES(s4u-${example}-parallel "${parallel-factories}" --cfg contexts/nthreads:4 ${CONTEXTS_SYNCHRO}
243                                              --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example}
244                                              --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
245                                              --cd ${CMAKE_CURRENT_SOURCE_DIR}/${example}
246                                              ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}.tesh)
247 endforeach()
248
249 # Test non-DPOR reductions on a given MC test
250 foreach(example mc-failing-assert)
251 # State equality is not tested because it would take about 15 hours to run that test on my machine.
252 # We should first optimize mmalloc_heap_differ() which takes ~4sec for each pair to compare (maybe {175 x 174/ 2} pairs here)
253 # See the comment on mmalloc_heap_differ() in compare.cpp for more info on why it's hard to optimize.
254 #
255 #  if(SIMGRID_HAVE_STATEFUL_MC)
256 #    ADD_TESH(s4u-${example}-statequality  --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example}
257 #                                      --setenv libdir=${CMAKE_BINARY_DIR}/lib
258 #                                      --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
259 #                                      --setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR}/${example}
260 #                                      --cd ${CMAKE_CURRENT_SOURCE_DIR}/${example}
261 #                                      ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}-statequality.tesh)
262 #  endif()
263
264   if(SIMGRID_HAVE_MC)
265     ADD_TESH(s4u-${example}-nodpor    --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example}
266                                       --setenv libdir=${CMAKE_BINARY_DIR}/lib
267                                       --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
268                                       --setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR}/${example}
269                                       --cd ${CMAKE_CURRENT_SOURCE_DIR}/${example}
270                                       ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}-nodpor.tesh)
271   endif()                                    
272   set(tesh_files    ${tesh_files}   ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}-statequality.tesh)
273   set(tesh_files    ${tesh_files}   ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}-nodpor.tesh)
274 endforeach()
275
276 # Examples not accepting factories
277 ##################################
278
279 foreach (example exec-ptask trace-categories trace-masterworkers trace-platform trace-process-migration
280                  trace-host-user-variables trace-link-user-variables trace-route-user-variables)
281   add_executable       (s4u-${example} EXCLUDE_FROM_ALL ${example}/s4u-${example}.cpp)
282   target_link_libraries(s4u-${example} simgrid)
283   set_target_properties(s4u-${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
284   add_dependencies(tests s4u-${example})
285
286   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u-${example}.tesh)
287   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u-${example}.cpp)
288
289   ADD_TESH(s4u-${example} --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example}
290                           --setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR}/${example}
291                           --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
292                           --cd ${CMAKE_CURRENT_BINARY_DIR}/${example}
293                           ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}.tesh)
294 endforeach()
295
296 if (NOT enable_memcheck)
297   ADD_TESH(debug-breakpoint --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/comm-pingpong
298                             --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
299                             ${CMAKE_CURRENT_SOURCE_DIR}/comm-pingpong/debug-breakpoint.tesh)
300 endif()
301
302 # Add all extra files to the archive
303 ####################################
304 set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp        PARENT_SCOPE)
305 set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/comm-pingpong/debug-breakpoint.tesh
306                                   ${CMAKE_CURRENT_SOURCE_DIR}/mc-bugged1-liveness/s4u-mc-bugged1-liveness.tesh
307                                   ${CMAKE_CURRENT_SOURCE_DIR}/mc-bugged1-liveness/s4u-mc-bugged1-liveness-visited.tesh  PARENT_SCOPE)
308 set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/s4u-actor-create_d.xml
309                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime_d.xml
310                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent_d.xml
311                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworkers/s4u-app-masterworkers_d.xml
312                                   ${CMAKE_CURRENT_SOURCE_DIR}/dag-scheduling/Montage_25.xml
313                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml
314                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/s4u-dht-kademlia_d.xml
315                                   ${CMAKE_CURRENT_SOURCE_DIR}/io-file-remote/s4u-io-file-remote_d.xml
316                                   ${CMAKE_CURRENT_SOURCE_DIR}/platform-failures/s4u-platform-failures_d.xml
317                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split_d.xml
318                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm_d.xml
319                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-io/s4u-replay-io_d.xml
320                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3hosts_2links_d.xml
321                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links-timer_d.xml
322                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links_d.xml
323                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/crosstraffic_d.xml
324                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/dogbone_d.xml
325                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/onelink_d.xml
326                                   ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/one_cluster_d.xml                PARENT_SCOPE)
327 set(bin_files     ${bin_files}    ${CMAKE_CURRENT_SOURCE_DIR}/battery-degradation/plot_battery_degradation.py
328                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/generate.py
329                                   ${CMAKE_CURRENT_SOURCE_DIR}/mc-bugged1-liveness/s4u-mc-bugged1-liveness-stack-cleaner
330                                   ${CMAKE_CURRENT_SOURCE_DIR}/mc-bugged1-liveness/promela_bugged1_liveness
331                                   ${CMAKE_CURRENT_SOURCE_DIR}/mc-bugged2-liveness/promela_bugged2_liveness PARENT_SCOPE)
332 set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/dag-from-dax/simple_dax_with_cycle.xml
333                                   ${CMAKE_CURRENT_SOURCE_DIR}/dag-from-dax/smalldax.xml
334                                   ${CMAKE_CURRENT_SOURCE_DIR}/dag-from-dax-simple/dag.xml
335                                   ${CMAKE_CURRENT_SOURCE_DIR}/dag-from-dot/dag.dot
336                                   ${CMAKE_CURRENT_SOURCE_DIR}/dag-from-dot-simple/dag.dot
337                                   ${CMAKE_CURRENT_SOURCE_DIR}/dag-from-dot/dag_with_cycle.dot
338                                   ${CMAKE_CURRENT_SOURCE_DIR}/dag-from-json-simple/dag.json
339                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split-p0.txt
340                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split-p1.txt
341                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm.txt
342                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-io/s4u-replay-io.txt                  PARENT_SCOPE)