Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Useless lower-case alias.
[simgrid.git] / src / mc / explo / simgrid_mc.cpp
1 /* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
11
12 #if HAVE_SMPI
13 #include "smpi/smpi.h"
14 #endif
15
16 #include <cstring>
17 #include <memory>
18 #include <unistd.h>
19
20 int main(int argc, char** argv)
21 {
22   xbt_assert(argc >= 2, "Missing arguments");
23
24   // Currently, we need this before sg_config_init:
25   _sg_do_model_check = 1;
26
27   // The initialization function can touch argv.
28   // We make a copy of argv before modifying it in order to pass the original value to the model-checked application:
29   std::vector<char*> argv_copy{argv, argv + argc + 1};
30
31   xbt_log_init(&argc, argv);
32 #if HAVE_SMPI
33   smpi_init_options(); // only performed once
34 #endif
35   sg_config_init(&argc, argv);
36
37   simgrid::mc::CheckerAlgorithm algo;
38   if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
39     algo = simgrid::mc::CheckerAlgorithm::CommDeterminism;
40   else if (_sg_mc_unfolding_checker)
41     algo = simgrid::mc::CheckerAlgorithm::UDPOR;
42   else if (_sg_mc_property_file.get().empty())
43     algo = simgrid::mc::CheckerAlgorithm::Safety;
44   else
45     algo = simgrid::mc::CheckerAlgorithm::Liveness;
46
47   int res      = SIMGRID_MC_EXIT_SUCCESS;
48   std::unique_ptr<simgrid::mc::Exploration> checker{simgrid::mc::Api::get().initialize(argv_copy.data(), algo)};
49   try {
50     checker->run();
51   } catch (const simgrid::mc::DeadlockError&) {
52     res = SIMGRID_MC_EXIT_DEADLOCK;
53   } catch (const simgrid::mc::TerminationError&) {
54     res = SIMGRID_MC_EXIT_NON_TERMINATION;
55   } catch (const simgrid::mc::LivenessError&) {
56     res = SIMGRID_MC_EXIT_LIVENESS;
57   }
58   simgrid::mc::Api::get().s_close();
59   checker.release(); // FIXME: this line should not exist, but it segfaults in liveness
60   return res;
61 }