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 const char* get_memory_map_addr(void *addr){
38 FILE *fp; /* File pointer to process's proc maps file */
39 char *line = NULL; /* Temporal storage for each line that is readed */
40 ssize_t read; /* Number of bytes readed */
41 size_t n = 0; /* Amount of bytes to read by getline */
43 fp = fopen("/proc/self/maps", "r");
46 perror("fopen failed");
53 xbt_dynar_t lfields = NULL;
54 xbt_dynar_t start_end = NULL;
58 while ((read = getline(&line, &n, fp)) != -1) {
60 xbt_str_trim(line, NULL);
61 xbt_str_strip_spaces(line);
62 lfields = xbt_str_split(line,NULL);
64 start_end = xbt_str_split(xbt_dynar_get_as(lfields, 0, char*), "-");
65 start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16);
66 end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16);
68 if((addr > start_addr) && ( addr < end_addr)){
71 if(start_addr == std_heap)
73 if(start_addr == raw_heap)
75 if(xbt_dynar_length(lfields) == 6)
76 return xbt_dynar_get_as(lfields, xbt_dynar_length(lfields) - 1, char*);
85 return "Unknown area";
89 int data_program_region_compare(void *d1, void *d2, size_t size){
94 for(i=0; i<size; i++){
95 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
96 fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
98 pointer_align = (i /sizeof(void *)) * sizeof(void *);
99 fprintf(stderr, "Pointed address : %p (in %s) - %p (in %s)\n", *((void **)((char *)d1 + pointer_align)), get_memory_map_addr(*((void **)((char *)d1 + pointer_align))), *((void **)((char *)d2 + pointer_align)), get_memory_map_addr(*((void **)((char *)d2 + pointer_align))));
103 fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
108 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
113 for(i=0; i<size; i++){
114 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
115 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region\n", i, (char *)d1 + i, (char *)d2 + i);
117 pointer_align = (i /sizeof(void *)) * sizeof(void *);
118 fprintf(stderr, "Pointed address : %p (in %s) - %p (in %s)\n", *((void **)((char *)d1 + pointer_align)), get_memory_map_addr(*((void **)((char *)d1 + pointer_align))), *((void **)((char *)d2 + pointer_align)), get_memory_map_addr(*((void **)((char *)d2 + pointer_align))));
122 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
127 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap){
130 if(s1->num_reg != s2->num_reg){
131 XBT_DEBUG("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
138 for(i=0 ; i< s1->num_reg ; i++){
140 if(s1->regions[i]->type != s2->regions[i]->type){
141 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
142 XBT_DEBUG("Different type of region");
149 switch(s1->regions[i]->type){
151 if(s1->regions[i]->size != s2->regions[i]->size){
152 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
153 XBT_DEBUG("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
159 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
160 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
161 XBT_DEBUG("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
167 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
168 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
169 XBT_DEBUG("Different heap (mmalloc_compare)");
177 if(s1->regions[i]->size != s2->regions[i]->size){
178 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
179 XBT_DEBUG("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
185 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
186 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
187 XBT_DEBUG("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
193 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
194 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
195 XBT_DEBUG("Different memcmp for data in libsimgrid");
203 if(s1->regions[i]->size != s2->regions[i]->size){
204 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
205 XBT_DEBUG("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
211 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
212 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
213 XBT_DEBUG("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
219 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
220 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
221 XBT_DEBUG("Different memcmp for data in program");
237 int reached(xbt_state_t st){
240 if(xbt_dynar_is_empty(reached_pairs)){
248 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
249 MC_take_snapshot_liveness(sn);
251 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
255 /* Get values of propositional symbols */
256 unsigned int cursor = 0;
257 xbt_propositional_symbol_t ps = NULL;
258 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
259 f = (int_f_void_t)ps->function;
261 xbt_dynar_push_as(prop_ato, int, res);
265 mc_pair_reached_t pair_test = NULL;
267 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
269 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
270 XBT_DEBUG("Pair reached #%u", cursor+1);
271 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
272 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
273 //XBT_DEBUG("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
274 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
275 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
276 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
277 MC_free_snapshot(sn);
278 xbt_dynar_reset(prop_ato);
285 XBT_DEBUG("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
288 XBT_DEBUG("Different values of propositional symbols");
291 XBT_DEBUG("Different automaton state");
295 MC_free_snapshot(sn);
296 xbt_dynar_reset(prop_ato);
304 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
306 xbt_dict_cursor_t cursor_dict = NULL;
309 smx_rdv_t rdv1, rdv2;
310 xbt_fifo_item_t item1, item2;
311 smx_action_t action1, action2;
312 xbt_fifo_item_t item_req1, item_req2;
313 smx_simcall_t req1, req2;
317 xbt_dict_foreach(d1, cursor_dict, key, data){
318 rdv1 = (smx_rdv_t)data;
319 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
321 XBT_DEBUG("Rdv point unknown");
324 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
325 XBT_DEBUG("Different total of actions in mailbox \"%s\" (%d - %d)", rdv1->name, xbt_fifo_size(rdv1->comm_fifo),xbt_fifo_size(rdv2->comm_fifo) );
329 XBT_DEBUG("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
331 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
332 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
334 while(i<xbt_fifo_size(rdv1->comm_fifo)){
335 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
336 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
338 if(action1->type != action2->type){
339 XBT_DEBUG("Different type of action");
343 if(action1->state != action2->state){
344 XBT_DEBUG("Different state of action");
348 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
349 XBT_DEBUG("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
353 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
354 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
356 while(j<xbt_fifo_size(action1->simcalls)){
358 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
359 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
361 if(req1->call != req2->call){
362 XBT_DEBUG("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
365 if(req1->issuer->pid != req2->issuer->pid){
366 XBT_DEBUG("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
370 item_req1 = xbt_fifo_get_next_item(item_req1);
371 item_req2 = xbt_fifo_get_next_item(item_req2);
377 switch(action1->type){
378 case 0: /* execution */
379 case 1: /* parallel execution */
380 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
384 if(action1->comm.type != action2->comm.type)
386 //XBT_DEBUG("Type of comm : %d", action1->comm.type);
388 switch(action1->comm.type){
390 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
392 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
395 case 1: /* RECEIVE */
396 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
398 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
402 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
404 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
406 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
408 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
412 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
414 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
416 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
418 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
422 } /* end of switch on type of comm */
424 if(action1->comm.refcount != action2->comm.refcount)
426 if(action1->comm.detached != action2->comm.detached)
428 if(action1->comm.rate != action2->comm.rate)
430 if(action1->comm.task_size != action2->comm.task_size)
432 if(action1->comm.src_buff != action2->comm.src_buff)
434 if(action1->comm.dst_buff != action2->comm.dst_buff)
436 if(action1->comm.src_data != action2->comm.src_data)
438 if(action1->comm.dst_data != action2->comm.dst_data)
443 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
446 case 4: /* synchro */
453 item1 = xbt_fifo_get_next_item(item1);
454 item2 = xbt_fifo_get_next_item(item2);
465 void set_pair_reached(xbt_state_t st){
470 mc_pair_reached_t pair = NULL;
471 pair = xbt_new0(s_mc_pair_reached_t, 1);
472 pair->automaton_state = st;
473 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
474 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
475 //pair->rdv_points = xbt_dict_new();
476 MC_take_snapshot_liveness(pair->system_state);
478 /* Get values of propositional symbols */
479 unsigned int cursor = 0;
480 xbt_propositional_symbol_t ps = NULL;
484 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
485 f = (int_f_void_t)ps->function;
487 xbt_dynar_push_as(pair->prop_ato, int, res);
490 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
492 xbt_dict_cursor_t cursor_dict = NULL;
495 xbt_fifo_item_t item;
498 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
499 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
500 new_rdv->name = strdup(((smx_rdv_t)data)->name);
501 new_rdv->comm_fifo = xbt_fifo_new();
502 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
503 smx_action_t a = xbt_new0(s_smx_action_t, 1);
504 memcpy(a, action, sizeof(s_smx_action_t));
505 xbt_fifo_push(new_rdv->comm_fifo, a);
506 XBT_DEBUG("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
508 XBT_DEBUG("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
510 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
511 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
514 xbt_dynar_push(reached_pairs, &pair);
521 int reached_hash(xbt_state_t st){
524 if(xbt_dynar_is_empty(reached_pairs_hash)){
532 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
533 MC_take_snapshot_liveness(sn);
536 unsigned int hash_regions[sn->num_reg];
537 for(j=0; j<sn->num_reg; j++){
538 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
542 /* Get values of propositional symbols */
543 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
544 unsigned int cursor = 0;
545 xbt_propositional_symbol_t ps = NULL;
549 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
550 f = (int_f_void_t)ps->function;
552 xbt_dynar_push_as(prop_ato, int, res);
555 mc_pair_reached_hash_t pair_test = NULL;
561 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
563 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
564 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
565 for(j=0 ; j< sn->num_reg ; j++){
566 if(hash_regions[j] != pair_test->hash_regions[j]){
570 if(region_diff == 0){
571 MC_free_snapshot(sn);
572 xbt_dynar_reset(prop_ato);
577 XBT_DEBUG("Different snapshot");
580 XBT_DEBUG("Different values of propositional symbols");
583 XBT_DEBUG("Different automaton state");
589 MC_free_snapshot(sn);
590 xbt_dynar_reset(prop_ato);
598 void set_pair_reached_hash(xbt_state_t st){
602 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
603 MC_take_snapshot_liveness(sn);
605 mc_pair_reached_hash_t pair = NULL;
606 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
607 pair->automaton_state = st;
608 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
609 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
613 for(i=0 ; i< sn->num_reg ; i++){
614 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
617 /* Get values of propositional symbols */
618 unsigned int cursor = 0;
619 xbt_propositional_symbol_t ps = NULL;
623 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
624 f = (int_f_void_t)ps->function;
626 xbt_dynar_push_as(pair->prop_ato, int, res);
629 xbt_dynar_push(reached_pairs_hash, &pair);
631 MC_free_snapshot(sn);
638 int visited(xbt_state_t st, int sc){
641 if(xbt_dynar_is_empty(visited_pairs)){
649 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
650 MC_take_snapshot_liveness(sn);
652 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
654 /* Get values of propositional symbols */
655 unsigned int cursor = 0;
656 xbt_propositional_symbol_t ps = NULL;
660 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
661 f = (int_f_void_t)ps->function;
663 xbt_dynar_push_as(prop_ato, int, res);
667 mc_pair_visited_t pair_test = NULL;
669 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
670 if(pair_test->search_cycle == sc) {
671 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
672 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
673 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
675 MC_free_snapshot(sn);
676 xbt_dynar_reset(prop_ato);
683 XBT_DEBUG("Different snapshot");
686 XBT_DEBUG("Different values of propositional symbols");
689 XBT_DEBUG("Different automaton state");
692 XBT_DEBUG("Different value of search_cycle");
697 MC_free_snapshot(sn);
698 xbt_dynar_reset(prop_ato);
707 int visited_hash(xbt_state_t st, int sc){
710 if(xbt_dynar_is_empty(visited_pairs_hash)){
718 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
719 MC_take_snapshot_liveness(sn);
722 unsigned int hash_regions[sn->num_reg];
723 for(j=0; j<sn->num_reg; j++){
724 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
728 /* Get values of propositional symbols */
729 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
730 unsigned int cursor = 0;
731 xbt_propositional_symbol_t ps = NULL;
735 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
736 f = (int_f_void_t)ps->function;
738 xbt_dynar_push_as(prop_ato, int, res);
741 mc_pair_visited_hash_t pair_test = NULL;
746 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
748 if(pair_test->search_cycle == sc) {
749 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
750 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
751 for(j=0 ; j< sn->num_reg ; j++){
752 if(hash_regions[j] != pair_test->hash_regions[j]){
756 if(region_diff == 0){
757 MC_free_snapshot(sn);
758 xbt_dynar_reset(prop_ato);
763 //XBT_DEBUG("Different snapshot");
766 //XBT_DEBUG("Different values of propositional symbols");
769 //XBT_DEBUG("Different automaton state");
772 //XBT_DEBUG("Different value of search_cycle");
778 MC_free_snapshot(sn);
779 xbt_dynar_reset(prop_ato);
787 void set_pair_visited_hash(xbt_state_t st, int sc){
791 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
792 MC_take_snapshot_liveness(sn);
794 mc_pair_visited_hash_t pair = NULL;
795 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
796 pair->automaton_state = st;
797 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
798 pair->search_cycle = sc;
799 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
803 for(i=0 ; i< sn->num_reg ; i++){
804 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
807 /* Get values of propositional symbols */
808 unsigned int cursor = 0;
809 xbt_propositional_symbol_t ps = NULL;
813 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
814 f = (int_f_void_t)ps->function;
816 xbt_dynar_push_as(pair->prop_ato, int, res);
819 xbt_dynar_push(visited_pairs_hash, &pair);
821 MC_free_snapshot(sn);
827 void set_pair_visited(xbt_state_t st, int sc){
832 mc_pair_visited_t pair = NULL;
833 pair = xbt_new0(s_mc_pair_visited_t, 1);
834 pair->automaton_state = st;
835 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
836 pair->search_cycle = sc;
837 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
838 MC_take_snapshot_liveness(pair->system_state);
841 /* Get values of propositional symbols */
842 unsigned int cursor = 0;
843 xbt_propositional_symbol_t ps = NULL;
847 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
848 f = (int_f_void_t)ps->function;
850 xbt_dynar_push_as(pair->prop_ato, int, res);
853 xbt_dynar_push(visited_pairs, &pair);
860 void MC_pair_delete(mc_pair_t pair){
861 xbt_free(pair->graph_state->proc_status);
862 xbt_free(pair->graph_state);
868 int MC_automaton_evaluate_label(xbt_exp_label_t l){
872 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
873 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
874 return (left_res || right_res);
877 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
878 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
879 return (left_res && right_res);
882 int res = MC_automaton_evaluate_label(l->u.exp_not);
886 unsigned int cursor = 0;
887 xbt_propositional_symbol_t p = NULL;
889 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
890 if(strcmp(p->pred, l->u.predicat) == 0){
891 f = (int_f_void_t)p->function;
906 /********************* Double-DFS stateless *******************/
908 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
909 xbt_free(pair->graph_state->proc_status);
910 xbt_free(pair->graph_state);
914 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
915 mc_pair_stateless_t p = NULL;
916 p = xbt_new0(s_mc_pair_stateless_t, 1);
917 p->automaton_state = st;
920 mc_stats_pair->expanded_pairs++;
924 void MC_ddfs_init(void){
926 XBT_DEBUG("**************************************************");
927 XBT_DEBUG("Double-DFS init");
928 XBT_DEBUG("**************************************************");
930 mc_pair_stateless_t mc_initial_pair = NULL;
931 mc_state_t initial_graph_state = NULL;
932 smx_process_t process;
935 MC_wait_for_requests();
939 initial_graph_state = MC_state_pair_new();
940 xbt_swag_foreach(process, simix_global->process_list){
941 if(MC_process_is_enabled(process)){
942 MC_state_interleave_process(initial_graph_state, process);
946 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
947 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
948 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
949 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
950 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
952 /* Save the initial state */
953 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
954 MC_take_snapshot_liveness(initial_snapshot_liveness);
958 unsigned int cursor = 0;
961 xbt_dynar_foreach(automaton->states, cursor, state){
962 if(state->type == -1){
965 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
966 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
970 MC_restore_snapshot(initial_snapshot_liveness);
977 if(state->type == 2){
980 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
981 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
984 set_pair_reached(state);
985 //set_pair_reached_hash(state);
988 MC_restore_snapshot(initial_snapshot_liveness);
1001 void MC_ddfs(int search_cycle){
1003 smx_process_t process;
1004 mc_pair_stateless_t current_pair = NULL;
1006 if(xbt_fifo_size(mc_stack_liveness) == 0)
1010 /* Get current pair */
1011 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
1013 /* Update current state in buchi automaton */
1014 automaton->current_state = current_pair->automaton_state;
1017 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
1018 XBT_DEBUG("Pair : graph=%p, automaton=%p(%s), %u interleave", current_pair->graph_state, current_pair->automaton_state, current_pair->automaton_state->id, MC_state_interleave_size(current_pair->graph_state));
1020 mc_stats_pair->visited_pairs++;
1025 mc_state_t next_graph_state = NULL;
1026 smx_simcall_t req = NULL;
1029 xbt_transition_t transition_succ;
1030 unsigned int cursor = 0;
1033 mc_pair_stateless_t next_pair = NULL;
1034 mc_pair_stateless_t pair_succ;
1036 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
1038 //set_pair_visited(current_pair->automaton_state, search_cycle);
1039 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
1041 //XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
1042 XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
1044 if(current_pair->requests > 0){
1046 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1048 /* Debug information */
1049 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
1050 req_str = MC_request_to_string(req, value);
1051 XBT_DEBUG("Execute: %s", req_str);
1055 MC_state_set_executed_request(current_pair->graph_state, req, value);
1057 /* Answer the request */
1058 SIMIX_simcall_pre(req, value);
1060 /* Wait for requests (schedules processes) */
1061 MC_wait_for_requests();
1066 /* Create the new expanded graph_state */
1067 next_graph_state = MC_state_pair_new();
1069 /* Get enabled process and insert it in the interleave set of the next graph_state */
1070 xbt_swag_foreach(process, simix_global->process_list){
1071 if(MC_process_is_enabled(process)){
1072 MC_state_interleave_process(next_graph_state, process);
1076 xbt_dynar_reset(successors);
1082 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1084 res = MC_automaton_evaluate_label(transition_succ->label);
1086 if(res == 1){ // enabled transition in automaton
1088 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1089 xbt_dynar_push(successors, &next_pair);
1097 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1099 res = MC_automaton_evaluate_label(transition_succ->label);
1101 if(res == 2){ // true transition in automaton
1103 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1104 xbt_dynar_push(successors, &next_pair);
1112 xbt_dynar_foreach(successors, cursor, pair_succ){
1114 if(search_cycle == 1){
1116 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1118 if(reached(pair_succ->automaton_state)){
1119 //if(reached_hash(pair_succ->automaton_state)){
1121 XBT_DEBUG("Next pair (depth = %d, %u interleave) already reached !", xbt_fifo_size(mc_stack_liveness) + 1, MC_state_interleave_size(pair_succ->graph_state));
1123 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1124 XBT_INFO("| ACCEPTANCE CYCLE |");
1125 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1126 XBT_INFO("Counter-example that violates formula :");
1127 MC_show_stack_liveness(mc_stack_liveness);
1128 MC_dump_stack_liveness(mc_stack_liveness);
1129 MC_print_statistics_pairs(mc_stats_pair);
1134 XBT_DEBUG("Next pair (depth =%d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
1136 set_pair_reached(pair_succ->automaton_state);
1137 //set_pair_reached_hash(pair_succ->automaton_state);
1139 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1140 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1143 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1146 MC_ddfs(search_cycle);
1152 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1153 //if(!visited(pair_succ->automaton_state, search_cycle)){
1156 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1159 MC_ddfs(search_cycle);
1163 XBT_DEBUG("Next pair already visited ! ");
1171 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1173 XBT_DEBUG("Next pair (depth =%d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
1175 set_pair_reached(pair_succ->automaton_state);
1176 //set_pair_reached_hash(pair_succ->automaton_state);
1180 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1181 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1185 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1186 //if(!visited(pair_succ->automaton_state, search_cycle)){
1189 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1192 MC_ddfs(search_cycle);
1196 XBT_DEBUG("Next pair already visited ! ");
1203 /* Restore system before checking others successors */
1204 if(cursor != (xbt_dynar_length(successors) - 1))
1205 MC_replay_liveness(mc_stack_liveness, 1);
1210 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1211 XBT_DEBUG("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1212 MC_replay_liveness(mc_stack_liveness, 0);
1217 }else{ /*No request to execute, search evolution in Büchi automaton */
1221 /* Create the new expanded graph_state */
1222 next_graph_state = MC_state_pair_new();
1224 xbt_dynar_reset(successors);
1230 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1232 res = MC_automaton_evaluate_label(transition_succ->label);
1234 if(res == 1){ // enabled transition in automaton
1236 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1237 xbt_dynar_push(successors, &next_pair);
1245 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1247 res = MC_automaton_evaluate_label(transition_succ->label);
1249 if(res == 2){ // true transition in automaton
1251 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1252 xbt_dynar_push(successors, &next_pair);
1260 xbt_dynar_foreach(successors, cursor, pair_succ){
1262 if(search_cycle == 1){
1264 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1266 if(reached(pair_succ->automaton_state)){
1267 //if(reached_hash(pair_succ->automaton_state)){
1269 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1271 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1272 XBT_INFO("| ACCEPTANCE CYCLE |");
1273 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1274 XBT_INFO("Counter-example that violates formula :");
1275 MC_show_stack_liveness(mc_stack_liveness);
1276 MC_dump_stack_liveness(mc_stack_liveness);
1277 MC_print_statistics_pairs(mc_stats_pair);
1282 XBT_DEBUG("Next pair (depth = %d) -> Acceptance pair : graph=%p, automaton=%p(%s)", xbt_fifo_size(mc_stack_liveness) + 1, pair_succ->graph_state, pair_succ->automaton_state, pair_succ->automaton_state->id);
1284 set_pair_reached(pair_succ->automaton_state);
1285 //set_pair_reached_hash(pair_succ->automaton_state);
1287 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1288 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1291 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1294 MC_ddfs(search_cycle);
1300 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1301 //if(!visited(pair_succ->automaton_state, search_cycle)){
1304 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1307 MC_ddfs(search_cycle);
1311 XBT_DEBUG("Next pair already visited ! ");
1319 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1321 set_pair_reached(pair_succ->automaton_state);
1322 //set_pair_reached_hash(pair_succ->automaton_state);
1326 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1327 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1331 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1332 //if(!visited(pair_succ->automaton_state, search_cycle)){
1335 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1338 MC_ddfs(search_cycle);
1342 XBT_DEBUG("Next pair already visited ! ");
1348 /* Restore system before checking others successors */
1349 if(cursor != xbt_dynar_length(successors) - 1)
1350 MC_replay_liveness(mc_stack_liveness, 1);
1359 XBT_DEBUG("Max depth reached");
1363 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1364 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %d, depth = %d) shifted in stack, maximum depth reached", current_pair->graph_state, current_pair->automaton_state, search_cycle, xbt_fifo_size(mc_stack_liveness) );
1366 XBT_DEBUG("Pair (graph=%p, automaton =%p, search_cycle = %d, depth = %d) shifted in stack", current_pair->graph_state, current_pair->automaton_state, search_cycle, xbt_fifo_size(mc_stack_liveness) );
1371 xbt_fifo_shift(mc_stack_liveness);
1372 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1373 xbt_dynar_pop(reached_pairs, NULL);
1374 //xbt_dynar_pop(reached_pairs_hash, NULL);