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 reached(xbt_state_t st){
38 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
41 if(xbt_dynar_is_empty(reached_pairs)){
49 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
50 MC_take_snapshot_liveness(sn);
52 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
56 /* Get values of propositional symbols */
57 unsigned int cursor = 0;
58 xbt_propositional_symbol_t ps = NULL;
59 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
60 f = (int_f_void_t)ps->function;
62 xbt_dynar_push_as(prop_ato, int, res);
66 mc_pair_reached_t pair_test = NULL;
68 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
70 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
71 XBT_INFO("Pair reached #%d", pair_test->nb);
72 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
73 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
74 //XBT_INFO("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
75 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
76 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
77 if(snapshot_compare(pair_test->system_state, sn) == 0){
80 xbt_dynar_reset(prop_ato);
93 XBT_INFO("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
96 XBT_INFO("Different values of propositional symbols");
99 XBT_INFO("Different automaton state");
103 MC_free_snapshot(sn);
104 xbt_dynar_reset(prop_ato);
118 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
120 xbt_dict_cursor_t cursor_dict = NULL;
123 smx_rdv_t rdv1, rdv2;
124 xbt_fifo_item_t item1, item2;
125 smx_action_t action1, action2;
126 xbt_fifo_item_t item_req1, item_req2;
127 smx_simcall_t req1, req2;
131 xbt_dict_foreach(d1, cursor_dict, key, data){
132 rdv1 = (smx_rdv_t)data;
133 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
135 XBT_INFO("Rdv point unknown");
138 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
139 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) );
143 XBT_INFO("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
145 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
146 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
148 while(i<xbt_fifo_size(rdv1->comm_fifo)){
149 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
150 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
152 if(action1->type != action2->type){
153 XBT_INFO("Different type of action");
157 if(action1->state != action2->state){
158 XBT_INFO("Different state of action");
162 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
163 XBT_INFO("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
167 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
168 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
170 while(j<xbt_fifo_size(action1->simcalls)){
172 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
173 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
175 if(req1->call != req2->call){
176 XBT_INFO("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
179 if(req1->issuer->pid != req2->issuer->pid){
180 XBT_INFO("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
184 item_req1 = xbt_fifo_get_next_item(item_req1);
185 item_req2 = xbt_fifo_get_next_item(item_req2);
191 switch(action1->type){
192 case 0: /* execution */
193 case 1: /* parallel execution */
194 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
198 if(action1->comm.type != action2->comm.type)
200 //XBT_INFO("Type of comm : %d", action1->comm.type);
202 switch(action1->comm.type){
204 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
206 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
209 case 1: /* RECEIVE */
210 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
212 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
216 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
218 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
220 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
222 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
226 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
228 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
230 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
232 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
236 } /* end of switch on type of comm */
238 if(action1->comm.refcount != action2->comm.refcount)
240 if(action1->comm.detached != action2->comm.detached)
242 if(action1->comm.rate != action2->comm.rate)
244 if(action1->comm.task_size != action2->comm.task_size)
246 if(action1->comm.src_buff != action2->comm.src_buff)
248 if(action1->comm.dst_buff != action2->comm.dst_buff)
250 if(action1->comm.src_data != action2->comm.src_data)
252 if(action1->comm.dst_data != action2->comm.dst_data)
257 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
260 case 4: /* synchro */
267 item1 = xbt_fifo_get_next_item(item1);
268 item2 = xbt_fifo_get_next_item(item2);
279 void set_pair_reached(xbt_state_t st){
281 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
285 mc_pair_reached_t pair = NULL;
286 pair = xbt_new0(s_mc_pair_reached_t, 1);
287 pair->nb = xbt_dynar_length(reached_pairs) + 1;
288 pair->automaton_state = st;
289 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
290 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
291 //pair->rdv_points = xbt_dict_new();
292 MC_take_snapshot_liveness(pair->system_state);
294 /* Get values of propositional symbols */
295 unsigned int cursor = 0;
296 xbt_propositional_symbol_t ps = NULL;
300 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
301 f = (int_f_void_t)ps->function;
303 xbt_dynar_push_as(pair->prop_ato, int, res);
306 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
308 xbt_dict_cursor_t cursor_dict = NULL;
311 xbt_fifo_item_t item;
314 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
315 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
316 new_rdv->name = strdup(((smx_rdv_t)data)->name);
317 new_rdv->comm_fifo = xbt_fifo_new();
318 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
319 smx_action_t a = xbt_new0(s_smx_action_t, 1);
320 memcpy(a, action, sizeof(s_smx_action_t));
321 xbt_fifo_push(new_rdv->comm_fifo, a);
322 XBT_INFO("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
324 XBT_INFO("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
326 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
327 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
330 xbt_dynar_push(reached_pairs, &pair);
342 int reached_hash(xbt_state_t st){
344 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
346 if(xbt_dynar_is_empty(reached_pairs_hash)){
354 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
355 MC_take_snapshot_liveness(sn);
358 unsigned int hash_regions[sn->num_reg];
359 for(j=0; j<sn->num_reg; j++){
360 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
364 /* Get values of propositional symbols */
365 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
366 unsigned int cursor = 0;
367 xbt_propositional_symbol_t ps = NULL;
371 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
372 f = (int_f_void_t)ps->function;
374 xbt_dynar_push_as(prop_ato, int, res);
377 mc_pair_reached_hash_t pair_test = NULL;
383 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
385 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
386 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
387 for(j=0 ; j< sn->num_reg ; j++){
388 if(hash_regions[j] != pair_test->hash_regions[j]){
392 if(region_diff == 0){
393 MC_free_snapshot(sn);
394 xbt_dynar_reset(prop_ato);
405 XBT_INFO("Different snapshot");
408 XBT_INFO("Different values of propositional symbols");
411 XBT_INFO("Different automaton state");
417 MC_free_snapshot(sn);
418 xbt_dynar_reset(prop_ato);
432 void set_pair_reached_hash(xbt_state_t st){
434 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
438 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
439 MC_take_snapshot_liveness(sn);
441 mc_pair_reached_hash_t pair = NULL;
442 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
443 pair->automaton_state = st;
444 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
445 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
449 for(i=0 ; i< sn->num_reg ; i++){
450 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
453 /* Get values of propositional symbols */
454 unsigned int cursor = 0;
455 xbt_propositional_symbol_t ps = NULL;
459 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
460 f = (int_f_void_t)ps->function;
462 xbt_dynar_push_as(pair->prop_ato, int, res);
465 xbt_dynar_push(reached_pairs_hash, &pair);
467 MC_free_snapshot(sn);
479 int visited(xbt_state_t st, int sc){
481 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
483 if(xbt_dynar_is_empty(visited_pairs)){
491 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
492 MC_take_snapshot_liveness(sn);
494 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
496 /* Get values of propositional symbols */
497 unsigned int cursor = 0;
498 xbt_propositional_symbol_t ps = NULL;
502 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
503 f = (int_f_void_t)ps->function;
505 xbt_dynar_push_as(prop_ato, int, res);
509 mc_pair_visited_t pair_test = NULL;
511 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
512 if(pair_test->search_cycle == sc) {
513 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
514 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
515 if(snapshot_compare(pair_test->system_state, sn) == 0){
517 MC_free_snapshot(sn);
518 xbt_dynar_reset(prop_ato);
530 XBT_INFO("Different snapshot");
533 XBT_INFO("Different values of propositional symbols");
536 XBT_INFO("Different automaton state");
539 XBT_INFO("Different value of search_cycle");
544 MC_free_snapshot(sn);
545 xbt_dynar_reset(prop_ato);
560 int visited_hash(xbt_state_t st, int sc){
562 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
564 if(xbt_dynar_is_empty(visited_pairs_hash)){
572 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
573 MC_take_snapshot_liveness(sn);
576 unsigned int hash_regions[sn->num_reg];
577 for(j=0; j<sn->num_reg; j++){
578 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
582 /* Get values of propositional symbols */
583 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
584 unsigned int cursor = 0;
585 xbt_propositional_symbol_t ps = NULL;
589 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
590 f = (int_f_void_t)ps->function;
592 xbt_dynar_push_as(prop_ato, int, res);
595 mc_pair_visited_hash_t pair_test = NULL;
600 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
602 if(pair_test->search_cycle == sc) {
603 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
604 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
605 for(j=0 ; j< sn->num_reg ; j++){
606 if(hash_regions[j] != pair_test->hash_regions[j]){
610 if(region_diff == 0){
611 MC_free_snapshot(sn);
612 xbt_dynar_reset(prop_ato);
623 //XBT_INFO("Different snapshot");
626 //XBT_INFO("Different values of propositional symbols");
629 //XBT_INFO("Different automaton state");
632 //XBT_INFO("Different value of search_cycle");
638 MC_free_snapshot(sn);
639 xbt_dynar_reset(prop_ato);
653 void set_pair_visited_hash(xbt_state_t st, int sc){
655 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
659 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
660 MC_take_snapshot_liveness(sn);
662 mc_pair_visited_hash_t pair = NULL;
663 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
664 pair->automaton_state = st;
665 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
666 pair->search_cycle = sc;
667 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
671 for(i=0 ; i< sn->num_reg ; i++){
672 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
675 /* Get values of propositional symbols */
676 unsigned int cursor = 0;
677 xbt_propositional_symbol_t ps = NULL;
681 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
682 f = (int_f_void_t)ps->function;
684 xbt_dynar_push_as(pair->prop_ato, int, res);
687 xbt_dynar_push(visited_pairs_hash, &pair);
689 MC_free_snapshot(sn);
700 void set_pair_visited(xbt_state_t st, int sc){
702 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
706 mc_pair_visited_t pair = NULL;
707 pair = xbt_new0(s_mc_pair_visited_t, 1);
708 pair->automaton_state = st;
709 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
710 pair->search_cycle = sc;
711 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
712 MC_take_snapshot_liveness(pair->system_state);
715 /* Get values of propositional symbols */
716 unsigned int cursor = 0;
717 xbt_propositional_symbol_t ps = NULL;
721 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
722 f = (int_f_void_t)ps->function;
724 xbt_dynar_push_as(pair->prop_ato, int, res);
727 xbt_dynar_push(visited_pairs, &pair);
738 void MC_pair_delete(mc_pair_t pair){
739 xbt_free(pair->graph_state->proc_status);
740 xbt_free(pair->graph_state);
746 int MC_automaton_evaluate_label(xbt_exp_label_t l){
750 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
751 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
752 return (left_res || right_res);
755 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
756 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
757 return (left_res && right_res);
760 int res = MC_automaton_evaluate_label(l->u.exp_not);
764 unsigned int cursor = 0;
765 xbt_propositional_symbol_t p = NULL;
767 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, p){
768 if(strcmp(p->pred, l->u.predicat) == 0){
769 f = (int_f_void_t)p->function;
784 /********************* Double-DFS stateless *******************/
786 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
787 xbt_free(pair->graph_state->proc_status);
788 xbt_free(pair->graph_state);
792 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
793 mc_pair_stateless_t p = NULL;
794 p = xbt_new0(s_mc_pair_stateless_t, 1);
795 p->automaton_state = st;
798 mc_stats_pair->expanded_pairs++;
802 void MC_ddfs_init(void){
804 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
806 XBT_INFO("**************************************************");
807 XBT_INFO("Double-DFS init");
808 XBT_INFO("**************************************************");
810 mc_pair_stateless_t mc_initial_pair = NULL;
811 mc_state_t initial_graph_state = NULL;
812 smx_process_t process;
815 MC_wait_for_requests();
819 initial_graph_state = MC_state_pair_new();
820 xbt_swag_foreach(process, simix_global->process_list){
821 if(MC_process_is_enabled(process)){
822 MC_state_interleave_process(initial_graph_state, process);
826 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
827 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
828 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
829 //visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
830 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
832 /* Save the initial state */
833 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
834 MC_take_snapshot_liveness(initial_snapshot_liveness);
838 unsigned int cursor = 0;
841 xbt_dynar_foreach(_mc_property_automaton->states, cursor, state){
842 if(state->type == -1){
845 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
846 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
850 MC_restore_snapshot(initial_snapshot_liveness);
857 if(state->type == 2){
860 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
861 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
864 set_pair_reached(state);
865 //set_pair_reached_hash(state);
868 MC_restore_snapshot(initial_snapshot_liveness);
887 void MC_ddfs(int search_cycle){
889 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
891 smx_process_t process;
892 mc_pair_stateless_t current_pair = NULL;
894 if(xbt_fifo_size(mc_stack_liveness) == 0)
898 /* Get current pair */
899 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
901 /* Update current state in buchi automaton */
902 _mc_property_automaton->current_state = current_pair->automaton_state;
905 XBT_INFO("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
906 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));
908 mc_stats_pair->visited_pairs++;
913 mc_state_t next_graph_state = NULL;
914 smx_simcall_t req = NULL;
917 xbt_transition_t transition_succ;
918 unsigned int cursor = 0;
921 mc_pair_stateless_t next_pair = NULL;
922 mc_pair_stateless_t pair_succ;
924 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
926 //set_pair_visited(current_pair->automaton_state, search_cycle);
927 //set_pair_visited_hash(current_pair->automaton_state, search_cycle);
929 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
930 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
932 if(current_pair->requests > 0){
934 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
936 /* Debug information */
938 req_str = MC_request_to_string(req, value);
939 XBT_INFO("Execute: %s", req_str);
942 MC_state_set_executed_request(current_pair->graph_state, req, value);
944 /* Answer the request */
945 SIMIX_simcall_pre(req, value);
947 /* Wait for requests (schedules processes) */
948 MC_wait_for_requests();
953 /* Create the new expanded graph_state */
954 next_graph_state = MC_state_pair_new();
956 /* Get enabled process and insert it in the interleave set of the next graph_state */
957 xbt_swag_foreach(process, simix_global->process_list){
958 if(MC_process_is_enabled(process)){
959 MC_state_interleave_process(next_graph_state, process);
963 xbt_dynar_reset(successors);
969 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
971 res = MC_automaton_evaluate_label(transition_succ->label);
973 if(res == 1){ // enabled transition in automaton
975 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
976 xbt_dynar_push(successors, &next_pair);
984 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
986 res = MC_automaton_evaluate_label(transition_succ->label);
988 if(res == 2){ // true 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(successors, cursor, pair_succ){
1001 if(search_cycle == 1){
1003 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1005 if(reached(pair_succ->automaton_state)){
1006 //if(reached_hash(pair_succ->automaton_state)){
1008 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));
1010 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1011 XBT_INFO("| ACCEPTANCE CYCLE |");
1012 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1013 XBT_INFO("Counter-example that violates formula :");
1014 MC_show_stack_liveness(mc_stack_liveness);
1015 MC_dump_stack_liveness(mc_stack_liveness);
1016 MC_print_statistics_pairs(mc_stats_pair);
1021 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);
1023 set_pair_reached(pair_succ->automaton_state);
1024 //set_pair_reached_hash(pair_succ->automaton_state);
1026 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1027 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1030 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1033 MC_ddfs(search_cycle);
1039 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1040 //if(!visited(pair_succ->automaton_state, search_cycle)){
1043 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1046 MC_ddfs(search_cycle);
1050 XBT_INFO("Next pair already visited ! ");
1058 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1060 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);
1062 set_pair_reached(pair_succ->automaton_state);
1063 //set_pair_reached_hash(pair_succ->automaton_state);
1067 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1068 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1072 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1073 //if(!visited(pair_succ->automaton_state, search_cycle)){
1076 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1079 MC_ddfs(search_cycle);
1083 XBT_INFO("Next pair already visited ! ");
1090 /* Restore system before checking others successors */
1091 if(cursor != (xbt_dynar_length(successors) - 1))
1092 MC_replay_liveness(mc_stack_liveness, 1);
1097 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1098 XBT_INFO("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1099 MC_replay_liveness(mc_stack_liveness, 0);
1104 }else{ /*No request to execute, search evolution in Büchi automaton */
1108 /* Create the new expanded graph_state */
1109 next_graph_state = MC_state_pair_new();
1111 xbt_dynar_reset(successors);
1117 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1119 res = MC_automaton_evaluate_label(transition_succ->label);
1121 if(res == 1){ // enabled transition in automaton
1123 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1124 xbt_dynar_push(successors, &next_pair);
1132 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1134 res = MC_automaton_evaluate_label(transition_succ->label);
1136 if(res == 2){ // true 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(successors, cursor, pair_succ){
1149 if(search_cycle == 1){
1151 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1153 if(reached(pair_succ->automaton_state)){
1154 //if(reached_hash(pair_succ->automaton_state)){
1156 XBT_INFO("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1158 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1159 XBT_INFO("| ACCEPTANCE CYCLE |");
1160 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1161 XBT_INFO("Counter-example that violates formula :");
1162 MC_show_stack_liveness(mc_stack_liveness);
1163 MC_dump_stack_liveness(mc_stack_liveness);
1164 MC_print_statistics_pairs(mc_stats_pair);
1169 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);
1171 set_pair_reached(pair_succ->automaton_state);
1172 //set_pair_reached_hash(pair_succ->automaton_state);
1174 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1175 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1178 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1181 MC_ddfs(search_cycle);
1187 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1188 //if(!visited(pair_succ->automaton_state, search_cycle)){
1191 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1194 MC_ddfs(search_cycle);
1198 XBT_INFO("Next pair already visited ! ");
1206 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1208 set_pair_reached(pair_succ->automaton_state);
1209 //set_pair_reached_hash(pair_succ->automaton_state);
1213 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1214 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1218 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1219 //if(!visited(pair_succ->automaton_state, search_cycle)){
1222 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1225 MC_ddfs(search_cycle);
1229 XBT_INFO("Next pair already visited ! ");
1235 /* Restore system before checking others successors */
1236 if(cursor != xbt_dynar_length(successors) - 1)
1237 MC_replay_liveness(mc_stack_liveness, 1);
1246 XBT_INFO("Max depth reached");
1250 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1251 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) );
1253 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) );
1258 xbt_fifo_shift(mc_stack_liveness);
1259 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1260 xbt_dynar_pop(reached_pairs, NULL);
1261 //xbt_dynar_pop(reached_pairs_hash, NULL);
1275 XBT_TEST_SUITE("mc_liveness", "Model checking liveness properties");
1276 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(mc_liveness);
1278 XBT_TEST_UNIT("snapshots_comparison", test_compare_snapshot, "Comparison of snapshots")
1283 /* Save first snapshot */
1284 mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
1285 MC_take_snapshot_liveness(snapshot1);
1287 /* Save second snapshot */
1288 mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
1289 MC_take_snapshot_liveness(snapshot2);
1293 xbt_test_assert(snapshot_compare(snapshot1, snapshot2) == 0, "Different consecutive snapshot");
1298 XBT_TEST_UNIT("snapshots_comparison2", test2_compare_snapshot, "Comparison of snapshots with modification between")
1303 /* Save first snapshot */
1304 mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
1305 MC_take_snapshot_liveness(snapshot1);
1309 void *test = snapshot1;
1310 test = (char*)test+1;
1311 char* t= strdup("toto");
1316 /* Save second snapshot */
1317 mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
1318 MC_take_snapshot_liveness(snapshot2);
1320 xbt_test_assert(snapshot_compare(snapshot1, snapshot2) != 0, "Same snapshot with new allocations");