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 typedef SnapList<ModelAction *> action_list_t;
23 /** @brief Model checker execution stats */
24 struct execution_stats {
25 int num_total; /**< @brief Total number of executions */
26 int num_buggy_executions; /** @brief Number of buggy executions */
27 int num_complete; /**< @brief Number of feasible, non-buggy, complete executions */
30 /** @brief The central structure for model-checking */
35 model_params * getParams();
38 /** Exit the model checker, intended for pluggins. */
39 void exit_model_checker();
41 /** @returns the context for the main model-checking system thread */
42 ucontext_t * get_system_context() { return &system_context; }
44 ModelExecution * get_execution() const { return execution; }
45 ModelHistory * get_history() const { return history; }
47 int get_execution_number() const { return execution_number; }
49 Thread * get_thread(thread_id_t tid) const;
50 Thread * get_thread(const ModelAction *act) const;
52 Thread * get_current_thread() const;
54 void switch_from_master(Thread *thread);
55 uint64_t switch_to_master(ModelAction *act);
56 uint64_t switch_thread(ModelAction *act);
58 void continueExecution(Thread *old);
59 void finishExecution(Thread *old);
61 void chooseThread(ModelAction *act, Thread *thr);
62 Thread * getNextThread();
63 void handleChosenThread(Thread *old);
64 void handleNewValidThread(Thread *old, Thread *next);
66 void assert_bug(const char *msg, ...);
68 void assert_user_bug(const char *msg);
71 void add_trace_analysis(TraceAnalysis *a) { trace_analyses.push_back(a); }
72 void set_inspect_plugin(TraceAnalysis *a) { inspect_plugin=a; }
74 Thread * getInitThread() {return init_thread;}
75 Scheduler * getScheduler() {return scheduler;}
78 /** Snapshot id we return to restart. */
81 /** The scheduler to use: tracks the running/ready Threads */
82 Scheduler * const scheduler;
83 ModelHistory * history;
84 ModelExecution *execution;
89 unsigned int curr_thread_num;
91 Thread * chosen_thread;
95 modelclock_t checkfree;
97 unsigned int get_num_threads() const;
99 void finish_execution(bool moreexecutions);
100 bool should_terminate_execution();
102 Thread * get_next_thread();
103 void reset_to_initial_state();
105 ucontext_t system_context;
107 ModelVector<TraceAnalysis *> trace_analyses;
109 /** @bref Plugin that can inspect new actions. */
110 TraceAnalysis *inspect_plugin;
111 /** @brief The cumulative execution stats */
112 struct execution_stats stats;
114 void run_trace_analyses();
115 void print_bugs() const;
116 void print_execution(bool printbugs) const;
117 void print_stats() const;
120 extern ModelChecker *model;
121 void parse_options(struct model_params *params);
122 void install_trace_analyses(ModelExecution *execution);
124 #endif /* __MODEL_H__ */