2 * @brief Core model checker.
12 #include "hashtable.h"
14 #include "modeltypes.h"
15 #include "stl-model.h"
18 #include "classlist.h"
19 #include "snapshot-interface.h"
21 #define ENTER_MODEL_FLAG (inside_model = 1)
22 #define EXIT_MODEL_FLAG (inside_model = 0)
23 #define GET_MODEL_FLAG (inside_model)
24 #define RESTORE_MODEL_FLAG(f) (inside_model = f)
26 /** @brief Model checker execution stats */
27 struct execution_stats {
28 int num_total; /**< @brief Total number of executions */
29 int num_buggy_executions; /** @brief Number of buggy executions */
30 int num_complete; /**< @brief Number of feasible, non-buggy, complete executions */
33 /** @brief The central structure for model-checking */
38 model_params * getParams();
40 /** Exit the model checker, intended for pluggins. */
41 void exit_model_checker();
43 ModelExecution * get_execution() const { return execution; }
45 int get_execution_number() const { return execution_number; }
47 Thread * get_thread(thread_id_t tid) const;
48 Thread * get_thread(const ModelAction *act) const;
50 Thread * get_current_thread() const;
51 thread_id_t get_current_thread_id() const;
53 uint64_t switch_thread(ModelAction *act);
55 void assert_bug(const char *msg, ...);
57 void assert_user_bug(const char *msg);
60 void add_trace_analysis(TraceAnalysis *a) { trace_analyses.push_back(a); }
61 void set_inspect_plugin(TraceAnalysis *a) { inspect_plugin=a; }
63 Thread * getInitThread() {return init_thread;}
64 Scheduler * getScheduler() {return scheduler;}
67 /** Snapshot id we return to restart. */
70 /** The scheduler to use: tracks the running/ready Threads */
71 Scheduler * const scheduler;
72 ModelExecution *execution;
77 unsigned int curr_thread_num;
78 Thread * chosen_thread;
81 void startRunExecution(Thread *old);
82 void finishRunExecution(Thread *old);
83 Thread * getNextThread(Thread *old);
84 bool handleChosenThread(Thread *old);
86 modelclock_t checkfree;
88 unsigned int get_num_threads() const;
90 void finish_execution(bool moreexecutions);
91 bool should_terminate_execution();
93 Thread * get_next_thread();
94 void reset_to_initial_state();
96 ModelVector<TraceAnalysis *> trace_analyses;
97 char random_state[256];
99 /** @bref Plugin that can inspect new actions. */
100 TraceAnalysis *inspect_plugin;
101 /** @brief The cumulative execution stats */
102 struct execution_stats stats;
104 void run_trace_analyses();
105 void print_bugs() const;
106 void print_execution(bool printbugs) const;
107 void print_stats() const;
110 extern int inside_model;
111 extern ModelChecker *model;
112 void parse_options(struct model_params *params);
113 void install_trace_analyses(ModelExecution *execution);
114 void createModelIfNotExist();
116 #endif /* __MODEL_H__ */