1 /* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/sg_config.hpp"
7 #include "src/internal_config.h"
8 #include "src/mc/explo/Exploration.hpp"
9 #include "src/mc/mc_config.hpp"
10 #include "src/mc/mc_exit.hpp"
13 #include "smpi/smpi.h"
20 using api = simgrid::mc::Api;
22 static inline char** argvdup(int argc, char** argv)
24 auto* argv_copy = new char*[argc + 1];
25 std::memcpy(argv_copy, argv, sizeof(char*) * argc);
26 argv_copy[argc] = nullptr;
30 int main(int argc, char** argv)
32 xbt_assert(argc >= 2, "Missing arguments");
34 // Currently, we need this before sg_config_init:
35 _sg_do_model_check = 1;
37 // The initialization function can touch argv.
38 // We make a copy of argv before modifying it in order to pass the original value to the model-checked application:
39 char** argv_copy = argvdup(argc, argv);
41 xbt_log_init(&argc, argv);
43 smpi_init_options(); // only performed once
45 sg_config_init(&argc, argv);
47 simgrid::mc::CheckerAlgorithm algo;
48 if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
49 algo = simgrid::mc::CheckerAlgorithm::CommDeterminism;
50 else if (_sg_mc_unfolding_checker)
51 algo = simgrid::mc::CheckerAlgorithm::UDPOR;
52 else if (_sg_mc_property_file.get().empty())
53 algo = simgrid::mc::CheckerAlgorithm::Safety;
55 algo = simgrid::mc::CheckerAlgorithm::Liveness;
57 int res = SIMGRID_MC_EXIT_SUCCESS;
58 auto checker = api::get().initialize(argv_copy, algo);
61 } catch (const simgrid::mc::DeadlockError&) {
62 res = SIMGRID_MC_EXIT_DEADLOCK;
63 } catch (const simgrid::mc::TerminationError&) {
64 res = SIMGRID_MC_EXIT_NON_TERMINATION;
65 } catch (const simgrid::mc::LivenessError&) {
66 res = SIMGRID_MC_EXIT_LIVENESS;
70 // delete checker; SEGFAULT in liveness