Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check return code, and report errors.
[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 "xbt.h"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
12
13
14 int test_amount = 99;           /* Up to 999 to not break the logs (and thus the testing mecanism) */
15 int crasher_amount = 99;        /* Up to 99  to not break the logs (and thus the testing mecanism) */
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   int i;
25
26   for (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 int crasher(int argc, char *argv[]);
37 int crasher(int argc, char *argv[])
38 {
39   int i;
40   xbt_os_thread_t *crashers;
41
42   xbt_init(&argc, argv);
43
44   /* initializations of the philosopher mecanisms */
45   id = xbt_new0(int, crasher_amount);
46   crashers = xbt_new(xbt_os_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_os_thread_create(name, &crasher_thread, &id[i], NULL );
56     free(name);
57   }
58
59   /* wait for them */
60   for (i = 0; i < crasher_amount; i++)
61     xbt_os_thread_join(crashers[i],NULL);
62
63   xbt_free(crashers);
64   xbt_free(id);
65
66   return 0;
67 }
68
69 int main(int argc, char *argv[])
70 {
71   return crasher(argc, argv);
72 }