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/mc_exit.h"
28 #include "src/mc/Session.hpp"
29 #include "src/mc/Checker.hpp"
31 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
34 char** argvdup(int argc, char** argv)
36 char** argv_copy = xbt_new(char*, argc+1);
37 std::memcpy(argv_copy, argv, sizeof(char*) * argc);
38 argv_copy[argc] = nullptr;
43 std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
45 if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
46 return std::unique_ptr<simgrid::mc::Checker>(
47 simgrid::mc::createCommunicationDeterminismChecker(session));
48 else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0')
49 return std::unique_ptr<simgrid::mc::Checker>(
50 simgrid::mc::createSafetyChecker(session));
52 return std::unique_ptr<simgrid::mc::Checker>(
53 simgrid::mc::createLivenessChecker(session));
56 int main(int argc, char** argv)
58 using simgrid::mc::Session;
62 xbt_die("Missing arguments.\n");
64 // Currently, we need this before sg_config_init:
65 _sg_do_model_check = 1;
67 // The initialisation function can touch argv.
68 // We make a copy of argv before modifying it in order to pass the original
69 // value to the model-checked:
70 char** argv_copy = argvdup(argc, argv);
71 xbt_log_init(&argc, argv);
72 sg_config_init(&argc, argv);
74 std::unique_ptr<Session> session =
75 std::unique_ptr<Session>(Session::spawnvp(argv_copy[1], argv_copy+1));
78 simgrid::mc::session = session.get();
79 std::unique_ptr<simgrid::mc::Checker> checker = createChecker(*session);
80 int res = checker->run();
85 catch(std::exception& e) {
86 XBT_ERROR("Exception: %s", e.what());
87 return SIMGRID_MC_EXIT_ERROR;
90 XBT_ERROR("Unknown exception");
91 return SIMGRID_MC_EXIT_ERROR;