Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make this test more robust to cruft that may remain on disk
[simgrid.git] / teshsuite / xbt / parallel_log_crashtest / parallel_log_crashtest.c
1 /* synchro_crashtest -- tries to crash the logging mechanism by doing parallel logs*/
2
3 /* Copyright (c) 2007-2018. 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 "xbt.h"
10
11 #include <stdio.h> /* snprintf */
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
14
15 const int test_amount    = 99;  /* Up to 99 to not break the logs (and thus the testing mechanism) */
16 const int crasher_amount = 99;  /* Up to 99 to not break the logs (and thus the testing mechanism) */
17 int *id;                        /* to pass a pointer to the threads without race condition */
18
19 int more_info = 0;              /* SET IT TO TRUE TO GET MORE INFO */
20
21 /* Code ran by each thread */
22 static void* crasher_thread(void *arg)
23 {
24   int id = *(int *) arg;
25
26   for (int i = 0; i < test_amount; i++) {
27     if (more_info)
28       XBT_INFO("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
29              test_amount - i, id, id, id, id, id, id, id, id, id);
30     else
31       XBT_INFO("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
32   }
33   return NULL;
34 }
35
36 static int crasher()
37 {
38   /* initializations of the philosopher mechanisms */
39   id = xbt_new0(int, crasher_amount);
40   xbt_os_thread_t* crashers = xbt_new(xbt_os_thread_t, crasher_amount);
41
42   /* spawn threads */
43   for (int i = 0; i < crasher_amount; i++) {
44     id[i]       = i;
45     crashers[i] = xbt_os_thread_create(&crasher_thread, &id[i]);
46   }
47
48   /* wait for them */
49   for (int i = 0; i < crasher_amount; i++)
50     xbt_os_thread_join(crashers[i],NULL);
51
52   xbt_free(crashers);
53   xbt_free(id);
54
55   return 0;
56 }
57
58 int main(int argc, char *argv[])
59 {
60   MSG_init(&argc, argv);
61   return crasher();
62 }