Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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-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 "simgrid/msg.h"
10 #include "xbt.h"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
13
14 int test_amount = 99;           /* Up to 999 to not break the logs (and thus the testing mechanism) */
15 int crasher_amount = 99;        /* Up to 99  to not break the logs (and thus the testing mechanism) */
16 int *id;                        /* to pass a pointer to the threads without race condition */
17
18 int more_info = 0;              /* SET IT TO TRUE TO GET MORE INFO */
19
20 /* Code ran by each thread */
21 static void* crasher_thread(void *arg)
22 {
23   int id = *(int *) arg;
24
25   for (int i = 0; i < test_amount; i++) {
26     if (more_info)
27       XBT_INFO("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
28              test_amount - i, id, id, id, id, id, id, id, id, id);
29     else
30       XBT_INFO("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
31   }
32   return NULL;
33 }
34
35 static int crasher(int argc, char *argv[])
36 {
37   int i;
38   xbt_os_thread_t *crashers;
39
40   /* initializations of the philosopher mechanisms */
41   id = xbt_new0(int, crasher_amount);
42   crashers = xbt_new(xbt_os_thread_t, crasher_amount);
43
44   for (i = 0; i < crasher_amount; i++)
45     id[i] = i;
46
47   /* spawn threads */
48   for (i = 0; i < crasher_amount; i++) {
49     char *name = bprintf("thread %d", i);
50     crashers[i] = xbt_os_thread_create(name, &crasher_thread, &id[i], NULL );
51     free(name);
52   }
53
54   /* wait for them */
55   for (i = 0; i < crasher_amount; i++)
56     xbt_os_thread_join(crashers[i],NULL);
57
58   xbt_free(crashers);
59   xbt_free(id);
60
61   return 0;
62 }
63
64 int main(int argc, char *argv[])
65 {
66   MSG_init(&argc, argv);
67   return crasher(argc, argv);
68 }