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);
96 /* Pass remaining arguments to user program */
97 params->argc = argc - (optind - 1);
98 params->argv = argv + (optind - 1);
100 /* Reset program name */
101 params->argv[0] = argv[0];
103 /* Reset (global) optind for potential use by user program */
113 /** The model_main function contains the main model checking loop. */
114 static void model_main() {
115 struct model_params params;
117 param_defaults(¶ms);
119 parse_options(¶ms, main_argc, main_argv);
121 //Initialize race detector
124 //Create the singleton SnapshotStack object
125 snapshotObject = new SnapshotStack();
127 model = new ModelChecker(params);
128 snapshotObject->snapshotStep(0);
136 * Main function. Just initializes snapshotting library and the
137 * snapshotting library calls the model_main function.
139 int main(int argc, char ** argv) {
143 /* Configure output redirection for the model-checker */
146 /* Let's jump in quickly and start running stuff */
147 initSnapshotLibrary(10000, 1024, 1024, 4000, &model_main);