Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a cmake flag to not compile MSG at all
[simgrid.git] / teshsuite / xbt / parallel_log_crashtest / parallel_log_crashtest.cpp
1 /* synchro_crashtest -- tries to crash the logging mechanism by doing parallel logs*/
2
3 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "simgrid/s4u/Engine.hpp"
9 #include <thread>
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
12
13 const int test_amount    = 99; /* Up to 99 to not break the logs (and thus the testing mechanism) */
14 const int crasher_amount = 99; /* Up to 99 to not break the logs (and thus the testing mechanism) */
15
16 int more_info = 0; /* SET IT TO TRUE TO GET MORE INFO */
17
18 /* Code ran by each thread */
19 static void crasher_thread(int id)
20 {
21   for (int i = 0; i < test_amount; i++) {
22     if (more_info)
23       XBT_INFO("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)", test_amount - i, id, id, id, id, id, id, id, id,
24                id);
25     else
26       XBT_INFO("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
27   }
28 }
29
30 int main(int argc, char* argv[])
31 {
32   simgrid::s4u::Engine e(&argc, argv);
33
34   std::thread crashers[crasher_amount];
35
36   /* spawn threads */
37   for (int i = 0; i < crasher_amount; i++) {
38     crashers[i] = std::thread(crasher_thread, i);
39   }
40
41   /* wait for them */
42   for (int i = 0; i < crasher_amount; i++)
43     crashers[i].join();
44
45   return 0;
46 }