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){
140 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
143 if(xbt_dynar_is_empty(reached_pairs)){
151 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
152 MC_take_snapshot_liveness(sn);
154 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
158 /* Get values of propositional symbols */
159 unsigned int cursor = 0;
160 xbt_propositional_symbol_t ps = NULL;
161 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
162 f = (int_f_void_t)ps->function;
164 xbt_dynar_push_as(prop_ato, int, res);
168 mc_pair_reached_t pair_test = NULL;
170 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
172 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
173 XBT_INFO("Pair reached #%d", pair_test->nb);
174 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
175 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
176 //XBT_INFO("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
177 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
178 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
179 if(snapshot_compare(pair_test->system_state, sn) == 0){
181 MC_free_snapshot(sn);
182 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);
220 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
222 xbt_dict_cursor_t cursor_dict = NULL;
225 smx_rdv_t rdv1, rdv2;
226 xbt_fifo_item_t item1, item2;
227 smx_action_t action1, action2;
228 xbt_fifo_item_t item_req1, item_req2;
229 smx_simcall_t req1, req2;
233 xbt_dict_foreach(d1, cursor_dict, key, data){
234 rdv1 = (smx_rdv_t)data;
235 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
237 XBT_INFO("Rdv point unknown");
240 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
241 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) );
245 XBT_INFO("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
247 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
248 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
250 while(i<xbt_fifo_size(rdv1->comm_fifo)){
251 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
252 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
254 if(action1->type != action2->type){
255 XBT_INFO("Different type of action");
259 if(action1->state != action2->state){
260 XBT_INFO("Different state of action");
264 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
265 XBT_INFO("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
269 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
270 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
272 while(j<xbt_fifo_size(action1->simcalls)){
274 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
275 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
277 if(req1->call != req2->call){
278 XBT_INFO("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
281 if(req1->issuer->pid != req2->issuer->pid){
282 XBT_INFO("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
286 item_req1 = xbt_fifo_get_next_item(item_req1);
287 item_req2 = xbt_fifo_get_next_item(item_req2);
293 switch(action1->type){
294 case 0: /* execution */
295 case 1: /* parallel execution */
296 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
300 if(action1->comm.type != action2->comm.type)
302 //XBT_INFO("Type of comm : %d", action1->comm.type);
304 switch(action1->comm.type){
306 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
308 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
311 case 1: /* RECEIVE */
312 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
314 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
318 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
320 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
322 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
324 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
328 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
330 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
332 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
334 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
338 } /* end of switch on type of comm */
340 if(action1->comm.refcount != action2->comm.refcount)
342 if(action1->comm.detached != action2->comm.detached)
344 if(action1->comm.rate != action2->comm.rate)
346 if(action1->comm.task_size != action2->comm.task_size)
348 if(action1->comm.src_buff != action2->comm.src_buff)
350 if(action1->comm.dst_buff != action2->comm.dst_buff)
352 if(action1->comm.src_data != action2->comm.src_data)
354 if(action1->comm.dst_data != action2->comm.dst_data)
359 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
362 case 4: /* synchro */
369 item1 = xbt_fifo_get_next_item(item1);
370 item2 = xbt_fifo_get_next_item(item2);
381 void set_pair_reached(xbt_state_t st){
383 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
387 mc_pair_reached_t pair = NULL;
388 pair = xbt_new0(s_mc_pair_reached_t, 1);
389 pair->nb = xbt_dynar_length(reached_pairs) + 1;
390 pair->automaton_state = st;
391 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
392 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
393 //pair->rdv_points = xbt_dict_new();
394 MC_take_snapshot_liveness(pair->system_state);
396 /* Get values of propositional symbols */
397 unsigned int cursor = 0;
398 xbt_propositional_symbol_t ps = NULL;
402 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
403 f = (int_f_void_t)ps->function;
405 xbt_dynar_push_as(pair->prop_ato, int, res);
408 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
410 xbt_dict_cursor_t cursor_dict = NULL;
413 xbt_fifo_item_t item;
416 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
417 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
418 new_rdv->name = strdup(((smx_rdv_t)data)->name);
419 new_rdv->comm_fifo = xbt_fifo_new();
420 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
421 smx_action_t a = xbt_new0(s_smx_action_t, 1);
422 memcpy(a, action, sizeof(s_smx_action_t));
423 xbt_fifo_push(new_rdv->comm_fifo, a);
424 XBT_INFO("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
426 XBT_INFO("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
428 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
429 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
432 xbt_dynar_push(reached_pairs, &pair);
444 int reached_hash(xbt_state_t st){
446 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
448 if(xbt_dynar_is_empty(reached_pairs_hash)){
456 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
457 MC_take_snapshot_liveness(sn);
460 unsigned int hash_regions[sn->num_reg];
461 for(j=0; j<sn->num_reg; j++){
462 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
466 /* Get values of propositional symbols */
467 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
468 unsigned int cursor = 0;
469 xbt_propositional_symbol_t ps = NULL;
473 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
474 f = (int_f_void_t)ps->function;
476 xbt_dynar_push_as(prop_ato, int, res);
479 mc_pair_reached_hash_t pair_test = NULL;
485 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
487 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
488 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
489 for(j=0 ; j< sn->num_reg ; j++){
490 if(hash_regions[j] != pair_test->hash_regions[j]){
494 if(region_diff == 0){
495 MC_free_snapshot(sn);
496 xbt_dynar_reset(prop_ato);
507 XBT_INFO("Different snapshot");
510 XBT_INFO("Different values of propositional symbols");
513 XBT_INFO("Different automaton state");
519 MC_free_snapshot(sn);
520 xbt_dynar_reset(prop_ato);
534 void set_pair_reached_hash(xbt_state_t st){
536 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
540 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
541 MC_take_snapshot_liveness(sn);
543 mc_pair_reached_hash_t pair = NULL;
544 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
545 pair->automaton_state = st;
546 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
547 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
551 for(i=0 ; i< sn->num_reg ; i++){
552 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
555 /* Get values of propositional symbols */
556 unsigned int cursor = 0;
557 xbt_propositional_symbol_t ps = NULL;
561 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
562 f = (int_f_void_t)ps->function;
564 xbt_dynar_push_as(pair->prop_ato, int, res);
567 xbt_dynar_push(reached_pairs_hash, &pair);
569 MC_free_snapshot(sn);
581 int visited(xbt_state_t st, int sc){
583 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
585 if(xbt_dynar_is_empty(visited_pairs)){
593 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
594 MC_take_snapshot_liveness(sn);
596 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
598 /* Get values of propositional symbols */
599 unsigned int cursor = 0;
600 xbt_propositional_symbol_t ps = NULL;
604 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
605 f = (int_f_void_t)ps->function;
607 xbt_dynar_push_as(prop_ato, int, res);
611 mc_pair_visited_t pair_test = NULL;
613 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
614 if(pair_test->search_cycle == sc) {
615 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
616 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
617 if(snapshot_compare(pair_test->system_state, sn) == 0){
619 MC_free_snapshot(sn);
620 xbt_dynar_reset(prop_ato);
632 XBT_INFO("Different snapshot");
635 XBT_INFO("Different values of propositional symbols");
638 XBT_INFO("Different automaton state");
641 XBT_INFO("Different value of search_cycle");
646 MC_free_snapshot(sn);
647 xbt_dynar_reset(prop_ato);
662 int visited_hash(xbt_state_t st, int sc){
664 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
666 if(xbt_dynar_is_empty(visited_pairs_hash)){
674 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
675 MC_take_snapshot_liveness(sn);
678 unsigned int hash_regions[sn->num_reg];
679 for(j=0; j<sn->num_reg; j++){
680 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
684 /* Get values of propositional symbols */
685 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
686 unsigned int cursor = 0;
687 xbt_propositional_symbol_t ps = NULL;
691 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
692 f = (int_f_void_t)ps->function;
694 xbt_dynar_push_as(prop_ato, int, res);
697 mc_pair_visited_hash_t pair_test = NULL;
702 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
704 if(pair_test->search_cycle == sc) {
705 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
706 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
707 for(j=0 ; j< sn->num_reg ; j++){
708 if(hash_regions[j] != pair_test->hash_regions[j]){
712 if(region_diff == 0){
713 MC_free_snapshot(sn);
714 xbt_dynar_reset(prop_ato);
725 //XBT_INFO("Different snapshot");
728 //XBT_INFO("Different values of propositional symbols");
731 //XBT_INFO("Different automaton state");
734 //XBT_INFO("Different value of search_cycle");
740 MC_free_snapshot(sn);
741 xbt_dynar_reset(prop_ato);
755 void set_pair_visited_hash(xbt_state_t st, int sc){
757 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
761 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
762 MC_take_snapshot_liveness(sn);
764 mc_pair_visited_hash_t pair = NULL;
765 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
766 pair->automaton_state = st;
767 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
768 pair->search_cycle = sc;
769 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
773 for(i=0 ; i< sn->num_reg ; i++){
774 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
777 /* Get values of propositional symbols */
778 unsigned int cursor = 0;
779 xbt_propositional_symbol_t ps = NULL;
783 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
784 f = (int_f_void_t)ps->function;
786 xbt_dynar_push_as(pair->prop_ato, int, res);
789 xbt_dynar_push(visited_pairs_hash, &pair);
791 MC_free_snapshot(sn);
802 void set_pair_visited(xbt_state_t st, int sc){
804 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
808 mc_pair_visited_t pair = NULL;
809 pair = xbt_new0(s_mc_pair_visited_t, 1);
810 pair->automaton_state = st;
811 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
812 pair->search_cycle = sc;
813 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
814 MC_take_snapshot_liveness(pair->system_state);
817 /* Get values of propositional symbols */
818 unsigned int cursor = 0;
819 xbt_propositional_symbol_t ps = NULL;
823 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps){
824 f = (int_f_void_t)ps->function;
826 xbt_dynar_push_as(pair->prop_ato, int, res);
829 xbt_dynar_push(visited_pairs, &pair);
840 void MC_pair_delete(mc_pair_t pair){
841 xbt_free(pair->graph_state->proc_status);
842 xbt_free(pair->graph_state);
848 int MC_automaton_evaluate_label(xbt_exp_label_t l){
852 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
853 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
854 return (left_res || right_res);
857 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
858 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
859 return (left_res && right_res);
862 int res = MC_automaton_evaluate_label(l->u.exp_not);
866 unsigned int cursor = 0;
867 xbt_propositional_symbol_t p = NULL;
869 xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, p){
870 if(strcmp(p->pred, l->u.predicat) == 0){
871 f = (int_f_void_t)p->function;
886 /********************* Double-DFS stateless *******************/
888 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
889 xbt_free(pair->graph_state->proc_status);
890 xbt_free(pair->graph_state);
894 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
895 mc_pair_stateless_t p = NULL;
896 p = xbt_new0(s_mc_pair_stateless_t, 1);
897 p->automaton_state = st;
900 mc_stats_pair->expanded_pairs++;
904 void MC_ddfs_init(void){
906 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
908 XBT_INFO("**************************************************");
909 XBT_INFO("Double-DFS init");
910 XBT_INFO("**************************************************");
912 mc_pair_stateless_t mc_initial_pair = NULL;
913 mc_state_t initial_graph_state = NULL;
914 smx_process_t process;
917 MC_wait_for_requests();
921 initial_graph_state = MC_state_pair_new();
922 xbt_swag_foreach(process, simix_global->process_list){
923 if(MC_process_is_enabled(process)){
924 MC_state_interleave_process(initial_graph_state, process);
928 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
929 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
930 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
931 //visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
932 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
934 /* Save the initial state */
935 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
936 MC_take_snapshot_liveness(initial_snapshot_liveness);
940 unsigned int cursor = 0;
943 xbt_dynar_foreach(_mc_property_automaton->states, cursor, state){
944 if(state->type == -1){
947 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
948 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
952 MC_restore_snapshot(initial_snapshot_liveness);
959 if(state->type == 2){
962 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
963 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
966 set_pair_reached(state);
967 //set_pair_reached_hash(state);
970 MC_restore_snapshot(initial_snapshot_liveness);
989 void MC_ddfs(int search_cycle){
991 raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
993 smx_process_t process;
994 mc_pair_stateless_t current_pair = NULL;
996 if(xbt_fifo_size(mc_stack_liveness) == 0)
1000 /* Get current pair */
1001 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
1003 /* Update current state in buchi automaton */
1004 _mc_property_automaton->current_state = current_pair->automaton_state;
1007 XBT_INFO("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
1008 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));
1010 mc_stats_pair->visited_pairs++;
1015 mc_state_t next_graph_state = NULL;
1016 smx_simcall_t req = NULL;
1019 xbt_transition_t transition_succ;
1020 unsigned int cursor = 0;
1023 mc_pair_stateless_t next_pair = NULL;
1024 mc_pair_stateless_t pair_succ;
1026 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
1028 //set_pair_visited(current_pair->automaton_state, search_cycle);
1029 //set_pair_visited_hash(current_pair->automaton_state, search_cycle);
1031 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
1032 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
1034 if(current_pair->requests > 0){
1036 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1038 /* Debug information */
1040 req_str = MC_request_to_string(req, value);
1041 XBT_INFO("Execute: %s", req_str);
1044 MC_state_set_executed_request(current_pair->graph_state, req, value);
1046 /* Answer the request */
1047 SIMIX_simcall_pre(req, value);
1049 /* Wait for requests (schedules processes) */
1050 MC_wait_for_requests();
1055 /* Create the new expanded graph_state */
1056 next_graph_state = MC_state_pair_new();
1058 /* Get enabled process and insert it in the interleave set of the next graph_state */
1059 xbt_swag_foreach(process, simix_global->process_list){
1060 if(MC_process_is_enabled(process)){
1061 MC_state_interleave_process(next_graph_state, process);
1065 xbt_dynar_reset(successors);
1071 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1073 res = MC_automaton_evaluate_label(transition_succ->label);
1075 if(res == 1){ // enabled transition in automaton
1077 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1078 xbt_dynar_push(successors, &next_pair);
1086 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1088 res = MC_automaton_evaluate_label(transition_succ->label);
1090 if(res == 2){ // true transition in automaton
1092 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1093 xbt_dynar_push(successors, &next_pair);
1101 xbt_dynar_foreach(successors, cursor, pair_succ){
1103 if(search_cycle == 1){
1105 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1107 if(reached(pair_succ->automaton_state)){
1108 //if(reached_hash(pair_succ->automaton_state)){
1110 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));
1112 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1113 XBT_INFO("| ACCEPTANCE CYCLE |");
1114 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1115 XBT_INFO("Counter-example that violates formula :");
1116 MC_show_stack_liveness(mc_stack_liveness);
1117 MC_dump_stack_liveness(mc_stack_liveness);
1118 MC_print_statistics_pairs(mc_stats_pair);
1123 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);
1125 set_pair_reached(pair_succ->automaton_state);
1126 //set_pair_reached_hash(pair_succ->automaton_state);
1128 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1129 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1132 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1135 MC_ddfs(search_cycle);
1141 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1142 //if(!visited(pair_succ->automaton_state, search_cycle)){
1145 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1148 MC_ddfs(search_cycle);
1152 XBT_INFO("Next pair already visited ! ");
1160 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1162 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);
1164 set_pair_reached(pair_succ->automaton_state);
1165 //set_pair_reached_hash(pair_succ->automaton_state);
1169 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1170 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1174 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1175 //if(!visited(pair_succ->automaton_state, search_cycle)){
1178 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1181 MC_ddfs(search_cycle);
1185 XBT_INFO("Next pair already visited ! ");
1192 /* Restore system before checking others successors */
1193 if(cursor != (xbt_dynar_length(successors) - 1))
1194 MC_replay_liveness(mc_stack_liveness, 1);
1199 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1200 XBT_INFO("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1201 MC_replay_liveness(mc_stack_liveness, 0);
1206 }else{ /*No request to execute, search evolution in Büchi automaton */
1210 /* Create the new expanded graph_state */
1211 next_graph_state = MC_state_pair_new();
1213 xbt_dynar_reset(successors);
1219 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1221 res = MC_automaton_evaluate_label(transition_succ->label);
1223 if(res == 1){ // enabled transition in automaton
1225 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1226 xbt_dynar_push(successors, &next_pair);
1234 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1236 res = MC_automaton_evaluate_label(transition_succ->label);
1238 if(res == 2){ // true transition in automaton
1240 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1241 xbt_dynar_push(successors, &next_pair);
1249 xbt_dynar_foreach(successors, cursor, pair_succ){
1251 if(search_cycle == 1){
1253 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1255 if(reached(pair_succ->automaton_state)){
1256 //if(reached_hash(pair_succ->automaton_state)){
1258 XBT_INFO("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1260 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1261 XBT_INFO("| ACCEPTANCE CYCLE |");
1262 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1263 XBT_INFO("Counter-example that violates formula :");
1264 MC_show_stack_liveness(mc_stack_liveness);
1265 MC_dump_stack_liveness(mc_stack_liveness);
1266 MC_print_statistics_pairs(mc_stats_pair);
1271 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);
1273 set_pair_reached(pair_succ->automaton_state);
1274 //set_pair_reached_hash(pair_succ->automaton_state);
1276 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1277 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1280 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1283 MC_ddfs(search_cycle);
1289 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1290 //if(!visited(pair_succ->automaton_state, search_cycle)){
1293 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1296 MC_ddfs(search_cycle);
1300 XBT_INFO("Next pair already visited ! ");
1308 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1310 set_pair_reached(pair_succ->automaton_state);
1311 //set_pair_reached_hash(pair_succ->automaton_state);
1315 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1316 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1320 //if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1321 //if(!visited(pair_succ->automaton_state, search_cycle)){
1324 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1327 MC_ddfs(search_cycle);
1331 XBT_INFO("Next pair already visited ! ");
1337 /* Restore system before checking others successors */
1338 if(cursor != xbt_dynar_length(successors) - 1)
1339 MC_replay_liveness(mc_stack_liveness, 1);
1348 XBT_INFO("Max depth reached");
1352 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1353 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) );
1355 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) );
1360 xbt_fifo_shift(mc_stack_liveness);
1361 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1362 xbt_dynar_pop(reached_pairs, NULL);
1363 //xbt_dynar_pop(reached_pairs_hash, NULL);
1377 XBT_TEST_SUITE("mc_liveness", "Model checking liveness properties");
1378 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(mc_liveness);
1380 XBT_TEST_UNIT("snapshots_comparison", test_compare_snapshot, "Comparison of snapshots")
1385 /* Save first snapshot */
1386 mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
1387 MC_take_snapshot_liveness(snapshot1);
1389 /* Save second snapshot */
1390 mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
1391 MC_take_snapshot_liveness(snapshot2);
1395 xbt_test_assert(snapshot_compare(snapshot1, snapshot2) == 0, "Different consecutive snapshot");
1400 XBT_TEST_UNIT("snapshots_comparison2", test2_compare_snapshot, "Comparison of snapshots with modification between")
1405 /* Save first snapshot */
1406 mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
1407 MC_take_snapshot_liveness(snapshot1);
1411 void *test = snapshot1;
1412 test = (char*)test+1;
1413 char* t= strdup("toto");
1418 /* Save second snapshot */
1419 mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
1420 MC_take_snapshot_liveness(snapshot2);
1422 xbt_test_assert(snapshot_compare(snapshot1, snapshot2) != 0, "Same snapshot with new allocations");