Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a few more cosmetics
[simgrid.git] / teshsuite / xbt / parallel_log / parallel_log_crashtest.c
1 /* synchro_crashtest -- tries to crash the logging mecanism by doing // logs*/
2
3 /* Copyright (c) 2007-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "xbt.h"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
12
13 int test_amount = 99;           /* Up to 999 to not break the logs (and thus the testing mecanism) */
14 int crasher_amount = 99;        /* Up to 99  to not break the logs (and thus the testing mecanism) */
15 int *id;                        /* to pass a pointer to the threads without race condition */
16
17 int more_info = 0;              /* SET IT TO TRUE TO GET MORE INFO */
18
19 /* Code ran by each thread */
20 static void* crasher_thread(void *arg)
21 {
22   int id = *(int *) arg;
23
24   for (int i = 0; i < test_amount; i++) {
25     if (more_info)
26       XBT_INFO("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
27              test_amount - i, id, id, id, id, id, id, id, id, id);
28     else
29       XBT_INFO("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
30   }
31   return NULL;
32 }
33
34 int crasher(int argc, char *argv[]);
35 int crasher(int argc, char *argv[])
36 {
37   int i;
38   xbt_os_thread_t *crashers;
39
40   xbt_init(&argc, argv);
41
42   /* initializations of the philosopher mecanisms */
43   id = xbt_new0(int, crasher_amount);
44   crashers = xbt_new(xbt_os_thread_t, crasher_amount);
45
46   for (i = 0; i < crasher_amount; i++)
47     id[i] = i;
48
49   /* spawn threads */
50   for (i = 0; i < crasher_amount; i++) {
51     char *name = bprintf("thread %d", i);
52     crashers[i] = xbt_os_thread_create(name, &crasher_thread, &id[i], NULL );
53     free(name);
54   }
55
56   /* wait for them */
57   for (i = 0; i < crasher_amount; i++)
58     xbt_os_thread_join(crashers[i],NULL);
59
60   xbt_free(crashers);
61   xbt_free(id);
62
63   return 0;
64 }
65
66 int main(int argc, char *argv[])
67 {
68   return crasher(argc, argv);
69 }