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){
40 for(i=0; i<size; i++){
41 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
42 fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
47 fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
52 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
56 for(i=0; i<size; i++){
57 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
58 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region\n", i, (char *)d1 + i, (char *)d2 + i);
63 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
68 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
71 if(s1->num_reg != s2->num_reg){
72 XBT_INFO("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
79 for(i=0 ; i< s1->num_reg ; i++){
81 if(s1->regions[i]->type != s2->regions[i]->type){
82 XBT_INFO("Different type of region");
86 switch(s1->regions[i]->type){
88 if(s1->regions[i]->size != s2->regions[i]->size){
89 XBT_INFO("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
92 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
93 XBT_INFO("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
96 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data)){
97 XBT_INFO("Different heap (mmalloc_compare)");
102 if(s1->regions[i]->size != s2->regions[i]->size){
103 XBT_INFO("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
106 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
107 XBT_INFO("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
110 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
111 XBT_INFO("Different memcmp for data in libsimgrid");
116 if(s1->regions[i]->size != s2->regions[i]->size){
117 XBT_INFO("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
120 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
121 XBT_INFO("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
124 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
125 XBT_INFO("Different memcmp for data in program");
138 int reached(xbt_state_t st){
141 if(xbt_dynar_is_empty(reached_pairs)){
149 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
150 MC_take_snapshot_liveness(sn);
152 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
156 /* Get values of propositional symbols */
157 unsigned int cursor = 0;
158 xbt_propositional_symbol_t ps = NULL;
159 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
160 f = (int_f_void_t)ps->function;
162 xbt_dynar_push_as(prop_ato, int, res);
166 mc_pair_reached_t pair_test = NULL;
168 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
170 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
171 XBT_INFO("Pair reached #%d", pair_test->nb);
172 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
173 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
174 //XBT_INFO("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
175 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
176 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
177 if(snapshot_compare(pair_test->system_state, sn) == 0){
179 MC_free_snapshot(sn);
180 xbt_dynar_reset(prop_ato);
187 XBT_INFO("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
190 XBT_INFO("Different values of propositional symbols");
193 XBT_INFO("Different automaton state");
197 MC_free_snapshot(sn);
198 xbt_dynar_reset(prop_ato);
206 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
208 xbt_dict_cursor_t cursor_dict = NULL;
211 smx_rdv_t rdv1, rdv2;
212 xbt_fifo_item_t item1, item2;
213 smx_action_t action1, action2;
214 xbt_fifo_item_t item_req1, item_req2;
215 smx_simcall_t req1, req2;
219 xbt_dict_foreach(d1, cursor_dict, key, data){
220 rdv1 = (smx_rdv_t)data;
221 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
223 XBT_INFO("Rdv point unknown");
226 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
227 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) );
231 XBT_INFO("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
233 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
234 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
236 while(i<xbt_fifo_size(rdv1->comm_fifo)){
237 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
238 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
240 if(action1->type != action2->type){
241 XBT_INFO("Different type of action");
245 if(action1->state != action2->state){
246 XBT_INFO("Different state of action");
250 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
251 XBT_INFO("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
255 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
256 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
258 while(j<xbt_fifo_size(action1->simcalls)){
260 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
261 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
263 if(req1->call != req2->call){
264 XBT_INFO("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
267 if(req1->issuer->pid != req2->issuer->pid){
268 XBT_INFO("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
272 item_req1 = xbt_fifo_get_next_item(item_req1);
273 item_req2 = xbt_fifo_get_next_item(item_req2);
279 switch(action1->type){
280 case 0: /* execution */
281 case 1: /* parallel execution */
282 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
286 if(action1->comm.type != action2->comm.type)
288 //XBT_INFO("Type of comm : %d", action1->comm.type);
290 switch(action1->comm.type){
292 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
294 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
297 case 1: /* RECEIVE */
298 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
300 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
304 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
306 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
308 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
310 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
314 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
316 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
318 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
320 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
324 } /* end of switch on type of comm */
326 if(action1->comm.refcount != action2->comm.refcount)
328 if(action1->comm.detached != action2->comm.detached)
330 if(action1->comm.rate != action2->comm.rate)
332 if(action1->comm.task_size != action2->comm.task_size)
334 if(action1->comm.src_buff != action2->comm.src_buff)
336 if(action1->comm.dst_buff != action2->comm.dst_buff)
338 if(action1->comm.src_data != action2->comm.src_data)
340 if(action1->comm.dst_data != action2->comm.dst_data)
345 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
348 case 4: /* synchro */
355 item1 = xbt_fifo_get_next_item(item1);
356 item2 = xbt_fifo_get_next_item(item2);
367 void set_pair_reached(xbt_state_t st){
372 mc_pair_reached_t pair = NULL;
373 pair = xbt_new0(s_mc_pair_reached_t, 1);
374 pair->nb = xbt_dynar_length(reached_pairs) + 1;
375 pair->automaton_state = st;
376 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
377 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
378 //pair->rdv_points = xbt_dict_new();
379 MC_take_snapshot_liveness(pair->system_state);
381 /* Get values of propositional symbols */
382 unsigned int cursor = 0;
383 xbt_propositional_symbol_t ps = NULL;
387 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
388 f = (int_f_void_t)ps->function;
390 xbt_dynar_push_as(pair->prop_ato, int, res);
393 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
395 xbt_dict_cursor_t cursor_dict = NULL;
398 xbt_fifo_item_t item;
401 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
402 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
403 new_rdv->name = strdup(((smx_rdv_t)data)->name);
404 new_rdv->comm_fifo = xbt_fifo_new();
405 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
406 smx_action_t a = xbt_new0(s_smx_action_t, 1);
407 memcpy(a, action, sizeof(s_smx_action_t));
408 xbt_fifo_push(new_rdv->comm_fifo, a);
409 XBT_INFO("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
411 XBT_INFO("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
413 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
414 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
417 xbt_dynar_push(reached_pairs, &pair);
424 int reached_hash(xbt_state_t st){
427 if(xbt_dynar_is_empty(reached_pairs_hash)){
435 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
436 MC_take_snapshot_liveness(sn);
439 unsigned int hash_regions[sn->num_reg];
440 for(j=0; j<sn->num_reg; j++){
441 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
445 /* Get values of propositional symbols */
446 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
447 unsigned int cursor = 0;
448 xbt_propositional_symbol_t ps = NULL;
452 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
453 f = (int_f_void_t)ps->function;
455 xbt_dynar_push_as(prop_ato, int, res);
458 mc_pair_reached_hash_t pair_test = NULL;
464 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
466 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
467 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
468 for(j=0 ; j< sn->num_reg ; j++){
469 if(hash_regions[j] != pair_test->hash_regions[j]){
473 if(region_diff == 0){
474 MC_free_snapshot(sn);
475 xbt_dynar_reset(prop_ato);
480 XBT_INFO("Different snapshot");
483 XBT_INFO("Different values of propositional symbols");
486 XBT_INFO("Different automaton state");
492 MC_free_snapshot(sn);
493 xbt_dynar_reset(prop_ato);
501 void set_pair_reached_hash(xbt_state_t st){
505 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
506 MC_take_snapshot_liveness(sn);
508 mc_pair_reached_hash_t pair = NULL;
509 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
510 pair->automaton_state = st;
511 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
512 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
516 for(i=0 ; i< sn->num_reg ; i++){
517 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
520 /* Get values of propositional symbols */
521 unsigned int cursor = 0;
522 xbt_propositional_symbol_t ps = NULL;
526 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
527 f = (int_f_void_t)ps->function;
529 xbt_dynar_push_as(pair->prop_ato, int, res);
532 xbt_dynar_push(reached_pairs_hash, &pair);
534 MC_free_snapshot(sn);
541 int visited(xbt_state_t st, int sc){
544 if(xbt_dynar_is_empty(visited_pairs)){
552 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
553 MC_take_snapshot_liveness(sn);
555 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
557 /* Get values of propositional symbols */
558 unsigned int cursor = 0;
559 xbt_propositional_symbol_t ps = NULL;
563 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
564 f = (int_f_void_t)ps->function;
566 xbt_dynar_push_as(prop_ato, int, res);
570 mc_pair_visited_t pair_test = NULL;
572 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
573 if(pair_test->search_cycle == sc) {
574 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
575 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
576 if(snapshot_compare(pair_test->system_state, sn) == 0){
578 MC_free_snapshot(sn);
579 xbt_dynar_reset(prop_ato);
586 XBT_INFO("Different snapshot");
589 XBT_INFO("Different values of propositional symbols");
592 XBT_INFO("Different automaton state");
595 XBT_INFO("Different value of search_cycle");
600 MC_free_snapshot(sn);
601 xbt_dynar_reset(prop_ato);
610 int visited_hash(xbt_state_t st, int sc){
613 if(xbt_dynar_is_empty(visited_pairs_hash)){
621 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
622 MC_take_snapshot_liveness(sn);
625 unsigned int hash_regions[sn->num_reg];
626 for(j=0; j<sn->num_reg; j++){
627 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
631 /* Get values of propositional symbols */
632 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
633 unsigned int cursor = 0;
634 xbt_propositional_symbol_t ps = NULL;
638 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
639 f = (int_f_void_t)ps->function;
641 xbt_dynar_push_as(prop_ato, int, res);
644 mc_pair_visited_hash_t pair_test = NULL;
649 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
651 if(pair_test->search_cycle == sc) {
652 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
653 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
654 for(j=0 ; j< sn->num_reg ; j++){
655 if(hash_regions[j] != pair_test->hash_regions[j]){
659 if(region_diff == 0){
660 MC_free_snapshot(sn);
661 xbt_dynar_reset(prop_ato);
666 //XBT_INFO("Different snapshot");
669 //XBT_INFO("Different values of propositional symbols");
672 //XBT_INFO("Different automaton state");
675 //XBT_INFO("Different value of search_cycle");
681 MC_free_snapshot(sn);
682 xbt_dynar_reset(prop_ato);
690 void set_pair_visited_hash(xbt_state_t st, int sc){
694 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
695 MC_take_snapshot_liveness(sn);
697 mc_pair_visited_hash_t pair = NULL;
698 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
699 pair->automaton_state = st;
700 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
701 pair->search_cycle = sc;
702 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
706 for(i=0 ; i< sn->num_reg ; i++){
707 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
710 /* Get values of propositional symbols */
711 unsigned int cursor = 0;
712 xbt_propositional_symbol_t ps = NULL;
716 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
717 f = (int_f_void_t)ps->function;
719 xbt_dynar_push_as(pair->prop_ato, int, res);
722 xbt_dynar_push(visited_pairs_hash, &pair);
724 MC_free_snapshot(sn);
730 void set_pair_visited(xbt_state_t st, int sc){
735 mc_pair_visited_t pair = NULL;
736 pair = xbt_new0(s_mc_pair_visited_t, 1);
737 pair->automaton_state = st;
738 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
739 pair->search_cycle = sc;
740 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
741 MC_take_snapshot_liveness(pair->system_state);
744 /* Get values of propositional symbols */
745 unsigned int cursor = 0;
746 xbt_propositional_symbol_t ps = NULL;
750 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
751 f = (int_f_void_t)ps->function;
753 xbt_dynar_push_as(pair->prop_ato, int, res);
756 xbt_dynar_push(visited_pairs, &pair);
763 void MC_pair_delete(mc_pair_t pair){
764 xbt_free(pair->graph_state->proc_status);
765 xbt_free(pair->graph_state);
771 int MC_automaton_evaluate_label(xbt_exp_label_t l){
775 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
776 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
777 return (left_res || right_res);
780 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
781 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
782 return (left_res && right_res);
785 int res = MC_automaton_evaluate_label(l->u.exp_not);
789 unsigned int cursor = 0;
790 xbt_propositional_symbol_t p = NULL;
792 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
793 if(strcmp(p->pred, l->u.predicat) == 0){
794 f = (int_f_void_t)p->function;
809 /********************* Double-DFS stateless *******************/
811 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
812 xbt_free(pair->graph_state->proc_status);
813 xbt_free(pair->graph_state);
817 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
818 mc_pair_stateless_t p = NULL;
819 p = xbt_new0(s_mc_pair_stateless_t, 1);
820 p->automaton_state = st;
823 mc_stats_pair->expanded_pairs++;
827 void MC_ddfs_init(void){
829 XBT_INFO("**************************************************");
830 XBT_INFO("Double-DFS init");
831 XBT_INFO("**************************************************");
833 mc_pair_stateless_t mc_initial_pair = NULL;
834 mc_state_t initial_graph_state = NULL;
835 smx_process_t process;
838 MC_wait_for_requests();
842 initial_graph_state = MC_state_pair_new();
843 xbt_swag_foreach(process, simix_global->process_list){
844 if(MC_process_is_enabled(process)){
845 MC_state_interleave_process(initial_graph_state, process);
849 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
850 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
851 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
852 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
853 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
855 /* Save the initial state */
856 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
857 MC_take_snapshot_liveness(initial_snapshot_liveness);
861 unsigned int cursor = 0;
864 xbt_dynar_foreach(automaton->states, cursor, state){
865 if(state->type == -1){
868 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
869 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
873 MC_restore_snapshot(initial_snapshot_liveness);
880 if(state->type == 2){
883 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
884 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
887 set_pair_reached(state);
888 //set_pair_reached_hash(state);
891 MC_restore_snapshot(initial_snapshot_liveness);
904 void MC_ddfs(int search_cycle){
906 smx_process_t process;
907 mc_pair_stateless_t current_pair = NULL;
909 if(xbt_fifo_size(mc_stack_liveness) == 0)
913 /* Get current pair */
914 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
916 /* Update current state in buchi automaton */
917 automaton->current_state = current_pair->automaton_state;
920 XBT_INFO("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
921 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));
923 mc_stats_pair->visited_pairs++;
928 mc_state_t next_graph_state = NULL;
929 smx_simcall_t req = NULL;
932 xbt_transition_t transition_succ;
933 unsigned int cursor = 0;
936 mc_pair_stateless_t next_pair = NULL;
937 mc_pair_stateless_t pair_succ;
939 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
941 //set_pair_visited(current_pair->automaton_state, search_cycle);
942 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
944 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
945 XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
947 if(current_pair->requests > 0){
949 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
951 /* Debug information */
953 req_str = MC_request_to_string(req, value);
954 XBT_INFO("Execute: %s", req_str);
957 MC_state_set_executed_request(current_pair->graph_state, req, value);
959 /* Answer the request */
960 SIMIX_simcall_pre(req, value);
962 /* Wait for requests (schedules processes) */
963 MC_wait_for_requests();
968 /* Create the new expanded graph_state */
969 next_graph_state = MC_state_pair_new();
971 /* Get enabled process and insert it in the interleave set of the next graph_state */
972 xbt_swag_foreach(process, simix_global->process_list){
973 if(MC_process_is_enabled(process)){
974 MC_state_interleave_process(next_graph_state, process);
978 xbt_dynar_reset(successors);
984 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
986 res = MC_automaton_evaluate_label(transition_succ->label);
988 if(res == 1){ // enabled transition in automaton
990 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
991 xbt_dynar_push(successors, &next_pair);
999 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1001 res = MC_automaton_evaluate_label(transition_succ->label);
1003 if(res == 2){ // true transition in automaton
1005 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1006 xbt_dynar_push(successors, &next_pair);
1014 xbt_dynar_foreach(successors, cursor, pair_succ){
1016 if(search_cycle == 1){
1018 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1020 if(reached(pair_succ->automaton_state)){
1021 //if(reached_hash(pair_succ->automaton_state)){
1023 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));
1025 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1026 XBT_INFO("| ACCEPTANCE CYCLE |");
1027 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1028 XBT_INFO("Counter-example that violates formula :");
1029 MC_show_stack_liveness(mc_stack_liveness);
1030 MC_dump_stack_liveness(mc_stack_liveness);
1031 MC_print_statistics_pairs(mc_stats_pair);
1036 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);
1038 set_pair_reached(pair_succ->automaton_state);
1039 //set_pair_reached_hash(pair_succ->automaton_state);
1041 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1042 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1045 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1048 MC_ddfs(search_cycle);
1054 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1055 //if(!visited(pair_succ->automaton_state, search_cycle)){
1058 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1061 MC_ddfs(search_cycle);
1065 XBT_INFO("Next pair already visited ! ");
1073 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1075 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);
1077 set_pair_reached(pair_succ->automaton_state);
1078 //set_pair_reached_hash(pair_succ->automaton_state);
1082 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1083 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1087 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1088 //if(!visited(pair_succ->automaton_state, search_cycle)){
1091 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1094 MC_ddfs(search_cycle);
1098 XBT_INFO("Next pair already visited ! ");
1105 /* Restore system before checking others successors */
1106 if(cursor != (xbt_dynar_length(successors) - 1))
1107 MC_replay_liveness(mc_stack_liveness, 1);
1112 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1113 XBT_INFO("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1114 MC_replay_liveness(mc_stack_liveness, 0);
1119 }else{ /*No request to execute, search evolution in Büchi automaton */
1123 /* Create the new expanded graph_state */
1124 next_graph_state = MC_state_pair_new();
1126 xbt_dynar_reset(successors);
1132 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1134 res = MC_automaton_evaluate_label(transition_succ->label);
1136 if(res == 1){ // enabled transition in automaton
1138 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1139 xbt_dynar_push(successors, &next_pair);
1147 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1149 res = MC_automaton_evaluate_label(transition_succ->label);
1151 if(res == 2){ // true transition in automaton
1153 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1154 xbt_dynar_push(successors, &next_pair);
1162 xbt_dynar_foreach(successors, cursor, pair_succ){
1164 if(search_cycle == 1){
1166 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1168 if(reached(pair_succ->automaton_state)){
1169 //if(reached_hash(pair_succ->automaton_state)){
1171 XBT_INFO("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1173 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1174 XBT_INFO("| ACCEPTANCE CYCLE |");
1175 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1176 XBT_INFO("Counter-example that violates formula :");
1177 MC_show_stack_liveness(mc_stack_liveness);
1178 MC_dump_stack_liveness(mc_stack_liveness);
1179 MC_print_statistics_pairs(mc_stats_pair);
1184 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);
1186 set_pair_reached(pair_succ->automaton_state);
1187 //set_pair_reached_hash(pair_succ->automaton_state);
1189 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1190 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1193 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1196 MC_ddfs(search_cycle);
1202 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1203 //if(!visited(pair_succ->automaton_state, search_cycle)){
1206 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1209 MC_ddfs(search_cycle);
1213 XBT_INFO("Next pair already visited ! ");
1221 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1223 set_pair_reached(pair_succ->automaton_state);
1224 //set_pair_reached_hash(pair_succ->automaton_state);
1228 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1229 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1233 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1234 //if(!visited(pair_succ->automaton_state, search_cycle)){
1237 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1240 MC_ddfs(search_cycle);
1244 XBT_INFO("Next pair already visited ! ");
1250 /* Restore system before checking others successors */
1251 if(cursor != xbt_dynar_length(successors) - 1)
1252 MC_replay_liveness(mc_stack_liveness, 1);
1261 XBT_INFO("Max depth reached");
1265 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1266 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) );
1268 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) );
1273 xbt_fifo_shift(mc_stack_liveness);
1274 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1275 xbt_dynar_pop(reached_pairs, NULL);
1276 //xbt_dynar_pop(reached_pairs_hash, NULL);
1287 XBT_TEST_SUITE("mc_liveness", "Model checking liveness properties");
1288 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(mc_liveness);
1290 XBT_TEST_UNIT("snapshots_comparison", test_compare_snapshot, "Comparison of snapshots")
1295 /* Save first snapshot */
1296 mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
1297 MC_take_snapshot_liveness(snapshot1);
1299 /* Save second snapshot */
1300 mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
1301 MC_take_snapshot_liveness(snapshot2);
1305 xbt_test_assert(snapshot_compare(snapshot1, snapshot2) == 0, "Different consecutive snapshot");
1310 XBT_TEST_UNIT("snapshots_comparison2", test2_compare_snapshot, "Comparison of snapshots with modification between")
1315 /* Save first snapshot */
1316 mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
1317 MC_take_snapshot_liveness(snapshot1);
1321 void *test = snapshot1;
1322 test = (char*)test+1;
1323 char* t= strdup("toto");
1328 /* Save second snapshot */
1329 mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
1330 MC_take_snapshot_liveness(snapshot2);
1332 xbt_test_assert(snapshot_compare(snapshot1, snapshot2) != 0, "Same snapshot with new allocations");