1 /* Copyright (c) 2015-2021. 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_config.hpp"
10 #include "src/mc/mc_exit.hpp"
11 #include "src/internal_config.h"
14 #include "smpi/smpi.h"
21 using api = simgrid::mc::Api;
24 char** argvdup(int argc, char** argv)
26 auto* argv_copy = new char*[argc + 1];
27 std::memcpy(argv_copy, argv, sizeof(char*) * argc);
28 argv_copy[argc] = nullptr;
32 int main(int argc, char** argv)
34 xbt_assert(argc >= 2, "Missing arguments");
36 // Currently, we need this before sg_config_init:
37 _sg_do_model_check = 1;
39 // The initialization function can touch argv.
40 // We make a copy of argv before modifying it in order to pass the original value to the model-checked application:
41 char** argv_copy = argvdup(argc, argv);
43 xbt_log_init(&argc, argv);
45 smpi_init_options(); // only performed once
47 sg_config_init(&argc, argv);
49 simgrid::mc::CheckerAlgorithm algo;
50 if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
51 algo = simgrid::mc::CheckerAlgorithm::CommDeterminism;
52 else if (_sg_mc_unfolding_checker)
53 algo = simgrid::mc::CheckerAlgorithm::UDPOR;
54 else if (_sg_mc_property_file.get().empty())
55 algo = simgrid::mc::CheckerAlgorithm::Safety;
57 algo = simgrid::mc::CheckerAlgorithm::Liveness;
59 int res = SIMGRID_MC_EXIT_SUCCESS;
60 auto checker = api::get().initialize(argv_copy, algo);
63 } catch (const simgrid::mc::DeadlockError&) {
64 res = SIMGRID_MC_EXIT_DEADLOCK;
65 } catch (const simgrid::mc::TerminationError&) {
66 res = SIMGRID_MC_EXIT_NON_TERMINATION;
67 } catch (const simgrid::mc::LivenessError&) {
68 res = SIMGRID_MC_EXIT_LIVENESS;