Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill 2 more functions from mc::api
[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/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"
18
19 #include <xbt/asserts.h>
20 #include <xbt/log.h>
21 #include "simgrid/s4u/Host.hpp"
22 #include "xbt/string.hpp"
23 #if HAVE_SMPI
24 #include "src/smpi/include/smpi_request.hpp"
25 #endif
26
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(Api, mc, "Logging specific to MC Facade APIs ");
28 XBT_LOG_EXTERNAL_CATEGORY(mc_global);
29
30 namespace simgrid::mc {
31
32 simgrid::mc::Exploration* Api::initialize(char** argv, const std::unordered_map<std::string, std::string>& env,
33                                           simgrid::mc::ExplorationAlgorithm algo)
34 {
35   remote_app_ = std::make_unique<simgrid::mc::RemoteApp>([argv, &env] {
36     int i = 1;
37     while (argv[i] != nullptr && argv[i][0] == '-')
38       i++;
39
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);
43     }
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));
48   });
49
50   simgrid::mc::Exploration* explo;
51   switch (algo) {
52     case ExplorationAlgorithm::CommDeterminism:
53       explo = simgrid::mc::create_communication_determinism_checker(*(remote_app_.get()));
54       break;
55
56     case ExplorationAlgorithm::UDPOR:
57       explo = simgrid::mc::create_udpor_checker(*(remote_app_.get()));
58       break;
59
60     case ExplorationAlgorithm::Safety:
61       explo = simgrid::mc::create_dfs_exploration(*(remote_app_.get()));
62       break;
63
64     case ExplorationAlgorithm::Liveness:
65       explo = simgrid::mc::create_liveness_checker(*(remote_app_.get()));
66       break;
67
68     default:
69       THROW_IMPOSSIBLE;
70   }
71
72   mc_model_checker->set_exploration(explo);
73   return explo;
74 }
75
76
77 std::size_t Api::get_remote_heap_bytes() const
78 {
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;
82 }
83
84 void Api::restore_state(const simgrid::mc::Snapshot* system_state) const
85 {
86   system_state->restore(&mc_model_checker->get_remote_process());
87 }
88
89 bool Api::snapshot_equal(const Snapshot* s1, const Snapshot* s2) const
90 {
91   return simgrid::mc::snapshot_equal(s1, s2);
92 }
93
94 simgrid::mc::Snapshot* Api::take_snapshot(long num_state) const
95 {
96   auto snapshot = new simgrid::mc::Snapshot(num_state);
97   return snapshot;
98 }
99
100 } // namespace simgrid::mc