Logo AND Algorithmique Numérique Distribuée

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