X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e4d3739e981eb46fbfca0ff837c681e26e8a44c6..20bbf9b0608d4ab29fb25ab4f795001d0cdca5b5:/src/mc/mc_safety.cpp diff --git a/src/mc/mc_safety.cpp b/src/mc/mc_safety.cpp index 7336489ef4..f25f11c37d 100644 --- a/src/mc/mc_safety.cpp +++ b/src/mc/mc_safety.cpp @@ -4,18 +4,24 @@ /* 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 "mc_state.h" -#include "mc_request.h" -#include "mc_safety.h" -#include "mc_private.h" -#include "mc_record.h" -#include "mc_smx.h" -#include "mc_client.h" -#include "mc_exit.h" +#include -#include "xbt/mmalloc/mmprivate.h" +#include +#include +#include + +#include "src/mc/mc_state.h" +#include "src/mc/mc_request.h" +#include "src/mc/mc_safety.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_exit.h" + +#include "src/xbt/mmalloc/mmprivate.h" extern "C" { @@ -28,7 +34,7 @@ static int is_exploration_stack_state(mc_state_t current_state){ xbt_fifo_item_t item; mc_state_t stack_state; - for(item = xbt_fifo_get_first_item(mc_stack); item != NULL; item = xbt_fifo_get_next_item(item)) { + for(item = xbt_fifo_get_first_item(mc_stack); item != nullptr; item = xbt_fifo_get_next_item(item)) { stack_state = (mc_state_t) xbt_fifo_get_item_content(item); if(snapshot_compare(stack_state, current_state) == 0){ XBT_INFO("Non-progressive cycle : state %d -> state %d", stack_state->num, current_state->num); @@ -54,7 +60,7 @@ static void MC_pre_modelcheck_safety() XBT_DEBUG("Initial state"); /* Wait for requests (schedules processes) */ - MC_wait_for_requests(); + mc_model_checker->wait_for_requests(); /* Get an enabled process and insert it in the interleave set of the initial state */ smx_process_t process; @@ -73,16 +79,16 @@ static void MC_pre_modelcheck_safety() /** \brief Model-check the application using a DFS exploration * with DPOR (Dynamic Partial Order Reductions) */ -void MC_modelcheck_safety(void) +int MC_modelcheck_safety(void) { MC_modelcheck_safety_init(); - char *req_str = NULL; + char *req_str = nullptr; int value; - smx_simcall_t req = NULL; - mc_state_t state = NULL, prev_state = NULL, next_state = NULL; - xbt_fifo_item_t item = NULL; - mc_visited_state_t visited_state = NULL; + smx_simcall_t req = nullptr; + mc_state_t state = nullptr, prev_state = NULL, next_state = NULL; + xbt_fifo_item_t item = nullptr; + mc_visited_state_t visited_state = nullptr; while (xbt_fifo_size(mc_stack) > 0) { @@ -101,13 +107,13 @@ void MC_modelcheck_safety(void) /* If there are processes to interleave and the maximum depth has not been reached then perform one step of the exploration algorithm */ if (xbt_fifo_size(mc_stack) <= _sg_mc_max_depth && !user_max_depth_reached - && (req = MC_state_get_request(state, &value)) && visited_state == NULL) { + && (req = MC_state_get_request(state, &value)) && visited_state == nullptr) { req_str = MC_request_to_string(req, value, MC_REQUEST_SIMIX); XBT_DEBUG("Execute: %s", req_str); xbt_free(req_str); - if (dot_output != NULL) { + if (dot_output != nullptr) { req_str = MC_request_get_dot_output(req, value); } @@ -119,20 +125,20 @@ void MC_modelcheck_safety(void) /* Answer the request */ MC_simcall_handle(req, value); - MC_wait_for_requests(); + mc_model_checker->wait_for_requests(); /* Create the new expanded state */ next_state = MC_state_new(); if(_sg_mc_termination && is_exploration_stack_state(next_state)){ MC_show_non_termination(); - exit(SIMGRID_EXIT_NON_TERMINATION); + return SIMGRID_MC_EXIT_NON_TERMINATION; } - if ((visited_state = is_visited_state(next_state)) == NULL) { + if ((visited_state = is_visited_state(next_state)) == nullptr) { /* Get an enabled process and insert it in the interleave set of the next state */ - smx_process_t process = NULL; + smx_process_t process = nullptr; MC_EACH_SIMIX_PROCESS(process, if (MC_process_is_enabled(process)) { MC_state_interleave_process(next_state, process); @@ -141,19 +147,19 @@ void MC_modelcheck_safety(void) } ); - if (dot_output != NULL) - fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, next_state->num, req_str); + if (dot_output != nullptr) + std::fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, next_state->num, req_str); } else { - if (dot_output != NULL) - fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str); + if (dot_output != nullptr) + std::fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str); } xbt_fifo_unshift(mc_stack, next_state); - if (dot_output != NULL) + if (dot_output != nullptr) xbt_free(req_str); /* Let's loop again */ @@ -161,11 +167,11 @@ void MC_modelcheck_safety(void) /* The interleave set is empty or the maximum depth is reached, let's back-track */ } else { - if ((xbt_fifo_size(mc_stack) > _sg_mc_max_depth) || user_max_depth_reached || visited_state != NULL) { + if ((xbt_fifo_size(mc_stack) > _sg_mc_max_depth) || user_max_depth_reached || visited_state != nullptr) { - if (user_max_depth_reached && visited_state == NULL) + if (user_max_depth_reached && visited_state == nullptr) XBT_DEBUG("User max depth reached !"); - else if (visited_state == NULL) + else if (visited_state == nullptr) XBT_WARN("/!\\ Max depth reached ! /!\\ "); else XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.", visited_state->other_num == -1 ? visited_state->num : visited_state->other_num); @@ -181,12 +187,12 @@ void MC_modelcheck_safety(void) XBT_DEBUG("Delete state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1); MC_state_delete(state, !state->in_visited_states ? 1 : 0); - visited_state = NULL; + visited_state = nullptr; /* Check for deadlocks */ if (MC_deadlock_check()) { - MC_show_deadlock(NULL); - exit(SIMGRID_EXIT_DEADLOCK); + MC_show_deadlock(nullptr); + return SIMGRID_MC_EXIT_DEADLOCK; } /* Traverse the stack backwards until a state with a non empty interleave @@ -201,7 +207,7 @@ void MC_modelcheck_safety(void) req = MC_state_get_internal_request(state); if (req->call == SIMCALL_MUTEX_LOCK || req->call == SIMCALL_MUTEX_TRYLOCK) xbt_die("Mutex is currently not supported with DPOR, " - "use --cfg=model-check/reduction:dpor"); + "use --cfg=model-check/reduction:none"); const smx_process_t issuer = MC_smx_simcall_get_issuer(req); xbt_fifo_foreach(mc_stack, item, prev_state, mc_state_t) { if (MC_request_depend(req, MC_state_get_internal_request(prev_state))) { @@ -259,7 +265,7 @@ void MC_modelcheck_safety(void) XBT_INFO("No property violation found."); MC_print_statistics(mc_stats); - exit(SIMGRID_EXIT_SUCCESS); + return SIMGRID_MC_EXIT_SUCCESS; } static void MC_modelcheck_safety_init(void) @@ -273,7 +279,7 @@ static void MC_modelcheck_safety_init(void) XBT_INFO("Check non progressive cycles"); else XBT_INFO("Check a safety property"); - MC_wait_for_requests(); + mc_model_checker->wait_for_requests(); XBT_DEBUG("Starting the safety algorithm"); @@ -286,5 +292,5 @@ static void MC_modelcheck_safety_init(void) /* Save the initial state */ initial_global_state = xbt_new0(s_mc_global_t, 1); - initial_global_state->snapshot = MC_take_snapshot(0); + initial_global_state->snapshot = simgrid::mc::take_snapshot(0); }