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){
39 char *pointed_address1 = NULL, *pointed_address2 = NULL;
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);
48 fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
50 free(pointed_address1);
51 free(pointed_address2);
56 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
59 char *pointed_address1 = NULL, *pointed_address2 = NULL;
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\n", i, (char *)d1 + i, (char *)d2 + i);
68 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
70 free(pointed_address1);
71 free(pointed_address2);
76 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap){
79 if(s1->num_reg != s2->num_reg){
80 XBT_INFO("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 XBT_INFO("Different type of region");
94 switch(s1->regions[i]->type){
96 if(s1->regions[i]->size != s2->regions[i]->size){
97 XBT_INFO("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
100 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
101 XBT_INFO("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
104 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
105 XBT_INFO("Different heap (mmalloc_compare)");
110 if(s1->regions[i]->size != s2->regions[i]->size){
111 XBT_INFO("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
114 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
115 XBT_INFO("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
118 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
119 XBT_INFO("Different memcmp for data in libsimgrid");
124 if(s1->regions[i]->size != s2->regions[i]->size){
125 XBT_INFO("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
128 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
129 XBT_INFO("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
132 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
133 XBT_INFO("Different memcmp for data in program");
146 int reached(xbt_state_t st){
149 if(xbt_dynar_is_empty(reached_pairs)){
157 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
158 MC_take_snapshot_liveness(sn);
160 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
164 /* Get values of propositional symbols */
165 unsigned int cursor = 0;
166 xbt_propositional_symbol_t ps = NULL;
167 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
168 f = (int_f_void_t)ps->function;
170 xbt_dynar_push_as(prop_ato, int, res);
174 mc_pair_reached_t pair_test = NULL;
176 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
178 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
179 XBT_INFO("Pair reached #%d", pair_test->nb);
180 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
181 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
182 //XBT_INFO("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
183 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
184 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
185 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
187 MC_free_snapshot(sn);
188 xbt_dynar_reset(prop_ato);
195 XBT_INFO("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
198 XBT_INFO("Different values of propositional symbols");
201 XBT_INFO("Different automaton state");
205 MC_free_snapshot(sn);
206 xbt_dynar_reset(prop_ato);
214 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
216 xbt_dict_cursor_t cursor_dict = NULL;
219 smx_rdv_t rdv1, rdv2;
220 xbt_fifo_item_t item1, item2;
221 smx_action_t action1, action2;
222 xbt_fifo_item_t item_req1, item_req2;
223 smx_simcall_t req1, req2;
227 xbt_dict_foreach(d1, cursor_dict, key, data){
228 rdv1 = (smx_rdv_t)data;
229 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
231 XBT_INFO("Rdv point unknown");
234 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
235 XBT_INFO("Different total of actions in mailbox \"%s\" (%d - %d)", rdv1->name, xbt_fifo_size(rdv1->comm_fifo),xbt_fifo_size(rdv2->comm_fifo) );
239 XBT_INFO("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
241 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
242 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
244 while(i<xbt_fifo_size(rdv1->comm_fifo)){
245 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
246 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
248 if(action1->type != action2->type){
249 XBT_INFO("Different type of action");
253 if(action1->state != action2->state){
254 XBT_INFO("Different state of action");
258 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
259 XBT_INFO("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
263 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
264 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
266 while(j<xbt_fifo_size(action1->simcalls)){
268 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
269 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
271 if(req1->call != req2->call){
272 XBT_INFO("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
275 if(req1->issuer->pid != req2->issuer->pid){
276 XBT_INFO("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
280 item_req1 = xbt_fifo_get_next_item(item_req1);
281 item_req2 = xbt_fifo_get_next_item(item_req2);
287 switch(action1->type){
288 case 0: /* execution */
289 case 1: /* parallel execution */
290 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
294 if(action1->comm.type != action2->comm.type)
296 //XBT_INFO("Type of comm : %d", action1->comm.type);
298 switch(action1->comm.type){
300 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
302 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
305 case 1: /* RECEIVE */
306 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
308 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
312 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
314 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
316 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
318 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
322 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
324 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
326 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
328 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
332 } /* end of switch on type of comm */
334 if(action1->comm.refcount != action2->comm.refcount)
336 if(action1->comm.detached != action2->comm.detached)
338 if(action1->comm.rate != action2->comm.rate)
340 if(action1->comm.task_size != action2->comm.task_size)
342 if(action1->comm.src_buff != action2->comm.src_buff)
344 if(action1->comm.dst_buff != action2->comm.dst_buff)
346 if(action1->comm.src_data != action2->comm.src_data)
348 if(action1->comm.dst_data != action2->comm.dst_data)
353 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
356 case 4: /* synchro */
363 item1 = xbt_fifo_get_next_item(item1);
364 item2 = xbt_fifo_get_next_item(item2);
375 void set_pair_reached(xbt_state_t st){
380 mc_pair_reached_t pair = NULL;
381 pair = xbt_new0(s_mc_pair_reached_t, 1);
382 pair->nb = xbt_dynar_length(reached_pairs) + 1;
383 pair->automaton_state = st;
384 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
385 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
386 //pair->rdv_points = xbt_dict_new();
387 MC_take_snapshot_liveness(pair->system_state);
389 /* Get values of propositional symbols */
390 unsigned int cursor = 0;
391 xbt_propositional_symbol_t ps = NULL;
395 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
396 f = (int_f_void_t)ps->function;
398 xbt_dynar_push_as(pair->prop_ato, int, res);
401 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
403 xbt_dict_cursor_t cursor_dict = NULL;
406 xbt_fifo_item_t item;
409 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
410 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
411 new_rdv->name = strdup(((smx_rdv_t)data)->name);
412 new_rdv->comm_fifo = xbt_fifo_new();
413 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
414 smx_action_t a = xbt_new0(s_smx_action_t, 1);
415 memcpy(a, action, sizeof(s_smx_action_t));
416 xbt_fifo_push(new_rdv->comm_fifo, a);
417 XBT_INFO("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
419 XBT_INFO("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
421 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
422 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
425 xbt_dynar_push(reached_pairs, &pair);
432 int reached_hash(xbt_state_t st){
435 if(xbt_dynar_is_empty(reached_pairs_hash)){
443 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
444 MC_take_snapshot_liveness(sn);
447 unsigned int hash_regions[sn->num_reg];
448 for(j=0; j<sn->num_reg; j++){
449 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
453 /* Get values of propositional symbols */
454 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
455 unsigned int cursor = 0;
456 xbt_propositional_symbol_t ps = NULL;
460 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
461 f = (int_f_void_t)ps->function;
463 xbt_dynar_push_as(prop_ato, int, res);
466 mc_pair_reached_hash_t pair_test = NULL;
472 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
474 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
475 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
476 for(j=0 ; j< sn->num_reg ; j++){
477 if(hash_regions[j] != pair_test->hash_regions[j]){
481 if(region_diff == 0){
482 MC_free_snapshot(sn);
483 xbt_dynar_reset(prop_ato);
488 XBT_INFO("Different snapshot");
491 XBT_INFO("Different values of propositional symbols");
494 XBT_INFO("Different automaton state");
500 MC_free_snapshot(sn);
501 xbt_dynar_reset(prop_ato);
509 void set_pair_reached_hash(xbt_state_t st){
513 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
514 MC_take_snapshot_liveness(sn);
516 mc_pair_reached_hash_t pair = NULL;
517 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
518 pair->automaton_state = st;
519 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
520 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
524 for(i=0 ; i< sn->num_reg ; i++){
525 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
528 /* Get values of propositional symbols */
529 unsigned int cursor = 0;
530 xbt_propositional_symbol_t ps = NULL;
534 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
535 f = (int_f_void_t)ps->function;
537 xbt_dynar_push_as(pair->prop_ato, int, res);
540 xbt_dynar_push(reached_pairs_hash, &pair);
542 MC_free_snapshot(sn);
549 int visited(xbt_state_t st, int sc){
552 if(xbt_dynar_is_empty(visited_pairs)){
560 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
561 MC_take_snapshot_liveness(sn);
563 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
565 /* Get values of propositional symbols */
566 unsigned int cursor = 0;
567 xbt_propositional_symbol_t ps = NULL;
571 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
572 f = (int_f_void_t)ps->function;
574 xbt_dynar_push_as(prop_ato, int, res);
578 mc_pair_visited_t pair_test = NULL;
580 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
581 if(pair_test->search_cycle == sc) {
582 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
583 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
584 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
586 MC_free_snapshot(sn);
587 xbt_dynar_reset(prop_ato);
594 XBT_INFO("Different snapshot");
597 XBT_INFO("Different values of propositional symbols");
600 XBT_INFO("Different automaton state");
603 XBT_INFO("Different value of search_cycle");
608 MC_free_snapshot(sn);
609 xbt_dynar_reset(prop_ato);
618 int visited_hash(xbt_state_t st, int sc){
621 if(xbt_dynar_is_empty(visited_pairs_hash)){
629 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
630 MC_take_snapshot_liveness(sn);
633 unsigned int hash_regions[sn->num_reg];
634 for(j=0; j<sn->num_reg; j++){
635 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
639 /* Get values of propositional symbols */
640 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
641 unsigned int cursor = 0;
642 xbt_propositional_symbol_t ps = NULL;
646 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
647 f = (int_f_void_t)ps->function;
649 xbt_dynar_push_as(prop_ato, int, res);
652 mc_pair_visited_hash_t pair_test = NULL;
657 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
659 if(pair_test->search_cycle == sc) {
660 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
661 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
662 for(j=0 ; j< sn->num_reg ; j++){
663 if(hash_regions[j] != pair_test->hash_regions[j]){
667 if(region_diff == 0){
668 MC_free_snapshot(sn);
669 xbt_dynar_reset(prop_ato);
674 //XBT_INFO("Different snapshot");
677 //XBT_INFO("Different values of propositional symbols");
680 //XBT_INFO("Different automaton state");
683 //XBT_INFO("Different value of search_cycle");
689 MC_free_snapshot(sn);
690 xbt_dynar_reset(prop_ato);
698 void set_pair_visited_hash(xbt_state_t st, int sc){
702 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
703 MC_take_snapshot_liveness(sn);
705 mc_pair_visited_hash_t pair = NULL;
706 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
707 pair->automaton_state = st;
708 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
709 pair->search_cycle = sc;
710 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
714 for(i=0 ; i< sn->num_reg ; i++){
715 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
718 /* Get values of propositional symbols */
719 unsigned int cursor = 0;
720 xbt_propositional_symbol_t ps = NULL;
724 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
725 f = (int_f_void_t)ps->function;
727 xbt_dynar_push_as(pair->prop_ato, int, res);
730 xbt_dynar_push(visited_pairs_hash, &pair);
732 MC_free_snapshot(sn);
738 void set_pair_visited(xbt_state_t st, int sc){
743 mc_pair_visited_t pair = NULL;
744 pair = xbt_new0(s_mc_pair_visited_t, 1);
745 pair->automaton_state = st;
746 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
747 pair->search_cycle = sc;
748 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
749 MC_take_snapshot_liveness(pair->system_state);
752 /* Get values of propositional symbols */
753 unsigned int cursor = 0;
754 xbt_propositional_symbol_t ps = NULL;
758 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
759 f = (int_f_void_t)ps->function;
761 xbt_dynar_push_as(pair->prop_ato, int, res);
764 xbt_dynar_push(visited_pairs, &pair);
771 void MC_pair_delete(mc_pair_t pair){
772 xbt_free(pair->graph_state->proc_status);
773 xbt_free(pair->graph_state);
779 int MC_automaton_evaluate_label(xbt_exp_label_t l){
783 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
784 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
785 return (left_res || right_res);
788 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
789 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
790 return (left_res && right_res);
793 int res = MC_automaton_evaluate_label(l->u.exp_not);
797 unsigned int cursor = 0;
798 xbt_propositional_symbol_t p = NULL;
800 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
801 if(strcmp(p->pred, l->u.predicat) == 0){
802 f = (int_f_void_t)p->function;
817 /********************* Double-DFS stateless *******************/
819 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
820 xbt_free(pair->graph_state->proc_status);
821 xbt_free(pair->graph_state);
825 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
826 mc_pair_stateless_t p = NULL;
827 p = xbt_new0(s_mc_pair_stateless_t, 1);
828 p->automaton_state = st;
831 mc_stats_pair->expanded_pairs++;
835 void MC_ddfs_init(void){
837 XBT_INFO("**************************************************");
838 XBT_INFO("Double-DFS init");
839 XBT_INFO("**************************************************");
841 mc_pair_stateless_t mc_initial_pair = NULL;
842 mc_state_t initial_graph_state = NULL;
843 smx_process_t process;
846 MC_wait_for_requests();
850 initial_graph_state = MC_state_pair_new();
851 xbt_swag_foreach(process, simix_global->process_list){
852 if(MC_process_is_enabled(process)){
853 MC_state_interleave_process(initial_graph_state, process);
857 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
858 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
859 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
860 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
861 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
863 /* Save the initial state */
864 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
865 MC_take_snapshot_liveness(initial_snapshot_liveness);
869 unsigned int cursor = 0;
872 xbt_dynar_foreach(automaton->states, cursor, state){
873 if(state->type == -1){
876 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
877 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
881 MC_restore_snapshot(initial_snapshot_liveness);
888 if(state->type == 2){
891 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
892 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
895 set_pair_reached(state);
896 //set_pair_reached_hash(state);
899 MC_restore_snapshot(initial_snapshot_liveness);
912 void MC_ddfs(int search_cycle){
914 smx_process_t process;
915 mc_pair_stateless_t current_pair = NULL;
917 if(xbt_fifo_size(mc_stack_liveness) == 0)
921 /* Get current pair */
922 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
924 /* Update current state in buchi automaton */
925 automaton->current_state = current_pair->automaton_state;
928 XBT_INFO("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
929 XBT_INFO("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));
931 mc_stats_pair->visited_pairs++;
936 mc_state_t next_graph_state = NULL;
937 smx_simcall_t req = NULL;
940 xbt_transition_t transition_succ;
941 unsigned int cursor = 0;
944 mc_pair_stateless_t next_pair = NULL;
945 mc_pair_stateless_t pair_succ;
947 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
949 //set_pair_visited(current_pair->automaton_state, search_cycle);
950 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
952 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
953 XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
955 if(current_pair->requests > 0){
957 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
959 /* Debug information */
961 req_str = MC_request_to_string(req, value);
962 XBT_INFO("Execute: %s", req_str);
965 MC_state_set_executed_request(current_pair->graph_state, req, value);
967 /* Answer the request */
968 SIMIX_simcall_pre(req, value);
970 /* Wait for requests (schedules processes) */
971 MC_wait_for_requests();
976 /* Create the new expanded graph_state */
977 next_graph_state = MC_state_pair_new();
979 /* Get enabled process and insert it in the interleave set of the next graph_state */
980 xbt_swag_foreach(process, simix_global->process_list){
981 if(MC_process_is_enabled(process)){
982 MC_state_interleave_process(next_graph_state, process);
986 xbt_dynar_reset(successors);
992 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
994 res = MC_automaton_evaluate_label(transition_succ->label);
996 if(res == 1){ // enabled transition in automaton
998 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
999 xbt_dynar_push(successors, &next_pair);
1007 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1009 res = MC_automaton_evaluate_label(transition_succ->label);
1011 if(res == 2){ // true transition in automaton
1013 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1014 xbt_dynar_push(successors, &next_pair);
1022 xbt_dynar_foreach(successors, cursor, pair_succ){
1024 if(search_cycle == 1){
1026 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1028 if(reached(pair_succ->automaton_state)){
1029 //if(reached_hash(pair_succ->automaton_state)){
1031 XBT_INFO("Next pair (depth = %d, %u interleave) already reached !", xbt_fifo_size(mc_stack_liveness) + 1, MC_state_interleave_size(pair_succ->graph_state));
1033 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1034 XBT_INFO("| ACCEPTANCE CYCLE |");
1035 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1036 XBT_INFO("Counter-example that violates formula :");
1037 MC_show_stack_liveness(mc_stack_liveness);
1038 MC_dump_stack_liveness(mc_stack_liveness);
1039 MC_print_statistics_pairs(mc_stats_pair);
1044 XBT_INFO("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);
1046 set_pair_reached(pair_succ->automaton_state);
1047 //set_pair_reached_hash(pair_succ->automaton_state);
1049 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1050 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1053 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1056 MC_ddfs(search_cycle);
1062 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1063 //if(!visited(pair_succ->automaton_state, search_cycle)){
1066 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1069 MC_ddfs(search_cycle);
1073 XBT_INFO("Next pair already visited ! ");
1081 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1083 XBT_INFO("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);
1085 set_pair_reached(pair_succ->automaton_state);
1086 //set_pair_reached_hash(pair_succ->automaton_state);
1090 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1091 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1095 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1096 //if(!visited(pair_succ->automaton_state, search_cycle)){
1099 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1102 MC_ddfs(search_cycle);
1106 XBT_INFO("Next pair already visited ! ");
1113 /* Restore system before checking others successors */
1114 if(cursor != (xbt_dynar_length(successors) - 1))
1115 MC_replay_liveness(mc_stack_liveness, 1);
1120 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1121 XBT_INFO("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1122 MC_replay_liveness(mc_stack_liveness, 0);
1127 }else{ /*No request to execute, search evolution in Büchi automaton */
1131 /* Create the new expanded graph_state */
1132 next_graph_state = MC_state_pair_new();
1134 xbt_dynar_reset(successors);
1140 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1142 res = MC_automaton_evaluate_label(transition_succ->label);
1144 if(res == 1){ // enabled transition in automaton
1146 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1147 xbt_dynar_push(successors, &next_pair);
1155 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1157 res = MC_automaton_evaluate_label(transition_succ->label);
1159 if(res == 2){ // true transition in automaton
1161 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1162 xbt_dynar_push(successors, &next_pair);
1170 xbt_dynar_foreach(successors, cursor, pair_succ){
1172 if(search_cycle == 1){
1174 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1176 if(reached(pair_succ->automaton_state)){
1177 //if(reached_hash(pair_succ->automaton_state)){
1179 XBT_INFO("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1181 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1182 XBT_INFO("| ACCEPTANCE CYCLE |");
1183 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1184 XBT_INFO("Counter-example that violates formula :");
1185 MC_show_stack_liveness(mc_stack_liveness);
1186 MC_dump_stack_liveness(mc_stack_liveness);
1187 MC_print_statistics_pairs(mc_stats_pair);
1192 XBT_INFO("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);
1194 set_pair_reached(pair_succ->automaton_state);
1195 //set_pair_reached_hash(pair_succ->automaton_state);
1197 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1198 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1201 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1204 MC_ddfs(search_cycle);
1210 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1211 //if(!visited(pair_succ->automaton_state, search_cycle)){
1214 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1217 MC_ddfs(search_cycle);
1221 XBT_INFO("Next pair already visited ! ");
1229 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1231 set_pair_reached(pair_succ->automaton_state);
1232 //set_pair_reached_hash(pair_succ->automaton_state);
1236 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1237 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1241 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1242 //if(!visited(pair_succ->automaton_state, search_cycle)){
1245 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1248 MC_ddfs(search_cycle);
1252 XBT_INFO("Next pair already visited ! ");
1258 /* Restore system before checking others successors */
1259 if(cursor != xbt_dynar_length(successors) - 1)
1260 MC_replay_liveness(mc_stack_liveness, 1);
1269 XBT_INFO("Max depth reached");
1273 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1274 XBT_INFO("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) );
1276 XBT_INFO("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) );
1281 xbt_fifo_shift(mc_stack_liveness);
1282 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1283 xbt_dynar_pop(reached_pairs, NULL);
1284 //xbt_dynar_pop(reached_pairs_hash, NULL);