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/smpi/include/smpi_config.hpp"
9 #include "src/mc/Session.hpp"
10 #include "src/mc/checker/Checker.hpp"
11 #include "src/mc/mc_config.hpp"
12 #include "src/mc/mc_exit.hpp"
19 char** argvdup(int argc, char** argv)
21 char** argv_copy = new char*[argc + 1];
22 std::memcpy(argv_copy, argv, sizeof(char*) * argc);
23 argv_copy[argc] = nullptr;
27 static std::unique_ptr<simgrid::mc::Checker> create_checker(simgrid::mc::Session& session)
29 if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
30 return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createCommunicationDeterminismChecker(session));
31 else if (_sg_mc_property_file.get().empty())
32 return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createSafetyChecker(session));
34 return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createLivenessChecker(session));
37 int main(int argc, char** argv)
40 xbt_die("Missing arguments.\n");
42 // Currently, we need this before sg_config_init:
43 _sg_do_model_check = 1;
45 // The initialization function can touch argv.
46 // We make a copy of argv before modifying it in order to pass the original
47 // value to the model-checked:
48 char** argv_copy = argvdup(argc, argv);
49 xbt_log_init(&argc, argv);
50 smpi_init_options();//only performed once
51 sg_config_init(&argc, argv);
52 simgrid::mc::session = new simgrid::mc::Session([argv_copy] { execvp(argv_copy[1], argv_copy + 1); });
55 std::unique_ptr<simgrid::mc::Checker> checker = create_checker(*simgrid::mc::session);
56 int res = SIMGRID_MC_EXIT_SUCCESS;
59 } catch (const simgrid::mc::DeadlockError&) {
60 res = SIMGRID_MC_EXIT_DEADLOCK;
61 } catch (const simgrid::mc::TerminationError&) {
62 res = SIMGRID_MC_EXIT_NON_TERMINATION;
63 } catch (const simgrid::mc::LivenessError&) {
64 res = SIMGRID_MC_EXIT_LIVENESS;
67 simgrid::mc::session->close();