1 /* Copyright (c) 2014-2017. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
16 #include "xbt/sysdep.h"
18 #include "simgrid/simix.h"
20 #include "src/kernel/context/Context.hpp"
21 #include "src/simix/ActorImpl.hpp"
22 #include "src/simix/smx_private.h"
23 #include "src/mc/mc_replay.h"
24 #include "src/mc/mc_record.h"
26 #include "src/mc/mc_base.h"
27 #include "src/mc/Transition.hpp"
30 #include "src/mc/mc_request.h"
31 #include "src/mc/mc_private.h"
32 #include "src/mc/mc_state.h"
33 #include "src/mc/mc_smx.h"
34 #include "src/mc/checker/Checker.hpp"
37 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
38 " Logging specific to MC record/replay facility");
41 char* MC_record_path = nullptr;
47 void replay(RecordTrace const& trace)
49 simgrid::mc::wait_for_requests();
51 for (simgrid::mc::Transition const& transition : trace) {
52 XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
55 smx_actor_t process = SIMIX_process_from_PID(transition.pid);
57 xbt_die("Unexpected process (pid:%d).", transition.pid);
58 smx_simcall_t simcall = &(process->simcall);
59 if (not simcall || simcall->call == SIMCALL_NONE)
60 xbt_die("No simcall for process %d.", transition.pid);
61 if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(process))
62 xbt_die("Unexpected simcall.");
64 // Execute the request:
65 SIMIX_simcall_handle(simcall, transition.argument);
66 simgrid::mc::wait_for_requests();
70 void replay(const char* path_string)
72 simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
73 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string);
74 simgrid::mc::replay(trace);
75 simgrid::mc::processes_time.clear();
78 RecordTrace parseRecordTrace(const char* data)
81 XBT_INFO("path=%s", data);
82 if (data == nullptr || data[0] == '\0')
83 throw std::runtime_error("Could not parse record path");
85 const char* current = data;
88 simgrid::mc::Transition item;
89 int count = sscanf(current, "%d/%d", &item.pid, &item.argument);
90 if(count != 2 && count != 1)
91 throw std::runtime_error("Could not parse record path");
95 const char* end = std::strchr(current, ';');
107 std::string traceToString(simgrid::mc::RecordTrace const& trace)
109 std::ostringstream stream;
110 for (auto i = trace.begin(); i != trace.end(); ++i) {
111 if (i != trace.begin())
115 stream << '/' << i->argument;
120 void dumpRecordPath()
122 if (MC_record_is_active()) {
123 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
124 XBT_INFO("Path = %s", traceToString(trace).c_str());