1 /* Copyright (c) 2008-2012 Da SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "mc_private.h"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_liveness, mc,
10 "Logging specific to algorithms for liveness properties verification");
12 xbt_dynar_t reached_pairs;
13 xbt_dynar_t reached_pairs_hash;
14 xbt_dynar_t visited_pairs;
15 xbt_dynar_t visited_pairs_hash;
16 xbt_dynar_t successors;
18 xbt_dynar_t hosts_table;
21 /* fast implementation of djb2 algorithm */
22 unsigned int hash_region(char *str, int str_len){
25 register unsigned int hash = 5381;
29 hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
36 int data_program_region_compare(void *d1, void *d2, size_t size){
41 for(i=0; i<size; i++){
42 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
43 fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
45 pointer_align = (i /sizeof(void *)) * sizeof(void *);
46 fprintf(stderr, "Pointer address : %p - %p\n", (char *)d1 + pointer_align, (char *)d2 + pointer_align);
47 fprintf(stderr, "Pointed address : %p - %p\n", *((void **)((char *)d1 + pointer_align)), *((void **)((char *)d2 + pointer_align)));
51 fprintf(stderr, "Hamming distance between data program regions : %d", distance);
56 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
61 for(i=0; i<size; i++){
62 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
63 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region", i, (char *)d1 + i, (char *)d2 + i);
65 pointer_align = (i /sizeof(void *)) * sizeof(void *);
66 fprintf(stderr, "Pointer address : %p - %p\n", (char *)d1 + pointer_align, (char *)d2 + pointer_align);
67 fprintf(stderr, "Pointed address : %p - %p\n", *((void **)((char *)d1 + pointer_align)), *((void **)((char *)d2 + pointer_align)));
71 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d", distance);
76 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
79 if(s1->num_reg != s2->num_reg){
80 XBT_DEBUG("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
87 for(i=0 ; i< s1->num_reg ; i++){
89 if(s1->regions[i]->type != s2->regions[i]->type){
90 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
91 XBT_DEBUG("Different type of region");
98 switch(s1->regions[i]->type){
100 if(s1->regions[i]->size != s2->regions[i]->size){
101 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
102 XBT_DEBUG("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
108 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
109 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
110 XBT_DEBUG("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
116 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data)){
117 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
118 XBT_DEBUG("Different heap (mmalloc_compare)");
126 if(s1->regions[i]->size != s2->regions[i]->size){
127 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
128 XBT_DEBUG("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
134 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
135 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
136 XBT_DEBUG("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
142 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
143 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
144 XBT_DEBUG("Different memcmp for data in libsimgrid");
152 if(s1->regions[i]->size != s2->regions[i]->size){
153 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
154 XBT_DEBUG("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
160 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
161 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
162 XBT_DEBUG("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
168 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
169 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
170 XBT_DEBUG("Different memcmp for data in libsimgrid");
186 int reached(xbt_state_t st){
189 if(xbt_dynar_is_empty(reached_pairs)){
197 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
198 MC_take_snapshot_liveness(sn);
200 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
204 /* Get values of propositional symbols */
205 unsigned int cursor = 0;
206 xbt_propositional_symbol_t ps = NULL;
207 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
208 f = (int_f_void_t)ps->function;
210 xbt_dynar_push_as(prop_ato, int, res);
214 mc_pair_reached_t pair_test = NULL;
216 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
218 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
219 XBT_DEBUG("Pair reached #%u", cursor+1);
220 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
221 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
222 //XBT_DEBUG("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
223 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
224 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
225 if(snapshot_compare(pair_test->system_state, sn) == 0){
226 MC_free_snapshot(sn);
227 xbt_dynar_reset(prop_ato);
234 XBT_DEBUG("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
237 XBT_DEBUG("Different values of propositional symbols");
240 XBT_DEBUG("Different automaton state");
244 MC_free_snapshot(sn);
245 xbt_dynar_reset(prop_ato);
253 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
255 xbt_dict_cursor_t cursor_dict = NULL;
258 smx_rdv_t rdv1, rdv2;
259 xbt_fifo_item_t item1, item2;
260 smx_action_t action1, action2;
261 xbt_fifo_item_t item_req1, item_req2;
262 smx_simcall_t req1, req2;
266 xbt_dict_foreach(d1, cursor_dict, key, data){
267 rdv1 = (smx_rdv_t)data;
268 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
270 XBT_DEBUG("Rdv point unknown");
273 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
274 XBT_DEBUG("Different total of actions in mailbox \"%s\" (%d - %d)", rdv1->name, xbt_fifo_size(rdv1->comm_fifo),xbt_fifo_size(rdv2->comm_fifo) );
278 XBT_DEBUG("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
280 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
281 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
283 while(i<xbt_fifo_size(rdv1->comm_fifo)){
284 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
285 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
287 if(action1->type != action2->type){
288 XBT_DEBUG("Different type of action");
292 if(action1->state != action2->state){
293 XBT_DEBUG("Different state of action");
297 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
298 XBT_DEBUG("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
302 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
303 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
305 while(j<xbt_fifo_size(action1->simcalls)){
307 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
308 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
310 if(req1->call != req2->call){
311 XBT_DEBUG("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
314 if(req1->issuer->pid != req2->issuer->pid){
315 XBT_DEBUG("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
319 item_req1 = xbt_fifo_get_next_item(item_req1);
320 item_req2 = xbt_fifo_get_next_item(item_req2);
326 switch(action1->type){
327 case 0: /* execution */
328 case 1: /* parallel execution */
329 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
333 if(action1->comm.type != action2->comm.type)
335 //XBT_DEBUG("Type of comm : %d", action1->comm.type);
337 switch(action1->comm.type){
339 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
341 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
344 case 1: /* RECEIVE */
345 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
347 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
351 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
353 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
355 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
357 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
361 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
363 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
365 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
367 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
371 } /* end of switch on type of comm */
373 if(action1->comm.refcount != action2->comm.refcount)
375 if(action1->comm.detached != action2->comm.detached)
377 if(action1->comm.rate != action2->comm.rate)
379 if(action1->comm.task_size != action2->comm.task_size)
381 if(action1->comm.src_buff != action2->comm.src_buff)
383 if(action1->comm.dst_buff != action2->comm.dst_buff)
385 if(action1->comm.src_data != action2->comm.src_data)
387 if(action1->comm.dst_data != action2->comm.dst_data)
392 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
395 case 4: /* synchro */
402 item1 = xbt_fifo_get_next_item(item1);
403 item2 = xbt_fifo_get_next_item(item2);
414 void set_pair_reached(xbt_state_t st){
419 mc_pair_reached_t pair = NULL;
420 pair = xbt_new0(s_mc_pair_reached_t, 1);
421 pair->automaton_state = st;
422 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
423 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
424 //pair->rdv_points = xbt_dict_new();
425 MC_take_snapshot_liveness(pair->system_state);
427 /* Get values of propositional symbols */
428 unsigned int cursor = 0;
429 xbt_propositional_symbol_t ps = NULL;
433 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
434 f = (int_f_void_t)ps->function;
436 xbt_dynar_push_as(pair->prop_ato, int, res);
439 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
441 xbt_dict_cursor_t cursor_dict = NULL;
444 xbt_fifo_item_t item;
447 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
448 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
449 new_rdv->name = strdup(((smx_rdv_t)data)->name);
450 new_rdv->comm_fifo = xbt_fifo_new();
451 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
452 smx_action_t a = xbt_new0(s_smx_action_t, 1);
453 memcpy(a, action, sizeof(s_smx_action_t));
454 xbt_fifo_push(new_rdv->comm_fifo, a);
455 XBT_DEBUG("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
457 XBT_DEBUG("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
459 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
460 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
463 xbt_dynar_push(reached_pairs, &pair);
470 int reached_hash(xbt_state_t st){
473 if(xbt_dynar_is_empty(reached_pairs_hash)){
481 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
482 MC_take_snapshot_liveness(sn);
485 unsigned int hash_regions[sn->num_reg];
486 for(j=0; j<sn->num_reg; j++){
487 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
491 /* Get values of propositional symbols */
492 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
493 unsigned int cursor = 0;
494 xbt_propositional_symbol_t ps = NULL;
498 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
499 f = (int_f_void_t)ps->function;
501 xbt_dynar_push_as(prop_ato, int, res);
504 mc_pair_reached_hash_t pair_test = NULL;
510 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
512 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
513 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
514 for(j=0 ; j< sn->num_reg ; j++){
515 if(hash_regions[j] != pair_test->hash_regions[j]){
519 if(region_diff == 0){
520 MC_free_snapshot(sn);
521 xbt_dynar_reset(prop_ato);
526 XBT_DEBUG("Different snapshot");
529 XBT_DEBUG("Different values of propositional symbols");
532 XBT_DEBUG("Different automaton state");
538 MC_free_snapshot(sn);
539 xbt_dynar_reset(prop_ato);
547 void set_pair_reached_hash(xbt_state_t st){
551 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
552 MC_take_snapshot_liveness(sn);
554 mc_pair_reached_hash_t pair = NULL;
555 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
556 pair->automaton_state = st;
557 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
558 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
562 for(i=0 ; i< sn->num_reg ; i++){
563 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
566 /* Get values of propositional symbols */
567 unsigned int cursor = 0;
568 xbt_propositional_symbol_t ps = NULL;
572 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
573 f = (int_f_void_t)ps->function;
575 xbt_dynar_push_as(pair->prop_ato, int, res);
578 xbt_dynar_push(reached_pairs_hash, &pair);
580 MC_free_snapshot(sn);
587 int visited(xbt_state_t st, int sc){
590 if(xbt_dynar_is_empty(visited_pairs)){
598 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
599 MC_take_snapshot_liveness(sn);
601 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
603 /* Get values of propositional symbols */
604 unsigned int cursor = 0;
605 xbt_propositional_symbol_t ps = NULL;
609 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
610 f = (int_f_void_t)ps->function;
612 xbt_dynar_push_as(prop_ato, int, res);
616 mc_pair_visited_t pair_test = NULL;
618 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
619 if(pair_test->search_cycle == sc) {
620 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
621 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
622 if(snapshot_compare(pair_test->system_state, sn) == 0){
624 MC_free_snapshot(sn);
625 xbt_dynar_reset(prop_ato);
632 XBT_DEBUG("Different snapshot");
635 XBT_DEBUG("Different values of propositional symbols");
638 XBT_DEBUG("Different automaton state");
641 XBT_DEBUG("Different value of search_cycle");
646 MC_free_snapshot(sn);
647 xbt_dynar_reset(prop_ato);
656 int visited_hash(xbt_state_t st, int sc){
659 if(xbt_dynar_is_empty(visited_pairs_hash)){
667 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
668 MC_take_snapshot_liveness(sn);
671 unsigned int hash_regions[sn->num_reg];
672 for(j=0; j<sn->num_reg; j++){
673 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
677 /* Get values of propositional symbols */
678 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
679 unsigned int cursor = 0;
680 xbt_propositional_symbol_t ps = NULL;
684 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
685 f = (int_f_void_t)ps->function;
687 xbt_dynar_push_as(prop_ato, int, res);
690 mc_pair_visited_hash_t pair_test = NULL;
695 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
697 if(pair_test->search_cycle == sc) {
698 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
699 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
700 for(j=0 ; j< sn->num_reg ; j++){
701 if(hash_regions[j] != pair_test->hash_regions[j]){
705 if(region_diff == 0){
706 MC_free_snapshot(sn);
707 xbt_dynar_reset(prop_ato);
712 //XBT_DEBUG("Different snapshot");
715 //XBT_DEBUG("Different values of propositional symbols");
718 //XBT_DEBUG("Different automaton state");
721 //XBT_DEBUG("Different value of search_cycle");
727 MC_free_snapshot(sn);
728 xbt_dynar_reset(prop_ato);
736 void set_pair_visited_hash(xbt_state_t st, int sc){
740 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
741 MC_take_snapshot_liveness(sn);
743 mc_pair_visited_hash_t pair = NULL;
744 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
745 pair->automaton_state = st;
746 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
747 pair->search_cycle = sc;
748 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
752 for(i=0 ; i< sn->num_reg ; i++){
753 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
756 /* Get values of propositional symbols */
757 unsigned int cursor = 0;
758 xbt_propositional_symbol_t ps = NULL;
762 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
763 f = (int_f_void_t)ps->function;
765 xbt_dynar_push_as(pair->prop_ato, int, res);
768 xbt_dynar_push(visited_pairs_hash, &pair);
770 MC_free_snapshot(sn);
776 void set_pair_visited(xbt_state_t st, int sc){
781 mc_pair_visited_t pair = NULL;
782 pair = xbt_new0(s_mc_pair_visited_t, 1);
783 pair->automaton_state = st;
784 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
785 pair->search_cycle = sc;
786 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
787 MC_take_snapshot_liveness(pair->system_state);
790 /* Get values of propositional symbols */
791 unsigned int cursor = 0;
792 xbt_propositional_symbol_t ps = NULL;
796 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
797 f = (int_f_void_t)ps->function;
799 xbt_dynar_push_as(pair->prop_ato, int, res);
802 xbt_dynar_push(visited_pairs, &pair);
809 void MC_pair_delete(mc_pair_t pair){
810 xbt_free(pair->graph_state->proc_status);
811 xbt_free(pair->graph_state);
817 int MC_automaton_evaluate_label(xbt_exp_label_t l){
821 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
822 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
823 return (left_res || right_res);
826 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
827 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
828 return (left_res && right_res);
831 int res = MC_automaton_evaluate_label(l->u.exp_not);
835 unsigned int cursor = 0;
836 xbt_propositional_symbol_t p = NULL;
838 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
839 if(strcmp(p->pred, l->u.predicat) == 0){
840 f = (int_f_void_t)p->function;
855 /********************* Double-DFS stateless *******************/
857 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
858 xbt_free(pair->graph_state->proc_status);
859 xbt_free(pair->graph_state);
863 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
864 mc_pair_stateless_t p = NULL;
865 p = xbt_new0(s_mc_pair_stateless_t, 1);
866 p->automaton_state = st;
869 mc_stats_pair->expanded_pairs++;
873 void MC_ddfs_init(void){
875 XBT_DEBUG("**************************************************");
876 XBT_DEBUG("Double-DFS init");
877 XBT_DEBUG("**************************************************");
879 XBT_DEBUG("Std heap : %p", std_heap);
880 XBT_DEBUG("Raw heap : %p", raw_heap);
882 mc_pair_stateless_t mc_initial_pair = NULL;
883 mc_state_t initial_graph_state = NULL;
884 smx_process_t process;
887 MC_wait_for_requests();
891 initial_graph_state = MC_state_pair_new();
892 xbt_swag_foreach(process, simix_global->process_list){
893 if(MC_process_is_enabled(process)){
894 MC_state_interleave_process(initial_graph_state, process);
898 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
899 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
900 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
901 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
902 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
904 /* Save the initial state */
905 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
906 MC_take_snapshot_liveness(initial_snapshot_liveness);
910 unsigned int cursor = 0;
913 xbt_dynar_foreach(automaton->states, cursor, state){
914 if(state->type == -1){
917 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
918 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
922 MC_restore_snapshot(initial_snapshot_liveness);
929 if(state->type == 2){
932 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
933 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
936 set_pair_reached(state);
937 //set_pair_reached_hash(state);
940 MC_restore_snapshot(initial_snapshot_liveness);
953 void MC_ddfs(int search_cycle){
955 smx_process_t process;
956 mc_pair_stateless_t current_pair = NULL;
958 if(xbt_fifo_size(mc_stack_liveness) == 0)
962 /* Get current pair */
963 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
965 /* Update current state in buchi automaton */
966 automaton->current_state = current_pair->automaton_state;
969 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
970 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));
972 mc_stats_pair->visited_pairs++;
977 mc_state_t next_graph_state = NULL;
978 smx_simcall_t req = NULL;
981 xbt_transition_t transition_succ;
982 unsigned int cursor = 0;
985 mc_pair_stateless_t next_pair = NULL;
986 mc_pair_stateless_t pair_succ;
988 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
990 //set_pair_visited(current_pair->automaton_state, search_cycle);
991 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
993 //XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
994 XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
996 if(current_pair->requests > 0){
998 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1000 /* Debug information */
1001 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
1002 req_str = MC_request_to_string(req, value);
1003 XBT_DEBUG("Execute: %s", req_str);
1007 MC_state_set_executed_request(current_pair->graph_state, req, value);
1009 /* Answer the request */
1010 SIMIX_simcall_pre(req, value);
1012 /* Wait for requests (schedules processes) */
1013 MC_wait_for_requests();
1018 /* Create the new expanded graph_state */
1019 next_graph_state = MC_state_pair_new();
1021 /* Get enabled process and insert it in the interleave set of the next graph_state */
1022 xbt_swag_foreach(process, simix_global->process_list){
1023 if(MC_process_is_enabled(process)){
1024 MC_state_interleave_process(next_graph_state, process);
1028 xbt_dynar_reset(successors);
1034 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1036 res = MC_automaton_evaluate_label(transition_succ->label);
1038 if(res == 1){ // enabled transition in automaton
1040 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1041 xbt_dynar_push(successors, &next_pair);
1049 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1051 res = MC_automaton_evaluate_label(transition_succ->label);
1053 if(res == 2){ // true transition in automaton
1055 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1056 xbt_dynar_push(successors, &next_pair);
1064 xbt_dynar_foreach(successors, cursor, pair_succ){
1066 if(search_cycle == 1){
1068 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1070 if(reached(pair_succ->automaton_state)){
1071 //if(reached_hash(pair_succ->automaton_state)){
1073 XBT_DEBUG("Next pair (depth = %d, %u interleave) already reached !", xbt_fifo_size(mc_stack_liveness) + 1, MC_state_interleave_size(pair_succ->graph_state));
1075 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1076 XBT_INFO("| ACCEPTANCE CYCLE |");
1077 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1078 XBT_INFO("Counter-example that violates formula :");
1079 MC_show_stack_liveness(mc_stack_liveness);
1080 MC_dump_stack_liveness(mc_stack_liveness);
1081 MC_print_statistics_pairs(mc_stats_pair);
1086 XBT_DEBUG("Next pair (depth =%d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
1088 set_pair_reached(pair_succ->automaton_state);
1089 //set_pair_reached_hash(pair_succ->automaton_state);
1091 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1092 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1095 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1098 MC_ddfs(search_cycle);
1104 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1105 //if(!visited(pair_succ->automaton_state, search_cycle)){
1108 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1111 MC_ddfs(search_cycle);
1115 XBT_DEBUG("Next pair already visited ! ");
1123 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1125 XBT_DEBUG("Next pair (depth =%d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
1127 set_pair_reached(pair_succ->automaton_state);
1128 //set_pair_reached_hash(pair_succ->automaton_state);
1132 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1133 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1137 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1138 //if(!visited(pair_succ->automaton_state, search_cycle)){
1141 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1144 MC_ddfs(search_cycle);
1148 XBT_DEBUG("Next pair already visited ! ");
1155 /* Restore system before checking others successors */
1156 if(cursor != (xbt_dynar_length(successors) - 1))
1157 MC_replay_liveness(mc_stack_liveness, 1);
1162 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1163 XBT_DEBUG("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1164 MC_replay_liveness(mc_stack_liveness, 0);
1169 }else{ /*No request to execute, search evolution in Büchi automaton */
1173 /* Create the new expanded graph_state */
1174 next_graph_state = MC_state_pair_new();
1176 xbt_dynar_reset(successors);
1182 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1184 res = MC_automaton_evaluate_label(transition_succ->label);
1186 if(res == 1){ // enabled transition in automaton
1188 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1189 xbt_dynar_push(successors, &next_pair);
1197 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1199 res = MC_automaton_evaluate_label(transition_succ->label);
1201 if(res == 2){ // true transition in automaton
1203 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1204 xbt_dynar_push(successors, &next_pair);
1212 xbt_dynar_foreach(successors, cursor, pair_succ){
1214 if(search_cycle == 1){
1216 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1218 if(reached(pair_succ->automaton_state)){
1219 //if(reached_hash(pair_succ->automaton_state)){
1221 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1223 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1224 XBT_INFO("| ACCEPTANCE CYCLE |");
1225 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1226 XBT_INFO("Counter-example that violates formula :");
1227 MC_show_stack_liveness(mc_stack_liveness);
1228 MC_dump_stack_liveness(mc_stack_liveness);
1229 MC_print_statistics_pairs(mc_stats_pair);
1234 XBT_DEBUG("Next pair (depth = %d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
1236 set_pair_reached(pair_succ->automaton_state);
1237 //set_pair_reached_hash(pair_succ->automaton_state);
1239 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1240 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1243 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1246 MC_ddfs(search_cycle);
1252 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1253 //if(!visited(pair_succ->automaton_state, search_cycle)){
1256 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1259 MC_ddfs(search_cycle);
1263 XBT_DEBUG("Next pair already visited ! ");
1271 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1273 set_pair_reached(pair_succ->automaton_state);
1274 //set_pair_reached_hash(pair_succ->automaton_state);
1278 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1279 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1283 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1284 //if(!visited(pair_succ->automaton_state, search_cycle)){
1287 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1290 MC_ddfs(search_cycle);
1294 XBT_DEBUG("Next pair already visited ! ");
1300 /* Restore system before checking others successors */
1301 if(cursor != xbt_dynar_length(successors) - 1)
1302 MC_replay_liveness(mc_stack_liveness, 1);
1311 XBT_DEBUG("Max depth reached");
1315 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1316 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %d, depth = %d) shifted in stack, maximum depth reached", current_pair->graph_state, current_pair->automaton_state, search_cycle, xbt_fifo_size(mc_stack_liveness) );
1318 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %d, depth = %d) shifted in stack", current_pair->graph_state, current_pair->automaton_state, search_cycle, xbt_fifo_size(mc_stack_liveness) );
1323 xbt_fifo_shift(mc_stack_liveness);
1324 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1325 xbt_dynar_pop(reached_pairs, NULL);
1326 //xbt_dynar_pop(reached_pairs_hash, NULL);