Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
714a753bbe06aa4a8249420ce48ac7cf302c98d6
[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-2019. 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/msg.h"
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(void* arg)
20 {
21   int id = *(int*)arg;
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   return NULL;
31 }
32
33 int main(int argc, char* argv[])
34 {
35   MSG_init(&argc, argv);
36
37   int id[crasher_amount];
38   std::thread crashers[crasher_amount];
39
40   /* spawn threads */
41   for (int i = 0; i < crasher_amount; i++) {
42     id[i]       = i;
43     crashers[i] = std::thread(crasher_thread, &id[i]);
44   }
45
46   /* wait for them */
47   for (int i = 0; i < crasher_amount; i++)
48     crashers[i].join();
49
50   return 0;
51 }