Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b469ab0da3b0dfa1f907afd8e1a5cb799450070b
[simgrid.git] / src / mc / api.cpp
1 /* Copyright (c) 2020-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "api.hpp"
7
8 #include "src/kernel/activity/MailboxImpl.hpp"
9 #include "src/kernel/activity/MutexImpl.hpp"
10 #include "src/kernel/actor/SimcallObserver.hpp"
11 #include "src/mc/Session.hpp"
12 #include "src/mc/checker/Checker.hpp"
13 #include "src/mc/mc_base.hpp"
14 #include "src/mc/mc_comm_pattern.hpp"
15 #include "src/mc/mc_exit.hpp"
16 #include "src/mc/mc_pattern.hpp"
17 #include "src/mc/mc_private.hpp"
18 #include "src/mc/remote/RemoteProcess.hpp"
19 #include "src/surf/HostImpl.hpp"
20
21 #include <xbt/asserts.h>
22 #include <xbt/log.h>
23 #include "simgrid/s4u/Host.hpp"
24 #include "xbt/string.hpp"
25 #if HAVE_SMPI
26 #include "src/smpi/include/smpi_request.hpp"
27 #endif
28
29 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(Api, mc, "Logging specific to MC Facade APIs ");
30 XBT_LOG_EXTERNAL_CATEGORY(mc_global);
31
32 using Simcall = simgrid::simix::Simcall;
33
34 namespace simgrid {
35 namespace mc {
36
37 static inline const char* get_color(int id)
38 {
39   static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
40                                                        "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
41                                                        "lightblue", "tan"}};
42   return colors[id % colors.size()];
43 }
44
45 static std::string pointer_to_string(void* pointer)
46 {
47   return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? xbt::string_printf("%p", pointer) : "(verbose only)";
48 }
49
50 static std::string buff_size_to_string(size_t buff_size)
51 {
52   return XBT_LOG_ISENABLED(Api, xbt_log_priority_verbose) ? std::to_string(buff_size) : "(verbose only)";
53 }
54
55 static void simcall_translate(smx_simcall_t req, Remote<kernel::activity::CommImpl>& buffered_comm);
56
57 /* Search an enabled transition for the given process.
58  *
59  * This can be seen as an iterator returning the next transition of the process.
60  *
61  * We only consider the processes that are both
62  *  - marked "to be interleaved" in their ActorState (controlled by the checker algorithm).
63  *  - which simcall can currently be executed (like a comm where the other partner is already known)
64  * Once we returned the last enabled transition of a process, it is marked done.
65  *
66  * Things can get muddled with the WAITANY and TESTANY simcalls, that are rewritten on the fly to a bunch of WAIT
67  * (resp TEST) transitions using the transition.argument field to remember what was the last returned sub-transition.
68  */
69 static inline smx_simcall_t MC_state_choose_request_for_process(const RemoteProcess& process, simgrid::mc::State* state,
70                                                                 smx_actor_t actor)
71 {
72   /* reset the outgoing transition */
73   simgrid::mc::ActorState* procstate = &state->actor_states_[actor->get_pid()];
74   state->transition_.aid_              = -1;
75   state->transition_.times_considered_ = -1;
76   state->transition_.textual[0]        = '\0';
77   state->executed_req_.call_         = Simcall::NONE;
78
79   if (not simgrid::mc::actor_is_enabled(actor))
80     return nullptr; // Not executable in the application
81
82   smx_simcall_t req = nullptr;
83   if (actor->simcall_.observer_ != nullptr) {
84     state->transition_.times_considered_ = procstate->get_times_considered_and_inc();
85     if (actor->simcall_.mc_max_consider_ <= procstate->get_times_considered())
86       procstate->set_done();
87     req = &actor->simcall_;
88   } else {
89     procstate->set_done();
90     state->transition_.times_considered_ = 0;
91     req                                  = &actor->simcall_;
92   }
93   if (not req)
94     return nullptr;
95
96   state->transition_.aid_ = actor->get_pid();
97   state->executed_req_    = *req;
98
99   // Fetch the data of the request and translate it:
100   state->internal_req_ = *req;
101   state->internal_req_.mc_value_ = state->transition_.times_considered_;
102
103   return req;
104 }
105
106 kernel::activity::CommImpl* Api::get_comm_or_nullptr(smx_simcall_t const r) const
107 {
108   if (auto wait = dynamic_cast<kernel::actor::ActivityWaitSimcall*>(r->observer_))
109     return static_cast<kernel::activity::CommImpl*>(wait->get_activity());
110   if (auto test = dynamic_cast<kernel::actor::ActivityTestSimcall*>(r->observer_))
111     return static_cast<kernel::activity::CommImpl*>(test->get_activity());
112   return nullptr;
113 }
114
115 /** Statically "upcast" a s_smx_actor_t into an ActorInformation
116  *
117  *  This gets 'actorInfo' from '&actorInfo->copy'. It upcasts in the
118  *  sense that we could achieve the same thing by having ActorInformation
119  *  inherit from s_smx_actor_t but we don't really want to do that.
120  */
121 simgrid::mc::ActorInformation* Api::actor_info_cast(smx_actor_t actor) const
122 {
123   simgrid::mc::ActorInformation temp;
124   std::size_t offset = (char*)temp.copy.get_buffer() - (char*)&temp;
125
126   auto* process_info = reinterpret_cast<simgrid::mc::ActorInformation*>((char*)actor - offset);
127   return process_info;
128 }
129
130 bool Api::simcall_check_dependency(smx_simcall_t req1, smx_simcall_t req2) const
131 {
132   const auto IRECV = Simcall::COMM_IRECV;
133   const auto ISEND = Simcall::COMM_ISEND;
134   const auto WAIT  = Simcall::COMM_WAIT;
135
136   if (req1->issuer_ == req2->issuer_) // Done in observer for TEST and WAIT
137     return false;
138
139   /* The independence theorem only consider 4 simcalls. All others are dependent with anything. */
140   if (req1->call_ != ISEND && req1->call_ != IRECV && req1->call_ != WAIT)
141     return true;
142   if (req2->call_ != ISEND && req2->call_ != IRECV && req2->call_ != WAIT)
143     return true;
144
145   /* Make sure that req1 and req2 are in alphabetic order */
146   if (req1->call_ > req2->call_) {
147     auto temp = req1;
148     req1      = req2;
149     req2      = temp;
150   }
151
152   auto comm2 = get_comm_or_nullptr(req2);
153
154   /* First case: that's not the same kind of request (we also know that req1 < req2 alphabetically) */
155   if (req1->call_ != req2->call_) {
156     if (req1->call_ == IRECV && req2->call_ == ISEND)
157       return false;
158
159     if ((req1->call_ == IRECV || req1->call_ == ISEND) && req2->call_ == WAIT) {
160       auto mbox1 = get_mbox_remote_addr(req1);
161       auto mbox2 = remote(comm2->mbox_cpy);
162
163       if (mbox1 != mbox2 && simcall_comm_wait__get__timeout(req2) <= 0)
164         return false;
165
166       if ((req1->issuer_ != comm2->src_actor_.get()) && (req1->issuer_ != comm2->dst_actor_.get()) &&
167           simcall_comm_wait__get__timeout(req2) <= 0)
168         return false;
169
170       if ((req1->call_ == ISEND) && (comm2->type_ == kernel::activity::CommImpl::Type::SEND) &&
171           (comm2->src_buff_ != simcall_comm_isend__get__src_buff(req1)) && simcall_comm_wait__get__timeout(req2) <= 0)
172         return false;
173
174       if ((req1->call_ == IRECV) && (comm2->type_ == kernel::activity::CommImpl::Type::RECEIVE) &&
175           (comm2->dst_buff_ != simcall_comm_irecv__get__dst_buff(req1)) && simcall_comm_wait__get__timeout(req2) <= 0)
176         return false;
177     }
178
179     /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
180      * test call. */
181 #if 0
182   if((req1->call == ISEND || req1->call == IRECV)
183       &&  req2->call == TEST)
184     return false;
185 #endif
186
187     return true;
188   }
189
190   /* Second case: req1 and req2 are of the same call type */
191   switch (req1->call_) {
192     case ISEND:
193       return simcall_comm_isend__get__mbox(req1) == simcall_comm_isend__get__mbox(req2);
194     case IRECV:
195       return simcall_comm_irecv__get__mbox(req1) == simcall_comm_irecv__get__mbox(req2);
196     default:
197       return true;
198   }
199 }
200
201 xbt::string const& Api::get_actor_host_name(smx_actor_t actor) const
202 {
203   if (mc_model_checker == nullptr)
204     return actor->get_host()->get_name();
205
206   const simgrid::mc::RemoteProcess* process = &mc_model_checker->get_remote_process();
207
208   // Read the simgrid::xbt::string in the MCed process:
209   simgrid::mc::ActorInformation* info = actor_info_cast(actor);
210
211   if (not info->hostname) {
212     Remote<s4u::Host> temp_host = process->read(remote(actor->get_host()));
213     auto remote_string_address  = remote(&xbt::string::to_string_data(temp_host.get_buffer()->get_impl()->get_name()));
214     simgrid::xbt::string_data remote_string = process->read(remote_string_address);
215     std::vector<char> hostname(remote_string.len + 1);
216     // no need to read the terminating null byte, and thus hostname[remote_string.len] is guaranteed to be '\0'
217     process->read_bytes(hostname.data(), remote_string.len, remote(remote_string.data));
218     info->hostname = &mc_model_checker->get_host_name(hostname.data());
219   }
220   return *info->hostname;
221 }
222
223 xbt::string const& Api::get_actor_name(smx_actor_t actor) const
224 {
225   if (mc_model_checker == nullptr)
226     return actor->get_name();
227
228   simgrid::mc::ActorInformation* info = actor_info_cast(actor);
229   if (info->name.empty()) {
230     const simgrid::mc::RemoteProcess* process = &mc_model_checker->get_remote_process();
231
232     simgrid::xbt::string_data string_data = simgrid::xbt::string::to_string_data(actor->name_);
233     info->name = process->read_string(remote(string_data.data), string_data.len);
234   }
235   return info->name;
236 }
237
238 std::string Api::get_actor_string(smx_actor_t actor) const
239 {
240   std::string res;
241   if (actor) {
242     res = "(" + std::to_string(actor->get_pid()) + ")";
243     if (actor->get_host())
244       res += std::string(get_actor_host_name(actor)) + " (" + std::string(get_actor_name(actor)) + ")";
245     else
246       res += get_actor_name(actor);
247   } else
248     res = "(0) ()";
249   return res;
250 }
251
252 std::string Api::get_actor_dot_label(smx_actor_t actor) const
253 {
254   std::string res = "(" + std::to_string(actor->get_pid()) + ")";
255   if (actor->get_host())
256     res += get_actor_host_name(actor);
257   return res;
258 }
259
260 simgrid::mc::Checker* Api::initialize(char** argv, simgrid::mc::CheckerAlgorithm algo) const
261 {
262   auto session = new simgrid::mc::Session([argv] {
263     int i = 1;
264     while (argv[i] != nullptr && argv[i][0] == '-')
265       i++;
266     xbt_assert(argv[i] != nullptr,
267                "Unable to find a binary to exec on the command line. Did you only pass config flags?");
268     execvp(argv[i], argv + i);
269     xbt_die("The model-checked process failed to exec(%s): %s", argv[i], strerror(errno));
270   });
271
272   simgrid::mc::Checker* checker;
273   switch (algo) {
274     case CheckerAlgorithm::CommDeterminism:
275       checker = simgrid::mc::create_communication_determinism_checker(session);
276       break;
277
278     case CheckerAlgorithm::UDPOR:
279       checker = simgrid::mc::create_udpor_checker(session);
280       break;
281
282     case CheckerAlgorithm::Safety:
283       checker = simgrid::mc::create_safety_checker(session);
284       break;
285
286     case CheckerAlgorithm::Liveness:
287       checker = simgrid::mc::create_liveness_checker(session);
288       break;
289
290     default:
291       THROW_IMPOSSIBLE;
292   }
293
294   // FIXME: session and checker are never deleted
295   simgrid::mc::session_singleton = session;
296   mc_model_checker->setChecker(checker);
297   return checker;
298 }
299
300 std::vector<simgrid::mc::ActorInformation>& Api::get_actors() const
301 {
302   return mc_model_checker->get_remote_process().actors();
303 }
304
305 unsigned long Api::get_maxpid() const
306 {
307   return mc_model_checker->get_remote_process().get_maxpid();
308 }
309
310 int Api::get_actors_size() const
311 {
312   return mc_model_checker->get_remote_process().actors().size();
313 }
314
315 RemotePtr<kernel::activity::CommImpl> Api::get_comm_isend_raw_addr(smx_simcall_t request) const
316 {
317   return remote(static_cast<kernel::activity::CommImpl*>(simcall_comm_isend__getraw__result(request)));
318 }
319
320 RemotePtr<kernel::activity::CommImpl> Api::get_comm_waitany_raw_addr(smx_simcall_t request, int value) const
321 {
322   auto addr      = simcall_comm_waitany__getraw__comms(request) + value;
323   auto comm_addr = mc_model_checker->get_remote_process().read(remote(addr));
324   return RemotePtr<kernel::activity::CommImpl>(static_cast<kernel::activity::CommImpl*>(comm_addr));
325 }
326
327 std::string Api::get_pattern_comm_rdv(RemotePtr<kernel::activity::CommImpl> const& addr) const
328 {
329   Remote<kernel::activity::CommImpl> temp_activity;
330   mc_model_checker->get_remote_process().read(temp_activity, addr);
331   const kernel::activity::CommImpl* activity = temp_activity.get_buffer();
332
333   char* remote_name = mc_model_checker->get_remote_process().read<char*>(RemotePtr<char*>(
334       (uint64_t)(activity->get_mailbox() ? &activity->get_mailbox()->get_name() : &activity->mbox_cpy->get_name())));
335   auto rdv          = mc_model_checker->get_remote_process().read_string(RemotePtr<char>(remote_name));
336   return rdv;
337 }
338
339 unsigned long Api::get_pattern_comm_src_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
340 {
341   Remote<kernel::activity::CommImpl> temp_activity;
342   mc_model_checker->get_remote_process().read(temp_activity, addr);
343   const kernel::activity::CommImpl* activity = temp_activity.get_buffer();
344   auto src_proc =
345       mc_model_checker->get_remote_process().resolve_actor(mc::remote(activity->src_actor_.get()))->get_pid();
346   return src_proc;
347 }
348
349 unsigned long Api::get_pattern_comm_dst_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const
350 {
351   Remote<kernel::activity::CommImpl> temp_activity;
352   mc_model_checker->get_remote_process().read(temp_activity, addr);
353   const kernel::activity::CommImpl* activity = temp_activity.get_buffer();
354   auto src_proc =
355       mc_model_checker->get_remote_process().resolve_actor(mc::remote(activity->dst_actor_.get()))->get_pid();
356   return src_proc;
357 }
358
359 std::vector<char> Api::get_pattern_comm_data(RemotePtr<kernel::activity::CommImpl> const& addr) const
360 {
361   simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
362   mc_model_checker->get_remote_process().read(temp_comm, addr);
363   const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
364
365   std::vector<char> buffer{};
366   if (comm->src_buff_ != nullptr) {
367     buffer.resize(comm->src_buff_size_);
368     mc_model_checker->get_remote_process().read_bytes(buffer.data(), buffer.size(), remote(comm->src_buff_));
369   }
370   return buffer;
371 }
372
373 #if HAVE_SMPI
374 bool Api::check_send_request_detached(smx_simcall_t const& simcall) const
375 {
376   Remote<simgrid::smpi::Request> mpi_request;
377   mc_model_checker->get_remote_process().read(
378       mpi_request, remote(static_cast<smpi::Request*>(simcall_comm_isend__get__data(simcall))));
379   return mpi_request.get_buffer()->detached();
380 }
381 #endif
382
383 smx_actor_t Api::get_src_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
384 {
385   simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
386   mc_model_checker->get_remote_process().read(temp_comm, comm_addr);
387   const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
388
389   auto src_proc = mc_model_checker->get_remote_process().resolve_actor(simgrid::mc::remote(comm->src_actor_.get()));
390   return src_proc;
391 }
392
393 smx_actor_t Api::get_dst_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const
394 {
395   simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
396   mc_model_checker->get_remote_process().read(temp_comm, comm_addr);
397   const simgrid::kernel::activity::CommImpl* comm = temp_comm.get_buffer();
398
399   auto dst_proc = mc_model_checker->get_remote_process().resolve_actor(simgrid::mc::remote(comm->dst_actor_.get()));
400   return dst_proc;
401 }
402
403 std::size_t Api::get_remote_heap_bytes() const
404 {
405   RemoteProcess& process    = mc_model_checker->get_remote_process();
406   auto heap_bytes_used      = mmalloc_get_bytes_used_remote(process.get_heap()->heaplimit, process.get_malloc_info());
407   return heap_bytes_used;
408 }
409
410 void Api::mc_inc_visited_states() const
411 {
412   mc_model_checker->visited_states++;
413 }
414
415 void Api::mc_inc_executed_trans() const
416 {
417   mc_model_checker->executed_transitions++;
418 }
419
420 unsigned long Api::mc_get_visited_states() const
421 {
422   return mc_model_checker->visited_states;
423 }
424
425 unsigned long Api::mc_get_executed_trans() const
426 {
427   return mc_model_checker->executed_transitions;
428 }
429
430 void Api::mc_check_deadlock() const
431 {
432   if (mc_model_checker->checkDeadlock()) {
433     XBT_CINFO(mc_global, "**************************");
434     XBT_CINFO(mc_global, "*** DEADLOCK DETECTED ***");
435     XBT_CINFO(mc_global, "**************************");
436     XBT_CINFO(mc_global, "Counter-example execution trace:");
437     for (auto const& s : mc_model_checker->getChecker()->get_textual_trace())
438       XBT_CINFO(mc_global, "  %s", s.c_str());
439     simgrid::mc::dumpRecordPath();
440     simgrid::mc::session_singleton->log_state();
441     throw DeadlockError();
442   }
443 }
444
445 /** Get the issuer of a simcall (`req->issuer`)
446  *
447  *  In split-process mode, it does the black magic necessary to get an address
448  *  of a (shallow) copy of the data structure the issuer SIMIX actor in the local
449  *  address space.
450  *
451  *  @param process the MCed process
452  *  @param req     the simcall (copied in the local process)
453  */
454 smx_actor_t Api::simcall_get_issuer(s_smx_simcall const* req) const
455 {
456   xbt_assert(mc_model_checker != nullptr);
457
458   // This is the address of the smx_actor in the MCed process:
459   auto address = simgrid::mc::remote(req->issuer_);
460
461   // Lookup by address:
462   for (auto& actor : mc_model_checker->get_remote_process().actors())
463     if (actor.address == address)
464       return actor.copy.get_buffer();
465   for (auto& actor : mc_model_checker->get_remote_process().dead_actors())
466     if (actor.address == address)
467       return actor.copy.get_buffer();
468
469   xbt_die("Issuer not found");
470 }
471
472 RemotePtr<kernel::activity::MailboxImpl> Api::get_mbox_remote_addr(smx_simcall_t const req) const
473 {
474   if (req->call_ == Simcall::COMM_ISEND)
475     return remote(simcall_comm_isend__get__mbox(req));
476   if (req->call_ == Simcall::COMM_IRECV)
477     return remote(simcall_comm_irecv__get__mbox(req));
478   THROW_IMPOSSIBLE;
479 }
480
481 RemotePtr<kernel::activity::ActivityImpl> Api::get_comm_remote_addr(smx_simcall_t const req) const
482 {
483   if (req->call_ == Simcall::COMM_ISEND)
484     return remote(simcall_comm_isend__getraw__result(req));
485   if (req->call_ == Simcall::COMM_IRECV)
486     return remote(simcall_comm_irecv__getraw__result(req));
487   THROW_IMPOSSIBLE;
488 }
489
490 void Api::handle_simcall(Transition const& transition) const
491 {
492   mc_model_checker->handle_simcall(transition);
493 }
494
495 void Api::mc_wait_for_requests() const
496 {
497   mc_model_checker->wait_for_requests();
498 }
499
500 void Api::mc_exit(int status) const
501 {
502   mc_model_checker->exit(status);
503 }
504
505 void Api::dump_record_path() const
506 {
507   simgrid::mc::dumpRecordPath();
508 }
509
510 smx_simcall_t Api::mc_state_choose_request(simgrid::mc::State* state) const
511 {
512   RemoteProcess& process = mc_model_checker->get_remote_process();
513   for (auto& actor : process.actors()) {
514     /* Only consider the actors that were marked as interleaving by the checker algorithm */
515     if (not state->actor_states_[actor.copy.get_buffer()->get_pid()].is_todo())
516       continue;
517
518     smx_simcall_t res = MC_state_choose_request_for_process(process, state, actor.copy.get_buffer());
519     if (res)
520       return res;
521   }
522   return nullptr;
523 }
524
525 std::list<transition_detail_t> Api::get_enabled_transitions(simgrid::mc::State* state) const
526 {
527   std::list<transition_detail_t> tr_list{};
528
529   for (auto& actor : mc_model_checker->get_remote_process().actors()) {
530     auto actor_pid  = actor.copy.get_buffer()->get_pid();
531     auto actor_impl = actor.copy.get_buffer();
532
533     // Only consider the actors that were marked as interleaving by the checker algorithm
534     if (not state->actor_states_[actor_pid].is_todo())
535       continue;
536     // Not executable in the application
537     if (not simgrid::mc::actor_is_enabled(actor_impl))
538       continue;
539
540     auto transition       = std::make_unique<s_transition_detail>();
541     Simcall simcall_call  = actor_impl->simcall_.call_;
542     smx_simcall_t simcall = &actor_impl->simcall_;
543     transition->call_     = simcall_call;
544     switch (simcall_call) {
545       case Simcall::COMM_ISEND:
546       case Simcall::COMM_IRECV:
547         transition->mbox_remote_addr = get_mbox_remote_addr(simcall);
548         transition->comm_remote_addr = get_comm_remote_addr(simcall);
549         break;
550
551       default:
552         break;
553     }
554     tr_list.emplace_back(std::move(transition));
555   }
556
557   return tr_list;
558 }
559
560 std::string Api::request_to_string(smx_simcall_t req, int value) const
561 {
562   xbt_assert(mc_model_checker != nullptr, "Must be called from MCer");
563
564   smx_actor_t issuer = simcall_get_issuer(req);
565
566   if (issuer->simcall_.observer_ != nullptr)
567     return mc_model_checker->simcall_to_string(issuer->get_pid(), value);
568   else
569     return "[" + get_actor_string(issuer) + "] " + SIMIX_simcall_name(*req) + "(unknown?)";
570 }
571
572 std::string Api::request_get_dot_output(smx_simcall_t req, int value) const
573 {
574   if (req->observer_ != nullptr) {
575     const smx_actor_t issuer = simcall_get_issuer(req);
576     const char* color        = get_color(issuer->get_pid() - 1);
577     return "label = \"" + mc_model_checker->simcall_dot_label(issuer->get_pid(), value) + "\", color = " + color +
578            ", fontcolor = " + color;
579   } else
580     return "UNIMPLEMENTED";
581 }
582
583 #if HAVE_SMPI
584 int Api::get_smpi_request_tag(smx_simcall_t const& simcall, simgrid::simix::Simcall type) const
585 {
586   void* simcall_data = nullptr;
587   if (type == Simcall::COMM_ISEND)
588     simcall_data = simcall_comm_isend__get__data(simcall);
589   else if (type == Simcall::COMM_IRECV)
590     simcall_data = simcall_comm_irecv__get__data(simcall);
591   Remote<simgrid::smpi::Request> mpi_request;
592   mc_model_checker->get_remote_process().read(mpi_request, remote(static_cast<smpi::Request*>(simcall_data)));
593   return mpi_request.get_buffer()->tag();
594 }
595 #endif
596
597 void Api::restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const
598 {
599   system_state->restore(&mc_model_checker->get_remote_process());
600 }
601
602 void Api::log_state() const
603 {
604   session_singleton->log_state();
605 }
606
607 bool Api::snapshot_equal(const Snapshot* s1, const Snapshot* s2) const
608 {
609   return simgrid::mc::snapshot_equal(s1, s2);
610 }
611
612 simgrid::mc::Snapshot* Api::take_snapshot(int num_state) const
613 {
614   auto snapshot = new simgrid::mc::Snapshot(num_state);
615   return snapshot;
616 }
617
618 void Api::s_close() const
619 {
620   session_singleton->close();
621 }
622
623 void Api::execute(Transition& transition, smx_simcall_t simcall) const
624 {
625   /* FIXME: once all simcalls have observers, kill the simcall parameter and use mc_model_checker->simcall_to_string() */
626   transition.textual = request_to_string(simcall, transition.times_considered_);
627   session_singleton->execute(transition);
628 }
629
630 void Api::automaton_load(const char* file) const
631 {
632   MC_automaton_load(file);
633 }
634
635 std::vector<int> Api::automaton_propositional_symbol_evaluate() const
636 {
637   unsigned int cursor = 0;
638   std::vector<int> values;
639   xbt_automaton_propositional_symbol_t ps = nullptr;
640   xbt_dynar_foreach (mc::property_automaton->propositional_symbols, cursor, ps)
641     values.push_back(xbt_automaton_propositional_symbol_evaluate(ps));
642   return values;
643 }
644
645 std::vector<xbt_automaton_state_t> Api::get_automaton_state() const
646 {
647   std::vector<xbt_automaton_state_t> automaton_stack;
648   unsigned int cursor = 0;
649   xbt_automaton_state_t automaton_state;
650   xbt_dynar_foreach (mc::property_automaton->states, cursor, automaton_state)
651     if (automaton_state->type == -1)
652       automaton_stack.push_back(automaton_state);
653   return automaton_stack;
654 }
655
656 int Api::compare_automaton_exp_label(const xbt_automaton_exp_label* l) const
657 {
658   unsigned int cursor                    = 0;
659   xbt_automaton_propositional_symbol_t p = nullptr;
660   xbt_dynar_foreach (simgrid::mc::property_automaton->propositional_symbols, cursor, p) {
661     if (std::strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0)
662       return cursor;
663   }
664   return -1;
665 }
666
667 void Api::set_property_automaton(xbt_automaton_state_t const& automaton_state) const
668 {
669   mc::property_automaton->current_state = automaton_state;
670 }
671
672 xbt_automaton_exp_label_t Api::get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const
673 {
674   const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
675   return transition->label;
676 }
677
678 xbt_automaton_state_t Api::get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const
679 {
680   const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
681   return transition->dst;
682 }
683
684 } // namespace mc
685 } // namespace simgrid