1 /* Copyright (c) 2014-2020. The 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 "src/mc/mc_record.hpp"
7 #include "src/kernel/activity/CommImpl.hpp"
8 #include "src/kernel/context/Context.hpp"
9 #include "src/mc/Transition.hpp"
10 #include "src/mc/mc_base.h"
11 #include "src/mc/mc_replay.hpp"
14 #include "src/mc/checker/Checker.hpp"
15 #include "src/mc/mc_private.hpp"
16 #include "src/mc/mc_request.hpp"
17 #include "src/mc/mc_smx.hpp"
18 #include "src/mc/mc_state.hpp"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, "Logging specific to MC record/replay facility");
26 void replay(RecordTrace const& trace)
28 simgrid::mc::wait_for_requests();
30 for (simgrid::mc::Transition const& transition : trace) {
31 XBT_DEBUG("Executing %i$%i", transition.pid_, transition.argument_);
34 smx_actor_t process = SIMIX_process_from_PID(transition.pid_);
36 xbt_die("Unexpected process (pid:%d).", transition.pid_);
37 const s_smx_simcall* simcall = &(process->simcall);
38 if (simcall == nullptr || simcall->call_ == SIMCALL_NONE)
39 xbt_die("No simcall for process %d.", transition.pid_);
40 if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(process))
41 xbt_die("Unexpected simcall.");
43 // Execute the request:
44 simcall->issuer_->simcall_handle(transition.argument_);
45 simgrid::mc::wait_for_requests();
49 void replay(const std::string& path_string)
51 simgrid::mc::processes_time.resize(simgrid::kernel::actor::get_maxpid());
52 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
53 simgrid::mc::replay(trace);
54 simgrid::mc::processes_time.clear();
57 RecordTrace parseRecordTrace(const char* data)
60 XBT_INFO("path=%s", data);
61 if (data == nullptr || data[0] == '\0')
62 throw std::invalid_argument("Could not parse record path");
64 const char* current = data;
66 simgrid::mc::Transition item;
67 int count = sscanf(current, "%d/%d", &item.pid_, &item.argument_);
69 if(count != 2 && count != 1)
70 throw std::invalid_argument("Could not parse record path");
74 const char* end = std::strchr(current, ';');
86 std::string traceToString(simgrid::mc::RecordTrace const& trace)
88 std::ostringstream stream;
89 for (auto i = trace.begin(); i != trace.end(); ++i) {
90 if (i != trace.begin())
94 stream << '/' << i->argument_;
101 RecordTrace trace = mc_model_checker->getChecker()->get_record_trace();
102 XBT_INFO("Path = %s", traceToString(trace).c_str());