Change initialize a bit
[c11tester.git] / model.h
1 /** @file model.h
2  *  @brief Core model checker.
3  */
4
5 #ifndef __MODEL_H__
6 #define __MODEL_H__
7
8 #include <cstddef>
9 #include <inttypes.h>
10
11 #include "mymemory.h"
12 #include "hashtable.h"
13 #include "config.h"
14 #include "modeltypes.h"
15 #include "stl-model.h"
16 #include "context.h"
17 #include "params.h"
18 #include "classlist.h"
19 #include "snapshot-interface.h"
20
21 /** @brief Model checker execution stats */
22 struct execution_stats {
23         int num_total;  /**< @brief Total number of executions */
24         int num_buggy_executions;       /** @brief Number of buggy executions */
25         int num_complete;       /**< @brief Number of feasible, non-buggy, complete executions */
26 };
27
28 /** @brief The central structure for model-checking */
29 class ModelChecker {
30 public:
31         ModelChecker();
32         ~ModelChecker();
33         model_params * getParams();
34
35         /** Exit the model checker, intended for pluggins. */
36         void exit_model_checker();
37
38         ModelExecution * get_execution() const { return execution; }
39         ModelHistory * get_history() const { return history; }
40
41         int get_execution_number() const { return execution_number; }
42
43         Thread * get_thread(thread_id_t tid) const;
44         Thread * get_thread(const ModelAction *act) const;
45
46         Thread * get_current_thread() const;
47         thread_id_t get_current_thread_id() const;
48
49         uint64_t switch_thread(ModelAction *act);
50
51         void assert_bug(const char *msg, ...);
52
53         void assert_user_bug(const char *msg);
54
55         model_params params;
56         void add_trace_analysis(TraceAnalysis *a) {     trace_analyses.push_back(a); }
57         void set_inspect_plugin(TraceAnalysis *a) {     inspect_plugin=a;       }
58         void startChecker();
59         Thread * getInitThread() {return init_thread;}
60         Scheduler * getScheduler() {return scheduler;}
61         MEMALLOC
62 private:
63         /** Snapshot id we return to restart. */
64         snapshot_id snapshot;
65
66         /** The scheduler to use: tracks the running/ready Threads */
67         Scheduler * const scheduler;
68         ModelHistory * history;
69         ModelExecution *execution;
70         Thread * init_thread;
71
72         int execution_number;
73
74         unsigned int curr_thread_num;
75         Thread * chosen_thread;
76         bool break_execution;
77
78         void startRunExecution(Thread *old);
79         void finishRunExecution(Thread *old);
80         Thread * getNextThread(Thread *old);
81         bool handleChosenThread(Thread *old);
82
83         modelclock_t checkfree;
84
85         unsigned int get_num_threads() const;
86
87         void finish_execution(bool moreexecutions);
88         bool should_terminate_execution();
89
90         Thread * get_next_thread();
91         void reset_to_initial_state();
92
93         ModelVector<TraceAnalysis *> trace_analyses;
94         char random_state[256];
95
96         /** @bref Plugin that can inspect new actions. */
97         TraceAnalysis *inspect_plugin;
98         /** @brief The cumulative execution stats */
99         struct execution_stats stats;
100         void record_stats();
101         void run_trace_analyses();
102         void print_bugs() const;
103         void print_execution(bool printbugs) const;
104         void print_stats() const;
105 };
106
107 extern ModelChecker *model;
108 void parse_options(struct model_params *params);
109 void install_trace_analyses(ModelExecution *execution);
110 void createModelIfNotExist();
111
112 #endif  /* __MODEL_H__ */