-static inline const char* get_color(int id)
-{
- static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
- "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
- "lightblue", "tan"}};
- return colors[id % colors.size()];
-}
-
-static std::string pointer_to_string(void* pointer)
-{
- return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? xbt::string_printf("%p", pointer) : "(verbose only)";
-}
-
-static std::string buff_size_to_string(size_t buff_size)
-{
- return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? std::to_string(buff_size) : "(verbose only)";
-}
-
-static void simcall_translate(smx_simcall_t req,
- simgrid::mc::Remote<simgrid::kernel::activity::CommImpl>& buffered_comm);
-
-static bool request_is_enabled_by_idx(const RemoteProcess& process, smx_simcall_t req, unsigned int idx)
-{
- kernel::activity::CommImpl* remote_act = nullptr;
- switch (req->call_) {
- case Simcall::COMM_WAIT:
- /* FIXME: check also that src and dst processes are not suspended */
- remote_act = simcall_comm_wait__getraw__comm(req);
- break;
-
- case Simcall::COMM_WAITANY:
- remote_act = process.read(remote(simcall_comm_waitany__get__comms(req) + idx));
- break;
-
- case Simcall::COMM_TESTANY:
- remote_act = process.read(remote(simcall_comm_testany__get__comms(req) + idx));
- break;
-
- default:
- return true;
- }
-
- Remote<kernel::activity::CommImpl> temp_comm;
- process.read(temp_comm, remote(remote_act));
- const kernel::activity::CommImpl* comm = temp_comm.get_buffer();
- return comm->src_actor_.get() && comm->dst_actor_.get();
-}
-
-/* Search an enabled transition for the given process.
- *
- * This can be seen as an iterator returning the next transition of the process.
- *
- * We only consider the processes that are both
- * - marked "to be interleaved" in their ActorState (controlled by the checker algorithm).
- * - which simcall can currently be executed (like a comm where the other partner is already known)
- * Once we returned the last enabled transition of a process, it is marked done.
- *
- * Things can get muddled with the WAITANY and TESTANY simcalls, that are rewritten on the fly to a bunch of WAIT
- * (resp TEST) transitions using the transition.argument field to remember what was the last returned sub-transition.
- */
-static inline smx_simcall_t MC_state_choose_request_for_process(const RemoteProcess& process, simgrid::mc::State* state,
- smx_actor_t actor)
-{
- /* reset the outgoing transition */
- simgrid::mc::ActorState* procstate = &state->actor_states_[actor->get_pid()];
- state->transition_.aid_ = -1;
- state->transition_.times_considered_ = -1;
- state->transition_.textual[0] = '\0';
- state->executed_req_.call_ = Simcall::NONE;
-
- if (not simgrid::mc::actor_is_enabled(actor))
- return nullptr; // Not executable in the application
-
- smx_simcall_t req = nullptr;
- if (actor->simcall_.observer_ != nullptr) {
- state->transition_.times_considered_ = procstate->times_considered;
- procstate->times_considered++;
- if (actor->simcall_.mc_max_consider_ <= procstate->times_considered)
- procstate->set_done();
- req = &actor->simcall_;
- } else
- switch (actor->simcall_.call_) {
- case Simcall::COMM_WAITANY:
- state->transition_.times_considered_ = -1;
- while (procstate->times_considered < simcall_comm_waitany__get__count(&actor->simcall_)) {
- if (simgrid::mc::request_is_enabled_by_idx(process, &actor->simcall_, procstate->times_considered)) {
- state->transition_.times_considered_ = procstate->times_considered;
- ++procstate->times_considered;
- break;
- }
- ++procstate->times_considered;
- }
-
- if (procstate->times_considered >= simcall_comm_waitany__get__count(&actor->simcall_))
- procstate->set_done();
- if (state->transition_.times_considered_ != -1)
- req = &actor->simcall_;
- break;
-
- case Simcall::COMM_TESTANY:
- state->transition_.times_considered_ = -1;
- while (procstate->times_considered < simcall_comm_testany__get__count(&actor->simcall_)) {
- if (simgrid::mc::request_is_enabled_by_idx(process, &actor->simcall_, procstate->times_considered)) {
- state->transition_.times_considered_ = procstate->times_considered;
- ++procstate->times_considered;
- break;
- }
- ++procstate->times_considered;
- }
-
- if (procstate->times_considered >= simcall_comm_testany__get__count(&actor->simcall_))
- procstate->set_done();
- if (state->transition_.times_considered_ != -1)
- req = &actor->simcall_;
- break;
-
- case Simcall::COMM_WAIT: {
- simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> remote_act =
- remote(simcall_comm_wait__get__comm(&actor->simcall_));
- simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_act;
- process.read(temp_act, remote_act);
- const simgrid::kernel::activity::CommImpl* act = temp_act.get_buffer();
- if (act->src_actor_.get() && act->dst_actor_.get())
- state->transition_.times_considered_ = 0; // OK
- else if (act->src_actor_.get() == nullptr && act->state_ == simgrid::kernel::activity::State::READY &&
- act->detached())
- state->transition_.times_considered_ = 0; // OK
- else
- state->transition_.times_considered_ = -1; // timeout
- procstate->set_done();
- req = &actor->simcall_;
- break;
- }
-
- default:
- procstate->set_done();
- state->transition_.times_considered_ = 0;
- req = &actor->simcall_;
- break;
- }
- if (not req)
- return nullptr;
-
- state->transition_.aid_ = actor->get_pid();
- state->executed_req_ = *req;
-
- // Fetch the data of the request and translate it:
- state->internal_req_ = *req;
- state->internal_req_.mc_value_ = state->transition_.times_considered_;
- simcall_translate(&state->internal_req_, state->internal_comm_);
-
- return req;
-}
-
-static void simcall_translate(smx_simcall_t req,
- simgrid::mc::Remote<simgrid::kernel::activity::CommImpl>& buffered_comm)
-{
- simgrid::kernel::activity::CommImpl* chosen_comm;
-
- /* The waitany and testany request are transformed into a wait or test request over the corresponding communication
- * action so it can be treated later by the dependence function. */
- switch (req->call_) {
- case Simcall::COMM_WAITANY:
- req->call_ = Simcall::COMM_WAIT;
- chosen_comm =
- mc_model_checker->get_remote_process().read(remote(simcall_comm_waitany__get__comms(req) + req->mc_value_));
-
- mc_model_checker->get_remote_process().read(buffered_comm, remote(chosen_comm));
- simcall_comm_wait__set__comm(req, buffered_comm.get_buffer());
- simcall_comm_wait__set__timeout(req, 0);
- break;
-
- case Simcall::COMM_TESTANY:
- req->call_ = Simcall::COMM_TEST;
- chosen_comm =
- mc_model_checker->get_remote_process().read(remote(simcall_comm_testany__get__comms(req) + req->mc_value_));
-
- mc_model_checker->get_remote_process().read(buffered_comm, remote(chosen_comm));
- simcall_comm_test__set__comm(req, buffered_comm.get_buffer());
- simcall_comm_test__set__result(req, req->mc_value_);
- break;
-
- case Simcall::COMM_WAIT:
- chosen_comm = simcall_comm_wait__get__comm(req);
- mc_model_checker->get_remote_process().read(buffered_comm, remote(chosen_comm));
- simcall_comm_wait__set__comm(req, buffered_comm.get_buffer());
- break;
-
- case Simcall::COMM_TEST:
- chosen_comm = simcall_comm_test__get__comm(req);
- mc_model_checker->get_remote_process().read(buffered_comm, remote(chosen_comm));
- simcall_comm_test__set__comm(req, buffered_comm.get_buffer());
- break;
-
- default:
- /* No translation needed */
- break;
- }
-}
-
-simgrid::kernel::activity::CommImpl* Api::get_comm_or_nullptr(smx_simcall_t const r) const
-{
- if (r->call_ == Simcall::COMM_WAIT)
- return simcall_comm_wait__get__comm(r);
- if (r->call_ == Simcall::COMM_TEST)
- return simcall_comm_test__get__comm(r);
- return nullptr;
-}
-