2 * @brief Entry point for the model checker.
9 #include "threads-model.h"
13 /* global "model" object */
15 #include "snapshot-interface.h"
17 static void param_defaults(struct model_params * params) {
19 params->maxfuturedelay = 100;
20 params->fairwindow = 0;
21 params->enabledcount = 1;
25 static void print_usage(struct model_params *params) {
27 "Usage: <program name> [MC_OPTIONS] -- [PROGRAM ARGUMENTS]\n"
30 "-h Display this help message and exit\n"
31 "-m Maximum times a thread can read from the same write\n"
32 " while other writes exist. Default: %d\n"
33 "-s Maximum actions that the model checker will wait for\n"
34 " a write from the future past the expected number of\n"
35 " actions. Default: %d\n"
36 "-f Specify a fairness window in which actions that are\n"
37 " enabled sufficiently many times should receive\n"
38 " priority for execution. Default: %d\n"
39 "-e Enabled count. Default: %d\n"
40 "-b Upper length bound. Default: %d\n"
41 "-- Program arguments follow.\n\n",
42 params->maxreads, params->maxfuturedelay, params->fairwindow, params->enabledcount, params->bound);
46 static void parse_options(struct model_params *params, int *argc, char ***argv) {
47 const char *shortopts = "hm:s:f:e:b:";
50 while (!error && (opt = getopt(*argc, *argv, shortopts)) != -1) {
56 params->maxfuturedelay = atoi(optarg);
59 params->fairwindow = atoi(optarg);
62 params->enabledcount = atoi(optarg);
65 params->bound = atoi(optarg);
68 params->maxreads = atoi(optarg);
75 (*argv)[optind - 1] = (*argv)[0];
76 (*argc) -= (optind - 1);
77 (*argv) += (optind - 1);
87 /** Wrapper to run the user's main function, with appropriate arguments */
88 void wrapper_user_main(void *)
90 user_main(main_argc, main_argv);
93 /** The model_main function contains the main model checking loop. */
94 static void model_main() {
96 struct model_params params;
98 param_defaults(¶ms);
100 parse_options(¶ms, &main_argc, &main_argv);
102 //Initialize race detector
105 //Create the singleton SnapshotStack object
106 snapshotObject = new SnapshotStack();
108 model = new ModelChecker(params);
110 snapshotObject->snapshotStep(0);
112 /* Start user program */
113 model->add_thread(new Thread(&user_thread, &wrapper_user_main, NULL));
115 /* Wait for all threads to complete */
116 model->finish_execution();
117 } while (model->next_execution());
125 * Main function. Just initializes snapshotting library and the
126 * snapshotting library calls the model_main function.
128 int main(int argc, char ** argv) {
132 /* Let's jump in quickly and start running stuff */
133 initSnapshotLibrary(10000, 1024, 1024, 4000, &model_main);