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, *map;
56 while ((read = getline(&line, &n, fp)) != -1) {
58 line[read - 1] = '\0';
60 lfields[0] = strtok(line, " ");
62 for (i = 1; i < 5 && lfields[i - 1] != NULL; i++) {
63 lfields[i] = strtok(NULL, " ");
66 map = strtok(NULL, " ");
68 lfields[5] = strdup(map);
70 lfields[5] = strdup("Anonymous");
72 start = strtok(lfields[0], "-");
73 start_addr = (void *) strtoul(start, &endptr, 16);
75 if(start_addr == std_heap)
76 lfields[5] = strdup("std_heap");
77 if(start_addr == raw_heap)
78 lfields[5] = strdup("raw_heap");
79 end = strtok(NULL, "-");
80 end_addr = (void *) strtoul(end, &endptr, 16);
82 if((addr > start_addr) && ( addr < end_addr)){
85 if(lfields[5] != NULL){
94 return "Unknown area";
98 int data_program_region_compare(void *d1, void *d2, size_t size){
103 for(i=0; i<size; i++){
104 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
105 fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
107 pointer_align = (i /sizeof(void *)) * sizeof(void *);
108 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))));
112 fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
117 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
122 for(i=0; i<size; i++){
123 if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
124 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region\n", i, (char *)d1 + i, (char *)d2 + i);
126 pointer_align = (i /sizeof(void *)) * sizeof(void *);
127 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))));
131 fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
136 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap){
139 if(s1->num_reg != s2->num_reg){
140 XBT_DEBUG("Different num_reg (s1 = %u, s2 = %u)", s1->num_reg, s2->num_reg);
147 for(i=0 ; i< s1->num_reg ; i++){
149 if(s1->regions[i]->type != s2->regions[i]->type){
150 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
151 XBT_DEBUG("Different type of region");
158 switch(s1->regions[i]->type){
160 if(s1->regions[i]->size != s2->regions[i]->size){
161 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
162 XBT_DEBUG("Different size of heap (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
168 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
169 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
170 XBT_DEBUG("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
176 if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
177 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
178 XBT_DEBUG("Different heap (mmalloc_compare)");
186 if(s1->regions[i]->size != s2->regions[i]->size){
187 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
188 XBT_DEBUG("Different size of libsimgrid (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
194 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
195 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
196 XBT_DEBUG("Different start addr of libsimgrid (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
202 if(data_program_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
203 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
204 XBT_DEBUG("Different memcmp for data in libsimgrid");
212 if(s1->regions[i]->size != s2->regions[i]->size){
213 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
214 XBT_DEBUG("Different size of data program (s1 = %zu, s2 = %zu)", s1->regions[i]->size, s2->regions[i]->size);
220 if(s1->regions[i]->start_addr != s2->regions[i]->start_addr){
221 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
222 XBT_DEBUG("Different start addr of data program (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
228 if(data_libsimgrid_region_compare(s1->regions[i]->data, s2->regions[i]->data, s1->regions[i]->size) != 0){
229 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
230 XBT_DEBUG("Different memcmp for data in libsimgrid");
246 int reached(xbt_state_t st){
249 if(xbt_dynar_is_empty(reached_pairs)){
257 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
258 MC_take_snapshot_liveness(sn);
260 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
264 /* Get values of propositional symbols */
265 unsigned int cursor = 0;
266 xbt_propositional_symbol_t ps = NULL;
267 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
268 f = (int_f_void_t)ps->function;
270 xbt_dynar_push_as(prop_ato, int, res);
274 mc_pair_reached_t pair_test = NULL;
276 //xbt_dict_t current_rdv_points = SIMIX_get_rdv_points();
278 xbt_dynar_foreach(reached_pairs, cursor, pair_test){
279 XBT_DEBUG("Pair reached #%u", cursor+1);
280 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
281 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
282 //XBT_DEBUG("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
283 //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
284 //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
285 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
286 MC_free_snapshot(sn);
287 xbt_dynar_reset(prop_ato);
294 XBT_DEBUG("Different size of rdv points (%d - %d)",xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points) );
297 XBT_DEBUG("Different values of propositional symbols");
300 XBT_DEBUG("Different automaton state");
304 MC_free_snapshot(sn);
305 xbt_dynar_reset(prop_ato);
313 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2){ /* d1 = pair_test, d2 = current_pair */
315 xbt_dict_cursor_t cursor_dict = NULL;
318 smx_rdv_t rdv1, rdv2;
319 xbt_fifo_item_t item1, item2;
320 smx_action_t action1, action2;
321 xbt_fifo_item_t item_req1, item_req2;
322 smx_simcall_t req1, req2;
326 xbt_dict_foreach(d1, cursor_dict, key, data){
327 rdv1 = (smx_rdv_t)data;
328 rdv2 = xbt_dict_get_or_null(d2, rdv1->name);
330 XBT_DEBUG("Rdv point unknown");
333 if(xbt_fifo_size(rdv1->comm_fifo) != xbt_fifo_size(rdv2->comm_fifo)){
334 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) );
338 XBT_DEBUG("Total of actions in mailbox \"%s\" : %d", rdv1->name, xbt_fifo_size(rdv1->comm_fifo));
340 item1 = xbt_fifo_get_first_item(rdv1->comm_fifo);
341 item2 = xbt_fifo_get_first_item(rdv2->comm_fifo);
343 while(i<xbt_fifo_size(rdv1->comm_fifo)){
344 action1 = (smx_action_t) xbt_fifo_get_item_content(item1);
345 action2 = (smx_action_t) xbt_fifo_get_item_content(item2);
347 if(action1->type != action2->type){
348 XBT_DEBUG("Different type of action");
352 if(action1->state != action2->state){
353 XBT_DEBUG("Different state of action");
357 if(xbt_fifo_size(action1->simcalls) != xbt_fifo_size(action2->simcalls)){
358 XBT_DEBUG("Different size of simcall list (%d - %d", xbt_fifo_size(action1->simcalls), xbt_fifo_size(action2->simcalls));
362 item_req1 = xbt_fifo_get_first_item(action1->simcalls);
363 item_req2 = xbt_fifo_get_first_item(action2->simcalls);
365 while(j<xbt_fifo_size(action1->simcalls)){
367 req1 = (smx_simcall_t) xbt_fifo_get_item_content(item_req1);
368 req2 = (smx_simcall_t) xbt_fifo_get_item_content(item_req2);
370 if(req1->call != req2->call){
371 XBT_DEBUG("Different simcall call in simcalls of action (%d - %d)", (int)req1->call, (int)req2->call);
374 if(req1->issuer->pid != req2->issuer->pid){
375 XBT_DEBUG("Different simcall issuer in simcalls of action (%lu- %lu)", req1->issuer->pid, req2->issuer->pid);
379 item_req1 = xbt_fifo_get_next_item(item_req1);
380 item_req2 = xbt_fifo_get_next_item(item_req2);
386 switch(action1->type){
387 case 0: /* execution */
388 case 1: /* parallel execution */
389 if(strcmp(action1->execution.host->name, action2->execution.host->name) != 0)
393 if(action1->comm.type != action2->comm.type)
395 //XBT_DEBUG("Type of comm : %d", action1->comm.type);
397 switch(action1->comm.type){
399 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
401 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
404 case 1: /* RECEIVE */
405 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
407 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
411 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
413 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
415 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
417 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
421 if(action1->comm.src_proc->pid != action2->comm.src_proc->pid)
423 if(strcmp(action1->comm.src_proc->smx_host->name, action2->comm.src_proc->smx_host->name) != 0)
425 if(action1->comm.dst_proc->pid != action2->comm.dst_proc->pid)
427 if(strcmp(action1->comm.dst_proc->smx_host->name, action2->comm.dst_proc->smx_host->name) != 0)
431 } /* end of switch on type of comm */
433 if(action1->comm.refcount != action2->comm.refcount)
435 if(action1->comm.detached != action2->comm.detached)
437 if(action1->comm.rate != action2->comm.rate)
439 if(action1->comm.task_size != action2->comm.task_size)
441 if(action1->comm.src_buff != action2->comm.src_buff)
443 if(action1->comm.dst_buff != action2->comm.dst_buff)
445 if(action1->comm.src_data != action2->comm.src_data)
447 if(action1->comm.dst_data != action2->comm.dst_data)
452 if(strcmp(action1->sleep.host->name, action2->sleep.host->name) != 0)
455 case 4: /* synchro */
462 item1 = xbt_fifo_get_next_item(item1);
463 item2 = xbt_fifo_get_next_item(item2);
474 void set_pair_reached(xbt_state_t st){
479 mc_pair_reached_t pair = NULL;
480 pair = xbt_new0(s_mc_pair_reached_t, 1);
481 pair->automaton_state = st;
482 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
483 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
484 //pair->rdv_points = xbt_dict_new();
485 MC_take_snapshot_liveness(pair->system_state);
487 /* Get values of propositional symbols */
488 unsigned int cursor = 0;
489 xbt_propositional_symbol_t ps = NULL;
493 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
494 f = (int_f_void_t)ps->function;
496 xbt_dynar_push_as(pair->prop_ato, int, res);
499 /*xbt_dict_t rdv_points = SIMIX_get_rdv_points();
501 xbt_dict_cursor_t cursor_dict = NULL;
504 xbt_fifo_item_t item;
507 xbt_dict_foreach(rdv_points, cursor_dict, key, data){
508 smx_rdv_t new_rdv = xbt_new0(s_smx_rvpoint_t, 1);
509 new_rdv->name = strdup(((smx_rdv_t)data)->name);
510 new_rdv->comm_fifo = xbt_fifo_new();
511 xbt_fifo_foreach(((smx_rdv_t)data)->comm_fifo, item, action, smx_action_t) {
512 smx_action_t a = xbt_new0(s_smx_action_t, 1);
513 memcpy(a, action, sizeof(s_smx_action_t));
514 xbt_fifo_push(new_rdv->comm_fifo, a);
515 XBT_DEBUG("New action (type = %d, state = %d) in mailbox \"%s\"", action->type, action->state, key);
517 XBT_DEBUG("Type of communication : %d, Ref count = %d", action->comm.type, action->comm.refcount);
519 //new_rdv->comm_fifo = xbt_fifo_copy(((smx_rdv_t)data)->comm_fifo);
520 xbt_dict_set(pair->rdv_points, new_rdv->name, new_rdv, NULL);
523 xbt_dynar_push(reached_pairs, &pair);
530 int reached_hash(xbt_state_t st){
533 if(xbt_dynar_is_empty(reached_pairs_hash)){
541 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
542 MC_take_snapshot_liveness(sn);
545 unsigned int hash_regions[sn->num_reg];
546 for(j=0; j<sn->num_reg; j++){
547 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
551 /* Get values of propositional symbols */
552 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
553 unsigned int cursor = 0;
554 xbt_propositional_symbol_t ps = NULL;
558 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
559 f = (int_f_void_t)ps->function;
561 xbt_dynar_push_as(prop_ato, int, res);
564 mc_pair_reached_hash_t pair_test = NULL;
570 xbt_dynar_foreach(reached_pairs_hash, cursor, pair_test){
572 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
573 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
574 for(j=0 ; j< sn->num_reg ; j++){
575 if(hash_regions[j] != pair_test->hash_regions[j]){
579 if(region_diff == 0){
580 MC_free_snapshot(sn);
581 xbt_dynar_reset(prop_ato);
586 XBT_DEBUG("Different snapshot");
589 XBT_DEBUG("Different values of propositional symbols");
592 XBT_DEBUG("Different automaton state");
598 MC_free_snapshot(sn);
599 xbt_dynar_reset(prop_ato);
607 void set_pair_reached_hash(xbt_state_t st){
611 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
612 MC_take_snapshot_liveness(sn);
614 mc_pair_reached_hash_t pair = NULL;
615 pair = xbt_new0(s_mc_pair_reached_hash_t, 1);
616 pair->automaton_state = st;
617 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
618 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
622 for(i=0 ; i< sn->num_reg ; i++){
623 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
626 /* Get values of propositional symbols */
627 unsigned int cursor = 0;
628 xbt_propositional_symbol_t ps = NULL;
632 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
633 f = (int_f_void_t)ps->function;
635 xbt_dynar_push_as(pair->prop_ato, int, res);
638 xbt_dynar_push(reached_pairs_hash, &pair);
640 MC_free_snapshot(sn);
647 int visited(xbt_state_t st, int sc){
650 if(xbt_dynar_is_empty(visited_pairs)){
658 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
659 MC_take_snapshot_liveness(sn);
661 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
663 /* Get values of propositional symbols */
664 unsigned int cursor = 0;
665 xbt_propositional_symbol_t ps = NULL;
669 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
670 f = (int_f_void_t)ps->function;
672 xbt_dynar_push_as(prop_ato, int, res);
676 mc_pair_visited_t pair_test = NULL;
678 xbt_dynar_foreach(visited_pairs, cursor, pair_test){
679 if(pair_test->search_cycle == sc) {
680 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
681 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
682 if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
684 MC_free_snapshot(sn);
685 xbt_dynar_reset(prop_ato);
692 XBT_DEBUG("Different snapshot");
695 XBT_DEBUG("Different values of propositional symbols");
698 XBT_DEBUG("Different automaton state");
701 XBT_DEBUG("Different value of search_cycle");
706 MC_free_snapshot(sn);
707 xbt_dynar_reset(prop_ato);
716 int visited_hash(xbt_state_t st, int sc){
719 if(xbt_dynar_is_empty(visited_pairs_hash)){
727 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
728 MC_take_snapshot_liveness(sn);
731 unsigned int hash_regions[sn->num_reg];
732 for(j=0; j<sn->num_reg; j++){
733 hash_regions[j] = hash_region(sn->regions[j]->data, sn->regions[j]->size);
737 /* Get values of propositional symbols */
738 xbt_dynar_t prop_ato = xbt_dynar_new(sizeof(int), NULL);
739 unsigned int cursor = 0;
740 xbt_propositional_symbol_t ps = NULL;
744 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
745 f = (int_f_void_t)ps->function;
747 xbt_dynar_push_as(prop_ato, int, res);
750 mc_pair_visited_hash_t pair_test = NULL;
755 xbt_dynar_foreach(visited_pairs_hash, cursor, pair_test){
757 if(pair_test->search_cycle == sc) {
758 if(automaton_state_compare(pair_test->automaton_state, st) == 0){
759 if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
760 for(j=0 ; j< sn->num_reg ; j++){
761 if(hash_regions[j] != pair_test->hash_regions[j]){
765 if(region_diff == 0){
766 MC_free_snapshot(sn);
767 xbt_dynar_reset(prop_ato);
772 //XBT_DEBUG("Different snapshot");
775 //XBT_DEBUG("Different values of propositional symbols");
778 //XBT_DEBUG("Different automaton state");
781 //XBT_DEBUG("Different value of search_cycle");
787 MC_free_snapshot(sn);
788 xbt_dynar_reset(prop_ato);
796 void set_pair_visited_hash(xbt_state_t st, int sc){
800 mc_snapshot_t sn = xbt_new0(s_mc_snapshot_t, 1);
801 MC_take_snapshot_liveness(sn);
803 mc_pair_visited_hash_t pair = NULL;
804 pair = xbt_new0(s_mc_pair_visited_hash_t, 1);
805 pair->automaton_state = st;
806 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
807 pair->search_cycle = sc;
808 pair->hash_regions = malloc(sizeof(unsigned int) * sn->num_reg);
812 for(i=0 ; i< sn->num_reg ; i++){
813 pair->hash_regions[i] = hash_region(sn->regions[i]->data, sn->regions[i]->size);
816 /* Get values of propositional symbols */
817 unsigned int cursor = 0;
818 xbt_propositional_symbol_t ps = NULL;
822 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
823 f = (int_f_void_t)ps->function;
825 xbt_dynar_push_as(pair->prop_ato, int, res);
828 xbt_dynar_push(visited_pairs_hash, &pair);
830 MC_free_snapshot(sn);
836 void set_pair_visited(xbt_state_t st, int sc){
841 mc_pair_visited_t pair = NULL;
842 pair = xbt_new0(s_mc_pair_visited_t, 1);
843 pair->automaton_state = st;
844 pair->prop_ato = xbt_dynar_new(sizeof(int), NULL);
845 pair->search_cycle = sc;
846 pair->system_state = xbt_new0(s_mc_snapshot_t, 1);
847 MC_take_snapshot_liveness(pair->system_state);
850 /* Get values of propositional symbols */
851 unsigned int cursor = 0;
852 xbt_propositional_symbol_t ps = NULL;
856 xbt_dynar_foreach(automaton->propositional_symbols, cursor, ps){
857 f = (int_f_void_t)ps->function;
859 xbt_dynar_push_as(pair->prop_ato, int, res);
862 xbt_dynar_push(visited_pairs, &pair);
869 void MC_pair_delete(mc_pair_t pair){
870 xbt_free(pair->graph_state->proc_status);
871 xbt_free(pair->graph_state);
877 int MC_automaton_evaluate_label(xbt_exp_label_t l){
881 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
882 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
883 return (left_res || right_res);
886 int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp);
887 int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp);
888 return (left_res && right_res);
891 int res = MC_automaton_evaluate_label(l->u.exp_not);
895 unsigned int cursor = 0;
896 xbt_propositional_symbol_t p = NULL;
898 xbt_dynar_foreach(automaton->propositional_symbols, cursor, p){
899 if(strcmp(p->pred, l->u.predicat) == 0){
900 f = (int_f_void_t)p->function;
915 /********************* Double-DFS stateless *******************/
917 void MC_pair_stateless_delete(mc_pair_stateless_t pair){
918 xbt_free(pair->graph_state->proc_status);
919 xbt_free(pair->graph_state);
923 mc_pair_stateless_t new_pair_stateless(mc_state_t sg, xbt_state_t st, int r){
924 mc_pair_stateless_t p = NULL;
925 p = xbt_new0(s_mc_pair_stateless_t, 1);
926 p->automaton_state = st;
929 mc_stats_pair->expanded_pairs++;
933 void MC_ddfs_init(void){
935 XBT_DEBUG("**************************************************");
936 XBT_DEBUG("Double-DFS init");
937 XBT_DEBUG("**************************************************");
939 mc_pair_stateless_t mc_initial_pair = NULL;
940 mc_state_t initial_graph_state = NULL;
941 smx_process_t process;
944 MC_wait_for_requests();
948 initial_graph_state = MC_state_pair_new();
949 xbt_swag_foreach(process, simix_global->process_list){
950 if(MC_process_is_enabled(process)){
951 MC_state_interleave_process(initial_graph_state, process);
955 reached_pairs = xbt_dynar_new(sizeof(mc_pair_reached_t), NULL);
956 //reached_pairs_hash = xbt_dynar_new(sizeof(mc_pair_reached_hash_t), NULL);
957 //visited_pairs = xbt_dynar_new(sizeof(mc_pair_visited_t), NULL);
958 visited_pairs_hash = xbt_dynar_new(sizeof(mc_pair_visited_hash_t), NULL);
959 successors = xbt_dynar_new(sizeof(mc_pair_stateless_t), NULL);
961 /* Save the initial state */
962 initial_snapshot_liveness = xbt_new0(s_mc_snapshot_t, 1);
963 MC_take_snapshot_liveness(initial_snapshot_liveness);
967 unsigned int cursor = 0;
970 xbt_dynar_foreach(automaton->states, cursor, state){
971 if(state->type == -1){
974 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
975 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
979 MC_restore_snapshot(initial_snapshot_liveness);
986 if(state->type == 2){
989 mc_initial_pair = new_pair_stateless(initial_graph_state, state, MC_state_interleave_size(initial_graph_state));
990 xbt_fifo_unshift(mc_stack_liveness, mc_initial_pair);
993 set_pair_reached(state);
994 //set_pair_reached_hash(state);
997 MC_restore_snapshot(initial_snapshot_liveness);
1010 void MC_ddfs(int search_cycle){
1012 smx_process_t process;
1013 mc_pair_stateless_t current_pair = NULL;
1015 if(xbt_fifo_size(mc_stack_liveness) == 0)
1019 /* Get current pair */
1020 current_pair = (mc_pair_stateless_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack_liveness));
1022 /* Update current state in buchi automaton */
1023 automaton->current_state = current_pair->automaton_state;
1026 XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d )", xbt_fifo_size(mc_stack_liveness), search_cycle);
1027 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));
1029 mc_stats_pair->visited_pairs++;
1034 mc_state_t next_graph_state = NULL;
1035 smx_simcall_t req = NULL;
1038 xbt_transition_t transition_succ;
1039 unsigned int cursor = 0;
1042 mc_pair_stateless_t next_pair = NULL;
1043 mc_pair_stateless_t pair_succ;
1045 if(xbt_fifo_size(mc_stack_liveness) < MAX_DEPTH_LIVENESS){
1047 //set_pair_visited(current_pair->automaton_state, search_cycle);
1048 set_pair_visited_hash(current_pair->automaton_state, search_cycle);
1050 //XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs));
1051 XBT_DEBUG("Visited pairs : %lu", xbt_dynar_length(visited_pairs_hash));
1053 if(current_pair->requests > 0){
1055 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
1057 /* Debug information */
1058 if(XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)){
1059 req_str = MC_request_to_string(req, value);
1060 XBT_DEBUG("Execute: %s", req_str);
1064 MC_state_set_executed_request(current_pair->graph_state, req, value);
1066 /* Answer the request */
1067 SIMIX_simcall_pre(req, value);
1069 /* Wait for requests (schedules processes) */
1070 MC_wait_for_requests();
1075 /* Create the new expanded graph_state */
1076 next_graph_state = MC_state_pair_new();
1078 /* Get enabled process and insert it in the interleave set of the next graph_state */
1079 xbt_swag_foreach(process, simix_global->process_list){
1080 if(MC_process_is_enabled(process)){
1081 MC_state_interleave_process(next_graph_state, process);
1085 xbt_dynar_reset(successors);
1091 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1093 res = MC_automaton_evaluate_label(transition_succ->label);
1095 if(res == 1){ // enabled transition in automaton
1097 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1098 xbt_dynar_push(successors, &next_pair);
1106 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1108 res = MC_automaton_evaluate_label(transition_succ->label);
1110 if(res == 2){ // true transition in automaton
1112 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1113 xbt_dynar_push(successors, &next_pair);
1121 xbt_dynar_foreach(successors, cursor, pair_succ){
1123 if(search_cycle == 1){
1125 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1127 if(reached(pair_succ->automaton_state)){
1128 //if(reached_hash(pair_succ->automaton_state)){
1130 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));
1132 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1133 XBT_INFO("| ACCEPTANCE CYCLE |");
1134 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1135 XBT_INFO("Counter-example that violates formula :");
1136 MC_show_stack_liveness(mc_stack_liveness);
1137 MC_dump_stack_liveness(mc_stack_liveness);
1138 MC_print_statistics_pairs(mc_stats_pair);
1143 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);
1145 set_pair_reached(pair_succ->automaton_state);
1146 //set_pair_reached_hash(pair_succ->automaton_state);
1148 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1149 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1152 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1155 MC_ddfs(search_cycle);
1161 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1162 //if(!visited(pair_succ->automaton_state, search_cycle)){
1165 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1168 MC_ddfs(search_cycle);
1172 XBT_DEBUG("Next pair already visited ! ");
1180 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1182 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);
1184 set_pair_reached(pair_succ->automaton_state);
1185 //set_pair_reached_hash(pair_succ->automaton_state);
1189 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1190 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1194 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1195 //if(!visited(pair_succ->automaton_state, search_cycle)){
1198 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1201 MC_ddfs(search_cycle);
1205 XBT_DEBUG("Next pair already visited ! ");
1212 /* Restore system before checking others successors */
1213 if(cursor != (xbt_dynar_length(successors) - 1))
1214 MC_replay_liveness(mc_stack_liveness, 1);
1219 if(MC_state_interleave_size(current_pair->graph_state) > 0){
1220 XBT_DEBUG("Backtracking to depth %d", xbt_fifo_size(mc_stack_liveness));
1221 MC_replay_liveness(mc_stack_liveness, 0);
1226 }else{ /*No request to execute, search evolution in Büchi automaton */
1230 /* Create the new expanded graph_state */
1231 next_graph_state = MC_state_pair_new();
1233 xbt_dynar_reset(successors);
1239 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1241 res = MC_automaton_evaluate_label(transition_succ->label);
1243 if(res == 1){ // enabled transition in automaton
1245 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1246 xbt_dynar_push(successors, &next_pair);
1254 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
1256 res = MC_automaton_evaluate_label(transition_succ->label);
1258 if(res == 2){ // true transition in automaton
1260 next_pair = new_pair_stateless(next_graph_state, transition_succ->dst, MC_state_interleave_size(next_graph_state));
1261 xbt_dynar_push(successors, &next_pair);
1269 xbt_dynar_foreach(successors, cursor, pair_succ){
1271 if(search_cycle == 1){
1273 if((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2)){
1275 if(reached(pair_succ->automaton_state)){
1276 //if(reached_hash(pair_succ->automaton_state)){
1278 XBT_DEBUG("Next pair (depth = %d) already reached !", xbt_fifo_size(mc_stack_liveness) + 1);
1280 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1281 XBT_INFO("| ACCEPTANCE CYCLE |");
1282 XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
1283 XBT_INFO("Counter-example that violates formula :");
1284 MC_show_stack_liveness(mc_stack_liveness);
1285 MC_dump_stack_liveness(mc_stack_liveness);
1286 MC_print_statistics_pairs(mc_stats_pair);
1291 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);
1293 set_pair_reached(pair_succ->automaton_state);
1294 //set_pair_reached_hash(pair_succ->automaton_state);
1296 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1297 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1300 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1303 MC_ddfs(search_cycle);
1309 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1310 //if(!visited(pair_succ->automaton_state, search_cycle)){
1313 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1316 MC_ddfs(search_cycle);
1320 XBT_DEBUG("Next pair already visited ! ");
1328 if(((pair_succ->automaton_state->type == 1) || (pair_succ->automaton_state->type == 2))){
1330 set_pair_reached(pair_succ->automaton_state);
1331 //set_pair_reached_hash(pair_succ->automaton_state);
1335 XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs));
1336 //XBT_DEBUG("Reached pairs : %lu", xbt_dynar_length(reached_pairs_hash));
1340 if(!visited_hash(pair_succ->automaton_state, search_cycle)){
1341 //if(!visited(pair_succ->automaton_state, search_cycle)){
1344 xbt_fifo_unshift(mc_stack_liveness, pair_succ);
1347 MC_ddfs(search_cycle);
1351 XBT_DEBUG("Next pair already visited ! ");
1357 /* Restore system before checking others successors */
1358 if(cursor != xbt_dynar_length(successors) - 1)
1359 MC_replay_liveness(mc_stack_liveness, 1);
1368 XBT_DEBUG("Max depth reached");
1372 if(xbt_fifo_size(mc_stack_liveness) == MAX_DEPTH_LIVENESS ){
1373 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) );
1375 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) );
1380 xbt_fifo_shift(mc_stack_liveness);
1381 if((current_pair->automaton_state->type == 1) || (current_pair->automaton_state->type == 2)){
1382 xbt_dynar_pop(reached_pairs, NULL);
1383 //xbt_dynar_pop(reached_pairs_hash, NULL);