4 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_liveness, mc,
5 "Logging specific to algorithms for liveness properties verification");
7 xbt_fifo_t reached_pairs;
8 xbt_fifo_t visited_pairs;
9 xbt_dynar_t successors;
11 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
13 //XBT_DEBUG("Compare snapshot");
15 if(s1->num_reg != s2->num_reg){
16 XBT_DEBUG("Different num_reg (s1 = %d, s2 = %d)", s1->num_reg, s2->num_reg);
20 //XBT_DEBUG("Num reg : %d", s1->num_reg);
25 for(i=0 ; i< s1->num_reg ; i++){
27 if(s1->regions[i]->type != s2->regions[i]->type){
28 //XBT_DEBUG("Different type of region");
32 switch(s1->regions[i]->type){
34 //XBT_DEBUG("Region : heap");
35 if(s1->regions[i]->size != s2->regions[i]->size){
36 //XBT_DEBUG("Different size of heap (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
39 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
40 //XBT_DEBUG("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
43 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data)){
44 //XBT_DEBUG("Different heap (mmalloc_compare)");
49 //XBT_DEBUG("Region : libsimgrid");
50 if(s1->regions[i]->size != s2->regions[i]->size){
51 //XBT_DEBUG("Different size of libsimgrid (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
54 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
55 //XBT_DEBUG("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
58 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
59 //XBT_DEBUG("Different memcmp for data in libsimgrid");
64 //XBT_DEBUG("Region : program");
65 if(s1->regions[i]->size != s2->regions[i]->size){
66 //XBT_DEBUG("Different size of program (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
69 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
70 //XBT_DEBUG("Different start addr of program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
73 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
74 //XBT_DEBUG("Different memcmp for data in program");
79 //XBT_DEBUG("Region : stack");
80 if(s1->regions[i]->size != s2->regions[i]->size){
81 //XBT_DEBUG("Different size of stack (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
84 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
85 //XBT_DEBUG("Different start addr of stack (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
88 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
89 //XBT_DEBUG("Different memcmp for data in stack");
100 int reached(xbt_automaton_t a, xbt_state_t st, char *prgm){
103 if(xbt_fifo_size(reached_pairs) == 0){
111 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
115 /* Get values of propositional symbols */
116 unsigned int cursor = 0;
117 xbt_propositional_symbol_t ps = NULL;
118 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
121 xbt_dynar_push_as(prop_ato, int, res);
124 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
125 MC_take_snapshot_liveness(sn, prgm);
128 xbt_fifo_item_t item = xbt_fifo_get_first_item(reached_pairs);
129 mc_pair_reached_t pair_test = NULL;
132 while(i < xbt_fifo_size(reached_pairs) && item != NULL){
134 pair_test = (mc_pair_reached_t) xbt_fifo_get_item_content(item);
136 if(pair_test != NULL){
137 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
138 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
139 if(snapshot_compare(sn, pair_test->system_state) == 0){
141 MC_free_snapshot(sn);
142 xbt_dynar_reset(prop_ato);
151 item = xbt_fifo_get_next_item(item);
157 MC_free_snapshot(sn);
158 xbt_dynar_reset(prop_ato);
166 void set_pair_reached(xbt_automaton_t a, xbt_state_t st, char *prgm){
171 mc_pair_reached_t pair = NULL;
172 pair = xbt_new0(s_mc_pair_reached_t, 1);
173 pair->automaton_state = st;
174 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
175 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
176 MC_take_snapshot_liveness(pair->system_state, prgm);
178 /* Get values of propositional symbols */
179 unsigned int cursor = 0;
180 xbt_propositional_symbol_t ps = NULL;
184 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
187 xbt_dynar_push_as(pair->prop_ato, int, res);
190 xbt_fifo_unshift(reached_pairs, pair);
197 int visited(xbt_automaton_t a, xbt_state_t st, int sc, char *prgm){
200 if(xbt_fifo_size(visited_pairs) == 0){
208 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
210 /* Get values of propositional symbols */
211 unsigned int cursor = 0;
212 xbt_propositional_symbol_t ps = NULL;
216 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
219 xbt_dynar_push_as(prop_ato, int, res);
222 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
223 MC_take_snapshot_liveness(sn, prgm);
226 xbt_fifo_item_t item = xbt_fifo_get_first_item(visited_pairs);
227 mc_pair_visited_t pair_test = NULL;
229 while(i < xbt_fifo_size(visited_pairs) && item != NULL){
231 pair_test = (mc_pair_visited_t) xbt_fifo_get_item_content(item);
233 if(pair_test != NULL){
234 if(pair_test->search_cycle == sc) {
235 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
236 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
237 if(snapshot_compare(sn, pair_test->system_state) == 0){
239 MC_free_snapshot(sn);
240 xbt_dynar_reset(prop_ato);
251 item = xbt_fifo_get_next_item(item);
257 MC_free_snapshot(sn);
258 xbt_dynar_reset(prop_ato);
266 void set_pair_visited(xbt_automaton_t a, xbt_state_t st, int sc, char *prgm){
271 mc_pair_visited_t pair = NULL;
272 pair = xbt_new0(s_mc_pair_visited_t, 1);
273 pair->automaton_state = st;
274 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
275 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
276 MC_take_snapshot_liveness(pair->system_state, prgm);
277 pair->search_cycle = sc;
279 /* Get values of propositional symbols */
280 unsigned int cursor = 0;
281 xbt_propositional_symbol_t ps = NULL;
285 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
288 xbt_dynar_push_as(pair->prop_ato, int, res);
291 xbt_fifo_unshift(visited_pairs, pair);
298 void MC_pair_delete(mc_pair_t pair){
299 xbt_free(pair->graph_state->proc_status);
300 xbt_free(pair->graph_state);
306 int MC_automaton_evaluate_label(xbt_automaton_t a, xbt_exp_label_t l){
310 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
311 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
312 return (left_res || right_res);
316 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
317 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
318 return (left_res && right_res);
322 int res = MC_automaton_evaluate_label(a, l->u.exp_not);
327 unsigned int cursor = 0;
328 xbt_propositional_symbol_t p = NULL;
329 xbt_dynar_foreach(a->propositional_symbols, cursor, p){
330 if(strcmp(p->pred, l->u.predicat) == 0){
331 int (*f)() = p->function;
351 /********************* Double-DFS stateless *******************/
353 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
354 xbt_free(pair->graph_state->proc_status);
355 xbt_free(pair->graph_state);
359 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
360 mc_pair_stateless_t p = NULL;
361 p = xbt_new0(s_mc_pair_stateless_t, 1);
362 p->automaton_state = st;
365 mc_stats_pair->expanded_pairs++;
369 void MC_ddfs_stateless_init(xbt_automaton_t a, char *prgm){
371 XBT_DEBUG("**************************************************");
372 XBT_DEBUG("Double-DFS stateless init");
373 XBT_DEBUG("**************************************************");
375 mc_pair_stateless_t mc_initial_pair = NULL;
376 mc_state_t initial_graph_state = NULL;
377 smx_process_t process;
379 MC_wait_for_requests();
383 initial_graph_state = MC_state_pair_new();
384 xbt_swag_foreach(process, simix_global->process_list){
385 if(MC_process_is_enabled(process)){
386 MC_state_interleave_process(initial_graph_state, process);
390 reached_pairs = xbt_fifo_new();
391 visited_pairs = xbt_fifo_new();
392 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
394 /* Save the initial state */
395 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
396 MC_take_snapshot_to_restore_liveness(initial_snapshot_liveness, prgm);
400 unsigned int cursor = 0;
403 xbt_dynar_foreach(a->states, cursor, state){
404 if(state->type == -1){
407 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
408 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
412 MC_restore_snapshot(initial_snapshot_liveness);
416 MC_ddfs_stateless(a, 0, 0, prgm);
419 if(state->type == 2){
422 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
423 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
426 set_pair_reached(a, state, prgm);
429 MC_restore_snapshot(initial_snapshot_liveness);
433 MC_ddfs_stateless(a, 1, 0, prgm);
442 void MC_ddfs_stateless(xbt_automaton_t a, int search_cycle, int replay, char *prgm){
444 smx_process_t process;
445 mc_pair_stateless_t current_pair = NULL;
447 if(xbt_fifo_size(mc_stack_liveness_stateless) == 0)
451 MC_replay_liveness(mc_stack_liveness_stateless, 0);
452 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
453 xbt_swag_foreach(process, simix_global->process_list){
454 if(MC_process_is_enabled(process)){
455 MC_state_interleave_process(current_pair->graph_state, process);
460 /* Get current pair */
461 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
463 /* Update current state in buchi automaton */
464 a->current_state = current_pair->automaton_state;
467 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness_stateless), search_cycle);
468 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));
470 mc_stats_pair->visited_pairs++;
475 mc_state_t next_graph_state = NULL;
476 smx_req_t req = NULL;
479 xbt_transition_t transition_succ;
480 unsigned int cursor = 0;
483 mc_pair_stateless_t next_pair = NULL;
484 mc_pair_stateless_t pair_succ;
486 if(xbt_fifo_size(mc_stack_liveness_stateless) < MAX_DEPTH_LIVENESS){
488 set_pair_visited(a, current_pair->automaton_state, search_cycle, prgm);
490 //XBT_DEBUG("Visited pairs : %d", xbt_fifo_size(visited_pairs));
492 if(current_pair->requests > 0){
494 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
496 /* Debug information */
497 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
498 req_str = MC_request_to_string(req, value);
499 XBT_DEBUG("Execute: %s", req_str);
503 MC_state_set_executed_request(current_pair->graph_state, req, value);
505 /* Answer the request */
506 SIMIX_request_pre(req, value);
508 /* Wait for requests (schedules processes) */
509 MC_wait_for_requests();
514 /* Create the new expanded graph_state */
515 next_graph_state = MC_state_pair_new();
517 /* Get enabled process and insert it in the interleave set of the next graph_state */
518 xbt_swag_foreach(process, simix_global->process_list){
519 if(MC_process_is_enabled(process)){
520 MC_state_interleave_process(next_graph_state, process);
524 xbt_dynar_reset(successors);
530 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
532 res = MC_automaton_evaluate_label(a, transition_succ->label);
534 if(res == 1){ // enabled transition in automaton
536 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
537 xbt_dynar_push(successors, &next_pair);
545 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
547 res = MC_automaton_evaluate_label(a, transition_succ->label);
549 if(res == 2){ // true transition in automaton
551 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
552 xbt_dynar_push(successors, &next_pair);
560 xbt_dynar_foreach(successors, cursor, pair_succ){
562 if(!visited(a, pair_succ->automaton_state, search_cycle, prgm)){
564 if(search_cycle == 1){
566 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
568 if(reached(a, pair_succ->automaton_state, prgm) == 1){
570 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));
572 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
573 XBT_INFO("| ACCEPTANCE CYCLE |");
574 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
575 XBT_INFO("Counter-example that violates formula :");
576 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
577 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
578 MC_print_statistics_pairs(mc_stats_pair);
583 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);
585 set_pair_reached(a, pair_succ->automaton_state, prgm);
587 //XBT_DEBUG("Reached pairs : %d", xbt_fifo_size(reached_pairs));
595 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
597 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);
599 set_pair_reached(a, pair_succ->automaton_state, prgm);
603 //XBT_DEBUG("Reached pairs : %d", xbt_fifo_size(reached_pairs));
610 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
613 MC_ddfs_stateless(a, search_cycle, 0, prgm);
615 /* Restore system before checking others successors */
616 if(cursor != (xbt_dynar_length(successors) - 1))
617 MC_replay_liveness(mc_stack_liveness_stateless, 1);
621 XBT_DEBUG("Next pair already visited");
626 if(MC_state_interleave_size(current_pair->graph_state) > 0){
627 XBT_DEBUG("Backtracking to depth %u", xbt_fifo_size(mc_stack_liveness_stateless));
628 MC_replay_liveness(mc_stack_liveness_stateless, 0);
633 }else{ /*No request to execute, search evolution in Büchi automaton */
637 /* Create the new expanded graph_state */
638 next_graph_state = MC_state_pair_new();
640 xbt_dynar_reset(successors);
646 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
648 res = MC_automaton_evaluate_label(a, transition_succ->label);
650 if(res == 1){ // enabled transition in automaton
652 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
653 xbt_dynar_push(successors, &next_pair);
661 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
663 res = MC_automaton_evaluate_label(a, transition_succ->label);
665 if(res == 2){ // true transition in automaton
667 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
668 xbt_dynar_push(successors, &next_pair);
676 xbt_dynar_foreach(successors, cursor, pair_succ){
678 if(!visited(a, pair_succ->automaton_state, search_cycle, prgm)){
680 if(search_cycle == 1){
682 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
684 if(reached(a, pair_succ->automaton_state, prgm) == 1){
686 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness_stateless) + 1);
688 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
689 XBT_INFO("| ACCEPTANCE CYCLE |");
690 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
691 XBT_INFO("Counter-example that violates formula :");
692 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
693 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
694 MC_print_statistics_pairs(mc_stats_pair);
699 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);
701 set_pair_reached(a, pair_succ->automaton_state, prgm);
703 //XBT_DEBUG("Reached pairs : %d", xbt_fifo_size(reached_pairs));
711 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)) && (xbt_fifo_size(mc_stack_liveness_stateless) < (MAX_DEPTH_LIVENESS - 1))){
713 set_pair_reached(a, pair_succ->automaton_state, prgm);
717 //XBT_DEBUG("Reached pairs : %d", xbt_fifo_size(reached_pairs));
724 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
727 MC_ddfs_stateless(a, search_cycle, 0, prgm);
729 /* Restore system before checking others successors */
730 if(cursor != xbt_dynar_length(successors) - 1)
731 MC_replay_liveness(mc_stack_liveness_stateless, 1);
735 XBT_DEBUG("Next pair already visited");
745 XBT_DEBUG("Max depth reached");
749 if(xbt_fifo_size(mc_stack_liveness_stateless) == MAX_DEPTH_LIVENESS ){
750 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %u, depth = %d) shifted in stack, maximum depth reached", current_pair->graph_state, current_pair->automaton_state, search_cycle, xbt_fifo_size(mc_stack_liveness_stateless) );
752 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %u, depth = %d) shifted in stack", current_pair->graph_state, current_pair->automaton_state, search_cycle, xbt_fifo_size(mc_stack_liveness_stateless) );
757 xbt_fifo_shift(mc_stack_liveness_stateless);
758 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
759 xbt_fifo_shift(reached_pairs);