3 /* Creates a new iSend transition */
4 mc_transition_t MC_trans_isend_new(smx_rdv_t rdv)
6 mc_transition_t trans = xbt_new0(s_mc_transition_t, 1);
8 trans->type = mc_isend;
9 trans->process = SIMIX_process_self();
10 trans->isend.rdv = rdv;
11 trans->name = bprintf("[%s][%s] iSend (%p)", trans->process->smx_host->name,
12 trans->process->name, trans);
16 /* Creates a new iRecv transition */
17 mc_transition_t MC_trans_irecv_new(smx_rdv_t rdv)
19 mc_transition_t trans = xbt_new0(s_mc_transition_t, 1);
21 trans->type = mc_irecv;
22 trans->process = SIMIX_process_self();
23 trans->irecv.rdv = rdv;
24 trans->name = bprintf("[%s][%s] iRecv (%p)", trans->process->smx_host->name,
25 trans->process->name, trans);
29 /* Creates a new Wait transition */
30 mc_transition_t MC_trans_wait_new(smx_comm_t comm)
32 mc_transition_t trans = xbt_new0(s_mc_transition_t, 1);
34 trans->type = mc_wait;
35 trans->process = SIMIX_process_self();
36 trans->wait.comm = comm;
37 trans->name = bprintf("[%s][%s] Wait (%p)", trans->process->smx_host->name,
38 trans->process->name, trans);
42 /* Creates a new test transition */
43 mc_transition_t MC_trans_test_new(smx_comm_t comm)
45 mc_transition_t trans = xbt_new0(s_mc_transition_t, 1);
47 trans->type = mc_test;
48 trans->process = SIMIX_process_self();
49 trans->test.comm = comm;
50 trans->name = bprintf("[%s][%s] Test (%p)", trans->process->smx_host->name,
51 trans->process->name, trans);
55 /* Creates a new WaitAny transition */
56 mc_transition_t MC_trans_waitany_new(xbt_dynar_t comms)
58 mc_transition_t trans = xbt_new0(s_mc_transition_t, 1);
60 trans->type = mc_waitany;
61 trans->process = SIMIX_process_self();
62 trans->waitany.comms = comms;
63 trans->name = bprintf("[%s][%s] WaitAny (%p)", trans->process->smx_host->name,
64 trans->process->name, trans);
68 /* Creates a new Random transition */
69 mc_transition_t MC_trans_random_new(int min, int max)
71 mc_transition_t trans = xbt_new0(s_mc_transition_t, 1);
73 trans->type = mc_random;
74 trans->process = SIMIX_process_self();
75 trans->random.min = min;
76 trans->random.max = max;
77 trans->random.current_value = min;
78 trans->name = bprintf("[%s][%s] Random (%p)", trans->process->smx_host->name,
79 trans->process->name, trans);
83 /************************** Interception Functions ****************************/
84 /* These functions intercept all the actions relevant to the model-checking
85 * process, the only difference between them is the type of transition they
86 * create. The interception works by yielding the process performer of the
87 * action, and depending on the execution mode it behaves diferently.
88 * There are two running modes, a replay (back-track process) in which no
89 * transition needs to be created, or a new state expansion, which in
90 * consecuence a transition needs to be created and added to the set of
91 * transitions associated to the current state.
95 * \brief Intercept an iSend action
96 * \param rdv The rendez-vous of the iSend
98 void MC_trans_intercept_isend(smx_rdv_t rdv)
100 mc_transition_t trans=NULL;
101 mc_state_t current_state = NULL;
104 trans = MC_trans_isend_new(rdv);
105 current_state = (mc_state_t)
106 xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
107 xbt_setset_set_insert(current_state->created_transitions, trans);
108 xbt_setset_set_insert(current_state->transitions, trans);
111 SIMIX_process_yield();
115 * \brief Intercept an iRecv action
116 * \param rdv The rendez-vous of the iRecv
118 void MC_trans_intercept_irecv(smx_rdv_t rdv)
120 mc_transition_t trans=NULL;
121 mc_state_t current_state = NULL;
124 trans = MC_trans_irecv_new(rdv);
125 current_state = (mc_state_t)
126 xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
127 xbt_setset_set_insert(current_state->created_transitions, trans);
128 xbt_setset_set_insert(current_state->transitions, trans);
131 SIMIX_process_yield();
135 * \brief Intercept a Wait action
136 * \param comm The communication associated to the wait
138 void MC_trans_intercept_wait(smx_comm_t comm)
140 mc_transition_t trans=NULL;
141 mc_state_t current_state = NULL;
144 trans = MC_trans_wait_new(comm);
145 current_state = (mc_state_t)
146 xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
147 xbt_setset_set_insert(current_state->created_transitions, trans);
148 xbt_setset_set_insert(current_state->transitions, trans);
151 SIMIX_process_yield();
155 * \brief Intercept a Test action
156 * \param comm The communication associated to the Test
158 void MC_trans_intercept_test(smx_comm_t comm)
160 mc_transition_t trans=NULL;
161 mc_state_t current_state = NULL;
164 trans = MC_trans_test_new(comm);
165 current_state = (mc_state_t)
166 xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
167 xbt_setset_set_insert(current_state->created_transitions, trans);
168 xbt_setset_set_insert(current_state->transitions, trans);
171 SIMIX_process_yield();
175 * \brief Intercept a WaitAny action
176 * \param comms The communications associated to the WaitAny
178 void MC_trans_intercept_waitany(xbt_dynar_t comms)
180 mc_transition_t trans=NULL;
181 mc_state_t current_state = NULL;
184 trans = MC_trans_waitany_new(comms);
185 current_state = (mc_state_t)
186 xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
187 xbt_setset_set_insert(current_state->created_transitions, trans);
188 xbt_setset_set_insert(current_state->transitions, trans);
191 SIMIX_process_yield();
195 * \brief Intercept a Random action
196 * \param min The minimum value that can be returned by the Random action
197 * \param max The maximum value that can be returned by the Random action
199 void MC_trans_intercept_random(int min, int max)
201 mc_transition_t trans=NULL;
202 mc_state_t current_state = NULL;
205 trans = MC_trans_random_new(min, max);
206 current_state = (mc_state_t)
207 xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
208 xbt_setset_set_insert(current_state->created_transitions, trans);
209 xbt_setset_set_insert(current_state->transitions, trans);
212 SIMIX_process_yield();
216 * \brief Deletes a transition
217 * \param trans The transition to be deleted
219 void MC_transition_delete(mc_transition_t trans)
221 xbt_free(trans->name);
225 /* Compute the subset of enabled transitions of the transition set */
226 void MC_trans_compute_enabled(xbt_setset_set_t enabled, xbt_setset_set_t transitions)
228 mc_transition_t trans = NULL;
229 xbt_setset_cursor_t cursor = NULL;
230 /* Add all the transitions to the enabled set and then remove the disabled ones */
231 xbt_setset_add(enabled, transitions);
232 xbt_setset_foreach(transitions, cursor, trans){
233 if(trans->type == mc_wait
234 && (trans->wait.comm->src_proc == NULL || trans->wait.comm->dst_proc == NULL)){
235 xbt_setset_set_remove(enabled, trans);
241 * \brief Determine if two transitions are dependent
242 * \param t1 a transition
243 * \param t2 a transition
244 * \return TRUE if \a t1 and \a t2 are dependent. FALSE otherwise.
246 int MC_transition_depend(mc_transition_t t1, mc_transition_t t2)
248 if(t1->process == t2->process)
251 if(t1->type != t2->type)
254 if(t1->type == mc_isend && t2->type == mc_isend && t1->isend.rdv != t2->isend.rdv)
257 if(t1->type == mc_irecv && t2->type == mc_irecv && t1->irecv.rdv != t2->irecv.rdv)
260 if(t1->type == mc_wait && t2->type == mc_wait && t1->wait.comm == t2->wait.comm)
263 if(t1->type == mc_wait && t2->type == mc_wait
264 && t1->wait.comm->src_buff != NULL
265 && t1->wait.comm->dst_buff != NULL
266 && t2->wait.comm->src_buff != NULL
267 && t2->wait.comm->dst_buff != NULL
268 && t1->wait.comm->dst_buff != t2->wait.comm->src_buff
269 && t1->wait.comm->dst_buff != t2->wait.comm->dst_buff
270 && t2->wait.comm->dst_buff != t1->wait.comm->src_buff)