2 * @brief Entry point for the model checker.
7 #include "libthreads.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;
24 static void print_usage(struct model_params *params) {
26 "Usage: <program name> [MC_OPTIONS] -- [PROGRAM ARGUMENTS]\n"
29 "-h Display this help message and exit\n"
30 "-m Maximum times a thread can read from the same write\n"
31 " while other writes exist. Default: %d\n"
32 "-s Maximum actions that the model checker will wait for\n"
33 " a write from the future past the expected number of\n"
34 " actions. Default: %d\n"
35 "-f Specify a fairness window in which actions that are\n"
36 " enabled sufficiently many times should receive\n"
37 " priority for execution. Default: %d\n"
38 "-e Enabled count. Default: %d\n"
39 "-- Program arguments follow.\n\n",
40 params->maxreads, params->maxfuturedelay, params->fairwindow, params->enabledcount);
44 static void parse_options(struct model_params *params, int *argc, char ***argv) {
45 const char *shortopts = "hm:s:f:e:";
48 while (!error && (opt = getopt(*argc, *argv, shortopts)) != -1) {
54 params->maxfuturedelay = atoi(optarg);
57 params->fairwindow = atoi(optarg);
60 params->enabledcount = atoi(optarg);
63 params->maxreads = atoi(optarg);
80 /** The real_main function contains the main model checking loop. */
81 static void real_main() {
83 struct model_params params;
85 param_defaults(¶ms);
87 parse_options(¶ms, &main_argc, &main_argv);
89 //Initialize race detector
92 //Create the singleton SnapshotStack object
93 snapshotObject = new SnapshotStack();
95 model = new ModelChecker(params);
97 snapshotObject->snapshotStep(0);
99 /* Start user program */
100 model->add_thread(new Thread(&user_thread, (void (*)(void *)) &user_main, NULL));
102 /* Wait for all threads to complete */
103 model->finish_execution();
104 } while (model->next_execution());
112 * Main function. Just initializes snapshotting library and the
113 * snapshotting library calls the real_main function.
115 int main(int argc, char ** argv) {
119 /* Let's jump in quickly and start running stuff */
120 initSnapshotLibrary(10000, 1024, 1024, 4000, &real_main);