1 /* Copyright (c) 2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
19 #include "simgrid/sg_config.h"
20 #include "src/xbt_modinter.h"
22 #include "src/mc/mc_base.h"
23 #include "src/mc/mc_private.h"
24 #include "src/mc/mc_protocol.h"
25 #include "src/mc/mc_safety.h"
26 #include "src/mc/mc_comm_pattern.h"
27 #include "src/mc/LivenessChecker.hpp"
28 #include "src/mc/mc_exit.h"
29 #include "src/mc/Session.hpp"
30 #include "src/mc/Checker.hpp"
31 #include "src/mc/CommunicationDeterminismChecker.hpp"
32 #include "src/mc/SafetyChecker.hpp"
34 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
37 char** argvdup(int argc, char** argv)
39 char** argv_copy = xbt_new(char*, argc+1);
40 std::memcpy(argv_copy, argv, sizeof(char*) * argc);
41 argv_copy[argc] = nullptr;
46 std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
48 using simgrid::mc::Session;
49 using simgrid::mc::FunctionalChecker;
51 std::function<int(Session& session)> code;
52 if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
53 return std::unique_ptr<simgrid::mc::Checker>(
54 new simgrid::mc::CommunicationDeterminismChecker(session));
55 else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0')
56 return std::unique_ptr<simgrid::mc::Checker>(
57 new simgrid::mc::SafetyChecker(session));
59 return std::unique_ptr<simgrid::mc::Checker>(
60 new simgrid::mc::LivenessChecker(session));
62 return std::unique_ptr<simgrid::mc::Checker>(
63 new FunctionalChecker(session, std::move(code)));
66 int main(int argc, char** argv)
68 using simgrid::mc::Session;
72 xbt_die("Missing arguments.\n");
74 // Currently, we need this before sg_config_init:
75 _sg_do_model_check = 1;
76 mc_mode = MC_MODE_SERVER;
78 // The initialisation function can touch argv.
79 // We make a copy of argv before modifying it in order to pass the original
80 // value to the model-checked:
81 char** argv_copy = argvdup(argc, argv);
82 xbt_log_init(&argc, argv);
83 sg_config_init(&argc, argv);
85 std::unique_ptr<Session> session =
86 std::unique_ptr<Session>(Session::spawnvp(argv_copy[1], argv_copy+1));
89 simgrid::mc::session = session.get();
90 std::unique_ptr<simgrid::mc::Checker> checker = createChecker(*session);
91 int res = checker->run();
95 catch(std::exception& e) {
96 XBT_ERROR("Exception: %s", e.what());
97 return SIMGRID_MC_EXIT_ERROR;
100 XBT_ERROR("Unknown exception");
101 return SIMGRID_MC_EXIT_ERROR;