+++ /dev/null
-/* Copyright (c) 2020-2022. The SimGrid Team. All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "api.hpp"
-
-#include "src/kernel/activity/MailboxImpl.hpp"
-#include "src/kernel/activity/MutexImpl.hpp"
-#include "src/kernel/actor/SimcallObserver.hpp"
-#include "src/mc/Session.hpp"
-#include "src/mc/explo/Exploration.hpp"
-#include "src/mc/mc_base.hpp"
-#include "src/mc/mc_exit.hpp"
-#include "src/mc/mc_pattern.hpp"
-#include "src/mc/mc_private.hpp"
-#include "src/mc/remote/RemoteProcess.hpp"
-#include "src/surf/HostImpl.hpp"
-
-#include <xbt/asserts.h>
-#include <xbt/log.h>
-#include "simgrid/s4u/Host.hpp"
-#include "xbt/string.hpp"
-#if HAVE_SMPI
-#include "src/smpi/include/smpi_request.hpp"
-#endif
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(Api, mc, "Logging specific to MC Facade APIs ");
-XBT_LOG_EXTERNAL_CATEGORY(mc_global);
-
-namespace simgrid::mc {
-
-simgrid::mc::Exploration* Api::initialize(char** argv, const std::unordered_map<std::string, std::string>& env,
- simgrid::mc::ExplorationAlgorithm algo)
-{
- session_ = std::make_unique<simgrid::mc::Session>([argv, &env] {
- int i = 1;
- while (argv[i] != nullptr && argv[i][0] == '-')
- i++;
- for (auto const& kv : env) {
- const char* key = kv.first.c_str();
- const char* val = kv.second.c_str();
- XBT_INFO("setenv '%s'='%s'", key, val);
- setenv(key, val, 1);
- }
- xbt_assert(argv[i] != nullptr,
- "Unable to find a binary to exec on the command line. Did you only pass config flags?");
- execvp(argv[i], argv + i);
- xbt_die("The model-checked process failed to exec(%s): %s", argv[i], strerror(errno));
- });
-
- simgrid::mc::Exploration* explo;
- switch (algo) {
- case ExplorationAlgorithm::CommDeterminism:
- explo = simgrid::mc::create_communication_determinism_checker(session_.get());
- break;
-
- case ExplorationAlgorithm::UDPOR:
- explo = simgrid::mc::create_udpor_checker(session_.get());
- break;
-
- case ExplorationAlgorithm::Safety:
- explo = simgrid::mc::create_dfs_exploration(session_.get());
- break;
-
- case ExplorationAlgorithm::Liveness:
- explo = simgrid::mc::create_liveness_checker(session_.get());
- break;
-
- default:
- THROW_IMPOSSIBLE;
- }
-
- mc_model_checker->set_exploration(explo);
- return explo;
-}
-
-std::vector<simgrid::mc::ActorInformation>& Api::get_actors() const
-{
- return mc_model_checker->get_remote_process().actors();
-}
-
-unsigned long Api::get_maxpid() const
-{
- return mc_model_checker->get_remote_process().get_maxpid();
-}
-
-std::size_t Api::get_remote_heap_bytes() const
-{
- RemoteProcess& process = mc_model_checker->get_remote_process();
- auto heap_bytes_used = mmalloc_get_bytes_used_remote(process.get_heap()->heaplimit, process.get_malloc_info());
- return heap_bytes_used;
-}
-
-void Api::mc_inc_visited_states() const
-{
- mc_model_checker->inc_visited_states();
-}
-
-unsigned long Api::mc_get_visited_states() const
-{
- return mc_model_checker->get_visited_states();
-}
-
-void Api::mc_exit(int status) const
-{
- mc_model_checker->exit(status);
-}
-
-void Api::restore_state(const simgrid::mc::Snapshot* system_state) const
-{
- system_state->restore(&mc_model_checker->get_remote_process());
-}
-
-bool Api::snapshot_equal(const Snapshot* s1, const Snapshot* s2) const
-{
- return simgrid::mc::snapshot_equal(s1, s2);
-}
-
-simgrid::mc::Snapshot* Api::take_snapshot(long num_state) const
-{
- auto snapshot = new simgrid::mc::Snapshot(num_state);
- return snapshot;
-}
-
-void Api::s_close()
-{
- session_.reset();
- if (simgrid::mc::property_automaton != nullptr) {
- xbt_automaton_free(simgrid::mc::property_automaton);
- simgrid::mc::property_automaton = nullptr;
- }
-}
-
-void Api::automaton_load(const char* file) const
-{
- if (simgrid::mc::property_automaton == nullptr)
- simgrid::mc::property_automaton = xbt_automaton_new();
-
- xbt_automaton_load(simgrid::mc::property_automaton, file);
-}
-
-std::vector<int> Api::automaton_propositional_symbol_evaluate() const
-{
- unsigned int cursor = 0;
- std::vector<int> values;
- xbt_automaton_propositional_symbol_t ps = nullptr;
- xbt_dynar_foreach (mc::property_automaton->propositional_symbols, cursor, ps)
- values.push_back(xbt_automaton_propositional_symbol_evaluate(ps));
- return values;
-}
-
-std::vector<xbt_automaton_state_t> Api::get_automaton_state() const
-{
- std::vector<xbt_automaton_state_t> automaton_stack;
- unsigned int cursor = 0;
- xbt_automaton_state_t automaton_state;
- xbt_dynar_foreach (mc::property_automaton->states, cursor, automaton_state)
- if (automaton_state->type == -1)
- automaton_stack.push_back(automaton_state);
- return automaton_stack;
-}
-
-int Api::compare_automaton_exp_label(const xbt_automaton_exp_label* l) const
-{
- unsigned int cursor = 0;
- xbt_automaton_propositional_symbol_t p = nullptr;
- xbt_dynar_foreach (simgrid::mc::property_automaton->propositional_symbols, cursor, p) {
- if (std::strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0)
- return cursor;
- }
- return -1;
-}
-
-void Api::set_property_automaton(xbt_automaton_state_t const& automaton_state) const
-{
- mc::property_automaton->current_state = automaton_state;
-}
-
-xbt_automaton_exp_label_t Api::get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const
-{
- const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
- return transition->label;
-}
-
-xbt_automaton_state_t Api::get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const
-{
- const xbt_automaton_transition* transition = xbt_dynar_get_as(dynar, index, xbt_automaton_transition_t);
- return transition->dst;
-}
-
-} // namespace simgrid::mc