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 = NULL;
11 //mc_snapshot_t snapshot;
13 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
15 //XBT_DEBUG("Compare snapshot");
17 if(s1->num_reg != s2->num_reg){
18 XBT_DEBUG("Different num_reg (s1 = %d, s2 = %d)", s1->num_reg, s2->num_reg);
22 //XBT_DEBUG("Num reg : %d", s1->num_reg);
27 for(i=0 ; i< s1->num_reg ; i++){
29 if(s1->regions[i]->type != s2->regions[i]->type){
30 //XBT_DEBUG("Different type of region");
34 switch(s1->regions[i]->type){
36 //XBT_DEBUG("Region : heap");
37 if(s1->regions[i]->size != s2->regions[i]->size){
38 //XBT_DEBUG("Different size of heap (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
41 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
42 //XBT_DEBUG("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
45 if(mmalloc_compare_heap(s1->regions[i]->start_addr, s2->regions[i]->start_addr)){
46 //XBT_DEBUG("Different heap (mmalloc_compare)");
51 //XBT_DEBUG("Region : libsimgrid");
52 if(s1->regions[i]->size != s2->regions[i]->size){
53 //XBT_DEBUG("Different size of libsimgrid (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
56 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
57 //XBT_DEBUG("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
60 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
61 //XBT_DEBUG("Different memcmp for data in libsimgrid");
66 //XBT_DEBUG("Region : program");
67 if(s1->regions[i]->size != s2->regions[i]->size){
68 //XBT_DEBUG("Different size of program (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
71 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
72 //XBT_DEBUG("Different start addr of program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
75 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
76 //XBT_DEBUG("Different memcmp for data in program");
81 //XBT_DEBUG("Region : stack");
82 if(s1->regions[i]->size != s2->regions[i]->size){
83 //XBT_DEBUG("Different size of stack (s1 = %Zu, s2 = %Zu)", s1->regions[i]->size, s2->regions[i]->size);
86 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
87 //XBT_DEBUG("Different start addr of stack (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
90 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
91 //XBT_DEBUG("Different memcmp for data in stack");
102 int reached(xbt_automaton_t a, xbt_state_t st, char *prgm){
105 if(xbt_fifo_size(reached_pairs) == 0){
111 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
113 /* Get values of propositional symbols */
114 unsigned int cursor = 0;
115 xbt_propositional_symbol_t ps = NULL;
116 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
117 int (*f)() = ps->function;
119 xbt_dynar_push_as(prop_ato, int, res);
123 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
124 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;
131 while(i < xbt_fifo_size(reached_pairs)){
133 pair_test = (mc_pair_reached_t) xbt_fifo_get_item_content(item);
135 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
136 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
137 if(snapshot_compare(sn, pair_test->system_state) == 0){
139 MC_free_snapshot(sn);
146 item = xbt_fifo_get_next_item(item);
153 MC_free_snapshot(sn);
160 void set_pair_reached(xbt_automaton_t a, xbt_state_t st, char *prgm){
165 mc_pair_reached_t pair = NULL;
166 pair = xbt_new0(s_mc_pair_reached_t, 1);
167 pair->automaton_state = st;
168 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
169 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
170 MC_take_snapshot_liveness(pair->system_state, prgm);
172 /* Get values of propositional symbols */
173 unsigned int cursor = 0;
174 xbt_propositional_symbol_t ps = NULL;
175 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
176 int (*f)() = ps->function;
178 xbt_dynar_push_as(pair->prop_ato, int, res);
181 xbt_fifo_unshift(reached_pairs, pair);
188 int visited(xbt_automaton_t a, xbt_state_t st, int sc, char *prgm){
191 if(xbt_fifo_size(visited_pairs) == 0){
197 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
199 /* Get values of propositional symbols */
200 unsigned int cursor = 0;
201 xbt_propositional_symbol_t ps = NULL;
202 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
203 int (*f)() = ps->function;
205 xbt_dynar_push_as(prop_ato, int, res);
209 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
210 MC_take_snapshot_liveness(sn, prgm);
215 xbt_fifo_item_t item = xbt_fifo_get_first_item(visited_pairs);
216 mc_pair_visited_t pair_test = NULL;
218 while(i < xbt_fifo_size(visited_pairs)){
220 pair_test = (mc_pair_visited_t) xbt_fifo_get_item_content(item);
222 if(pair_test->search_cycle == sc) {
223 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
224 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
225 if(snapshot_compare(sn, pair_test->system_state) == 0){
227 MC_free_snapshot(sn);
235 item = xbt_fifo_get_next_item(item);
242 MC_free_snapshot(sn);
249 void set_pair_visited(xbt_automaton_t a, xbt_state_t st, int sc, char *prgm){
254 mc_pair_visited_t pair = NULL;
255 pair = xbt_new0(s_mc_pair_visited_t, 1);
256 pair->automaton_state = st;
257 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
258 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
259 MC_take_snapshot_liveness(pair->system_state, prgm);
260 pair->search_cycle = sc;
262 /* Get values of propositional symbols */
263 unsigned int cursor = 0;
264 xbt_propositional_symbol_t ps = NULL;
265 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
266 int (*f)() = ps->function;
268 xbt_dynar_push_as(pair->prop_ato, int, res);
271 xbt_fifo_unshift(visited_pairs, pair);
278 void MC_pair_delete(mc_pair_t pair){
279 xbt_free(pair->graph_state->proc_status);
280 xbt_free(pair->graph_state);
281 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
287 int MC_automaton_evaluate_label(xbt_automaton_t a, xbt_exp_label_t l){
291 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
292 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
293 return (left_res || right_res);
297 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
298 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
299 return (left_res && right_res);
303 int res = MC_automaton_evaluate_label(a, l->u.exp_not);
308 unsigned int cursor = 0;
309 xbt_propositional_symbol_t p = NULL;
310 xbt_dynar_foreach(a->propositional_symbols, cursor, p){
311 if(strcmp(p->pred, l->u.predicat) == 0){
312 int (*f)() = p->function;
332 /********************* Double-DFS stateless *******************/
334 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
335 xbt_free(pair->graph_state->proc_status);
336 xbt_free(pair->graph_state);
337 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
341 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
342 mc_pair_stateless_t p = NULL;
343 p = xbt_new0(s_mc_pair_stateless_t, 1);
344 p->automaton_state = st;
347 mc_stats_pair->expanded_pairs++;
351 void MC_ddfs_stateless_init(xbt_automaton_t a, char *prgm){
353 XBT_DEBUG("**************************************************");
354 XBT_DEBUG("Double-DFS stateless init");
355 XBT_DEBUG("**************************************************");
357 mc_pair_stateless_t mc_initial_pair = NULL;
358 mc_state_t initial_graph_state = NULL;
359 smx_process_t process;
361 MC_wait_for_requests();
365 initial_graph_state = MC_state_pair_new();
366 xbt_swag_foreach(process, simix_global->process_list){
367 if(MC_process_is_enabled(process)){
368 MC_state_interleave_process(initial_graph_state, process);
372 reached_pairs = xbt_fifo_new();
373 visited_pairs = xbt_fifo_new();
374 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
376 /* Save the initial state */
377 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
378 MC_take_snapshot_liveness(initial_snapshot_liveness, prgm);
382 unsigned int cursor = 0;
385 xbt_dynar_foreach(a->states, cursor, state){
386 if(state->type == -1){
389 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
390 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
394 MC_restore_snapshot(initial_snapshot_liveness);
398 MC_ddfs_stateless(a, 0, 0, prgm);
401 if(state->type == 2){
404 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
405 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
408 set_pair_reached(a, state, prgm);
411 MC_restore_snapshot(initial_snapshot_liveness);
415 MC_ddfs_stateless(a, 1, 0, prgm);
424 void MC_ddfs_stateless(xbt_automaton_t a, int search_cycle, int replay, char *prgm){
426 smx_process_t process;
427 mc_pair_stateless_t current_pair = NULL;
429 //mc_snapshot_t current_snapshot = NULL;
431 if(xbt_fifo_size(mc_stack_liveness_stateless) == 0)
435 MC_replay_liveness(mc_stack_liveness_stateless, 0);
436 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
437 xbt_swag_foreach(process, simix_global->process_list){
438 if(MC_process_is_enabled(process)){
439 MC_state_interleave_process(current_pair->graph_state, process);
444 /* Get current pair */
445 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
447 /* Update current state in buchi automaton */
448 a->current_state = current_pair->automaton_state;
451 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness_stateless), search_cycle);
452 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));
454 mc_stats_pair->visited_pairs++;
459 mc_state_t next_graph_state = NULL;
460 smx_req_t req = NULL;
463 xbt_transition_t transition_succ;
464 unsigned int cursor = 0;
467 mc_pair_stateless_t next_pair = NULL;
468 mc_pair_stateless_t pair_succ;
470 if(xbt_fifo_size(mc_stack_liveness_stateless) < MAX_DEPTH_LIVENESS){
472 set_pair_visited(a, current_pair->automaton_state, search_cycle, prgm);
474 if(current_pair->requests > 0){
476 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
478 /* Debug information */
479 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
480 req_str = MC_request_to_string(req, value);
481 XBT_DEBUG("Execute: %s", req_str);
485 MC_state_set_executed_request(current_pair->graph_state, req, value);
487 /* Answer the request */
488 SIMIX_request_pre(req, value);
490 /* Wait for requests (schedules processes) */
491 MC_wait_for_requests();
496 /* Create the new expanded graph_state */
497 next_graph_state = MC_state_pair_new();
499 /* Get enabled process and insert it in the interleave set of the next graph_state */
500 xbt_swag_foreach(process, simix_global->process_list){
501 if(MC_process_is_enabled(process)){
502 MC_state_interleave_process(next_graph_state, process);
506 xbt_dynar_reset(successors);
512 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
514 res = MC_automaton_evaluate_label(a, transition_succ->label);
516 if(res == 1){ // enabled transition in automaton
518 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
519 xbt_dynar_push(successors, &next_pair);
527 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
529 res = MC_automaton_evaluate_label(a, transition_succ->label);
531 if(res == 2){ // true transition in automaton
533 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
534 xbt_dynar_push(successors, &next_pair);
542 xbt_dynar_foreach(successors, cursor, pair_succ){
544 if(!visited(a, pair_succ->automaton_state, search_cycle, prgm)){
546 if(search_cycle == 1){
548 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
550 if(reached(a, pair_succ->automaton_state, prgm) == 1){
552 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));
554 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
555 XBT_INFO("| ACCEPTANCE CYCLE |");
556 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
557 XBT_INFO("Counter-example that violates formula :");
558 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
559 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
560 MC_print_statistics_pairs(mc_stats_pair);
565 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);
567 set_pair_reached(a, pair_succ->automaton_state, prgm);
575 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
577 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);
579 set_pair_reached(a, pair_succ->automaton_state, prgm);
588 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
591 MC_ddfs_stateless(a, search_cycle, 0, prgm);
593 /* Restore system before checking others successors */
594 if(cursor != (xbt_dynar_length(successors) - 1))
595 MC_replay_liveness(mc_stack_liveness_stateless, 1);
599 XBT_DEBUG("Next pair already visited");
604 if(MC_state_interleave_size(current_pair->graph_state) > 0){
605 XBT_DEBUG("Backtracking to depth %u", xbt_fifo_size(mc_stack_liveness_stateless));
606 MC_replay_liveness(mc_stack_liveness_stateless, 0);
611 }else{ /*No request to execute, search evolution in Büchi automaton */
615 /* Create the new expanded graph_state */
616 next_graph_state = MC_state_pair_new();
618 xbt_dynar_reset(successors);
624 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
626 res = MC_automaton_evaluate_label(a, transition_succ->label);
628 if(res == 1){ // enabled transition in automaton
630 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
631 xbt_dynar_push(successors, &next_pair);
639 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
641 res = MC_automaton_evaluate_label(a, transition_succ->label);
643 if(res == 2){ // true transition in automaton
645 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
646 xbt_dynar_push(successors, &next_pair);
654 xbt_dynar_foreach(successors, cursor, pair_succ){
656 if(!visited(a, pair_succ->automaton_state, search_cycle, prgm)){
658 if(search_cycle == 1){
660 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
662 if(reached(a, pair_succ->automaton_state, prgm) == 1){
664 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness_stateless) + 1);
666 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
667 XBT_INFO("| ACCEPTANCE CYCLE |");
668 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
669 XBT_INFO("Counter-example that violates formula :");
670 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
671 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
672 MC_print_statistics_pairs(mc_stats_pair);
677 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);
679 set_pair_reached(a, pair_succ->automaton_state, prgm);
687 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)) && (xbt_fifo_size(mc_stack_liveness_stateless) < (MAX_DEPTH_LIVENESS - 1))){
689 set_pair_reached(a, pair_succ->automaton_state, prgm);
698 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
701 MC_ddfs_stateless(a, search_cycle, 0, prgm);
703 /* Restore system before checking others successors */
704 if(cursor != xbt_dynar_length(successors) - 1)
705 MC_replay_liveness(mc_stack_liveness_stateless, 1);
709 XBT_DEBUG("Next pair already visited");
719 XBT_DEBUG("Max depth reached");
723 if(xbt_fifo_size(mc_stack_liveness_stateless) == MAX_DEPTH_LIVENESS ){
724 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) );
726 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) );
731 xbt_fifo_shift(mc_stack_liveness_stateless);
732 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
733 xbt_fifo_shift(reached_pairs);