Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
another mc_model_checker call location disappears
[simgrid.git] / src / mc / transition / Transition.cpp
1 /* Copyright (c) 2015-2023. 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 "src/mc/transition/Transition.hpp"
7 #include "src/kernel/actor/Simcall.hpp"
8 #include "xbt/asserts.h"
9 #include "xbt/string.hpp"
10 #include <simgrid/config.h>
11
12 #if SIMGRID_HAVE_MC
13 #include "src/mc/ModelChecker.hpp"
14 #include "src/mc/explo/Exploration.hpp"
15 #include "src/mc/transition/TransitionActorJoin.hpp"
16 #include "src/mc/transition/TransitionAny.hpp"
17 #include "src/mc/transition/TransitionComm.hpp"
18 #include "src/mc/transition/TransitionObjectAccess.hpp"
19 #include "src/mc/transition/TransitionRandom.hpp"
20 #include "src/mc/transition/TransitionSynchro.hpp"
21 #endif
22
23 #include <sstream>
24
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_transition, mc, "Logging specific to MC transitions");
26
27 namespace simgrid::mc {
28 unsigned long Transition::executed_transitions_ = 0;
29 unsigned long Transition::replayed_transitions_ = 0;
30
31 // Do not move this to the header, to ensure that we have a vtable for Transition
32 Transition::~Transition() = default;
33
34 std::string Transition::to_string(bool) const
35 {
36   return "";
37 }
38 std::string Transition::dot_string() const
39 {
40   static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
41                                                        "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
42                                                        "lightblue", "tan"}};
43   const char* color = colors[(aid_ - 1) % colors.size()];
44
45   return xbt::string_printf("label = \"[(%ld)] %s\", color = %s, fontcolor = %s", aid_, Transition::to_c_str(type_),
46                             color, color);
47 }
48 void Transition::replay(RemoteApp& app) const
49 {
50   replayed_transitions_++;
51
52 #if SIMGRID_HAVE_MC
53   app.handle_simcall(aid_, times_considered_, false);
54   app.wait_for_requests();
55 #endif
56 }
57
58 Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream)
59 {
60 #if SIMGRID_HAVE_MC
61   short type;
62   xbt_assert(stream >> type);
63
64   switch (auto simcall = static_cast<Transition::Type>(type)) {
65     case Transition::Type::BARRIER_ASYNC_LOCK:
66     case Transition::Type::BARRIER_WAIT:
67       return new BarrierTransition(issuer, times_considered, simcall, stream);
68
69     case Transition::Type::COMM_ASYNC_RECV:
70       return new CommRecvTransition(issuer, times_considered, stream);
71     case Transition::Type::COMM_ASYNC_SEND:
72       return new CommSendTransition(issuer, times_considered, stream);
73     case Transition::Type::COMM_TEST:
74       return new CommTestTransition(issuer, times_considered, stream);
75     case Transition::Type::COMM_WAIT:
76       return new CommWaitTransition(issuer, times_considered, stream);
77
78     case Transition::Type::TESTANY:
79       return new TestAnyTransition(issuer, times_considered, stream);
80     case Transition::Type::WAITANY:
81       return new WaitAnyTransition(issuer, times_considered, stream);
82
83     case Transition::Type::RANDOM:
84       return new RandomTransition(issuer, times_considered, stream);
85
86     case Transition::Type::MUTEX_TRYLOCK:
87     case Transition::Type::MUTEX_ASYNC_LOCK:
88     case Transition::Type::MUTEX_TEST:
89     case Transition::Type::MUTEX_WAIT:
90     case Transition::Type::MUTEX_UNLOCK:
91       return new MutexTransition(issuer, times_considered, simcall, stream);
92
93     case Transition::Type::SEM_ASYNC_LOCK:
94     case Transition::Type::SEM_UNLOCK:
95     case Transition::Type::SEM_WAIT:
96       return new SemaphoreTransition(issuer, times_considered, simcall, stream);
97
98     case Transition::Type::ACTOR_JOIN:
99       return new ActorJoinTransition(issuer, times_considered, stream);
100
101     case Transition::Type::OBJECT_ACCESS:
102       return new ObjectAccessTransition(issuer, times_considered, stream);
103
104     case Transition::Type::UNKNOWN:
105       return new Transition(Transition::Type::UNKNOWN, issuer, times_considered);
106
107     default:
108       break;
109   }
110   xbt_die("Invalid transition type %d received. Did you implement a new observer in the app without implementing the "
111           "corresponding transition in the checker?",
112           type);
113 #else
114   xbt_die("Deserializing transitions is only interesting in MC mode.");
115 #endif
116 }
117
118 } // namespace simgrid::mc