Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix argument quoting in tesh files.
[simgrid.git] / teshsuite / xbt / parallel_log_crashtest.c
1 /* synchro_crashtest -- tries to crash the logging mecanism by doing // logs*/
2
3 /* Copyright (c) 2007, 2008, 2009, 2010. 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 "gras.h"
10 #include "xbt/synchro.h"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
13
14
15 int test_amount = 99;           /* Up to 999 to not break the logs (and thus the testing mecanism) */
16 int crasher_amount = 99;        /* Up to 99  to not break the logs (and thus the testing mecanism) */
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   int i;
26
27   for (i = 0; i < test_amount; i++) {
28     if (more_info)
29       INFO10("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
30              test_amount - i, id, id, id, id, id, id, id, id, id);
31     else
32       INFO0("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
33   }
34 }
35
36 int crasher(int argc, char *argv[]);
37 int crasher(int argc, char *argv[])
38 {
39   int i;
40   xbt_thread_t *crashers;
41
42   gras_init(&argc, argv);
43
44   /* initializations of the philosopher mecanisms */
45   id = xbt_new0(int, crasher_amount);
46   crashers = xbt_new(xbt_thread_t, crasher_amount);
47
48   for (i = 0; i < crasher_amount; i++)
49     id[i] = i;
50
51   /* spawn threads */
52   for (i = 0; i < crasher_amount; i++) {
53     char *name = bprintf("thread %d", i);
54     crashers[i] =
55         xbt_thread_create(name, &crasher_thread, &id[i], 1 /* joinable */ );
56     free(name);
57   }
58
59   /* wait for them */
60   for (i = 0; i < crasher_amount; i++)
61     xbt_thread_join(crashers[i]);
62
63   xbt_free(crashers);
64   xbt_free(id);
65
66   gras_exit();
67   return 0;
68 }
69
70 int main(int argc, char *argv[])
71 {
72   int errcode;
73
74   errcode = crasher(argc, argv);
75
76   return errcode;
77 }