2 * @brief Core model checker.
12 #include "hashtable.h"
14 #include "modeltypes.h"
15 #include "stl-model.h"
19 /* Forward declaration */
31 typedef SnapList<ModelAction *> action_list_t;
33 /** @brief Model checker execution stats */
34 struct execution_stats {
35 int num_total; /**< @brief Total number of executions */
36 int num_infeasible; /**< @brief Number of infeasible executions */
37 int num_buggy_executions; /** @brief Number of buggy executions */
38 int num_complete; /**< @brief Number of feasible, non-buggy, complete executions */
39 int num_redundant; /**< @brief Number of redundant, aborted executions */
42 /** @brief The central structure for model-checking */
45 ModelChecker(struct model_params params);
50 /** Restart the model checker, intended for pluggins. */
53 /** Exit the model checker, intended for pluggins. */
54 void exit_model_checker();
56 /** Check the exit_flag. */
57 bool get_exit_flag() const { return exit_flag; }
59 /** @returns the context for the main model-checking system thread */
60 ucontext_t * get_system_context() { return &system_context; }
62 ModelExecution * get_execution() const { return execution; }
64 int get_execution_number() const { return execution_number; }
66 Thread * get_thread(thread_id_t tid) const;
67 Thread * get_thread(const ModelAction *act) const;
69 Thread * get_current_thread() const;
71 void switch_from_master(Thread *thread);
72 uint64_t switch_to_master(ModelAction *act);
74 bool assert_bug(const char *msg, ...);
75 void assert_user_bug(const char *msg);
77 const model_params params;
78 void add_trace_analysis(TraceAnalysis *a) { trace_analyses.push_back(a); }
79 void set_inspect_plugin(TraceAnalysis *a) { inspect_plugin=a; }
82 /** Flag indicates whether to restart the model checker. */
84 /** Flag indicates whether to exit the model checker. */
87 /** The scheduler to use: tracks the running/ready Threads */
88 Scheduler * const scheduler;
89 NodeStack * const node_stack;
90 ModelExecution *execution;
94 unsigned int get_num_threads() const;
96 void execute_sleep_set();
98 bool next_execution();
99 bool should_terminate_execution();
101 Thread * get_next_thread();
102 void reset_to_initial_state();
105 ModelAction *diverge;
106 ModelAction *earliest_diverge;
108 ucontext_t system_context;
110 ModelVector<TraceAnalysis *> trace_analyses;
112 /** @bref Implement restart. */
114 /** @bref Plugin that can inspect new actions. */
115 TraceAnalysis *inspect_plugin;
116 /** @brief The cumulative execution stats */
117 struct execution_stats stats;
119 void run_trace_analyses();
120 void print_bugs() const;
121 void print_execution(bool printbugs) const;
122 void print_stats() const;
124 friend void user_main_wrapper();
127 extern ModelChecker *model;
129 #endif /* __MODEL_H__ */