Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[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-2022. 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 "xbt/log.h"
10 #include <array>
11 #include <thread>
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
14
15 constexpr int test_amount    = 99; /* Up to 99 to not break the logs (and thus the testing mechanism) */
16 constexpr int crasher_amount = 99; /* Up to 99 to not break the logs (and thus the testing mechanism) */
17
18 constexpr bool more_info = false; /* SET IT TO TRUE TO GET MORE INFO */
19
20 /* Code ran by each thread */
21 static void crasher_thread(int id)
22 {
23   for (int i = 0; i < test_amount; i++) {
24     if (more_info)
25       XBT_INFO("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)", test_amount - i, id, id, id, id, id, id, id, id,
26                id);
27     else
28       XBT_INFO("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
29   }
30 }
31
32 int main(int argc, char* argv[])
33 {
34   simgrid::s4u::Engine e(&argc, argv);
35
36   std::array<std::thread, crasher_amount> crashers;
37
38   /* spawn threads */
39   int id = 0;
40   for (std::thread& thr : crashers)
41     thr = std::thread(crasher_thread, id++);
42
43   /* wait for them */
44   for (std::thread& thr : crashers)
45     thr.join();
46
47   return 0;
48 }