X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d13b1659a0c2551ee41b287a269e391bb2d7bc8a..20bbf9b0608d4ab29fb25ab4f795001d0cdca5b5:/src/mc/mc_liveness.cpp diff --git a/src/mc/mc_liveness.cpp b/src/mc/mc_liveness.cpp index 41be27f176..84e996d784 100644 --- a/src/mc/mc_liveness.cpp +++ b/src/mc/mc_liveness.cpp @@ -1,23 +1,30 @@ -/* Copyright (c) 2011-2014. The SimGrid Team. +/* Copyright (c) 2011-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include + #include #include -#include #include - -#include "mc_request.h" -#include "mc_liveness.h" -#include "mc_private.h" -#include "mc_record.h" -#include "mc_smx.h" -#include "mc_client.h" -#include "mc_replay.h" -#include "mc_safety.h" +#include +#include +#include +#include +#include + +#include "src/mc/mc_request.h" +#include "src/mc/mc_liveness.h" +#include "src/mc/mc_private.h" +#include "src/mc/mc_record.h" +#include "src/mc/mc_smx.h" +#include "src/mc/mc_client.h" +#include "src/mc/mc_replay.h" +#include "src/mc/mc_safety.h" +#include "src/mc/mc_exit.h" extern "C" { @@ -34,8 +41,8 @@ xbt_parmap_t parmap; static xbt_dynar_t get_atomic_propositions_values() { unsigned int cursor = 0; - xbt_automaton_propositional_symbol_t ps = NULL; - xbt_dynar_t values = xbt_dynar_new(sizeof(int), NULL); + xbt_automaton_propositional_symbol_t ps = nullptr; + xbt_dynar_t values = xbt_dynar_new(sizeof(int), nullptr); xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, ps) { int res = xbt_automaton_propositional_symbol_evaluate(ps); xbt_dynar_push_as(values, int, res); @@ -44,10 +51,9 @@ static xbt_dynar_t get_atomic_propositions_values() return values; } -static mc_visited_pair_t is_reached_acceptance_pair(mc_pair_t pair) { - xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap); - - mc_visited_pair_t new_pair = NULL; +static mc_visited_pair_t is_reached_acceptance_pair(mc_pair_t pair) +{ + mc_visited_pair_t new_pair = nullptr; new_pair = MC_visited_pair_new(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state); new_pair->acceptance_pair = 1; @@ -69,8 +75,6 @@ static mc_visited_pair_t is_reached_acceptance_pair(mc_pair_t pair) { // Parallell implementation /*res = xbt_parmap_mc_apply(parmap, snapshot_compare, xbt_dynar_get_ptr(acceptance_pairs, min), (max-min)+1, pair); if(res != -1){ - if(!raw_mem_set) - MC_SET_STD_HEAP; return ((mc_pair_t)xbt_dynar_get_as(acceptance_pairs, (min+res)-1, mc_pair_t))->num; } */ @@ -83,10 +87,9 @@ static mc_visited_pair_t is_reached_acceptance_pair(mc_pair_t pair) { if (snapshot_compare(pair_test, new_pair) == 0) { XBT_INFO("Pair %d already reached (equal to pair %d) !", new_pair->num, pair_test->num); xbt_fifo_shift(mc_stack); - if (dot_output != NULL) + if (dot_output != nullptr) fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", initial_global_state->prev_pair, pair_test->num, initial_global_state->prev_req); - mmalloc_set_current_heap(heap); - return NULL; + return nullptr; } } } @@ -105,18 +108,14 @@ static mc_visited_pair_t is_reached_acceptance_pair(mc_pair_t pair) { xbt_dynar_insert_at(acceptance_pairs, index, &new_pair); } } - } - mmalloc_set_current_heap(heap); return new_pair; } static void remove_acceptance_pair(int pair_num) { - xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap); - unsigned int cursor = 0; - mc_visited_pair_t pair_test = NULL; + mc_visited_pair_t pair_test = nullptr; int pair_found = 0; xbt_dynar_foreach(acceptance_pairs, cursor, pair_test) { @@ -135,8 +134,6 @@ static void remove_acceptance_pair(int pair_num) MC_visited_pair_delete(pair_test); } - - mmalloc_set_current_heap(heap); } @@ -161,9 +158,9 @@ static int MC_automaton_evaluate_label(xbt_automaton_exp_label_t l, } case 3:{ unsigned int cursor = 0; - xbt_automaton_propositional_symbol_t p = NULL; + xbt_automaton_propositional_symbol_t p = nullptr; xbt_dynar_foreach(_mc_property_automaton->propositional_symbols, cursor, p) { - if (strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0) + if (std::strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0) return (int) xbt_dynar_get_as(atomic_propositions_values, cursor, int); } return -1; @@ -176,24 +173,20 @@ static int MC_automaton_evaluate_label(xbt_automaton_exp_label_t l, } } -static void MC_modelcheck_liveness_main(void); +static int MC_modelcheck_liveness_main(void); static void MC_pre_modelcheck_liveness(void) { - initial_global_state->raw_mem_set = (mmalloc_get_current_heap() == mc_heap); - - mc_pair_t initial_pair = NULL; + mc_pair_t initial_pair = nullptr; smx_process_t process; - MC_wait_for_requests(); - - MC_SET_MC_HEAP; + mc_model_checker->wait_for_requests(); - acceptance_pairs = xbt_dynar_new(sizeof(mc_visited_pair_t), NULL); + acceptance_pairs = xbt_dynar_new(sizeof(mc_visited_pair_t), nullptr); if(_sg_mc_visited > 0) - visited_pairs = xbt_dynar_new(sizeof(mc_visited_pair_t), NULL); + visited_pairs = xbt_dynar_new(sizeof(mc_visited_pair_t), nullptr); - initial_global_state->snapshot = MC_take_snapshot(0); + initial_global_state->snapshot = simgrid::mc::take_snapshot(0); initial_global_state->prev_pair = 0; unsigned int cursor = 0; @@ -221,26 +214,19 @@ static void MC_pre_modelcheck_liveness(void) xbt_fifo_unshift(mc_stack, initial_pair); } } - - MC_SET_STD_HEAP; - - MC_modelcheck_liveness_main(); - - if (initial_global_state->raw_mem_set) - MC_SET_MC_HEAP; } -static void MC_modelcheck_liveness_main(void) +static int MC_modelcheck_liveness_main(void) { - smx_process_t process = NULL; - mc_pair_t current_pair = NULL; + smx_process_t process = nullptr; + mc_pair_t current_pair = nullptr; int value, res, visited_num = -1; - smx_simcall_t req = NULL; - xbt_automaton_transition_t transition_succ = NULL; + smx_simcall_t req = nullptr; + xbt_automaton_transition_t transition_succ = nullptr; int cursor = 0; - mc_pair_t next_pair = NULL; - xbt_dynar_t prop_values = NULL; - mc_visited_pair_t reached_pair = NULL; + mc_pair_t next_pair = nullptr; + xbt_dynar_t prop_values = nullptr; + mc_visited_pair_t reached_pair = nullptr; while(xbt_fifo_size(mc_stack) > 0){ @@ -259,42 +245,38 @@ static void MC_modelcheck_liveness_main(void) if (current_pair->automaton_state->type == 1 && current_pair->exploration_started == 0) { /* If new acceptance pair, return new pair */ - if ((reached_pair = is_reached_acceptance_pair(current_pair)) == NULL) { + if ((reached_pair = is_reached_acceptance_pair(current_pair)) == nullptr) { int counter_example_depth = current_pair->depth; XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); XBT_INFO("| ACCEPTANCE CYCLE |"); XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); XBT_INFO("Counter-example that violates formula :"); + MC_record_dump_path(mc_stack); MC_show_stack_liveness(mc_stack); MC_dump_stack_liveness(mc_stack); MC_print_statistics(mc_stats); XBT_INFO("Counter-example depth : %d", counter_example_depth); - xbt_abort(); + return SIMGRID_MC_EXIT_LIVENESS; } } /* Pair already visited ? stop the exploration on the current path */ if ((current_pair->exploration_started == 0) && (visited_num = is_visited_pair(reached_pair, current_pair)) != -1) { - if (dot_output != NULL){ - MC_SET_MC_HEAP; + if (dot_output != nullptr){ fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", initial_global_state->prev_pair, visited_num, initial_global_state->prev_req); fflush(dot_output); - MC_SET_STD_HEAP; } XBT_DEBUG("Pair already visited (equal to pair %d), exploration on the current path stopped.", visited_num); - MC_SET_MC_HEAP; current_pair->requests = 0; - MC_SET_STD_HEAP; goto backtracking; }else{ req = MC_state_get_request(current_pair->graph_state, &value); - if (dot_output != NULL) { - MC_SET_MC_HEAP; + if (dot_output != nullptr) { if (initial_global_state->prev_pair != 0 && initial_global_state->prev_pair != current_pair->num) { fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", initial_global_state->prev_pair, current_pair->num, initial_global_state->prev_req); xbt_free(initial_global_state->prev_req); @@ -304,7 +286,6 @@ static void MC_modelcheck_liveness_main(void) if (current_pair->search_cycle) fprintf(dot_output, "%d [shape=doublecircle];\n", current_pair->num); fflush(dot_output); - MC_SET_STD_HEAP; } char* req_str = MC_request_to_string(req, value, MC_REQUEST_SIMIX); @@ -323,9 +304,7 @@ static void MC_modelcheck_liveness_main(void) MC_simcall_handle(req, value); /* Wait for requests (schedules processes) */ - MC_wait_for_requests(); - - MC_SET_MC_HEAP; + mc_model_checker->wait_for_requests(); current_pair->requests--; current_pair->exploration_started = 1; @@ -363,9 +342,7 @@ static void MC_modelcheck_liveness_main(void) } cursor--; } - - MC_SET_STD_HEAP; - + } /* End of visited_pair test */ } else { @@ -374,18 +351,15 @@ static void MC_modelcheck_liveness_main(void) if(visited_num == -1) XBT_DEBUG("No more request to execute. Looking for backtracking point."); - MC_SET_MC_HEAP; - xbt_dynar_free(&prop_values); /* Traverse the stack backwards until a pair with a non empty interleave set is found, deleting all the pairs that have it empty in the way. */ - while ((current_pair = (mc_pair_t) xbt_fifo_shift(mc_stack)) != NULL) { + while ((current_pair = (mc_pair_t) xbt_fifo_shift(mc_stack)) != nullptr) { if (current_pair->requests > 0) { /* We found a backtracking point */ XBT_DEBUG("Backtracking to depth %d", current_pair->depth); xbt_fifo_unshift(mc_stack, current_pair); - MC_SET_STD_HEAP; MC_replay_liveness(mc_stack); XBT_DEBUG("Backtracking done"); break; @@ -397,43 +371,40 @@ static void MC_modelcheck_liveness_main(void) MC_pair_delete(current_pair); } } - - MC_SET_STD_HEAP; + } /* End of if (current_pair->requests > 0) else ... */ } /* End of while(xbt_fifo_size(mc_stack) > 0) */ - + + XBT_INFO("No property violation found."); + MC_print_statistics(mc_stats); + return SIMGRID_MC_EXIT_SUCCESS; } -void MC_modelcheck_liveness(void) +int MC_modelcheck_liveness(void) { if (mc_reduce_kind == e_mc_reduce_unset) mc_reduce_kind = e_mc_reduce_none; XBT_INFO("Check the liveness property %s", _sg_mc_property_file); MC_automaton_load(_sg_mc_property_file); - MC_wait_for_requests(); + mc_model_checker->wait_for_requests(); XBT_DEBUG("Starting the liveness algorithm"); _sg_mc_liveness = 1; - xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap); - /* Create exploration stack */ mc_stack = xbt_fifo_new(); /* Create the initial state */ initial_global_state = xbt_new0(s_mc_global_t, 1); - MC_SET_STD_HEAP; - MC_pre_modelcheck_liveness(); + int res = MC_modelcheck_liveness_main(); /* We're done */ - MC_print_statistics(mc_stats); xbt_free(mc_time); - mmalloc_set_current_heap(heap); - + return res; } }