Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Dummy SafetyChecker class
[simgrid.git] / src / mc / simgrid_mc.cpp
1 /* Copyright (c) 2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <exception>
8
9 #include <cstdlib>
10 #include <cstdio>
11 #include <cstring>
12
13 #include <utility>
14
15 #include <unistd.h>
16
17 #include <xbt/log.h>
18
19 #include "simgrid/sg_config.h"
20 #include "src/xbt_modinter.h"
21
22 #include "src/mc/mc_base.h"
23 #include "src/mc/mc_private.h"
24 #include "src/mc/mc_protocol.h"
25 #include "src/mc/mc_safety.h"
26 #include "src/mc/mc_comm_pattern.h"
27 #include "src/mc/mc_liveness.h"
28 #include "src/mc/mc_exit.h"
29 #include "src/mc/Session.hpp"
30 #include "src/mc/Checker.hpp"
31 #include "src/mc/SafetyChecker.hpp"
32
33 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
34
35 static
36 char** argvdup(int argc, char** argv)
37 {
38   char** argv_copy = xbt_new(char*, argc+1);
39   std::memcpy(argv_copy, argv, sizeof(char*) * argc);
40   argv_copy[argc] = nullptr;
41   return argv_copy;
42 }
43
44 static
45 std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
46 {
47   using simgrid::mc::Session;
48   using simgrid::mc::FunctionalChecker;
49
50   std::function<int(Session& session)> code;
51   if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
52     code = [](Session& session) {
53       return MC_modelcheck_comm_determinism(); };
54   else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0')
55     return std::unique_ptr<simgrid::mc::Checker>(
56       new simgrid::mc::SafetyChecker(session));
57   else
58     code = [](Session& session) {
59       return simgrid::mc::modelcheck_liveness(); };
60
61   return std::unique_ptr<simgrid::mc::Checker>(
62     new FunctionalChecker(session, std::move(code)));
63 }
64
65 int main(int argc, char** argv)
66 {
67   using simgrid::mc::Session;
68
69   try {
70     if (argc < 2)
71       xbt_die("Missing arguments.\n");
72
73     // Currently, we need this before sg_config_init:
74     _sg_do_model_check = 1;
75     mc_mode = MC_MODE_SERVER;
76
77     // The initialisation function can touch argv.
78     // We need to keep the original parameters in order to pass them to the
79     // model-checked process so we make a copy of them:
80     int argc_copy = argc;
81     char** argv_copy = argvdup(argc, argv);
82     xbt_log_init(&argc_copy, argv_copy);
83     sg_config_init(&argc_copy, argv_copy);
84
85     std::unique_ptr<Session> session =
86       std::unique_ptr<Session>(Session::spawnvp(argv[1], argv+1));
87     std::unique_ptr<simgrid::mc::Checker> checker = createChecker(*session);
88     int res = checker->run();
89     session->close();
90     return res;
91   }
92   catch(std::exception& e) {
93     XBT_ERROR("Exception: %s", e.what());
94     return SIMGRID_MC_EXIT_ERROR;
95   }
96   catch(...) {
97     XBT_ERROR("Unknown exception");
98     return SIMGRID_MC_EXIT_ERROR;
99   }
100 }