Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use simpler std::vector.
[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 int main(int argc, char** argv)
23 {
24   xbt_assert(argc >= 2, "Missing arguments");
25
26   // Currently, we need this before sg_config_init:
27   _sg_do_model_check = 1;
28
29   // The initialization function can touch argv.
30   // We make a copy of argv before modifying it in order to pass the original value to the model-checked application:
31   std::vector<char*> argv_copy{argv, argv + argc + 1};
32
33   xbt_log_init(&argc, argv);
34 #if HAVE_SMPI
35   smpi_init_options(); // only performed once
36 #endif
37   sg_config_init(&argc, argv);
38
39   simgrid::mc::CheckerAlgorithm algo;
40   if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
41     algo = simgrid::mc::CheckerAlgorithm::CommDeterminism;
42   else if (_sg_mc_unfolding_checker)
43     algo = simgrid::mc::CheckerAlgorithm::UDPOR;
44   else if (_sg_mc_property_file.get().empty())
45     algo = simgrid::mc::CheckerAlgorithm::Safety;
46   else
47     algo = simgrid::mc::CheckerAlgorithm::Liveness;
48
49   int res      = SIMGRID_MC_EXIT_SUCCESS;
50   auto checker = api::get().initialize(argv_copy.data(), algo);
51   try {
52     checker->run();
53   } catch (const simgrid::mc::DeadlockError&) {
54     res = SIMGRID_MC_EXIT_DEADLOCK;
55   } catch (const simgrid::mc::TerminationError&) {
56     res = SIMGRID_MC_EXIT_NON_TERMINATION;
57   } catch (const simgrid::mc::LivenessError&) {
58     res = SIMGRID_MC_EXIT_LIVENESS;
59   }
60   api::get().s_close();
61   // delete checker; SEGFAULT in liveness
62   return res;
63 }