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_INFO("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 XBT_INFO("Different type of region");
145 switch(s1->regions[i]->type){
147 if(s1->regions[i]->size != s2->regions[i]->size){
148 XBT_INFO("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
151 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
152 XBT_INFO("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
155 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
156 XBT_INFO("Different heap (mmalloc_compare)");
161 if(s1->regions[i]->size != s2->regions[i]->size){
162 XBT_INFO("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
165 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
166 XBT_INFO("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
169 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
170 XBT_INFO("Different memcmp for data in libsimgrid");
175 if(s1->regions[i]->size != s2->regions[i]->size){
176 XBT_INFO("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
179 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
180 XBT_INFO("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
183 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
184 XBT_INFO("Different memcmp for data in program");
197 int reached(xbt_state_t st){
200 if(xbt_dynar_is_empty(reached_pairs)){
208 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
209 MC_take_snapshot_liveness(sn);
211 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
215 /* Get values of propositional symbols */
216 unsigned int cursor = 0;
217 xbt_propositional_symbol_t ps = NULL;
218 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
219 f = (int_f_void_t)ps->function;
221 xbt_dynar_push_as(prop_ato, int, res);
225 mc_pair_reached_t pair_test = NULL;
227 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
229 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
230 XBT_INFO("Pair reached #%u", cursor+1);
231 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
232 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
233 //XBT_INFO("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
234 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
235 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
236 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
237 MC_free_snapshot(sn);
238 xbt_dynar_reset(prop_ato);
245 XBT_INFO("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
248 XBT_INFO("Different values of propositional symbols");
251 XBT_INFO("Different automaton state");
255 MC_free_snapshot(sn);
256 xbt_dynar_reset(prop_ato);
264 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
266 xbt_dict_cursor_t cursor_dict = NULL;
269 smx_rdv_t rdv1, rdv2;
270 xbt_fifo_item_t item1, item2;
271 smx_action_t action1, action2;
272 xbt_fifo_item_t item_req1, item_req2;
273 smx_simcall_t req1, req2;
277 xbt_dict_foreach(d1, cursor_dict, key, data){
278 rdv1 = (smx_rdv_t)data;
279 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
281 XBT_INFO("Rdv point unknown");
284 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
285 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) );
289 XBT_INFO("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
291 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
292 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
294 while(i<xbt_fifo_size(rdv1->comm_fifo)){
295 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
296 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
298 if(action1->type != action2->type){
299 XBT_INFO("Different type of action");
303 if(action1->state != action2->state){
304 XBT_INFO("Different state of action");
308 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
309 XBT_INFO("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
313 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
314 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
316 while(j<xbt_fifo_size(action1->simcalls)){
318 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
319 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
321 if(req1->call != req2->call){
322 XBT_INFO("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
325 if(req1->issuer->pid != req2->issuer->pid){
326 XBT_INFO("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
330 item_req1 = xbt_fifo_get_next_item(item_req1);
331 item_req2 = xbt_fifo_get_next_item(item_req2);
337 switch(action1->type){
338 case 0: /* execution */
339 case 1: /* parallel execution */
340 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
344 if(action1->comm.type != action2->comm.type)
346 //XBT_INFO("Type of comm : %d", action1->comm.type);
348 switch(action1->comm.type){
350 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
352 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
355 case 1: /* RECEIVE */
356 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
358 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
362 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
364 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
366 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
368 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
372 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
374 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
376 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
378 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
382 } /* end of switch on type of comm */
384 if(action1->comm.refcount != action2->comm.refcount)
386 if(action1->comm.detached != action2->comm.detached)
388 if(action1->comm.rate != action2->comm.rate)
390 if(action1->comm.task_size != action2->comm.task_size)
392 if(action1->comm.src_buff != action2->comm.src_buff)
394 if(action1->comm.dst_buff != action2->comm.dst_buff)
396 if(action1->comm.src_data != action2->comm.src_data)
398 if(action1->comm.dst_data != action2->comm.dst_data)
403 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
406 case 4: /* synchro */
413 item1 = xbt_fifo_get_next_item(item1);
414 item2 = xbt_fifo_get_next_item(item2);
425 void set_pair_reached(xbt_state_t st){
430 mc_pair_reached_t pair = NULL;
431 pair = xbt_new0(s_mc_pair_reached_t, 1);
432 pair->automaton_state = st;
433 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
434 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
435 //pair->rdv_points = xbt_dict_new();
436 MC_take_snapshot_liveness(pair->system_state);
438 /* Get values of propositional symbols */
439 unsigned int cursor = 0;
440 xbt_propositional_symbol_t ps = NULL;
444 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
445 f = (int_f_void_t)ps->function;
447 xbt_dynar_push_as(pair->prop_ato, int, res);
450 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
452 xbt_dict_cursor_t cursor_dict = NULL;
455 xbt_fifo_item_t item;
458 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
459 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
460 new_rdv->name = strdup(((smx_rdv_t)data)->name);
461 new_rdv->comm_fifo = xbt_fifo_new();
462 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
463 smx_action_t a = xbt_new0(s_smx_action_t, 1);
464 memcpy(a, action, sizeof(s_smx_action_t));
465 xbt_fifo_push(new_rdv->comm_fifo, a);
466 XBT_INFO("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
468 XBT_INFO("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
470 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
471 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
474 xbt_dynar_push(reached_pairs, &pair);
481 int reached_hash(xbt_state_t st){
484 if(xbt_dynar_is_empty(reached_pairs_hash)){
492 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
493 MC_take_snapshot_liveness(sn);
496 unsigned int hash_regions[sn->num_reg];
497 for(j=0; j<sn->num_reg; j++){
498 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
502 /* Get values of propositional symbols */
503 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
504 unsigned int cursor = 0;
505 xbt_propositional_symbol_t ps = NULL;
509 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
510 f = (int_f_void_t)ps->function;
512 xbt_dynar_push_as(prop_ato, int, res);
515 mc_pair_reached_hash_t pair_test = NULL;
521 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
523 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
524 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
525 for(j=0 ; j< sn->num_reg ; j++){
526 if(hash_regions[j] != pair_test->hash_regions[j]){
530 if(region_diff == 0){
531 MC_free_snapshot(sn);
532 xbt_dynar_reset(prop_ato);
537 XBT_INFO("Different snapshot");
540 XBT_INFO("Different values of propositional symbols");
543 XBT_INFO("Different automaton state");
549 MC_free_snapshot(sn);
550 xbt_dynar_reset(prop_ato);
558 void set_pair_reached_hash(xbt_state_t st){
562 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
563 MC_take_snapshot_liveness(sn);
565 mc_pair_reached_hash_t pair = NULL;
566 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
567 pair->automaton_state = st;
568 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
569 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
573 for(i=0 ; i< sn->num_reg ; i++){
574 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
577 /* Get values of propositional symbols */
578 unsigned int cursor = 0;
579 xbt_propositional_symbol_t ps = NULL;
583 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
584 f = (int_f_void_t)ps->function;
586 xbt_dynar_push_as(pair->prop_ato, int, res);
589 xbt_dynar_push(reached_pairs_hash, &pair);
591 MC_free_snapshot(sn);
598 int visited(xbt_state_t st, int sc){
601 if(xbt_dynar_is_empty(visited_pairs)){
609 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
610 MC_take_snapshot_liveness(sn);
612 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
614 /* Get values of propositional symbols */
615 unsigned int cursor = 0;
616 xbt_propositional_symbol_t ps = NULL;
620 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
621 f = (int_f_void_t)ps->function;
623 xbt_dynar_push_as(prop_ato, int, res);
627 mc_pair_visited_t pair_test = NULL;
629 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
630 if(pair_test->search_cycle == sc) {
631 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
632 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
633 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
635 MC_free_snapshot(sn);
636 xbt_dynar_reset(prop_ato);
643 XBT_INFO("Different snapshot");
646 XBT_INFO("Different values of propositional symbols");
649 XBT_INFO("Different automaton state");
652 XBT_INFO("Different value of search_cycle");
657 MC_free_snapshot(sn);
658 xbt_dynar_reset(prop_ato);
667 int visited_hash(xbt_state_t st, int sc){
670 if(xbt_dynar_is_empty(visited_pairs_hash)){
678 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
679 MC_take_snapshot_liveness(sn);
682 unsigned int hash_regions[sn->num_reg];
683 for(j=0; j<sn->num_reg; j++){
684 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
688 /* Get values of propositional symbols */
689 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
690 unsigned int cursor = 0;
691 xbt_propositional_symbol_t ps = NULL;
695 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
696 f = (int_f_void_t)ps->function;
698 xbt_dynar_push_as(prop_ato, int, res);
701 mc_pair_visited_hash_t pair_test = NULL;
706 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
708 if(pair_test->search_cycle == sc) {
709 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
710 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
711 for(j=0 ; j< sn->num_reg ; j++){
712 if(hash_regions[j] != pair_test->hash_regions[j]){
716 if(region_diff == 0){
717 MC_free_snapshot(sn);
718 xbt_dynar_reset(prop_ato);
723 //XBT_INFO("Different snapshot");
726 //XBT_INFO("Different values of propositional symbols");
729 //XBT_INFO("Different automaton state");
732 //XBT_INFO("Different value of search_cycle");
738 MC_free_snapshot(sn);
739 xbt_dynar_reset(prop_ato);
747 void set_pair_visited_hash(xbt_state_t st, int sc){
751 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
752 MC_take_snapshot_liveness(sn);
754 mc_pair_visited_hash_t pair = NULL;
755 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
756 pair->automaton_state = st;
757 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
758 pair->search_cycle = sc;
759 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
763 for(i=0 ; i< sn->num_reg ; i++){
764 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
767 /* Get values of propositional symbols */
768 unsigned int cursor = 0;
769 xbt_propositional_symbol_t ps = NULL;
773 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
774 f = (int_f_void_t)ps->function;
776 xbt_dynar_push_as(pair->prop_ato, int, res);
779 xbt_dynar_push(visited_pairs_hash, &pair);
781 MC_free_snapshot(sn);
787 void set_pair_visited(xbt_state_t st, int sc){
792 mc_pair_visited_t pair = NULL;
793 pair = xbt_new0(s_mc_pair_visited_t, 1);
794 pair->automaton_state = st;
795 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
796 pair->search_cycle = sc;
797 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
798 MC_take_snapshot_liveness(pair->system_state);
801 /* Get values of propositional symbols */
802 unsigned int cursor = 0;
803 xbt_propositional_symbol_t ps = NULL;
807 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
808 f = (int_f_void_t)ps->function;
810 xbt_dynar_push_as(pair->prop_ato, int, res);
813 xbt_dynar_push(visited_pairs, &pair);
820 void MC_pair_delete(mc_pair_t pair){
821 xbt_free(pair->graph_state->proc_status);
822 xbt_free(pair->graph_state);
828 int MC_automaton_evaluate_label(xbt_exp_label_t l){
832 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
833 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
834 return (left_res || right_res);
837 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
838 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
839 return (left_res && right_res);
842 int res = MC_automaton_evaluate_label(l->u.exp_not);
846 unsigned int cursor = 0;
847 xbt_propositional_symbol_t p = NULL;
849 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
850 if(strcmp(p->pred, l->u.predicat) == 0){
851 f = (int_f_void_t)p->function;
866 /********************* Double-DFS stateless *******************/
868 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
869 xbt_free(pair->graph_state->proc_status);
870 xbt_free(pair->graph_state);
874 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
875 mc_pair_stateless_t p = NULL;
876 p = xbt_new0(s_mc_pair_stateless_t, 1);
877 p->automaton_state = st;
880 mc_stats_pair->expanded_pairs++;
884 void MC_ddfs_init(void){
886 XBT_INFO("**************************************************");
887 XBT_INFO("Double-DFS init");
888 XBT_INFO("**************************************************");
890 mc_pair_stateless_t mc_initial_pair = NULL;
891 mc_state_t initial_graph_state = NULL;
892 smx_process_t process;
895 MC_wait_for_requests();
899 initial_graph_state = MC_state_pair_new();
900 xbt_swag_foreach(process, simix_global->process_list){
901 if(MC_process_is_enabled(process)){
902 MC_state_interleave_process(initial_graph_state, process);
906 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
907 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
908 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
909 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
910 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
912 /* Save the initial state */
913 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
914 MC_take_snapshot_liveness(initial_snapshot_liveness);
918 unsigned int cursor = 0;
921 xbt_dynar_foreach(automaton->states, cursor, state){
922 if(state->type == -1){
925 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
926 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
930 MC_restore_snapshot(initial_snapshot_liveness);
937 if(state->type == 2){
940 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
941 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
944 set_pair_reached(state);
945 //set_pair_reached_hash(state);
948 MC_restore_snapshot(initial_snapshot_liveness);
961 void MC_ddfs(int search_cycle){
963 smx_process_t process;
964 mc_pair_stateless_t current_pair = NULL;
966 if(xbt_fifo_size(mc_stack_liveness) == 0)
970 /* Get current pair */
971 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
973 /* Update current state in buchi automaton */
974 automaton->current_state = current_pair->automaton_state;
977 XBT_INFO("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
978 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));
980 mc_stats_pair->visited_pairs++;
985 mc_state_t next_graph_state = NULL;
986 smx_simcall_t req = NULL;
989 xbt_transition_t transition_succ;
990 unsigned int cursor = 0;
993 mc_pair_stateless_t next_pair = NULL;
994 mc_pair_stateless_t pair_succ;
996 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
998 //set_pair_visited(current_pair->automaton_state, search_cycle);
999 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
1001 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
1002 XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
1004 if(current_pair->requests > 0){
1006 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1008 /* Debug information */
1010 req_str = MC_request_to_string(req, value);
1011 XBT_INFO("Execute: %s", req_str);
1014 MC_state_set_executed_request(current_pair->graph_state, req, value);
1016 /* Answer the request */
1017 SIMIX_simcall_pre(req, value);
1019 /* Wait for requests (schedules processes) */
1020 MC_wait_for_requests();
1025 /* Create the new expanded graph_state */
1026 next_graph_state = MC_state_pair_new();
1028 /* Get enabled process and insert it in the interleave set of the next graph_state */
1029 xbt_swag_foreach(process, simix_global->process_list){
1030 if(MC_process_is_enabled(process)){
1031 MC_state_interleave_process(next_graph_state, process);
1035 xbt_dynar_reset(successors);
1041 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1043 res = MC_automaton_evaluate_label(transition_succ->label);
1045 if(res == 1){ // enabled transition in automaton
1047 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1048 xbt_dynar_push(successors, &next_pair);
1056 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1058 res = MC_automaton_evaluate_label(transition_succ->label);
1060 if(res == 2){ // true transition in automaton
1062 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1063 xbt_dynar_push(successors, &next_pair);
1071 xbt_dynar_foreach(successors, cursor, pair_succ){
1073 if(search_cycle == 1){
1075 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1077 if(reached(pair_succ->automaton_state)){
1078 //if(reached_hash(pair_succ->automaton_state)){
1080 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));
1082 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1083 XBT_INFO("| ACCEPTANCE CYCLE |");
1084 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1085 XBT_INFO("Counter-example that violates formula :");
1086 MC_show_stack_liveness(mc_stack_liveness);
1087 MC_dump_stack_liveness(mc_stack_liveness);
1088 MC_print_statistics_pairs(mc_stats_pair);
1093 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);
1095 set_pair_reached(pair_succ->automaton_state);
1096 //set_pair_reached_hash(pair_succ->automaton_state);
1098 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1099 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1102 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1105 MC_ddfs(search_cycle);
1111 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1112 //if(!visited(pair_succ->automaton_state, search_cycle)){
1115 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1118 MC_ddfs(search_cycle);
1122 XBT_INFO("Next pair already visited ! ");
1130 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1132 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);
1134 set_pair_reached(pair_succ->automaton_state);
1135 //set_pair_reached_hash(pair_succ->automaton_state);
1139 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1140 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1144 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1145 //if(!visited(pair_succ->automaton_state, search_cycle)){
1148 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1151 MC_ddfs(search_cycle);
1155 XBT_INFO("Next pair already visited ! ");
1162 /* Restore system before checking others successors */
1163 if(cursor != (xbt_dynar_length(successors) - 1))
1164 MC_replay_liveness(mc_stack_liveness, 1);
1169 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1170 XBT_INFO("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1171 MC_replay_liveness(mc_stack_liveness, 0);
1176 }else{ /*No request to execute, search evolution in Büchi automaton */
1180 /* Create the new expanded graph_state */
1181 next_graph_state = MC_state_pair_new();
1183 xbt_dynar_reset(successors);
1189 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1191 res = MC_automaton_evaluate_label(transition_succ->label);
1193 if(res == 1){ // enabled transition in automaton
1195 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1196 xbt_dynar_push(successors, &next_pair);
1204 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1206 res = MC_automaton_evaluate_label(transition_succ->label);
1208 if(res == 2){ // true transition in automaton
1210 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1211 xbt_dynar_push(successors, &next_pair);
1219 xbt_dynar_foreach(successors, cursor, pair_succ){
1221 if(search_cycle == 1){
1223 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1225 if(reached(pair_succ->automaton_state)){
1226 //if(reached_hash(pair_succ->automaton_state)){
1228 XBT_INFO("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1230 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1231 XBT_INFO("| ACCEPTANCE CYCLE |");
1232 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1233 XBT_INFO("Counter-example that violates formula :");
1234 MC_show_stack_liveness(mc_stack_liveness);
1235 MC_dump_stack_liveness(mc_stack_liveness);
1236 MC_print_statistics_pairs(mc_stats_pair);
1241 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);
1243 set_pair_reached(pair_succ->automaton_state);
1244 //set_pair_reached_hash(pair_succ->automaton_state);
1246 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1247 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1250 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1253 MC_ddfs(search_cycle);
1259 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1260 //if(!visited(pair_succ->automaton_state, search_cycle)){
1263 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1266 MC_ddfs(search_cycle);
1270 XBT_INFO("Next pair already visited ! ");
1278 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1280 set_pair_reached(pair_succ->automaton_state);
1281 //set_pair_reached_hash(pair_succ->automaton_state);
1285 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1286 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1290 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1291 //if(!visited(pair_succ->automaton_state, search_cycle)){
1294 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1297 MC_ddfs(search_cycle);
1301 XBT_INFO("Next pair already visited ! ");
1307 /* Restore system before checking others successors */
1308 if(cursor != xbt_dynar_length(successors) - 1)
1309 MC_replay_liveness(mc_stack_liveness, 1);
1318 XBT_INFO("Max depth reached");
1322 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1323 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) );
1325 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) );
1330 xbt_fifo_shift(mc_stack_liveness);
1331 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1332 xbt_dynar_pop(reached_pairs, NULL);
1333 //xbt_dynar_pop(reached_pairs_hash, NULL);