4 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_liveness, mc,
5 "Logging specific to algorithms for liveness properties verification");
7 xbt_dynar_t initial_pairs = NULL;
8 xbt_fifo_t reached_pairs;
9 xbt_dynar_t successors = NULL;
10 extern mc_snapshot_t initial_snapshot;
12 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
15 if(s1->num_reg != s2->num_reg){
16 XBT_DEBUG("Different num_reg");
23 for(i=0 ; i< s1->num_reg ; i++){
25 if(s1->regions[i]->size != s2->regions[i]->size){
26 XBT_DEBUG("Different size of region");
30 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
31 XBT_DEBUG("Different start addr of region");
35 if(s1->regions[i]->type != s2->regions[i]->type){
36 XBT_DEBUG("Different type of region");
41 if(s1->regions[i]->type == 0){
42 if(mmalloc_compare_heap(s1->regions[i]->start_addr, s2->regions[i]->start_addr)){
43 XBT_DEBUG("Different heap (mmalloc_compare)");
47 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
48 XBT_DEBUG("Different memcmp for data in libsimgrid or program");
60 int reached(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t s){
63 if(xbt_fifo_size(reached_pairs) == 0){
71 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
73 /* Get values of propositional symbols */
74 unsigned int cursor = 0;
75 xbt_propositional_symbol_t ps = NULL;
76 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
77 int (*f)() = ps->function;
79 xbt_dynar_push_as(prop_ato, int, res);
85 xbt_fifo_item_t item = xbt_fifo_get_first_item(reached_pairs);
86 mc_pair_reached_t pair_test = NULL;
88 while(i < xbt_fifo_size(reached_pairs)){
90 pair_test = (mc_pair_reached_t) xbt_fifo_get_item_content(item);
92 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
93 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
94 if(snapshot_compare(s, pair_test->system_state) == 0){
101 item = xbt_fifo_get_next_item(item);
113 void set_pair_reached(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t sn){
118 mc_pair_reached_t pair = NULL;
119 pair = xbt_new0(s_mc_pair_reached_t, 1);
120 pair->automaton_state = st;
121 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
122 pair->system_state = sn;
124 /* Get values of propositional symbols */
125 unsigned int cursor = 0;
126 xbt_propositional_symbol_t ps = NULL;
127 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
128 int (*f)() = ps->function;
130 xbt_dynar_push_as(pair->prop_ato, int, res);
133 xbt_fifo_unshift(reached_pairs, pair);
140 void MC_pair_delete(mc_pair_t pair){
141 xbt_free(pair->graph_state->proc_status);
142 xbt_free(pair->graph_state);
143 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
149 int MC_automaton_evaluate_label(xbt_automaton_t a, xbt_exp_label_t l){
153 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
154 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
155 return (left_res || right_res);
159 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
160 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
161 return (left_res && right_res);
165 int res = MC_automaton_evaluate_label(a, l->u.exp_not);
170 unsigned int cursor = 0;
171 xbt_propositional_symbol_t p = NULL;
172 xbt_dynar_foreach(a->propositional_symbols, cursor, p){
173 if(strcmp(p->pred, l->u.predicat) == 0){
174 int (*f)() = p->function;
194 /********************* Double-DFS stateless *******************/
196 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
197 xbt_free(pair->graph_state->proc_status);
198 xbt_free(pair->graph_state);
199 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
203 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
204 mc_pair_stateless_t p = NULL;
205 p = xbt_new0(s_mc_pair_stateless_t, 1);
206 p->automaton_state = st;
209 mc_stats_pair->expanded_pairs++;
215 void MC_ddfs_stateless_init(xbt_automaton_t a, char *prgm){
217 XBT_DEBUG("**************************************************");
218 XBT_DEBUG("Double-DFS stateless init");
219 XBT_DEBUG("**************************************************");
221 mc_pair_stateless_t mc_initial_pair = NULL;
222 mc_state_t initial_graph_state = NULL;
223 smx_process_t process;
225 MC_wait_for_requests();
229 initial_graph_state = MC_state_pair_new();
230 xbt_swag_foreach(process, simix_global->process_list){
231 if(MC_process_is_enabled(process)){
232 MC_state_interleave_process(initial_graph_state, process);
236 reached_pairs = xbt_fifo_new();
237 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
238 //snapshot = xbt_new0(s_mc_snapshot_t, 1);
240 initial_snapshot = xbt_new0(s_mc_snapshot_t, 1);
241 MC_take_snapshot_liveness(initial_snapshot, prgm);
245 unsigned int cursor = 0;
248 xbt_dynar_foreach(a->states, cursor, state){
249 if(state->type == -1){
252 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
253 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
257 MC_restore_snapshot(initial_snapshot);
261 MC_ddfs_stateless(a, 0, 0, prgm);
264 if(state->type == 2){
267 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
268 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
271 set_pair_reached(a, state, initial_snapshot);
274 MC_restore_snapshot(initial_snapshot);
278 MC_ddfs_stateless(a, 1, 0, prgm);
287 void MC_ddfs_stateless(xbt_automaton_t a, int search_cycle, int replay, char *prgm){
289 smx_process_t process;
290 mc_pair_stateless_t current_pair = NULL;
291 mc_snapshot_t snapshot = NULL;
293 if(xbt_fifo_size(mc_stack_liveness_stateless) == 0)
297 MC_replay_liveness(mc_stack_liveness_stateless, 0);
298 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
299 xbt_swag_foreach(process, simix_global->process_list){
300 if(MC_process_is_enabled(process)){
301 MC_state_interleave_process(current_pair->graph_state, process);
306 /* Get current pair */
307 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
309 /* Update current state in buchi automaton */
310 a->current_state = current_pair->automaton_state;
313 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness_stateless), search_cycle);
314 XBT_DEBUG("Pair : graph=%p, automaton=%p(%s), %u interleave", current_pair->graph_state, current_pair->automaton_state, current_pair->automaton_state->id, MC_state_interleave_size(current_pair->graph_state));
316 mc_stats_pair->visited_pairs++;
319 mc_state_t next_graph_state = NULL;
320 smx_req_t req = NULL;
323 xbt_transition_t transition_succ;
324 unsigned int cursor = 0;
327 mc_pair_stateless_t next_pair = NULL;
328 mc_pair_stateless_t pair_succ;
330 if(xbt_fifo_size(mc_stack_liveness_stateless) < MAX_DEPTH_LIVENESS){
332 if(current_pair->requests > 0){
334 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
336 /* Debug information */
337 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
338 req_str = MC_request_to_string(req, value);
339 XBT_DEBUG("Execute: %s", req_str);
343 MC_state_set_executed_request(current_pair->graph_state, req, value);
345 /* Answer the request */
346 SIMIX_request_pre(req, value);
348 /* Wait for requests (schedules processes) */
349 MC_wait_for_requests();
354 /* Create the new expanded graph_state */
355 next_graph_state = MC_state_pair_new();
357 /* Get enabled process and insert it in the interleave set of the next graph_state */
358 xbt_swag_foreach(process, simix_global->process_list){
359 if(MC_process_is_enabled(process)){
360 MC_state_interleave_process(next_graph_state, process);
364 xbt_dynar_reset(successors);
370 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
372 res = MC_automaton_evaluate_label(a, transition_succ->label);
374 if(res == 1){ // enabled transition in automaton
376 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
377 xbt_dynar_push(successors, &next_pair);
385 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
387 res = MC_automaton_evaluate_label(a, transition_succ->label);
389 if(res == 2){ // true transition in automaton
391 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
392 xbt_dynar_push(successors, &next_pair);
399 if(xbt_dynar_length(successors) == 0){
401 next_pair = new_pair_stateless(next_graph_state, current_pair->automaton_state, MC_state_interleave_size(next_graph_state));
402 xbt_dynar_push(successors, &next_pair);
408 xbt_dynar_foreach(successors, cursor, pair_succ){
410 if(search_cycle == 1){
412 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
415 snapshot = xbt_new0(s_mc_snapshot_t, 1);
416 MC_take_snapshot_liveness(snapshot, prgm);
419 if(reached(a, pair_succ->automaton_state, snapshot) == 1){
421 XBT_DEBUG("Next pair (depth = %d, %d interleave) already reached !", xbt_fifo_size(mc_stack_liveness_stateless) + 1, MC_state_interleave_size(pair_succ->graph_state));
423 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
424 XBT_INFO("| ACCEPTANCE CYCLE |");
425 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
426 XBT_INFO("Counter-example that violates formula :");
427 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
428 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
429 MC_print_statistics_pairs(mc_stats_pair);
434 XBT_DEBUG("Next pair (depth =%d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness_stateless) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
436 set_pair_reached(a, pair_succ->automaton_state, snapshot);
444 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
446 XBT_DEBUG("Next pair (depth =%d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness_stateless) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
449 snapshot = xbt_new0(s_mc_snapshot_t, 1);
450 MC_take_snapshot_liveness(snapshot, prgm);
453 set_pair_reached(a, pair_succ->automaton_state, snapshot);
462 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
465 MC_ddfs_stateless(a, search_cycle, 0, prgm);
467 /* Restore system before checking others successors */
468 if(cursor != (xbt_dynar_length(successors) - 1))
469 MC_replay_liveness(mc_stack_liveness_stateless, 1);
473 if(MC_state_interleave_size(current_pair->graph_state) > 0){
474 XBT_DEBUG("Backtracking to depth %u", xbt_fifo_size(mc_stack_liveness_stateless));
475 MC_replay_liveness(mc_stack_liveness_stateless, 0);
480 }else{ /*No request to execute, search evolution in Büchi automaton */
484 /* Create the new expanded graph_state */
485 next_graph_state = MC_state_pair_new();
487 xbt_dynar_reset(successors);
493 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
495 res = MC_automaton_evaluate_label(a, transition_succ->label);
497 if(res == 1){ // enabled transition in automaton
499 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
500 xbt_dynar_push(successors, &next_pair);
508 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
510 res = MC_automaton_evaluate_label(a, transition_succ->label);
512 if(res == 2){ // true transition in automaton
514 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
515 xbt_dynar_push(successors, &next_pair);
522 if(xbt_dynar_length(successors) == 0){
524 next_pair = new_pair_stateless(next_graph_state, current_pair->automaton_state, MC_state_interleave_size(next_graph_state));
525 xbt_dynar_push(successors, &next_pair);
531 xbt_dynar_foreach(successors, cursor, pair_succ){
533 if(search_cycle == 1){
535 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
538 snapshot = xbt_new0(s_mc_snapshot_t, 1);
539 MC_take_snapshot_liveness(snapshot, prgm);
542 if(reached(a, pair_succ->automaton_state, snapshot) == 1){
544 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness_stateless) + 1);
546 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
547 XBT_INFO("| ACCEPTANCE CYCLE |");
548 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
549 XBT_INFO("Counter-example that violates formula :");
550 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
551 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
552 MC_print_statistics_pairs(mc_stats_pair);
557 XBT_DEBUG("Next pair (depth =%d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness_stateless) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
559 set_pair_reached(a, pair_succ->automaton_state, snapshot);
567 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)) && (xbt_fifo_size(mc_stack_liveness_stateless) < (MAX_DEPTH_LIVENESS - 1))){
570 snapshot = xbt_new0(s_mc_snapshot_t, 1);
571 MC_take_snapshot_liveness(snapshot, prgm);
574 set_pair_reached(a, pair_succ->automaton_state, snapshot);
583 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
586 MC_ddfs_stateless(a, search_cycle, 0, prgm);
588 /* Restore system before checking others successors */
589 if(cursor != xbt_dynar_length(successors) - 1)
590 MC_replay_liveness(mc_stack_liveness_stateless, 1);
597 if(xbt_fifo_size(mc_stack_liveness_stateless) == MAX_DEPTH_LIVENESS ){
598 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %u) shifted in stack, maximum depth reached", current_pair->graph_state, current_pair->automaton_state, search_cycle);
600 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %u) shifted in stack", current_pair->graph_state, current_pair->automaton_state, search_cycle);
605 xbt_fifo_shift(mc_stack_liveness_stateless);
606 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
607 xbt_fifo_shift(reached_pairs);
608 MC_free_snapshot(snapshot);