Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revalidate all SafetyChecker tesh now that the output changed
[simgrid.git] / src / mc / api / Transition.hpp
1 /* Copyright (c) 2015-2022. 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 #ifndef SIMGRID_MC_TRANSITION_HPP
8 #define SIMGRID_MC_TRANSITION_HPP
9
10 #include "simgrid/forward.h" // aid_t
11 #include "xbt/utility.hpp"   // XBT_DECLARE_ENUM_CLASS
12
13 #include <sstream>
14 #include <string>
15
16 namespace simgrid {
17 namespace mc {
18
19 /** An element in the recorded path
20  *
21  *  At each decision point, we need to record which process transition
22  *  is triggered and potentially which value is associated with this
23  *  transition. The value is used to find which communication is triggered
24  *  in things like waitany and for associating a given value of MC_random()
25  *  calls.
26  */
27 class Transition {
28   /* Textual representation of the transition, to display backtraces */
29   static unsigned long executed_transitions_;
30   static unsigned long replayed_transitions_;
31
32   friend State; // FIXME remove this once we have a proper class to handle the statistics
33
34 public:
35   /* Ordering is important here. depends() implementations only consider subsequent types in this ordering */
36   XBT_DECLARE_ENUM_CLASS(Type, RANDOM, TESTANY, WAITANY, COMM_RECV, COMM_SEND, COMM_TEST, COMM_WAIT,
37                          /* UNKNOWN must be last */ UNKNOWN);
38   Type type_ = Type::UNKNOWN;
39
40   aid_t aid_ = 0;
41
42   /* Which transition was executed for this simcall
43    *
44    * Some simcalls can lead to different transitions:
45    *
46    * * waitany/testany can trigger on different messages;
47    *
48    * * random can produce different values.
49    */
50   int times_considered_ = 0;
51
52   Transition() = default;
53   Transition(Type type, aid_t issuer, int times_considered)
54       : type_(type), aid_(issuer), times_considered_(times_considered)
55   {
56   }
57   virtual ~Transition();
58
59   virtual std::string to_string(bool verbose = false) const;
60   virtual std::string dot_label() const;
61
62   /* Moves the application toward a path that was already explored, but don't change the current transition */
63   void replay() const;
64
65   virtual bool depends(const Transition* other) const { return true; }
66
67   /* Returns the total amount of transitions executed so far (for statistics) */
68   static unsigned long get_executed_transitions() { return executed_transitions_; }
69   /* Returns the total amount of transitions replayed so far while backtracing (for statistics) */
70   static unsigned long get_replayed_transitions() { return replayed_transitions_; }
71 };
72
73 class RandomTransition : public Transition {
74   int min_;
75   int max_;
76
77 public:
78   std::string to_string(bool verbose) const override;
79   std::string dot_label() const override;
80   RandomTransition(aid_t issuer, int times_considered, std::stringstream& stream);
81   bool depends(const Transition* other) const override { return false; } // Independent with any other transition
82 };
83
84 } // namespace mc
85 } // namespace simgrid
86
87 #endif