Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add suport for TestAny and WaitAny requests to the model-checker.
[simgrid.git] / src / mc / mc_request.c
1 #include "private.h"
2
3 int MC_request_depend(smx_req_t r1, smx_req_t r2)
4 {
5     if (r1->issuer == r2->issuer)
6     return FALSE;
7
8   if (r1->call != r2->call)
9     return FALSE;
10
11   if (r1->call == REQ_COMM_ISEND && r2->call == REQ_COMM_ISEND
12       && r1->comm_isend.rdv != r2->comm_isend.rdv)
13     return FALSE;
14
15   if (r1->call == REQ_COMM_IRECV && r2->call == REQ_COMM_IRECV
16       && r1->comm_irecv.rdv != r2->comm_irecv.rdv)
17     return FALSE;
18
19   if (r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_WAIT
20       && r1->comm_wait.comm == r2->comm_wait.comm)
21     return FALSE;
22
23   if (r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_WAIT
24       && r1->comm_wait.comm->comm.src_buff != NULL
25       && r1->comm_wait.comm->comm.dst_buff != NULL
26       && r2->comm_wait.comm->comm.src_buff != NULL
27       && r2->comm_wait.comm->comm.dst_buff != NULL
28       && r1->comm_wait.comm->comm.dst_buff != r2->comm_wait.comm->comm.src_buff
29       && r1->comm_wait.comm->comm.dst_buff != r2->comm_wait.comm->comm.dst_buff
30       && r2->comm_wait.comm->comm.dst_buff != r1->comm_wait.comm->comm.src_buff)
31     return FALSE;
32
33   return TRUE;
34 }
35
36 char *MC_request_to_string(smx_req_t req)
37 {
38   char *type = NULL, *args = NULL, *str = NULL; 
39   smx_action_t act = NULL;
40   size_t size = 0;
41   
42   switch(req->call){
43     case REQ_COMM_ISEND:
44       type = bprintf("iSend");
45       args = bprintf("src=%s, buff=%p, size=%zu", req->issuer->name, 
46                      req->comm_isend.src_buff, req->comm_isend.src_buff_size);
47       break;
48     case REQ_COMM_IRECV:
49       size = req->comm_irecv.dst_buff_size ? *req->comm_irecv.dst_buff_size : 0;
50       type = bprintf("iRecv");
51       args = bprintf("dst=%s, buff=%p, size=%zu", req->issuer->name, 
52                      req->comm_irecv.dst_buff, size);
53       break;
54     case REQ_COMM_WAIT:
55       act = req->comm_wait.comm;
56       type = bprintf("Wait");
57       args  = bprintf("%p [%s(%lu) -> %s(%lu)]", act,
58                       act->comm.src_proc ? act->comm.src_proc->name : "",
59                       act->comm.src_proc ? act->comm.src_proc->pid : 0,
60                       act->comm.dst_proc ? act->comm.dst_proc->name : "",
61                       act->comm.dst_proc ? act->comm.dst_proc->pid : 0);
62       break;
63     case REQ_COMM_TEST:
64       act = req->comm_test.comm;
65       type = bprintf("Test");
66       args  = bprintf("%p [%s -> %s]", act, 
67                       act->comm.src_proc ? act->comm.src_proc->name : "",
68                       act->comm.dst_proc ? act->comm.dst_proc->name : "");
69       break;
70
71     case REQ_COMM_WAITANY:
72       type = bprintf("WaitAny");
73       args = bprintf("-");
74       /* FIXME: improve output */
75       break;
76
77     case REQ_COMM_TESTANY:
78        type = bprintf("TestAny");
79        args = bprintf("-");
80        /* FIXME: improve output */
81        break;
82
83     default:
84       THROW_UNIMPLEMENTED;
85   }
86
87   str = bprintf("[(%lu)%s] %s (%s)", req->issuer->pid ,req->issuer->name, type, args);
88   xbt_free(type);
89   xbt_free(args);
90   return str;
91 }
92
93 unsigned int MC_request_testany_fail(smx_req_t req)
94 {
95   unsigned int cursor;
96   smx_action_t action;
97
98   xbt_dynar_foreach(req->comm_testany.comms, cursor, action){
99     if(action->comm.src_proc && action->comm.dst_proc)
100       return FALSE;
101   }
102
103   return TRUE;
104 }