1 /* Copyright (c) 2015-2019. 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. */
7 #include "simgrid/sg_config.hpp"
8 #include "src/mc/checker/Checker.hpp"
9 #include "src/mc/mc_exit.hpp"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
17 char** argvdup(int argc, char** argv)
19 char** argv_copy = new char*[argc + 1];
20 std::memcpy(argv_copy, argv, sizeof(char*) * argc);
21 argv_copy[argc] = nullptr;
25 static std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
27 if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
28 return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createCommunicationDeterminismChecker(session));
29 else if (_sg_mc_property_file.get().empty())
30 return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createSafetyChecker(session));
32 return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createLivenessChecker(session));
35 int main(int argc, char** argv)
37 using simgrid::mc::Session;
41 xbt_die("Missing arguments.\n");
43 // Currently, we need this before sg_config_init:
44 _sg_do_model_check = 1;
46 // The initialization function can touch argv.
47 // We make a copy of argv before modifying it in order to pass the original
48 // value to the model-checked:
49 char** argv_copy = argvdup(argc, argv);
50 xbt_log_init(&argc, argv);
51 sg_config_init(&argc, argv);
53 std::unique_ptr<Session> session =
54 std::unique_ptr<Session>(Session::spawnvp(argv_copy[1], argv_copy+1));
57 simgrid::mc::session = session.get();
58 std::unique_ptr<simgrid::mc::Checker> checker = createChecker(*session);
59 int res = SIMGRID_MC_EXIT_SUCCESS;
62 } catch (const simgrid::mc::DeadlockError&) {
63 res = SIMGRID_MC_EXIT_DEADLOCK;
64 } catch (const simgrid::mc::TerminationError&) {
65 res = SIMGRID_MC_EXIT_NON_TERMINATION;
66 } catch (const simgrid::mc::LivenessError&) {
67 res = SIMGRID_MC_EXIT_LIVENESS;
73 catch(std::exception& e) {
74 XBT_ERROR("Exception: %s", e.what());
75 return SIMGRID_MC_EXIT_ERROR;
78 XBT_ERROR("Unknown exception");
79 return SIMGRID_MC_EXIT_ERROR;