1 /* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_SIMCALL_INSPECTOR_HPP
7 #define SIMGRID_MC_SIMCALL_INSPECTOR_HPP
9 #include "simgrid/forward.h"
16 class SimcallInspector {
17 kernel::actor::ActorImpl* issuer_;
20 explicit SimcallInspector(kernel::actor::ActorImpl* issuer) : issuer_(issuer) {}
21 kernel::actor::ActorImpl* get_issuer() const { return issuer_; }
22 /** Whether this transition can currently be taken without blocking.
24 * For example, a mutex_lock is not enabled when the mutex is not free.
25 * A comm_receive is not enabled before the corresponding send has been issued.
27 virtual bool is_enabled() const { return true; }
29 /** Returns the amount of time that this transition can be used.
31 * If it's 1 (as with send/wait), there is no need to fork the state space exploration on this point.
32 * If it's more than one (as with mc_random or waitany), we need to consider this transition several times to start
35 virtual int get_max_consider() const { return 1; }
37 /** Prepares the simcall to be used.
39 * For most simcalls, this does nothing. Once enabled, there is nothing to do to prepare a send().
41 * It is useful only for the simcalls that can be used several times, such as waitany() or random().
42 * For them, prepare() selects the right outcome for the time being considered.
44 * The first time a simcall is considered, times_considered is 0, not 1.
46 virtual void prepare(int times_considered) { /* Nothing to do by default */}
48 /** Some simcalls may only be observable under some circumstances.
49 * Most simcalls are not visible from the MC because they don't have an inspector at all. */
50 virtual bool is_visible() const { return true; }
51 virtual std::string to_string(int times_considered) const = 0;
52 virtual std::string dot_label() const = 0;
55 class RandomSimcall : public SimcallInspector {
61 RandomSimcall(smx_actor_t actor, int min, int max) : SimcallInspector(actor), min_(min), max_(max) {}
62 int get_max_consider() const override;
63 void prepare(int times_considered) override;
64 std::string to_string(int times_considered) const override;
65 std::string dot_label() const override;
66 int get_value() const;
69 class MutexUnlockSimcall : public SimcallInspector {
70 using SimcallInspector::SimcallInspector;
73 std::string to_string(int times_considered) const override;
74 std::string dot_label() const override;
77 } // namespace simgrid