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_fifo_t visited_pairs;
10 xbt_dynar_t successors = NULL;
11 extern mc_snapshot_t initial_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);
25 for(i=0 ; i< s1->num_reg ; i++){
27 if(s1->regions[i]->size != s2->regions[i]->size){
28 XBT_DEBUG("Different size of region");
32 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
33 XBT_DEBUG("Different start addr of region");
37 if(s1->regions[i]->type != s2->regions[i]->type){
38 XBT_DEBUG("Different type of region");
43 if(s1->regions[i]->type == 0){
44 if(mmalloc_compare_heap(s1->regions[i]->start_addr, s2->regions[i]->start_addr)){
45 XBT_DEBUG("Different heap (mmalloc_compare)");
49 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
50 XBT_DEBUG("Different memcmp for data in libsimgrid or program");
62 int reached(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t s){
65 if(xbt_fifo_size(reached_pairs) == 0){
73 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
75 /* Get values of propositional symbols */
76 unsigned int cursor = 0;
77 xbt_propositional_symbol_t ps = NULL;
78 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
79 int (*f)() = ps->function;
81 xbt_dynar_push_as(prop_ato, int, res);
87 xbt_fifo_item_t item = xbt_fifo_get_first_item(reached_pairs);
88 mc_pair_reached_t pair_test = NULL;
90 while(i < xbt_fifo_size(reached_pairs)){
92 pair_test = (mc_pair_reached_t) xbt_fifo_get_item_content(item);
94 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
95 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
96 if(snapshot_compare(s, pair_test->system_state) == 0){
103 item = xbt_fifo_get_next_item(item);
115 void set_pair_reached(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t sn){
120 mc_pair_reached_t pair = NULL;
121 pair = xbt_new0(s_mc_pair_reached_t, 1);
122 pair->automaton_state = st;
123 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
124 pair->system_state = sn;
126 /* Get values of propositional symbols */
127 unsigned int cursor = 0;
128 xbt_propositional_symbol_t ps = NULL;
129 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
130 int (*f)() = ps->function;
132 xbt_dynar_push_as(pair->prop_ato, int, res);
135 xbt_fifo_unshift(reached_pairs, pair);
142 int visited(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t s, int sc){
145 if(xbt_fifo_size(visited_pairs) == 0){
153 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
155 /* Get values of propositional symbols */
156 unsigned int cursor = 0;
157 xbt_propositional_symbol_t ps = NULL;
158 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
159 int (*f)() = ps->function;
161 xbt_dynar_push_as(prop_ato, int, res);
167 xbt_fifo_item_t item = xbt_fifo_get_first_item(visited_pairs);
168 mc_pair_visited_t pair_test = NULL;
170 while(i < xbt_fifo_size(visited_pairs)){
172 pair_test = (mc_pair_visited_t) xbt_fifo_get_item_content(item);
174 if(pair_test->search_cycle == sc) {
175 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
176 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
177 if(snapshot_compare(s, pair_test->system_state) == 0){
185 item = xbt_fifo_get_next_item(item);
197 void set_pair_visited(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t sn, int sc){
202 mc_pair_visited_t pair = NULL;
203 pair = xbt_new0(s_mc_pair_visited_t, 1);
204 pair->automaton_state = st;
205 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
206 pair->system_state = sn;
207 pair->search_cycle = sc;
209 /* Get values of propositional symbols */
210 unsigned int cursor = 0;
211 xbt_propositional_symbol_t ps = NULL;
212 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
213 int (*f)() = ps->function;
215 xbt_dynar_push_as(pair->prop_ato, int, res);
218 xbt_fifo_unshift(visited_pairs, pair);
225 void MC_pair_delete(mc_pair_t pair){
226 xbt_free(pair->graph_state->proc_status);
227 xbt_free(pair->graph_state);
228 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
234 int MC_automaton_evaluate_label(xbt_automaton_t a, xbt_exp_label_t l){
238 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
239 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
240 return (left_res || right_res);
244 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
245 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
246 return (left_res && right_res);
250 int res = MC_automaton_evaluate_label(a, l->u.exp_not);
255 unsigned int cursor = 0;
256 xbt_propositional_symbol_t p = NULL;
257 xbt_dynar_foreach(a->propositional_symbols, cursor, p){
258 if(strcmp(p->pred, l->u.predicat) == 0){
259 int (*f)() = p->function;
279 /********************* Double-DFS stateless *******************/
281 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
282 xbt_free(pair->graph_state->proc_status);
283 xbt_free(pair->graph_state);
284 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
288 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
289 mc_pair_stateless_t p = NULL;
290 p = xbt_new0(s_mc_pair_stateless_t, 1);
291 p->automaton_state = st;
294 mc_stats_pair->expanded_pairs++;
298 void MC_ddfs_stateless_init(xbt_automaton_t a, char *prgm){
300 XBT_DEBUG("**************************************************");
301 XBT_DEBUG("Double-DFS stateless init");
302 XBT_DEBUG("**************************************************");
304 mc_pair_stateless_t mc_initial_pair = NULL;
305 mc_state_t initial_graph_state = NULL;
306 smx_process_t process;
308 MC_wait_for_requests();
312 initial_graph_state = MC_state_pair_new();
313 xbt_swag_foreach(process, simix_global->process_list){
314 if(MC_process_is_enabled(process)){
315 MC_state_interleave_process(initial_graph_state, process);
319 reached_pairs = xbt_fifo_new();
320 visited_pairs = xbt_fifo_new();
321 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
323 initial_snapshot = xbt_new0(s_mc_snapshot_t, 1);
324 MC_take_snapshot_liveness(initial_snapshot, prgm);
328 unsigned int cursor = 0;
331 xbt_dynar_foreach(a->states, cursor, state){
332 if(state->type == -1){
335 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
336 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
340 MC_restore_snapshot(initial_snapshot);
344 MC_ddfs_stateless(a, 0, 0, prgm);
347 if(state->type == 2){
350 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
351 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
354 set_pair_reached(a, state, initial_snapshot);
357 MC_restore_snapshot(initial_snapshot);
361 MC_ddfs_stateless(a, 1, 0, prgm);
370 void MC_ddfs_stateless(xbt_automaton_t a, int search_cycle, int replay, char *prgm){
372 smx_process_t process;
373 mc_pair_stateless_t current_pair = NULL;
374 mc_snapshot_t snapshot = NULL;
375 mc_snapshot_t current_snapshot = NULL;
377 if(xbt_fifo_size(mc_stack_liveness_stateless) == 0)
381 MC_replay_liveness(mc_stack_liveness_stateless, 0);
382 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
383 xbt_swag_foreach(process, simix_global->process_list){
384 if(MC_process_is_enabled(process)){
385 MC_state_interleave_process(current_pair->graph_state, process);
390 /* Get current pair */
391 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
393 /* Update current state in buchi automaton */
394 a->current_state = current_pair->automaton_state;
397 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness_stateless), search_cycle);
398 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));
400 mc_stats_pair->visited_pairs++;
403 mc_state_t next_graph_state = NULL;
404 smx_req_t req = NULL;
407 xbt_transition_t transition_succ;
408 unsigned int cursor = 0;
411 mc_pair_stateless_t next_pair = NULL;
412 mc_pair_stateless_t pair_succ;
414 if(xbt_fifo_size(mc_stack_liveness_stateless) < MAX_DEPTH_LIVENESS){
417 current_snapshot = xbt_new0(s_mc_snapshot_t, 1);
418 MC_take_snapshot_liveness(current_snapshot, prgm);
421 set_pair_visited(a, current_pair->automaton_state, current_snapshot, search_cycle);
423 if(current_pair->requests > 0){
425 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
427 /* Debug information */
428 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
429 req_str = MC_request_to_string(req, value);
430 XBT_DEBUG("Execute: %s", req_str);
434 MC_state_set_executed_request(current_pair->graph_state, req, value);
436 /* Answer the request */
437 SIMIX_request_pre(req, value);
439 /* Wait for requests (schedules processes) */
440 MC_wait_for_requests();
445 /* Create the new expanded graph_state */
446 next_graph_state = MC_state_pair_new();
448 /* Get enabled process and insert it in the interleave set of the next graph_state */
449 xbt_swag_foreach(process, simix_global->process_list){
450 if(MC_process_is_enabled(process)){
451 MC_state_interleave_process(next_graph_state, process);
455 xbt_dynar_reset(successors);
461 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
463 res = MC_automaton_evaluate_label(a, transition_succ->label);
465 if(res == 1){ // enabled transition in automaton
467 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
468 xbt_dynar_push(successors, &next_pair);
476 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
478 res = MC_automaton_evaluate_label(a, transition_succ->label);
480 if(res == 2){ // true transition in automaton
482 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
483 xbt_dynar_push(successors, &next_pair);
492 snapshot = xbt_new0(s_mc_snapshot_t, 1);
493 MC_take_snapshot_liveness(snapshot, prgm);
496 xbt_dynar_foreach(successors, cursor, pair_succ){
498 if(!visited(a, pair_succ->automaton_state, snapshot, search_cycle)){
500 if(search_cycle == 1){
502 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
504 if(reached(a, pair_succ->automaton_state, snapshot) == 1){
506 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));
508 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
509 XBT_INFO("| ACCEPTANCE CYCLE |");
510 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
511 XBT_INFO("Counter-example that violates formula :");
512 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
513 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
514 MC_print_statistics_pairs(mc_stats_pair);
519 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);
521 set_pair_reached(a, pair_succ->automaton_state, snapshot);
529 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
531 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);
533 set_pair_reached(a, pair_succ->automaton_state, snapshot);
542 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
545 MC_ddfs_stateless(a, search_cycle, 0, prgm);
547 /* Restore system before checking others successors */
548 if(cursor != (xbt_dynar_length(successors) - 1))
549 MC_replay_liveness(mc_stack_liveness_stateless, 1);
553 XBT_DEBUG("Next pair already visited");
558 if(MC_state_interleave_size(current_pair->graph_state) > 0){
559 XBT_DEBUG("Backtracking to depth %u", xbt_fifo_size(mc_stack_liveness_stateless));
560 MC_replay_liveness(mc_stack_liveness_stateless, 0);
565 }else{ /*No request to execute, search evolution in Büchi automaton */
569 /* Create the new expanded graph_state */
570 next_graph_state = MC_state_pair_new();
572 xbt_dynar_reset(successors);
578 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
580 res = MC_automaton_evaluate_label(a, transition_succ->label);
582 if(res == 1){ // enabled transition in automaton
584 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
585 xbt_dynar_push(successors, &next_pair);
593 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
595 res = MC_automaton_evaluate_label(a, transition_succ->label);
597 if(res == 2){ // true transition in automaton
599 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
600 xbt_dynar_push(successors, &next_pair);
609 snapshot = xbt_new0(s_mc_snapshot_t, 1);
610 MC_take_snapshot_liveness(snapshot, prgm);
613 xbt_dynar_foreach(successors, cursor, pair_succ){
615 if(!visited(a, pair_succ->automaton_state, snapshot, search_cycle)){
617 if(search_cycle == 1){
619 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
621 if(reached(a, pair_succ->automaton_state, snapshot) == 1){
623 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness_stateless) + 1);
625 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
626 XBT_INFO("| ACCEPTANCE CYCLE |");
627 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
628 XBT_INFO("Counter-example that violates formula :");
629 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
630 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
631 MC_print_statistics_pairs(mc_stats_pair);
636 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);
638 set_pair_reached(a, pair_succ->automaton_state, snapshot);
646 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)) && (xbt_fifo_size(mc_stack_liveness_stateless) < (MAX_DEPTH_LIVENESS - 1))){
648 set_pair_reached(a, pair_succ->automaton_state, snapshot);
657 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
660 MC_ddfs_stateless(a, search_cycle, 0, prgm);
662 /* Restore system before checking others successors */
663 if(cursor != xbt_dynar_length(successors) - 1)
664 MC_replay_liveness(mc_stack_liveness_stateless, 1);
668 XBT_DEBUG("Next pair already visited");
678 XBT_DEBUG("Max depth reached");
682 if(xbt_fifo_size(mc_stack_liveness_stateless) == MAX_DEPTH_LIVENESS ){
683 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);
685 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %u) shifted in stack", current_pair->graph_state, current_pair->automaton_state, search_cycle);
690 xbt_fifo_shift(mc_stack_liveness_stateless);
691 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
692 xbt_fifo_shift(reached_pairs);
695 MC_free_snapshot(snapshot);
696 MC_pair_stateless_delete(current_pair);