Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename mc::Checker to mc::Exploration as it defines an exploration algo
[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 using api = simgrid::mc::Api;
21
22 static inline char** argvdup(int argc, char** argv)
23 {
24   auto* argv_copy = new char*[argc + 1];
25   std::memcpy(argv_copy, argv, sizeof(char*) * argc);
26   argv_copy[argc] = nullptr;
27   return argv_copy;
28 }
29
30 int main(int argc, char** argv)
31 {
32   xbt_assert(argc >= 2, "Missing arguments");
33
34   // Currently, we need this before sg_config_init:
35   _sg_do_model_check = 1;
36
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);
40
41   xbt_log_init(&argc, argv);
42 #if HAVE_SMPI
43   smpi_init_options(); // only performed once
44 #endif
45   sg_config_init(&argc, argv);
46
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;
54   else
55     algo = simgrid::mc::CheckerAlgorithm::Liveness;
56
57   int res      = SIMGRID_MC_EXIT_SUCCESS;
58   auto checker = api::get().initialize(argv_copy, algo);
59   try {
60     checker->run();
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;
67   }
68   api::get().s_close();
69   delete[] argv_copy;
70   // delete checker; SEGFAULT in liveness
71   return res;
72 }