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 xbt_dynar_t lfields = NULL;
52 xbt_dynar_t start_end = NULL;
56 while ((read = getline(&line, &n, fp)) != -1) {
58 xbt_str_trim(line, NULL);
59 xbt_str_strip_spaces(line);
60 lfields = xbt_str_split(line,NULL);
62 start_end = xbt_str_split(xbt_dynar_get_as(lfields, 0, char*), "-");
63 start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16);
64 end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16);
66 if((addr > start_addr) && ( addr < end_addr)){
69 if(start_addr == std_heap)
71 if(start_addr == raw_heap)
73 if(xbt_dynar_length(lfields) == 6)
74 return xbt_dynar_get_as(lfields, xbt_dynar_length(lfields) - 1, char*);
83 return "Unknown area";
87 int data_program_region_compare(void *d1, void *d2, size_t size){
92 for(i=0; i<size; i++){
93 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
94 fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
96 pointer_align = (i /sizeof(void *)) * sizeof(void *);
97 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))));
101 fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
106 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
111 for(i=0; i<size; i++){
112 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
113 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region\n", i, (char *)d1 + i, (char *)d2 + i);
115 pointer_align = (i /sizeof(void *)) * sizeof(void *);
116 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))));
120 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
125 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap){
128 if(s1->num_reg != s2->num_reg){
129 XBT_DEBUG("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
136 for(i=0 ; i< s1->num_reg ; i++){
138 if(s1->regions[i]->type != s2->regions[i]->type){
139 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
140 XBT_DEBUG("Different type of region");
147 switch(s1->regions[i]->type){
149 if(s1->regions[i]->size != s2->regions[i]->size){
150 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
151 XBT_DEBUG("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
157 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
158 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
159 XBT_DEBUG("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
165 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
166 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
167 XBT_DEBUG("Different heap (mmalloc_compare)");
175 if(s1->regions[i]->size != s2->regions[i]->size){
176 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
177 XBT_DEBUG("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
183 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
184 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
185 XBT_DEBUG("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
191 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
192 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
193 XBT_DEBUG("Different memcmp for data in libsimgrid");
201 if(s1->regions[i]->size != s2->regions[i]->size){
202 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
203 XBT_DEBUG("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
209 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
210 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
211 XBT_DEBUG("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
217 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
218 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
219 XBT_DEBUG("Different memcmp for data in libsimgrid");
235 int reached(xbt_state_t st){
238 if(xbt_dynar_is_empty(reached_pairs)){
246 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
247 MC_take_snapshot_liveness(sn);
249 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
253 /* Get values of propositional symbols */
254 unsigned int cursor = 0;
255 xbt_propositional_symbol_t ps = NULL;
256 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
257 f = (int_f_void_t)ps->function;
259 xbt_dynar_push_as(prop_ato, int, res);
263 mc_pair_reached_t pair_test = NULL;
265 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
267 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
268 XBT_DEBUG("Pair reached #%u", cursor+1);
269 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
270 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
271 //XBT_DEBUG("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
272 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
273 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
274 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
275 MC_free_snapshot(sn);
276 xbt_dynar_reset(prop_ato);
283 XBT_DEBUG("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
286 XBT_DEBUG("Different values of propositional symbols");
289 XBT_DEBUG("Different automaton state");
293 MC_free_snapshot(sn);
294 xbt_dynar_reset(prop_ato);
302 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
304 xbt_dict_cursor_t cursor_dict = NULL;
307 smx_rdv_t rdv1, rdv2;
308 xbt_fifo_item_t item1, item2;
309 smx_action_t action1, action2;
310 xbt_fifo_item_t item_req1, item_req2;
311 smx_simcall_t req1, req2;
315 xbt_dict_foreach(d1, cursor_dict, key, data){
316 rdv1 = (smx_rdv_t)data;
317 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
319 XBT_DEBUG("Rdv point unknown");
322 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
323 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) );
327 XBT_DEBUG("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
329 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
330 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
332 while(i<xbt_fifo_size(rdv1->comm_fifo)){
333 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
334 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
336 if(action1->type != action2->type){
337 XBT_DEBUG("Different type of action");
341 if(action1->state != action2->state){
342 XBT_DEBUG("Different state of action");
346 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
347 XBT_DEBUG("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
351 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
352 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
354 while(j<xbt_fifo_size(action1->simcalls)){
356 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
357 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
359 if(req1->call != req2->call){
360 XBT_DEBUG("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
363 if(req1->issuer->pid != req2->issuer->pid){
364 XBT_DEBUG("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
368 item_req1 = xbt_fifo_get_next_item(item_req1);
369 item_req2 = xbt_fifo_get_next_item(item_req2);
375 switch(action1->type){
376 case 0: /* execution */
377 case 1: /* parallel execution */
378 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
382 if(action1->comm.type != action2->comm.type)
384 //XBT_DEBUG("Type of comm : %d", action1->comm.type);
386 switch(action1->comm.type){
388 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
390 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
393 case 1: /* RECEIVE */
394 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
396 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
400 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
402 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
404 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
406 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
410 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
412 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
414 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
416 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
420 } /* end of switch on type of comm */
422 if(action1->comm.refcount != action2->comm.refcount)
424 if(action1->comm.detached != action2->comm.detached)
426 if(action1->comm.rate != action2->comm.rate)
428 if(action1->comm.task_size != action2->comm.task_size)
430 if(action1->comm.src_buff != action2->comm.src_buff)
432 if(action1->comm.dst_buff != action2->comm.dst_buff)
434 if(action1->comm.src_data != action2->comm.src_data)
436 if(action1->comm.dst_data != action2->comm.dst_data)
441 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
444 case 4: /* synchro */
451 item1 = xbt_fifo_get_next_item(item1);
452 item2 = xbt_fifo_get_next_item(item2);
463 void set_pair_reached(xbt_state_t st){
468 mc_pair_reached_t pair = NULL;
469 pair = xbt_new0(s_mc_pair_reached_t, 1);
470 pair->automaton_state = st;
471 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
472 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
473 //pair->rdv_points = xbt_dict_new();
474 MC_take_snapshot_liveness(pair->system_state);
476 /* Get values of propositional symbols */
477 unsigned int cursor = 0;
478 xbt_propositional_symbol_t ps = NULL;
482 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
483 f = (int_f_void_t)ps->function;
485 xbt_dynar_push_as(pair->prop_ato, int, res);
488 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
490 xbt_dict_cursor_t cursor_dict = NULL;
493 xbt_fifo_item_t item;
496 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
497 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
498 new_rdv->name = strdup(((smx_rdv_t)data)->name);
499 new_rdv->comm_fifo = xbt_fifo_new();
500 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
501 smx_action_t a = xbt_new0(s_smx_action_t, 1);
502 memcpy(a, action, sizeof(s_smx_action_t));
503 xbt_fifo_push(new_rdv->comm_fifo, a);
504 XBT_DEBUG("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
506 XBT_DEBUG("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
508 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
509 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
512 xbt_dynar_push(reached_pairs, &pair);
519 int reached_hash(xbt_state_t st){
522 if(xbt_dynar_is_empty(reached_pairs_hash)){
530 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
531 MC_take_snapshot_liveness(sn);
534 unsigned int hash_regions[sn->num_reg];
535 for(j=0; j<sn->num_reg; j++){
536 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
540 /* Get values of propositional symbols */
541 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
542 unsigned int cursor = 0;
543 xbt_propositional_symbol_t ps = NULL;
547 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
548 f = (int_f_void_t)ps->function;
550 xbt_dynar_push_as(prop_ato, int, res);
553 mc_pair_reached_hash_t pair_test = NULL;
559 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
561 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
562 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
563 for(j=0 ; j< sn->num_reg ; j++){
564 if(hash_regions[j] != pair_test->hash_regions[j]){
568 if(region_diff == 0){
569 MC_free_snapshot(sn);
570 xbt_dynar_reset(prop_ato);
575 XBT_DEBUG("Different snapshot");
578 XBT_DEBUG("Different values of propositional symbols");
581 XBT_DEBUG("Different automaton state");
587 MC_free_snapshot(sn);
588 xbt_dynar_reset(prop_ato);
596 void set_pair_reached_hash(xbt_state_t st){
600 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
601 MC_take_snapshot_liveness(sn);
603 mc_pair_reached_hash_t pair = NULL;
604 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
605 pair->automaton_state = st;
606 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
607 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
611 for(i=0 ; i< sn->num_reg ; i++){
612 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
615 /* Get values of propositional symbols */
616 unsigned int cursor = 0;
617 xbt_propositional_symbol_t ps = NULL;
621 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
622 f = (int_f_void_t)ps->function;
624 xbt_dynar_push_as(pair->prop_ato, int, res);
627 xbt_dynar_push(reached_pairs_hash, &pair);
629 MC_free_snapshot(sn);
636 int visited(xbt_state_t st, int sc){
639 if(xbt_dynar_is_empty(visited_pairs)){
647 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
648 MC_take_snapshot_liveness(sn);
650 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
652 /* Get values of propositional symbols */
653 unsigned int cursor = 0;
654 xbt_propositional_symbol_t ps = NULL;
658 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
659 f = (int_f_void_t)ps->function;
661 xbt_dynar_push_as(prop_ato, int, res);
665 mc_pair_visited_t pair_test = NULL;
667 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
668 if(pair_test->search_cycle == sc) {
669 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
670 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
671 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
673 MC_free_snapshot(sn);
674 xbt_dynar_reset(prop_ato);
681 XBT_DEBUG("Different snapshot");
684 XBT_DEBUG("Different values of propositional symbols");
687 XBT_DEBUG("Different automaton state");
690 XBT_DEBUG("Different value of search_cycle");
695 MC_free_snapshot(sn);
696 xbt_dynar_reset(prop_ato);
705 int visited_hash(xbt_state_t st, int sc){
708 if(xbt_dynar_is_empty(visited_pairs_hash)){
716 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
717 MC_take_snapshot_liveness(sn);
720 unsigned int hash_regions[sn->num_reg];
721 for(j=0; j<sn->num_reg; j++){
722 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
726 /* Get values of propositional symbols */
727 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
728 unsigned int cursor = 0;
729 xbt_propositional_symbol_t ps = NULL;
733 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
734 f = (int_f_void_t)ps->function;
736 xbt_dynar_push_as(prop_ato, int, res);
739 mc_pair_visited_hash_t pair_test = NULL;
744 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
746 if(pair_test->search_cycle == sc) {
747 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
748 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
749 for(j=0 ; j< sn->num_reg ; j++){
750 if(hash_regions[j] != pair_test->hash_regions[j]){
754 if(region_diff == 0){
755 MC_free_snapshot(sn);
756 xbt_dynar_reset(prop_ato);
761 //XBT_DEBUG("Different snapshot");
764 //XBT_DEBUG("Different values of propositional symbols");
767 //XBT_DEBUG("Different automaton state");
770 //XBT_DEBUG("Different value of search_cycle");
776 MC_free_snapshot(sn);
777 xbt_dynar_reset(prop_ato);
785 void set_pair_visited_hash(xbt_state_t st, int sc){
789 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
790 MC_take_snapshot_liveness(sn);
792 mc_pair_visited_hash_t pair = NULL;
793 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
794 pair->automaton_state = st;
795 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
796 pair->search_cycle = sc;
797 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
801 for(i=0 ; i< sn->num_reg ; i++){
802 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
805 /* Get values of propositional symbols */
806 unsigned int cursor = 0;
807 xbt_propositional_symbol_t ps = NULL;
811 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
812 f = (int_f_void_t)ps->function;
814 xbt_dynar_push_as(pair->prop_ato, int, res);
817 xbt_dynar_push(visited_pairs_hash, &pair);
819 MC_free_snapshot(sn);
825 void set_pair_visited(xbt_state_t st, int sc){
830 mc_pair_visited_t pair = NULL;
831 pair = xbt_new0(s_mc_pair_visited_t, 1);
832 pair->automaton_state = st;
833 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
834 pair->search_cycle = sc;
835 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
836 MC_take_snapshot_liveness(pair->system_state);
839 /* Get values of propositional symbols */
840 unsigned int cursor = 0;
841 xbt_propositional_symbol_t ps = NULL;
845 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
846 f = (int_f_void_t)ps->function;
848 xbt_dynar_push_as(pair->prop_ato, int, res);
851 xbt_dynar_push(visited_pairs, &pair);
858 void MC_pair_delete(mc_pair_t pair){
859 xbt_free(pair->graph_state->proc_status);
860 xbt_free(pair->graph_state);
866 int MC_automaton_evaluate_label(xbt_exp_label_t l){
870 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
871 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
872 return (left_res || right_res);
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 res = MC_automaton_evaluate_label(l->u.exp_not);
884 unsigned int cursor = 0;
885 xbt_propositional_symbol_t p = NULL;
887 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
888 if(strcmp(p->pred, l->u.predicat) == 0){
889 f = (int_f_void_t)p->function;
904 /********************* Double-DFS stateless *******************/
906 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
907 xbt_free(pair->graph_state->proc_status);
908 xbt_free(pair->graph_state);
912 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
913 mc_pair_stateless_t p = NULL;
914 p = xbt_new0(s_mc_pair_stateless_t, 1);
915 p->automaton_state = st;
918 mc_stats_pair->expanded_pairs++;
922 void MC_ddfs_init(void){
924 XBT_DEBUG("**************************************************");
925 XBT_DEBUG("Double-DFS init");
926 XBT_DEBUG("**************************************************");
928 mc_pair_stateless_t mc_initial_pair = NULL;
929 mc_state_t initial_graph_state = NULL;
930 smx_process_t process;
933 MC_wait_for_requests();
937 initial_graph_state = MC_state_pair_new();
938 xbt_swag_foreach(process, simix_global->process_list){
939 if(MC_process_is_enabled(process)){
940 MC_state_interleave_process(initial_graph_state, process);
944 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
945 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
946 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
947 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
948 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
950 /* Save the initial state */
951 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
952 MC_take_snapshot_liveness(initial_snapshot_liveness);
956 unsigned int cursor = 0;
959 xbt_dynar_foreach(automaton->states, cursor, state){
960 if(state->type == -1){
963 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
964 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
968 MC_restore_snapshot(initial_snapshot_liveness);
975 if(state->type == 2){
978 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
979 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
982 set_pair_reached(state);
983 //set_pair_reached_hash(state);
986 MC_restore_snapshot(initial_snapshot_liveness);
999 void MC_ddfs(int search_cycle){
1001 smx_process_t process;
1002 mc_pair_stateless_t current_pair = NULL;
1004 if(xbt_fifo_size(mc_stack_liveness) == 0)
1008 /* Get current pair */
1009 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
1011 /* Update current state in buchi automaton */
1012 automaton->current_state = current_pair->automaton_state;
1015 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
1016 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));
1018 mc_stats_pair->visited_pairs++;
1023 mc_state_t next_graph_state = NULL;
1024 smx_simcall_t req = NULL;
1027 xbt_transition_t transition_succ;
1028 unsigned int cursor = 0;
1031 mc_pair_stateless_t next_pair = NULL;
1032 mc_pair_stateless_t pair_succ;
1034 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
1036 //set_pair_visited(current_pair->automaton_state, search_cycle);
1037 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
1039 //XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
1040 XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
1042 if(current_pair->requests > 0){
1044 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1046 /* Debug information */
1047 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
1048 req_str = MC_request_to_string(req, value);
1049 XBT_DEBUG("Execute: %s", req_str);
1053 MC_state_set_executed_request(current_pair->graph_state, req, value);
1055 /* Answer the request */
1056 SIMIX_simcall_pre(req, value);
1058 /* Wait for requests (schedules processes) */
1059 MC_wait_for_requests();
1064 /* Create the new expanded graph_state */
1065 next_graph_state = MC_state_pair_new();
1067 /* Get enabled process and insert it in the interleave set of the next graph_state */
1068 xbt_swag_foreach(process, simix_global->process_list){
1069 if(MC_process_is_enabled(process)){
1070 MC_state_interleave_process(next_graph_state, process);
1074 xbt_dynar_reset(successors);
1080 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1082 res = MC_automaton_evaluate_label(transition_succ->label);
1084 if(res == 1){ // enabled transition in automaton
1086 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1087 xbt_dynar_push(successors, &next_pair);
1095 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1097 res = MC_automaton_evaluate_label(transition_succ->label);
1099 if(res == 2){ // true transition in automaton
1101 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1102 xbt_dynar_push(successors, &next_pair);
1110 xbt_dynar_foreach(successors, cursor, pair_succ){
1112 if(search_cycle == 1){
1114 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1116 if(reached(pair_succ->automaton_state)){
1117 //if(reached_hash(pair_succ->automaton_state)){
1119 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));
1121 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1122 XBT_INFO("| ACCEPTANCE CYCLE |");
1123 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1124 XBT_INFO("Counter-example that violates formula :");
1125 MC_show_stack_liveness(mc_stack_liveness);
1126 MC_dump_stack_liveness(mc_stack_liveness);
1127 MC_print_statistics_pairs(mc_stats_pair);
1132 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);
1134 set_pair_reached(pair_succ->automaton_state);
1135 //set_pair_reached_hash(pair_succ->automaton_state);
1137 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1138 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1141 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1144 MC_ddfs(search_cycle);
1150 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1151 //if(!visited(pair_succ->automaton_state, search_cycle)){
1154 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1157 MC_ddfs(search_cycle);
1161 XBT_DEBUG("Next pair already visited ! ");
1169 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1171 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);
1173 set_pair_reached(pair_succ->automaton_state);
1174 //set_pair_reached_hash(pair_succ->automaton_state);
1178 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1179 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1183 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1184 //if(!visited(pair_succ->automaton_state, search_cycle)){
1187 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1190 MC_ddfs(search_cycle);
1194 XBT_DEBUG("Next pair already visited ! ");
1201 /* Restore system before checking others successors */
1202 if(cursor != (xbt_dynar_length(successors) - 1))
1203 MC_replay_liveness(mc_stack_liveness, 1);
1208 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1209 XBT_DEBUG("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1210 MC_replay_liveness(mc_stack_liveness, 0);
1215 }else{ /*No request to execute, search evolution in Büchi automaton */
1219 /* Create the new expanded graph_state */
1220 next_graph_state = MC_state_pair_new();
1222 xbt_dynar_reset(successors);
1228 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1230 res = MC_automaton_evaluate_label(transition_succ->label);
1232 if(res == 1){ // enabled transition in automaton
1234 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1235 xbt_dynar_push(successors, &next_pair);
1243 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1245 res = MC_automaton_evaluate_label(transition_succ->label);
1247 if(res == 2){ // true transition in automaton
1249 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1250 xbt_dynar_push(successors, &next_pair);
1258 xbt_dynar_foreach(successors, cursor, pair_succ){
1260 if(search_cycle == 1){
1262 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1264 if(reached(pair_succ->automaton_state)){
1265 //if(reached_hash(pair_succ->automaton_state)){
1267 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1269 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1270 XBT_INFO("| ACCEPTANCE CYCLE |");
1271 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1272 XBT_INFO("Counter-example that violates formula :");
1273 MC_show_stack_liveness(mc_stack_liveness);
1274 MC_dump_stack_liveness(mc_stack_liveness);
1275 MC_print_statistics_pairs(mc_stats_pair);
1280 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);
1282 set_pair_reached(pair_succ->automaton_state);
1283 //set_pair_reached_hash(pair_succ->automaton_state);
1285 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1286 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1289 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1292 MC_ddfs(search_cycle);
1298 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1299 //if(!visited(pair_succ->automaton_state, search_cycle)){
1302 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1305 MC_ddfs(search_cycle);
1309 XBT_DEBUG("Next pair already visited ! ");
1317 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1319 set_pair_reached(pair_succ->automaton_state);
1320 //set_pair_reached_hash(pair_succ->automaton_state);
1324 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1325 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1329 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1330 //if(!visited(pair_succ->automaton_state, search_cycle)){
1333 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1336 MC_ddfs(search_cycle);
1340 XBT_DEBUG("Next pair already visited ! ");
1346 /* Restore system before checking others successors */
1347 if(cursor != xbt_dynar_length(successors) - 1)
1348 MC_replay_liveness(mc_stack_liveness, 1);
1357 XBT_DEBUG("Max depth reached");
1361 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1362 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) );
1364 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) );
1369 xbt_fifo_shift(mc_stack_liveness);
1370 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1371 xbt_dynar_pop(reached_pairs, NULL);
1372 //xbt_dynar_pop(reached_pairs_hash, NULL);