2 * @brief Entry point for the model checker.
9 #include "threads-model.h"
14 /* global "model" object */
16 #include "snapshot-interface.h"
18 static void param_defaults(struct model_params * params) {
20 params->maxfuturedelay = 100;
21 params->fairwindow = 0;
22 params->enabledcount = 1;
24 params->maxfuturevalues = 0;
25 params->expireslop = 10;
29 static void print_usage(struct model_params *params) {
30 /* Reset defaults before printing */
31 param_defaults(params);
34 "Usage: <program name> [MC_OPTIONS] -- [PROGRAM ARGUMENTS]\n"
37 "-h Display this help message and exit\n"
38 "-m Maximum times a thread can read from the same write\n"
39 " while other writes exist. Default: %d\n"
40 "-M Maximum number of future values that can be sent to\n"
41 " the same read. Default: %d\n"
42 "-s Maximum actions that the model checker will wait for\n"
43 " a write from the future past the expected number of\n"
44 " actions. Default: %d\n"
45 "-S Future value expiration sloppiness. Default: %u\n"
46 "-f Specify a fairness window in which actions that are\n"
47 " enabled sufficiently many times should receive\n"
48 " priority for execution. Default: %d\n"
49 "-e Enabled count. Default: %d\n"
50 "-b Upper length bound. Default: %d\n"
51 "-v Print verbose execution information.\n"
52 "-- Program arguments follow.\n\n",
53 params->maxreads, params->maxfuturevalues, params->maxfuturedelay, params->expireslop, params->fairwindow, params->enabledcount, params->bound);
57 static void parse_options(struct model_params *params, int *argc, char ***argv) {
58 const char *shortopts = "hm:M:s:S:f:e:b:v";
61 while (!error && (opt = getopt(*argc, *argv, shortopts)) != -1) {
67 params->maxfuturedelay = atoi(optarg);
70 params->expireslop = atoi(optarg);
73 params->fairwindow = atoi(optarg);
76 params->enabledcount = atoi(optarg);
79 params->bound = atoi(optarg);
82 params->maxreads = atoi(optarg);
85 params->maxfuturevalues = atoi(optarg);
95 (*argv)[optind - 1] = (*argv)[0];
96 (*argc) -= (optind - 1);
97 (*argv) += (optind - 1);
107 /** The model_main function contains the main model checking loop. */
108 static void model_main() {
109 struct model_params params;
111 param_defaults(¶ms);
113 parse_options(¶ms, &main_argc, &main_argv);
115 /* Pass remaining arguments to user program */
116 params.argc = main_argc;
117 params.argv = main_argv;
119 //Initialize race detector
122 //Create the singleton SnapshotStack object
123 snapshotObject = new SnapshotStack();
125 model = new ModelChecker(params);
126 snapshotObject->snapshotStep(0);
134 * Main function. Just initializes snapshotting library and the
135 * snapshotting library calls the model_main function.
137 int main(int argc, char ** argv) {
141 /* Configure output redirection for the model-checker */
144 /* Let's jump in quickly and start running stuff */
145 initSnapshotLibrary(10000, 1024, 1024, 4000, &model_main);