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");
54 xbt_dynar_t lfields = NULL;
55 xbt_dynar_t start_end = NULL;
59 while ((read = getline(&line, &n, fp)) != -1) {
61 xbt_str_trim(line, NULL);
62 xbt_str_strip_spaces(line);
63 lfields = xbt_str_split(line,NULL);
65 start_end = xbt_str_split(xbt_dynar_get_as(lfields, 0, char*), "-");
66 start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16);
67 end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16);
69 if((addr > start_addr) && ( addr < end_addr)){
72 if(start_addr == std_heap){
73 xbt_dynar_reset(lfields);
75 xbt_dynar_reset(start_end);
79 if(start_addr == raw_heap){
80 xbt_dynar_reset(lfields);
82 xbt_dynar_reset(start_end);
86 if(xbt_dynar_length(lfields) == 6){
87 return xbt_dynar_get_as(lfields, xbt_dynar_length(lfields) - 1, char*);
89 xbt_dynar_reset(lfields);
91 xbt_dynar_reset(start_end);
99 xbt_dynar_reset(lfields);
101 xbt_dynar_reset(start_end);
105 return "Unknown area";
109 int data_program_region_compare(void *d1, void *d2, size_t size){
113 char *pointed_address1 = NULL, *pointed_address2 = NULL;
115 for(i=0; i<size; i++){
116 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
117 fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
119 pointer_align = (i /sizeof(void *)) * sizeof(void *);
120 pointed_address1 = strdup(get_memory_map_addr(*((void **)((char *)d1 + pointer_align))));
121 pointed_address2 = strdup(get_memory_map_addr(*((void **)((char *)d2 + pointer_align))));
122 fprintf(stderr, "Pointed address : %p (in %s) - %p (in %s)\n", *((void **)((char *)d1 + pointer_align)), pointed_address1, *((void **)((char *)d2 + pointer_align)), pointed_address2);
123 /* FIXME : compare values in pointed address thanks to DWARF */
127 fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
129 free(pointed_address1);
130 free(pointed_address2);
135 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
139 char *pointed_address1 = NULL, *pointed_address2 = NULL;
141 for(i=0; i<size; i++){
142 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
143 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region\n", i, (char *)d1 + i, (char *)d2 + i);
145 pointer_align = (i /sizeof(void *)) * sizeof(void *);
146 pointed_address1 = strdup(get_memory_map_addr(*((void **)((char *)d1 + pointer_align))));
147 pointed_address2 = strdup(get_memory_map_addr(*((void **)((char *)d2 + pointer_align))));
148 fprintf(stderr, "Pointed address : %p (in %s) - %p (in %s)\n", *((void **)((char *)d1 + pointer_align)), pointed_address1, *((void **)((char *)d2 + pointer_align)), pointed_address2);
149 /* FIXME : compare values in pointed address thanks to DWARF */
153 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
155 free(pointed_address1);
156 free(pointed_address2);
161 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap){
164 if(s1->num_reg != s2->num_reg){
165 XBT_INFO("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
172 for(i=0 ; i< s1->num_reg ; i++){
174 if(s1->regions[i]->type != s2->regions[i]->type){
175 XBT_INFO("Different type of region");
179 switch(s1->regions[i]->type){
181 if(s1->regions[i]->size != s2->regions[i]->size){
182 XBT_INFO("Different size of heap (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 XBT_INFO("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
189 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
190 XBT_INFO("Different heap (mmalloc_compare)");
195 if(s1->regions[i]->size != s2->regions[i]->size){
196 XBT_INFO("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
199 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
200 XBT_INFO("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
203 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
204 XBT_INFO("Different memcmp for data in libsimgrid");
209 if(s1->regions[i]->size != s2->regions[i]->size){
210 XBT_INFO("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
213 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
214 XBT_INFO("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
217 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
218 XBT_INFO("Different memcmp for data in program");
231 int reached(xbt_state_t st){
234 if(xbt_dynar_is_empty(reached_pairs)){
242 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
243 MC_take_snapshot_liveness(sn);
245 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
249 /* Get values of propositional symbols */
250 unsigned int cursor = 0;
251 xbt_propositional_symbol_t ps = NULL;
252 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
253 f = (int_f_void_t)ps->function;
255 xbt_dynar_push_as(prop_ato, int, res);
259 mc_pair_reached_t pair_test = NULL;
261 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
263 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
264 XBT_INFO("Pair reached #%d", pair_test->nb);
265 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
266 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
267 //XBT_INFO("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
268 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
269 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
270 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
272 MC_free_snapshot(sn);
273 xbt_dynar_reset(prop_ato);
280 XBT_INFO("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
283 XBT_INFO("Different values of propositional symbols");
286 XBT_INFO("Different automaton state");
290 MC_free_snapshot(sn);
291 xbt_dynar_reset(prop_ato);
299 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
301 xbt_dict_cursor_t cursor_dict = NULL;
304 smx_rdv_t rdv1, rdv2;
305 xbt_fifo_item_t item1, item2;
306 smx_action_t action1, action2;
307 xbt_fifo_item_t item_req1, item_req2;
308 smx_simcall_t req1, req2;
312 xbt_dict_foreach(d1, cursor_dict, key, data){
313 rdv1 = (smx_rdv_t)data;
314 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
316 XBT_INFO("Rdv point unknown");
319 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
320 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) );
324 XBT_INFO("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
326 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
327 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
329 while(i<xbt_fifo_size(rdv1->comm_fifo)){
330 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
331 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
333 if(action1->type != action2->type){
334 XBT_INFO("Different type of action");
338 if(action1->state != action2->state){
339 XBT_INFO("Different state of action");
343 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
344 XBT_INFO("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
348 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
349 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
351 while(j<xbt_fifo_size(action1->simcalls)){
353 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
354 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
356 if(req1->call != req2->call){
357 XBT_INFO("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
360 if(req1->issuer->pid != req2->issuer->pid){
361 XBT_INFO("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
365 item_req1 = xbt_fifo_get_next_item(item_req1);
366 item_req2 = xbt_fifo_get_next_item(item_req2);
372 switch(action1->type){
373 case 0: /* execution */
374 case 1: /* parallel execution */
375 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
379 if(action1->comm.type != action2->comm.type)
381 //XBT_INFO("Type of comm : %d", action1->comm.type);
383 switch(action1->comm.type){
385 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
387 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
390 case 1: /* RECEIVE */
391 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
393 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
397 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
399 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
401 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
403 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
407 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
409 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
411 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
413 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
417 } /* end of switch on type of comm */
419 if(action1->comm.refcount != action2->comm.refcount)
421 if(action1->comm.detached != action2->comm.detached)
423 if(action1->comm.rate != action2->comm.rate)
425 if(action1->comm.task_size != action2->comm.task_size)
427 if(action1->comm.src_buff != action2->comm.src_buff)
429 if(action1->comm.dst_buff != action2->comm.dst_buff)
431 if(action1->comm.src_data != action2->comm.src_data)
433 if(action1->comm.dst_data != action2->comm.dst_data)
438 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
441 case 4: /* synchro */
448 item1 = xbt_fifo_get_next_item(item1);
449 item2 = xbt_fifo_get_next_item(item2);
460 void set_pair_reached(xbt_state_t st){
465 mc_pair_reached_t pair = NULL;
466 pair = xbt_new0(s_mc_pair_reached_t, 1);
467 pair->nb = xbt_dynar_length(reached_pairs) + 1;
468 pair->automaton_state = st;
469 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
470 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
471 //pair->rdv_points = xbt_dict_new();
472 MC_take_snapshot_liveness(pair->system_state);
474 /* Get values of propositional symbols */
475 unsigned int cursor = 0;
476 xbt_propositional_symbol_t ps = NULL;
480 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
481 f = (int_f_void_t)ps->function;
483 xbt_dynar_push_as(pair->prop_ato, int, res);
486 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
488 xbt_dict_cursor_t cursor_dict = NULL;
491 xbt_fifo_item_t item;
494 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
495 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
496 new_rdv->name = strdup(((smx_rdv_t)data)->name);
497 new_rdv->comm_fifo = xbt_fifo_new();
498 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
499 smx_action_t a = xbt_new0(s_smx_action_t, 1);
500 memcpy(a, action, sizeof(s_smx_action_t));
501 xbt_fifo_push(new_rdv->comm_fifo, a);
502 XBT_INFO("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
504 XBT_INFO("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
506 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
507 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
510 xbt_dynar_push(reached_pairs, &pair);
517 int reached_hash(xbt_state_t st){
520 if(xbt_dynar_is_empty(reached_pairs_hash)){
528 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
529 MC_take_snapshot_liveness(sn);
532 unsigned int hash_regions[sn->num_reg];
533 for(j=0; j<sn->num_reg; j++){
534 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
538 /* Get values of propositional symbols */
539 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
540 unsigned int cursor = 0;
541 xbt_propositional_symbol_t ps = NULL;
545 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
546 f = (int_f_void_t)ps->function;
548 xbt_dynar_push_as(prop_ato, int, res);
551 mc_pair_reached_hash_t pair_test = NULL;
557 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
559 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
560 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
561 for(j=0 ; j< sn->num_reg ; j++){
562 if(hash_regions[j] != pair_test->hash_regions[j]){
566 if(region_diff == 0){
567 MC_free_snapshot(sn);
568 xbt_dynar_reset(prop_ato);
573 XBT_INFO("Different snapshot");
576 XBT_INFO("Different values of propositional symbols");
579 XBT_INFO("Different automaton state");
585 MC_free_snapshot(sn);
586 xbt_dynar_reset(prop_ato);
594 void set_pair_reached_hash(xbt_state_t st){
598 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
599 MC_take_snapshot_liveness(sn);
601 mc_pair_reached_hash_t pair = NULL;
602 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
603 pair->automaton_state = st;
604 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
605 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
609 for(i=0 ; i< sn->num_reg ; i++){
610 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
613 /* Get values of propositional symbols */
614 unsigned int cursor = 0;
615 xbt_propositional_symbol_t ps = NULL;
619 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
620 f = (int_f_void_t)ps->function;
622 xbt_dynar_push_as(pair->prop_ato, int, res);
625 xbt_dynar_push(reached_pairs_hash, &pair);
627 MC_free_snapshot(sn);
634 int visited(xbt_state_t st, int sc){
637 if(xbt_dynar_is_empty(visited_pairs)){
645 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
646 MC_take_snapshot_liveness(sn);
648 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
650 /* Get values of propositional symbols */
651 unsigned int cursor = 0;
652 xbt_propositional_symbol_t ps = NULL;
656 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
657 f = (int_f_void_t)ps->function;
659 xbt_dynar_push_as(prop_ato, int, res);
663 mc_pair_visited_t pair_test = NULL;
665 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
666 if(pair_test->search_cycle == sc) {
667 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
668 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
669 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
671 MC_free_snapshot(sn);
672 xbt_dynar_reset(prop_ato);
679 XBT_INFO("Different snapshot");
682 XBT_INFO("Different values of propositional symbols");
685 XBT_INFO("Different automaton state");
688 XBT_INFO("Different value of search_cycle");
693 MC_free_snapshot(sn);
694 xbt_dynar_reset(prop_ato);
703 int visited_hash(xbt_state_t st, int sc){
706 if(xbt_dynar_is_empty(visited_pairs_hash)){
714 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
715 MC_take_snapshot_liveness(sn);
718 unsigned int hash_regions[sn->num_reg];
719 for(j=0; j<sn->num_reg; j++){
720 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
724 /* Get values of propositional symbols */
725 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
726 unsigned int cursor = 0;
727 xbt_propositional_symbol_t ps = NULL;
731 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
732 f = (int_f_void_t)ps->function;
734 xbt_dynar_push_as(prop_ato, int, res);
737 mc_pair_visited_hash_t pair_test = NULL;
742 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
744 if(pair_test->search_cycle == sc) {
745 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
746 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
747 for(j=0 ; j< sn->num_reg ; j++){
748 if(hash_regions[j] != pair_test->hash_regions[j]){
752 if(region_diff == 0){
753 MC_free_snapshot(sn);
754 xbt_dynar_reset(prop_ato);
759 //XBT_INFO("Different snapshot");
762 //XBT_INFO("Different values of propositional symbols");
765 //XBT_INFO("Different automaton state");
768 //XBT_INFO("Different value of search_cycle");
774 MC_free_snapshot(sn);
775 xbt_dynar_reset(prop_ato);
783 void set_pair_visited_hash(xbt_state_t st, int sc){
787 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
788 MC_take_snapshot_liveness(sn);
790 mc_pair_visited_hash_t pair = NULL;
791 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
792 pair->automaton_state = st;
793 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
794 pair->search_cycle = sc;
795 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
799 for(i=0 ; i< sn->num_reg ; i++){
800 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
803 /* Get values of propositional symbols */
804 unsigned int cursor = 0;
805 xbt_propositional_symbol_t ps = NULL;
809 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
810 f = (int_f_void_t)ps->function;
812 xbt_dynar_push_as(pair->prop_ato, int, res);
815 xbt_dynar_push(visited_pairs_hash, &pair);
817 MC_free_snapshot(sn);
823 void set_pair_visited(xbt_state_t st, int sc){
828 mc_pair_visited_t pair = NULL;
829 pair = xbt_new0(s_mc_pair_visited_t, 1);
830 pair->automaton_state = st;
831 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
832 pair->search_cycle = sc;
833 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
834 MC_take_snapshot_liveness(pair->system_state);
837 /* Get values of propositional symbols */
838 unsigned int cursor = 0;
839 xbt_propositional_symbol_t ps = NULL;
843 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
844 f = (int_f_void_t)ps->function;
846 xbt_dynar_push_as(pair->prop_ato, int, res);
849 xbt_dynar_push(visited_pairs, &pair);
856 void MC_pair_delete(mc_pair_t pair){
857 xbt_free(pair->graph_state->proc_status);
858 xbt_free(pair->graph_state);
864 int MC_automaton_evaluate_label(xbt_exp_label_t l){
868 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
869 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
870 return (left_res || right_res);
873 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
874 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
875 return (left_res && right_res);
878 int res = MC_automaton_evaluate_label(l->u.exp_not);
882 unsigned int cursor = 0;
883 xbt_propositional_symbol_t p = NULL;
885 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
886 if(strcmp(p->pred, l->u.predicat) == 0){
887 f = (int_f_void_t)p->function;
902 /********************* Double-DFS stateless *******************/
904 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
905 xbt_free(pair->graph_state->proc_status);
906 xbt_free(pair->graph_state);
910 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
911 mc_pair_stateless_t p = NULL;
912 p = xbt_new0(s_mc_pair_stateless_t, 1);
913 p->automaton_state = st;
916 mc_stats_pair->expanded_pairs++;
920 void MC_ddfs_init(void){
922 XBT_INFO("**************************************************");
923 XBT_INFO("Double-DFS init");
924 XBT_INFO("**************************************************");
926 mc_pair_stateless_t mc_initial_pair = NULL;
927 mc_state_t initial_graph_state = NULL;
928 smx_process_t process;
931 MC_wait_for_requests();
935 initial_graph_state = MC_state_pair_new();
936 xbt_swag_foreach(process, simix_global->process_list){
937 if(MC_process_is_enabled(process)){
938 MC_state_interleave_process(initial_graph_state, process);
942 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
943 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
944 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
945 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
946 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
948 /* Save the initial state */
949 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
950 MC_take_snapshot_liveness(initial_snapshot_liveness);
954 unsigned int cursor = 0;
957 xbt_dynar_foreach(automaton->states, cursor, state){
958 if(state->type == -1){
961 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
962 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
966 MC_restore_snapshot(initial_snapshot_liveness);
973 if(state->type == 2){
976 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
977 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
980 set_pair_reached(state);
981 //set_pair_reached_hash(state);
984 MC_restore_snapshot(initial_snapshot_liveness);
997 void MC_ddfs(int search_cycle){
999 smx_process_t process;
1000 mc_pair_stateless_t current_pair = NULL;
1002 if(xbt_fifo_size(mc_stack_liveness) == 0)
1006 /* Get current pair */
1007 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
1009 /* Update current state in buchi automaton */
1010 automaton->current_state = current_pair->automaton_state;
1013 XBT_INFO("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
1014 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));
1016 mc_stats_pair->visited_pairs++;
1021 mc_state_t next_graph_state = NULL;
1022 smx_simcall_t req = NULL;
1025 xbt_transition_t transition_succ;
1026 unsigned int cursor = 0;
1029 mc_pair_stateless_t next_pair = NULL;
1030 mc_pair_stateless_t pair_succ;
1032 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
1034 //set_pair_visited(current_pair->automaton_state, search_cycle);
1035 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
1037 //XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
1038 XBT_INFO("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
1040 if(current_pair->requests > 0){
1042 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1044 /* Debug information */
1046 req_str = MC_request_to_string(req, value);
1047 XBT_INFO("Execute: %s", req_str);
1050 MC_state_set_executed_request(current_pair->graph_state, req, value);
1052 /* Answer the request */
1053 SIMIX_simcall_pre(req, value);
1055 /* Wait for requests (schedules processes) */
1056 MC_wait_for_requests();
1061 /* Create the new expanded graph_state */
1062 next_graph_state = MC_state_pair_new();
1064 /* Get enabled process and insert it in the interleave set of the next graph_state */
1065 xbt_swag_foreach(process, simix_global->process_list){
1066 if(MC_process_is_enabled(process)){
1067 MC_state_interleave_process(next_graph_state, process);
1071 xbt_dynar_reset(successors);
1077 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1079 res = MC_automaton_evaluate_label(transition_succ->label);
1081 if(res == 1){ // enabled transition in automaton
1083 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1084 xbt_dynar_push(successors, &next_pair);
1092 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1094 res = MC_automaton_evaluate_label(transition_succ->label);
1096 if(res == 2){ // true transition in automaton
1098 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1099 xbt_dynar_push(successors, &next_pair);
1107 xbt_dynar_foreach(successors, cursor, pair_succ){
1109 if(search_cycle == 1){
1111 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1113 if(reached(pair_succ->automaton_state)){
1114 //if(reached_hash(pair_succ->automaton_state)){
1116 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));
1118 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1119 XBT_INFO("| ACCEPTANCE CYCLE |");
1120 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1121 XBT_INFO("Counter-example that violates formula :");
1122 MC_show_stack_liveness(mc_stack_liveness);
1123 MC_dump_stack_liveness(mc_stack_liveness);
1124 MC_print_statistics_pairs(mc_stats_pair);
1129 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);
1131 set_pair_reached(pair_succ->automaton_state);
1132 //set_pair_reached_hash(pair_succ->automaton_state);
1134 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1135 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1138 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1141 MC_ddfs(search_cycle);
1147 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1148 //if(!visited(pair_succ->automaton_state, search_cycle)){
1151 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1154 MC_ddfs(search_cycle);
1158 XBT_INFO("Next pair already visited ! ");
1166 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1168 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);
1170 set_pair_reached(pair_succ->automaton_state);
1171 //set_pair_reached_hash(pair_succ->automaton_state);
1175 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1176 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1180 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1181 //if(!visited(pair_succ->automaton_state, search_cycle)){
1184 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1187 MC_ddfs(search_cycle);
1191 XBT_INFO("Next pair already visited ! ");
1198 /* Restore system before checking others successors */
1199 if(cursor != (xbt_dynar_length(successors) - 1))
1200 MC_replay_liveness(mc_stack_liveness, 1);
1205 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1206 XBT_INFO("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1207 MC_replay_liveness(mc_stack_liveness, 0);
1212 }else{ /*No request to execute, search evolution in Büchi automaton */
1216 /* Create the new expanded graph_state */
1217 next_graph_state = MC_state_pair_new();
1219 xbt_dynar_reset(successors);
1225 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1227 res = MC_automaton_evaluate_label(transition_succ->label);
1229 if(res == 1){ // enabled transition in automaton
1231 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1232 xbt_dynar_push(successors, &next_pair);
1240 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1242 res = MC_automaton_evaluate_label(transition_succ->label);
1244 if(res == 2){ // true transition in automaton
1246 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1247 xbt_dynar_push(successors, &next_pair);
1255 xbt_dynar_foreach(successors, cursor, pair_succ){
1257 if(search_cycle == 1){
1259 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1261 if(reached(pair_succ->automaton_state)){
1262 //if(reached_hash(pair_succ->automaton_state)){
1264 XBT_INFO("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1266 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1267 XBT_INFO("| ACCEPTANCE CYCLE |");
1268 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1269 XBT_INFO("Counter-example that violates formula :");
1270 MC_show_stack_liveness(mc_stack_liveness);
1271 MC_dump_stack_liveness(mc_stack_liveness);
1272 MC_print_statistics_pairs(mc_stats_pair);
1277 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);
1279 set_pair_reached(pair_succ->automaton_state);
1280 //set_pair_reached_hash(pair_succ->automaton_state);
1282 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1283 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1286 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1289 MC_ddfs(search_cycle);
1295 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1296 //if(!visited(pair_succ->automaton_state, search_cycle)){
1299 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1302 MC_ddfs(search_cycle);
1306 XBT_INFO("Next pair already visited ! ");
1314 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1316 set_pair_reached(pair_succ->automaton_state);
1317 //set_pair_reached_hash(pair_succ->automaton_state);
1321 XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1322 //XBT_INFO("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1326 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1327 //if(!visited(pair_succ->automaton_state, search_cycle)){
1330 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1333 MC_ddfs(search_cycle);
1337 XBT_INFO("Next pair already visited ! ");
1343 /* Restore system before checking others successors */
1344 if(cursor != xbt_dynar_length(successors) - 1)
1345 MC_replay_liveness(mc_stack_liveness, 1);
1354 XBT_INFO("Max depth reached");
1358 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1359 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) );
1361 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) );
1366 xbt_fifo_shift(mc_stack_liveness);
1367 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1368 xbt_dynar_pop(reached_pairs, NULL);
1369 //xbt_dynar_pop(reached_pairs_hash, NULL);