Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill all the autogenerated I've found. Feel free to kill the remaining ones: buildbot...
[simgrid.git] / teshsuite / xbt / parallel_log_crashtest.c
1 /* $Id$ */
2
3 /* synchro_crashtest -- tries to crash the logging mecanism by doing // logs*/
4
5 /* Copyright (c) 2007 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "gras.h"
11 #include "xbt/synchro.h"
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest,"Logs of this example");
14
15
16 int test_amount = 99;    /* Up to 999 to not break the logs (and thus the testing mecanism) */
17 int crasher_amount = 99; /* Up to 99  to not break the logs (and thus the testing mecanism) */
18 int *id; /* to pass a pointer to the threads without race condition */
19
20 int more_info=0; /* SET IT TO TRUE TO GET MORE INFO */
21
22 /*
23  * Some additionnal code to let the father wait the childs
24  */
25 xbt_mutex_t mut_end;
26 xbt_cond_t cond_end;
27 int running_threads;
28
29 xbt_mutex_t dead_end;
30
31 /* Code ran by each thread */
32 static void crasher_thread(void *arg) {
33    int id = *(int*)arg;
34    int i;
35
36    for (i=0; i<test_amount; i++) {
37      if (more_info)
38       INFO10("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",test_amount-i,id,id,id,id,id,id,id,id,id);
39      else
40        INFO0("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
41    }
42
43    xbt_mutex_acquire(mut_end);
44    running_threads--;
45    xbt_cond_signal(cond_end);
46    xbt_mutex_release(mut_end);
47 }
48
49 int crasher (int argc,char *argv[]);
50 int crasher (int argc,char *argv[]) {
51   int i;
52   xbt_thread_t *crashers;
53
54   gras_init(&argc,argv);
55
56   /* initializations of the philosopher mecanisms */
57   id = xbt_new0(int,crasher_amount);
58   crashers = xbt_new(xbt_thread_t,crasher_amount);
59
60   for (i=0; i<crasher_amount; i++)
61      id[i] = i;
62
63   /* setup the ending mecanism */
64   running_threads = crasher_amount;
65   cond_end = xbt_cond_init();
66   mut_end = xbt_mutex_init();
67
68   /* spawn threads */
69   for (i=0; i<crasher_amount; i++) {
70      char *name = bprintf("thread %d",i);
71      crashers[i] = xbt_thread_create(name,&crasher_thread,&id[i]);
72      free(name);
73   }
74
75   /* wait for them */
76   xbt_mutex_acquire(mut_end);
77   while (running_threads)
78      xbt_cond_wait(cond_end,mut_end);
79   xbt_mutex_release(mut_end);
80
81   gras_exit();
82   return 0;
83 }
84
85 int main(int argc, char *argv[]){
86   int errcode;
87
88   errcode=crasher(argc,argv);
89
90   return errcode;
91 }