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");
51 char *lfields[6], *start, *end, *endptr;
56 while ((read = getline(&line, &n, fp)) != -1) {
58 line[read - 1] = '\0';
60 lfields[0] = strtok(line, " ");
62 for (i = 1; i < 6 && lfields[i - 1] != NULL; i++) {
63 lfields[i] = strtok(NULL, " ");
66 start = strtok(lfields[0], "-");
67 start_addr = (void *) strtoul(start, &endptr, 16);
69 if(start_addr == std_heap)
70 lfields[5] = strdup("std_heap");
71 if(start_addr == raw_heap)
72 lfields[5] = strdup("raw_heap");
73 end = strtok(NULL, "-");
74 end_addr = (void *) strtoul(end, &endptr, 16);
76 if((addr > start_addr) && ( addr < end_addr)){
79 if(lfields[5] != NULL){
88 return "Unknown area";
92 int data_program_region_compare(void *d1, void *d2, size_t size){
97 for(i=0; i<size; i++){
98 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
99 fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
101 pointer_align = (i /sizeof(void *)) * sizeof(void *);
102 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))));
106 fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
111 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
116 for(i=0; i<size; i++){
117 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
118 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region\n", i, (char *)d1 + i, (char *)d2 + i);
120 pointer_align = (i /sizeof(void *)) * sizeof(void *);
121 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))));
125 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
130 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap){
133 if(s1->num_reg != s2->num_reg){
134 XBT_DEBUG("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
141 for(i=0 ; i< s1->num_reg ; i++){
143 if(s1->regions[i]->type != s2->regions[i]->type){
144 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
145 XBT_DEBUG("Different type of region");
152 switch(s1->regions[i]->type){
154 if(s1->regions[i]->size != s2->regions[i]->size){
155 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
156 XBT_DEBUG("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
162 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
163 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
164 XBT_DEBUG("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
170 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
171 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
172 XBT_DEBUG("Different heap (mmalloc_compare)");
180 if(s1->regions[i]->size != s2->regions[i]->size){
181 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
182 XBT_DEBUG("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
188 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
189 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
190 XBT_DEBUG("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
196 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
197 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
198 XBT_DEBUG("Different memcmp for data in libsimgrid");
206 if(s1->regions[i]->size != s2->regions[i]->size){
207 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
208 XBT_DEBUG("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
214 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
215 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
216 XBT_DEBUG("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
222 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
223 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
224 XBT_DEBUG("Different memcmp for data in libsimgrid");
240 int reached(xbt_state_t st){
243 if(xbt_dynar_is_empty(reached_pairs)){
251 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
252 MC_take_snapshot_liveness(sn);
254 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
258 /* Get values of propositional symbols */
259 unsigned int cursor = 0;
260 xbt_propositional_symbol_t ps = NULL;
261 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
262 f = (int_f_void_t)ps->function;
264 xbt_dynar_push_as(prop_ato, int, res);
268 mc_pair_reached_t pair_test = NULL;
270 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
272 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
273 XBT_DEBUG("Pair reached #%u", cursor+1);
274 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
275 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
276 //XBT_DEBUG("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
277 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
278 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
279 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
280 MC_free_snapshot(sn);
281 xbt_dynar_reset(prop_ato);
288 XBT_DEBUG("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
291 XBT_DEBUG("Different values of propositional symbols");
294 XBT_DEBUG("Different automaton state");
298 MC_free_snapshot(sn);
299 xbt_dynar_reset(prop_ato);
307 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
309 xbt_dict_cursor_t cursor_dict = NULL;
312 smx_rdv_t rdv1, rdv2;
313 xbt_fifo_item_t item1, item2;
314 smx_action_t action1, action2;
315 xbt_fifo_item_t item_req1, item_req2;
316 smx_simcall_t req1, req2;
320 xbt_dict_foreach(d1, cursor_dict, key, data){
321 rdv1 = (smx_rdv_t)data;
322 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
324 XBT_DEBUG("Rdv point unknown");
327 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
328 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) );
332 XBT_DEBUG("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
334 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
335 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
337 while(i<xbt_fifo_size(rdv1->comm_fifo)){
338 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
339 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
341 if(action1->type != action2->type){
342 XBT_DEBUG("Different type of action");
346 if(action1->state != action2->state){
347 XBT_DEBUG("Different state of action");
351 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
352 XBT_DEBUG("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
356 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
357 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
359 while(j<xbt_fifo_size(action1->simcalls)){
361 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
362 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
364 if(req1->call != req2->call){
365 XBT_DEBUG("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
368 if(req1->issuer->pid != req2->issuer->pid){
369 XBT_DEBUG("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
373 item_req1 = xbt_fifo_get_next_item(item_req1);
374 item_req2 = xbt_fifo_get_next_item(item_req2);
380 switch(action1->type){
381 case 0: /* execution */
382 case 1: /* parallel execution */
383 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
387 if(action1->comm.type != action2->comm.type)
389 //XBT_DEBUG("Type of comm : %d", action1->comm.type);
391 switch(action1->comm.type){
393 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
395 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
398 case 1: /* RECEIVE */
399 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
401 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
405 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
407 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
409 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
411 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
415 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
417 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
419 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
421 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
425 } /* end of switch on type of comm */
427 if(action1->comm.refcount != action2->comm.refcount)
429 if(action1->comm.detached != action2->comm.detached)
431 if(action1->comm.rate != action2->comm.rate)
433 if(action1->comm.task_size != action2->comm.task_size)
435 if(action1->comm.src_buff != action2->comm.src_buff)
437 if(action1->comm.dst_buff != action2->comm.dst_buff)
439 if(action1->comm.src_data != action2->comm.src_data)
441 if(action1->comm.dst_data != action2->comm.dst_data)
446 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
449 case 4: /* synchro */
456 item1 = xbt_fifo_get_next_item(item1);
457 item2 = xbt_fifo_get_next_item(item2);
468 void set_pair_reached(xbt_state_t st){
473 mc_pair_reached_t pair = NULL;
474 pair = xbt_new0(s_mc_pair_reached_t, 1);
475 pair->automaton_state = st;
476 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
477 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
478 //pair->rdv_points = xbt_dict_new();
479 MC_take_snapshot_liveness(pair->system_state);
481 /* Get values of propositional symbols */
482 unsigned int cursor = 0;
483 xbt_propositional_symbol_t ps = NULL;
487 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
488 f = (int_f_void_t)ps->function;
490 xbt_dynar_push_as(pair->prop_ato, int, res);
493 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
495 xbt_dict_cursor_t cursor_dict = NULL;
498 xbt_fifo_item_t item;
501 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
502 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
503 new_rdv->name = strdup(((smx_rdv_t)data)->name);
504 new_rdv->comm_fifo = xbt_fifo_new();
505 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
506 smx_action_t a = xbt_new0(s_smx_action_t, 1);
507 memcpy(a, action, sizeof(s_smx_action_t));
508 xbt_fifo_push(new_rdv->comm_fifo, a);
509 XBT_DEBUG("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
511 XBT_DEBUG("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
513 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
514 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
517 xbt_dynar_push(reached_pairs, &pair);
524 int reached_hash(xbt_state_t st){
527 if(xbt_dynar_is_empty(reached_pairs_hash)){
535 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
536 MC_take_snapshot_liveness(sn);
539 unsigned int hash_regions[sn->num_reg];
540 for(j=0; j<sn->num_reg; j++){
541 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
545 /* Get values of propositional symbols */
546 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
547 unsigned int cursor = 0;
548 xbt_propositional_symbol_t ps = NULL;
552 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
553 f = (int_f_void_t)ps->function;
555 xbt_dynar_push_as(prop_ato, int, res);
558 mc_pair_reached_hash_t pair_test = NULL;
564 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
566 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
567 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
568 for(j=0 ; j< sn->num_reg ; j++){
569 if(hash_regions[j] != pair_test->hash_regions[j]){
573 if(region_diff == 0){
574 MC_free_snapshot(sn);
575 xbt_dynar_reset(prop_ato);
580 XBT_DEBUG("Different snapshot");
583 XBT_DEBUG("Different values of propositional symbols");
586 XBT_DEBUG("Different automaton state");
592 MC_free_snapshot(sn);
593 xbt_dynar_reset(prop_ato);
601 void set_pair_reached_hash(xbt_state_t st){
605 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
606 MC_take_snapshot_liveness(sn);
608 mc_pair_reached_hash_t pair = NULL;
609 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
610 pair->automaton_state = st;
611 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
612 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
616 for(i=0 ; i< sn->num_reg ; i++){
617 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
620 /* Get values of propositional symbols */
621 unsigned int cursor = 0;
622 xbt_propositional_symbol_t ps = NULL;
626 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
627 f = (int_f_void_t)ps->function;
629 xbt_dynar_push_as(pair->prop_ato, int, res);
632 xbt_dynar_push(reached_pairs_hash, &pair);
634 MC_free_snapshot(sn);
641 int visited(xbt_state_t st, int sc){
644 if(xbt_dynar_is_empty(visited_pairs)){
652 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
653 MC_take_snapshot_liveness(sn);
655 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
657 /* Get values of propositional symbols */
658 unsigned int cursor = 0;
659 xbt_propositional_symbol_t ps = NULL;
663 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
664 f = (int_f_void_t)ps->function;
666 xbt_dynar_push_as(prop_ato, int, res);
670 mc_pair_visited_t pair_test = NULL;
672 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
673 if(pair_test->search_cycle == sc) {
674 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
675 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
676 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
678 MC_free_snapshot(sn);
679 xbt_dynar_reset(prop_ato);
686 XBT_DEBUG("Different snapshot");
689 XBT_DEBUG("Different values of propositional symbols");
692 XBT_DEBUG("Different automaton state");
695 XBT_DEBUG("Different value of search_cycle");
700 MC_free_snapshot(sn);
701 xbt_dynar_reset(prop_ato);
710 int visited_hash(xbt_state_t st, int sc){
713 if(xbt_dynar_is_empty(visited_pairs_hash)){
721 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
722 MC_take_snapshot_liveness(sn);
725 unsigned int hash_regions[sn->num_reg];
726 for(j=0; j<sn->num_reg; j++){
727 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
731 /* Get values of propositional symbols */
732 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
733 unsigned int cursor = 0;
734 xbt_propositional_symbol_t ps = NULL;
738 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
739 f = (int_f_void_t)ps->function;
741 xbt_dynar_push_as(prop_ato, int, res);
744 mc_pair_visited_hash_t pair_test = NULL;
749 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
751 if(pair_test->search_cycle == sc) {
752 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
753 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
754 for(j=0 ; j< sn->num_reg ; j++){
755 if(hash_regions[j] != pair_test->hash_regions[j]){
759 if(region_diff == 0){
760 MC_free_snapshot(sn);
761 xbt_dynar_reset(prop_ato);
766 //XBT_DEBUG("Different snapshot");
769 //XBT_DEBUG("Different values of propositional symbols");
772 //XBT_DEBUG("Different automaton state");
775 //XBT_DEBUG("Different value of search_cycle");
781 MC_free_snapshot(sn);
782 xbt_dynar_reset(prop_ato);
790 void set_pair_visited_hash(xbt_state_t st, int sc){
794 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
795 MC_take_snapshot_liveness(sn);
797 mc_pair_visited_hash_t pair = NULL;
798 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
799 pair->automaton_state = st;
800 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
801 pair->search_cycle = sc;
802 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
806 for(i=0 ; i< sn->num_reg ; i++){
807 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
810 /* Get values of propositional symbols */
811 unsigned int cursor = 0;
812 xbt_propositional_symbol_t ps = NULL;
816 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
817 f = (int_f_void_t)ps->function;
819 xbt_dynar_push_as(pair->prop_ato, int, res);
822 xbt_dynar_push(visited_pairs_hash, &pair);
824 MC_free_snapshot(sn);
830 void set_pair_visited(xbt_state_t st, int sc){
835 mc_pair_visited_t pair = NULL;
836 pair = xbt_new0(s_mc_pair_visited_t, 1);
837 pair->automaton_state = st;
838 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
839 pair->search_cycle = sc;
840 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
841 MC_take_snapshot_liveness(pair->system_state);
844 /* Get values of propositional symbols */
845 unsigned int cursor = 0;
846 xbt_propositional_symbol_t ps = NULL;
850 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
851 f = (int_f_void_t)ps->function;
853 xbt_dynar_push_as(pair->prop_ato, int, res);
856 xbt_dynar_push(visited_pairs, &pair);
863 void MC_pair_delete(mc_pair_t pair){
864 xbt_free(pair->graph_state->proc_status);
865 xbt_free(pair->graph_state);
871 int MC_automaton_evaluate_label(xbt_exp_label_t l){
875 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
876 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
877 return (left_res || right_res);
880 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
881 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
882 return (left_res && right_res);
885 int res = MC_automaton_evaluate_label(l->u.exp_not);
889 unsigned int cursor = 0;
890 xbt_propositional_symbol_t p = NULL;
892 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
893 if(strcmp(p->pred, l->u.predicat) == 0){
894 f = (int_f_void_t)p->function;
909 /********************* Double-DFS stateless *******************/
911 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
912 xbt_free(pair->graph_state->proc_status);
913 xbt_free(pair->graph_state);
917 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
918 mc_pair_stateless_t p = NULL;
919 p = xbt_new0(s_mc_pair_stateless_t, 1);
920 p->automaton_state = st;
923 mc_stats_pair->expanded_pairs++;
927 void MC_ddfs_init(void){
929 XBT_DEBUG("**************************************************");
930 XBT_DEBUG("Double-DFS init");
931 XBT_DEBUG("**************************************************");
933 XBT_DEBUG("Std heap : %p", std_heap);
934 XBT_DEBUG("Raw heap : %p", raw_heap);
936 mc_pair_stateless_t mc_initial_pair = NULL;
937 mc_state_t initial_graph_state = NULL;
938 smx_process_t process;
941 MC_wait_for_requests();
945 initial_graph_state = MC_state_pair_new();
946 xbt_swag_foreach(process, simix_global->process_list){
947 if(MC_process_is_enabled(process)){
948 MC_state_interleave_process(initial_graph_state, process);
952 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
953 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
954 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
955 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
956 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
958 /* Save the initial state */
959 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
960 MC_take_snapshot_liveness(initial_snapshot_liveness);
964 unsigned int cursor = 0;
967 xbt_dynar_foreach(automaton->states, cursor, state){
968 if(state->type == -1){
971 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
972 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
976 MC_restore_snapshot(initial_snapshot_liveness);
983 if(state->type == 2){
986 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
987 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
990 set_pair_reached(state);
991 //set_pair_reached_hash(state);
994 MC_restore_snapshot(initial_snapshot_liveness);
1007 void MC_ddfs(int search_cycle){
1009 smx_process_t process;
1010 mc_pair_stateless_t current_pair = NULL;
1012 if(xbt_fifo_size(mc_stack_liveness) == 0)
1016 /* Get current pair */
1017 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
1019 /* Update current state in buchi automaton */
1020 automaton->current_state = current_pair->automaton_state;
1023 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
1024 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));
1026 mc_stats_pair->visited_pairs++;
1031 mc_state_t next_graph_state = NULL;
1032 smx_simcall_t req = NULL;
1035 xbt_transition_t transition_succ;
1036 unsigned int cursor = 0;
1039 mc_pair_stateless_t next_pair = NULL;
1040 mc_pair_stateless_t pair_succ;
1042 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
1044 //set_pair_visited(current_pair->automaton_state, search_cycle);
1045 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
1047 //XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
1048 XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
1050 if(current_pair->requests > 0){
1052 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1054 /* Debug information */
1055 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
1056 req_str = MC_request_to_string(req, value);
1057 XBT_DEBUG("Execute: %s", req_str);
1061 MC_state_set_executed_request(current_pair->graph_state, req, value);
1063 /* Answer the request */
1064 SIMIX_simcall_pre(req, value);
1066 /* Wait for requests (schedules processes) */
1067 MC_wait_for_requests();
1072 /* Create the new expanded graph_state */
1073 next_graph_state = MC_state_pair_new();
1075 /* Get enabled process and insert it in the interleave set of the next graph_state */
1076 xbt_swag_foreach(process, simix_global->process_list){
1077 if(MC_process_is_enabled(process)){
1078 MC_state_interleave_process(next_graph_state, process);
1082 xbt_dynar_reset(successors);
1088 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1090 res = MC_automaton_evaluate_label(transition_succ->label);
1092 if(res == 1){ // enabled transition in automaton
1094 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1095 xbt_dynar_push(successors, &next_pair);
1103 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1105 res = MC_automaton_evaluate_label(transition_succ->label);
1107 if(res == 2){ // true transition in automaton
1109 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1110 xbt_dynar_push(successors, &next_pair);
1118 xbt_dynar_foreach(successors, cursor, pair_succ){
1120 if(search_cycle == 1){
1122 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1124 if(reached(pair_succ->automaton_state)){
1125 //if(reached_hash(pair_succ->automaton_state)){
1127 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));
1129 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1130 XBT_INFO("| ACCEPTANCE CYCLE |");
1131 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1132 XBT_INFO("Counter-example that violates formula :");
1133 MC_show_stack_liveness(mc_stack_liveness);
1134 MC_dump_stack_liveness(mc_stack_liveness);
1135 MC_print_statistics_pairs(mc_stats_pair);
1140 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);
1142 set_pair_reached(pair_succ->automaton_state);
1143 //set_pair_reached_hash(pair_succ->automaton_state);
1145 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1146 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1149 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1152 MC_ddfs(search_cycle);
1158 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1159 //if(!visited(pair_succ->automaton_state, search_cycle)){
1162 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1165 MC_ddfs(search_cycle);
1169 XBT_DEBUG("Next pair already visited ! ");
1177 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1179 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);
1181 set_pair_reached(pair_succ->automaton_state);
1182 //set_pair_reached_hash(pair_succ->automaton_state);
1186 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1187 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1191 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1192 //if(!visited(pair_succ->automaton_state, search_cycle)){
1195 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1198 MC_ddfs(search_cycle);
1202 XBT_DEBUG("Next pair already visited ! ");
1209 /* Restore system before checking others successors */
1210 if(cursor != (xbt_dynar_length(successors) - 1))
1211 MC_replay_liveness(mc_stack_liveness, 1);
1216 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1217 XBT_DEBUG("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1218 MC_replay_liveness(mc_stack_liveness, 0);
1223 }else{ /*No request to execute, search evolution in Büchi automaton */
1227 /* Create the new expanded graph_state */
1228 next_graph_state = MC_state_pair_new();
1230 xbt_dynar_reset(successors);
1236 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1238 res = MC_automaton_evaluate_label(transition_succ->label);
1240 if(res == 1){ // enabled transition in automaton
1242 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1243 xbt_dynar_push(successors, &next_pair);
1251 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1253 res = MC_automaton_evaluate_label(transition_succ->label);
1255 if(res == 2){ // true transition in automaton
1257 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1258 xbt_dynar_push(successors, &next_pair);
1266 xbt_dynar_foreach(successors, cursor, pair_succ){
1268 if(search_cycle == 1){
1270 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1272 if(reached(pair_succ->automaton_state)){
1273 //if(reached_hash(pair_succ->automaton_state)){
1275 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1277 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1278 XBT_INFO("| ACCEPTANCE CYCLE |");
1279 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1280 XBT_INFO("Counter-example that violates formula :");
1281 MC_show_stack_liveness(mc_stack_liveness);
1282 MC_dump_stack_liveness(mc_stack_liveness);
1283 MC_print_statistics_pairs(mc_stats_pair);
1288 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);
1290 set_pair_reached(pair_succ->automaton_state);
1291 //set_pair_reached_hash(pair_succ->automaton_state);
1293 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1294 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1297 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1300 MC_ddfs(search_cycle);
1306 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1307 //if(!visited(pair_succ->automaton_state, search_cycle)){
1310 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1313 MC_ddfs(search_cycle);
1317 XBT_DEBUG("Next pair already visited ! ");
1325 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1327 set_pair_reached(pair_succ->automaton_state);
1328 //set_pair_reached_hash(pair_succ->automaton_state);
1332 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1333 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1337 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1338 //if(!visited(pair_succ->automaton_state, search_cycle)){
1341 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1344 MC_ddfs(search_cycle);
1348 XBT_DEBUG("Next pair already visited ! ");
1354 /* Restore system before checking others successors */
1355 if(cursor != xbt_dynar_length(successors) - 1)
1356 MC_replay_liveness(mc_stack_liveness, 1);
1365 XBT_DEBUG("Max depth reached");
1369 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1370 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) );
1372 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) );
1377 xbt_fifo_shift(mc_stack_liveness);
1378 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1379 xbt_dynar_pop(reached_pairs, NULL);
1380 //xbt_dynar_pop(reached_pairs_hash, NULL);