namespace simgrid {
namespace mc {
-static void MC_show_non_termination(void)
-{
- XBT_INFO("******************************************");
- XBT_INFO("*** NON-PROGRESSIVE CYCLE DETECTED ***");
- XBT_INFO("******************************************");
- XBT_INFO("Counter-example execution trace:");
- for (auto& s : mc_model_checker->getChecker()->getTextualTrace())
- XBT_INFO("%s", s.c_str());
- simgrid::mc::session->logState();
-}
-
static int snapshot_compare(simgrid::mc::State* state1, simgrid::mc::State* state2)
{
simgrid::mc::Snapshot* s1 = state1->system_state.get();
return snapshot_compare(num1, s1, num2, s2);
}
-bool SafetyChecker::checkNonTermination(simgrid::mc::State* current_state)
+void SafetyChecker::checkNonTermination(simgrid::mc::State* current_state)
{
for (auto state = stack_.rbegin(); state != stack_.rend(); ++state)
if (snapshot_compare(state->get(), current_state) == 0) {
XBT_INFO("Non-progressive cycle: state %d -> state %d", (*state)->num, current_state->num);
- return true;
+ XBT_INFO("******************************************");
+ XBT_INFO("*** NON-PROGRESSIVE CYCLE DETECTED ***");
+ XBT_INFO("******************************************");
+ XBT_INFO("Counter-example execution trace:");
+ for (auto& s : mc_model_checker->getChecker()->getTextualTrace())
+ XBT_INFO("%s", s.c_str());
+ simgrid::mc::session->logState();
+
+ throw simgrid::mc::TerminationError();
}
- return false;
}
RecordTrace SafetyChecker::getRecordTrace() // override
XBT_INFO("Executed transitions = %lu", mc_model_checker->executed_transitions);
}
-int SafetyChecker::run()
+void SafetyChecker::run()
{
/* This function runs the DFS algorithm the state space.
* We do so iteratively instead of recursively, dealing with the call stack manually.
// Backtrack if we reached the maximum depth
if (stack_.size() > (std::size_t)_sg_mc_max_depth) {
XBT_WARN("/!\\ Max depth reached ! /!\\ ");
- int res = this->backtrack();
- if (res)
- return res;
- else
- continue;
+ this->backtrack();
+ continue;
}
// Backtrack if we are revisiting a state we saw previously
visitedState_->other_num == -1 ? visitedState_->num : visitedState_->other_num);
visitedState_ = nullptr;
- int res = this->backtrack();
- if (res)
- return res;
- else
- continue;
+ this->backtrack();
+ continue;
}
+ // Search an enabled transition in the current state; backtrack if the interleave set is empty
smx_simcall_t req = MC_state_get_request(state);
- // Backtrack if the interleave set is empty
if (req == nullptr) {
XBT_DEBUG("There are no more processes to interleave. (depth %zi)", stack_.size() + 1);
- int res = this->backtrack();
- if (res)
- return res;
- else
- continue;
+ this->backtrack();
+ continue;
}
// If there are processes to interleave and the maximum depth has not been
std::unique_ptr<simgrid::mc::State> next_state =
std::unique_ptr<simgrid::mc::State>(new simgrid::mc::State(++expandedStatesCount_));
- if (_sg_mc_termination && this->checkNonTermination(next_state.get())) {
- MC_show_non_termination();
- return SIMGRID_MC_EXIT_NON_TERMINATION;
- }
+ if (_sg_mc_termination)
+ this->checkNonTermination(next_state.get());
/* Check whether we already explored next_state in the past (but only if interested in state-equality reduction) */
if (_sg_mc_visited == true)
visitedState_ = visitedStates_.addVisitedState(expandedStatesCount_, next_state.get(), true);
/* If this is a new state (or if we don't care about state-equality reduction) */
- if (_sg_mc_visited == 0 || visitedState_ == nullptr) {
+ if (visitedState_ == nullptr) {
/* Get an enabled process and insert it in the interleave set of the next state */
for (auto& actor : mc_model_checker->process().actors())
XBT_INFO("No property violation found.");
simgrid::mc::session->logState();
- return SIMGRID_MC_EXIT_SUCCESS;
}
-int SafetyChecker::backtrack()
+void SafetyChecker::backtrack()
{
stack_.pop_back();
/* Check for deadlocks */
if (mc_model_checker->checkDeadlock()) {
MC_show_deadlock();
- return SIMGRID_MC_EXIT_DEADLOCK;
+ throw simgrid::mc::DeadlockError();
}
/* Traverse the stack backwards until a state with a non empty interleave
state->num, stack_.size() + 1);
}
}
- return SIMGRID_MC_EXIT_SUCCESS;
}
void SafetyChecker::restoreState()