1 /* Copyright (c) 2020-2022. 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. */
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/api/RemoteApp.hpp"
12 #include "src/mc/explo/Exploration.hpp"
13 #include "src/mc/mc_base.hpp"
14 #include "src/mc/mc_exit.hpp"
15 #include "src/mc/mc_private.hpp"
16 #include "src/mc/remote/RemoteProcess.hpp"
17 #include "src/surf/HostImpl.hpp"
19 #include <xbt/asserts.h>
21 #include "simgrid/s4u/Host.hpp"
22 #include "xbt/string.hpp"
24 #include "src/smpi/include/smpi_request.hpp"
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(Api, mc, "Logging specific to MC Facade APIs ");
28 XBT_LOG_EXTERNAL_CATEGORY(mc_global);
30 namespace simgrid::mc {
32 simgrid::mc::Exploration* Api::initialize(char** argv, const std::unordered_map<std::string, std::string>& env,
33 simgrid::mc::ExplorationAlgorithm algo)
35 remote_app_ = std::make_unique<simgrid::mc::RemoteApp>([argv, &env] {
37 while (argv[i] != nullptr && argv[i][0] == '-')
40 for (auto const& [key, val] : env) {
41 XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str());
42 setenv(key.c_str(), val.c_str(), 1);
44 xbt_assert(argv[i] != nullptr,
45 "Unable to find a binary to exec on the command line. Did you only pass config flags?");
46 execvp(argv[i], argv + i);
47 xbt_die("The model-checked process failed to exec(%s): %s", argv[i], strerror(errno));
50 simgrid::mc::Exploration* explo;
52 case ExplorationAlgorithm::CommDeterminism:
53 explo = simgrid::mc::create_communication_determinism_checker(*(remote_app_.get()));
56 case ExplorationAlgorithm::UDPOR:
57 explo = simgrid::mc::create_udpor_checker(*(remote_app_.get()));
60 case ExplorationAlgorithm::Safety:
61 explo = simgrid::mc::create_dfs_exploration(*(remote_app_.get()));
64 case ExplorationAlgorithm::Liveness:
65 explo = simgrid::mc::create_liveness_checker(*(remote_app_.get()));
72 mc_model_checker->set_exploration(explo);
77 std::size_t Api::get_remote_heap_bytes() const
79 RemoteProcess& process = mc_model_checker->get_remote_process();
80 auto heap_bytes_used = mmalloc_get_bytes_used_remote(process.get_heap()->heaplimit, process.get_malloc_info());
81 return heap_bytes_used;
84 bool Api::snapshot_equal(const Snapshot* s1, const Snapshot* s2) const
86 return simgrid::mc::snapshot_equal(s1, s2);
89 simgrid::mc::Snapshot* Api::take_snapshot(long num_state) const
91 auto snapshot = new simgrid::mc::Snapshot(num_state);
95 } // namespace simgrid::mc