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 /* Global variables for stateless algorithm */
13 mc_snapshot_t snapshot = NULL;
15 /* Global variables for stateful algorithm */
16 mc_snapshot_t next_snapshot = NULL;
17 mc_snapshot_t current_snapshot = NULL;
20 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
22 XBT_DEBUG("Compare snapshot");
24 if(s1->num_reg != s2->num_reg)
30 for(i=0 ; i< s1->num_reg ; i++){
32 if(s1->regions[i]->size != s2->regions[i]->size)
35 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr)
38 if(s1->regions[i]->type != s2->regions[i]->type)
41 //XBT_DEBUG("Size of region : %Zu", s1->regions[i]->size);
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)");
50 if(memcmp(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
51 XBT_DEBUG("Different memcmp for data in libsimgrid or program");
64 int reached(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t s){
67 if(xbt_fifo_size(reached_pairs) == 0){
72 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
74 /* Get values of propositional symbols */
75 unsigned int cursor = 0;
76 xbt_propositional_symbol_t ps = NULL;
77 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
78 int (*f)() = ps->function;
80 xbt_dynar_push_as(prop_ato, int, res);
83 mc_pair_reached_t pair_test;
84 xbt_fifo_item_t item = xbt_fifo_get_last_item(reached_pairs);
87 while(i< xbt_fifo_size(reached_pairs)){
89 pair_test = (mc_pair_reached_t) xbt_fifo_get_item_content(item);
91 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
92 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
93 if(snapshot_compare(pair_test->system_state, s) == 0){
100 item = xbt_fifo_get_prev_item(item);
110 void set_pair_reached(xbt_automaton_t a, xbt_state_t st, mc_snapshot_t sn){
115 mc_pair_reached_t pair = NULL;
116 pair = xbt_new0(s_mc_pair_reached_t, 1);
117 pair->automaton_state = st;
118 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
119 pair->system_state = sn;
121 /* Get values of propositional symbols */
122 unsigned int cursor = 0;
123 xbt_propositional_symbol_t ps = NULL;
124 xbt_dynar_foreach(a->propositional_symbols, cursor, ps){
125 int (*f)() = ps->function;
127 xbt_dynar_push_as(pair->prop_ato, int, res);
130 xbt_fifo_unshift(reached_pairs, pair);
137 void MC_pair_delete(mc_pair_t pair){
138 xbt_free(pair->graph_state->proc_status);
139 xbt_free(pair->graph_state);
140 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
146 int MC_automaton_evaluate_label(xbt_automaton_t a, xbt_exp_label_t l){
150 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
151 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
152 return (left_res || right_res);
156 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
157 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
158 return (left_res && right_res);
162 int res = MC_automaton_evaluate_label(a, l->u.exp_not);
167 unsigned int cursor = 0;
168 xbt_propositional_symbol_t p = NULL;
169 xbt_dynar_foreach(a->propositional_symbols, cursor, p){
170 if(strcmp(p->pred, l->u.predicat) == 0){
171 int (*f)() = p->function;
191 /********************* Double-DFS stateless *******************/
193 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
194 xbt_free(pair->graph_state->proc_status);
195 xbt_free(pair->graph_state);
196 //xbt_free(pair->automaton_state); -> FIXME : à implémenter
200 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
201 mc_pair_stateless_t p = NULL;
202 p = xbt_new0(s_mc_pair_stateless_t, 1);
203 p->automaton_state = st;
206 mc_stats_pair->expanded_pairs++;
212 void MC_ddfs_stateless_init(xbt_automaton_t a, char *prgm){
214 XBT_DEBUG("**************************************************");
215 XBT_DEBUG("Double-DFS stateless init");
216 XBT_DEBUG("**************************************************");
218 mc_pair_stateless_t mc_initial_pair = NULL;
219 mc_state_t initial_graph_state = NULL;
220 smx_process_t process;
222 MC_wait_for_requests();
226 initial_graph_state = MC_state_pair_new();
227 xbt_swag_foreach(process, simix_global->process_list){
228 if(MC_process_is_enabled(process)){
229 MC_state_interleave_process(initial_graph_state, process);
233 reached_pairs = xbt_fifo_new();
234 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
235 snapshot = xbt_new0(s_mc_snapshot_t, 1);
237 initial_snapshot = xbt_new0(s_mc_snapshot_t, 1);
238 MC_take_snapshot_liveness(initial_snapshot, prgm);
242 unsigned int cursor = 0;
245 xbt_dynar_foreach(a->states, cursor, state){
246 if(state->type == -1){
249 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
250 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
254 MC_restore_snapshot(initial_snapshot);
258 MC_ddfs_stateless(a, 0, 0, prgm);
261 if(state->type == 2){
264 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
265 xbt_fifo_unshift(mc_stack_liveness_stateless, mc_initial_pair);
268 set_pair_reached(a, state, initial_snapshot);
271 MC_restore_snapshot(initial_snapshot);
275 MC_ddfs_stateless(a, 1, 0, prgm);
284 void MC_ddfs_stateless(xbt_automaton_t a, int search_cycle, int replay, char *prgm){
286 smx_process_t process;
287 mc_pair_stateless_t current_pair = NULL;
289 if(xbt_fifo_size(mc_stack_liveness_stateless) == 0)
293 MC_replay_liveness(mc_stack_liveness_stateless, 0);
294 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
295 xbt_swag_foreach(process, simix_global->process_list){
296 if(MC_process_is_enabled(process)){
297 MC_state_interleave_process(current_pair->graph_state, process);
302 /* Get current pair */
303 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness_stateless));
305 /* Update current state in buchi automaton */
306 a->current_state = current_pair->automaton_state;
309 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness_stateless), search_cycle);
310 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));
312 mc_stats_pair->visited_pairs++;
315 mc_state_t next_graph_state = NULL;
316 smx_req_t req = NULL;
319 xbt_transition_t transition_succ;
320 unsigned int cursor = 0;
323 mc_pair_stateless_t next_pair = NULL;
324 mc_pair_stateless_t pair_succ;
326 if(xbt_fifo_size(mc_stack_liveness_stateless) < MAX_DEPTH_LIVENESS){
328 if(current_pair->requests > 0){
330 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
332 /* Debug information */
333 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
334 req_str = MC_request_to_string(req, value);
335 XBT_DEBUG("Execute: %s", req_str);
341 MC_state_set_executed_request(current_pair->graph_state, req, value);
343 /* Answer the request */
344 SIMIX_request_pre(req, value);
346 /* Wait for requests (schedules processes) */
347 MC_wait_for_requests();
349 unsigned int curs = 0;
350 xbt_propositional_symbol_t p = NULL;
351 xbt_dynar_foreach(a->propositional_symbols, curs, p){
352 int (*f)() = p->function;
354 if(strcmp(p->pred, "p") == 0){
355 XBT_DEBUG("p=%d",res);
357 XBT_DEBUG("q=%d",res);
365 /* Create the new expanded graph_state */
366 next_graph_state = MC_state_pair_new();
368 /* Get enabled process and insert it in the interleave set of the next graph_state */
369 xbt_swag_foreach(process, simix_global->process_list){
370 if(MC_process_is_enabled(process)){
371 MC_state_interleave_process(next_graph_state, process);
375 xbt_dynar_reset(successors);
381 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
383 res = MC_automaton_evaluate_label(a, transition_succ->label);
385 if(res == 1){ // enabled transition in automaton
387 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
388 xbt_dynar_push(successors, &next_pair);
396 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
398 res = MC_automaton_evaluate_label(a, transition_succ->label);
400 if(res == 2){ // true transition in automaton
402 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
403 xbt_dynar_push(successors, &next_pair);
410 if(xbt_dynar_length(successors) == 0){
412 next_pair = new_pair_stateless(next_graph_state, current_pair->automaton_state, MC_state_interleave_size(next_graph_state));
413 xbt_dynar_push(successors, &next_pair);
418 MC_take_snapshot(snapshot);
423 XBT_DEBUG("Successors length : %lu", xbt_dynar_length(successors));
426 xbt_dynar_foreach(successors, cursor, pair_succ){
428 if(search_cycle == 1){
430 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
433 MC_take_snapshot_liveness(snapshot, prgm);
436 if(reached(a, pair_succ->automaton_state, snapshot) == 1){
438 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness_stateless) + 1);
440 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
441 XBT_INFO("| ACCEPTANCE CYCLE |");
442 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
443 XBT_INFO("Counter-example that violates formula :");
444 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
445 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
446 MC_print_statistics_pairs(mc_stats_pair);
451 XBT_DEBUG("Acceptance pair : graph=%p, automaton=%p(%s)", pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
453 set_pair_reached(a, pair_succ->automaton_state, snapshot);
461 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
463 XBT_DEBUG("Acceptance pair : graph=%p, automaton=%p(%s)", pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
466 MC_take_snapshot_liveness(snapshot, prgm);
469 set_pair_reached(a, pair_succ->automaton_state, snapshot);
478 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
481 MC_ddfs_stateless(a, search_cycle, 0, prgm);
483 /* Restore system before checking others successors */
484 if(cursor != (xbt_dynar_length(successors) - 1))
485 MC_replay_liveness(mc_stack_liveness_stateless, 1);
489 if(MC_state_interleave_size(current_pair->graph_state) > 0){
490 XBT_DEBUG("Backtracking to depth %u", xbt_fifo_size(mc_stack_liveness_stateless));
491 MC_replay_liveness(mc_stack_liveness_stateless, 0);
496 }else{ /*No request to execute, search evolution in Büchi automaton */
500 /* Create the new expanded graph_state */
501 next_graph_state = MC_state_pair_new();
503 xbt_dynar_reset(successors);
509 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
511 res = MC_automaton_evaluate_label(a, transition_succ->label);
513 if(res == 1){ // enabled transition in automaton
515 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
516 xbt_dynar_push(successors, &next_pair);
524 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
526 res = MC_automaton_evaluate_label(a, transition_succ->label);
528 if(res == 2){ // true transition in automaton
530 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
531 xbt_dynar_push(successors, &next_pair);
538 if(xbt_dynar_length(successors) == 0){
540 next_pair = new_pair_stateless(next_graph_state, current_pair->automaton_state, MC_state_interleave_size(next_graph_state));
541 xbt_dynar_push(successors, &next_pair);
547 xbt_dynar_foreach(successors, cursor, pair_succ){
549 if(search_cycle == 1){
551 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
554 MC_take_snapshot_liveness(snapshot, prgm);
557 if(reached(a, pair_succ->automaton_state, snapshot) == 1){
559 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness_stateless) + 1);
561 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
562 XBT_INFO("| ACCEPTANCE CYCLE |");
563 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
564 XBT_INFO("Counter-example that violates formula :");
565 MC_show_stack_liveness_stateless(mc_stack_liveness_stateless);
566 MC_dump_stack_liveness_stateless(mc_stack_liveness_stateless);
567 MC_print_statistics_pairs(mc_stats_pair);
572 XBT_DEBUG("Acceptance pair : graph=%p, automaton=%p(%s)", pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
574 set_pair_reached(a, pair_succ->automaton_state, snapshot);
582 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)) && (xbt_fifo_size(mc_stack_liveness_stateless) < (MAX_DEPTH_LIVENESS - 1))){
585 MC_take_snapshot_liveness(snapshot, prgm);
588 set_pair_reached(a, pair_succ->automaton_state, snapshot);
597 xbt_fifo_unshift(mc_stack_liveness_stateless, pair_succ);
600 MC_ddfs_stateless(a, search_cycle, 0, prgm);
602 /* Restore system before checking others successors */
603 if(cursor != xbt_dynar_length(successors) - 1)
604 MC_replay_liveness(mc_stack_liveness_stateless, 1);
611 if(xbt_fifo_size(mc_stack_liveness_stateless) == MAX_DEPTH_LIVENESS ){
612 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);
614 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %u) shifted in stack", current_pair->graph_state, current_pair->automaton_state, search_cycle);
619 xbt_fifo_shift(mc_stack_liveness_stateless);
620 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2))
621 xbt_fifo_shift(reached_pairs);