2 * @brief Entry point for the model checker.
12 /* global "model" object */
15 #include "snapshot-interface.h"
16 #include "scanalysis.h"
18 static void param_defaults(struct model_params *params)
21 params->maxfuturedelay = 6;
22 params->fairwindow = 0;
23 params->yieldon = false;
24 params->yieldblock = false;
25 params->sc_trace_analysis = false;
26 params->enabledcount = 1;
28 params->maxfuturevalues = 0;
29 params->expireslop = 4;
30 params->verbose = !!DBG_ENABLED();
31 params->uninitvalue = 0;
34 static void print_usage(struct model_params *params)
36 /* Reset defaults before printing */
37 param_defaults(params);
40 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
41 "Distributed under the GPLv2\n"
42 "Written by Brian Norris and Brian Demsky\n"
44 "Usage: <program name> [MC_OPTIONS] -- [PROGRAM ARGUMENTS]\n"
47 "-h Display this help message and exit\n"
48 "-m Maximum times a thread can read from the same write\n"
49 " while other writes exist. Default: %d\n"
50 "-M Maximum number of future values that can be sent to\n"
51 " the same read. Default: %d\n"
52 "-s Maximum actions that the model checker will wait for\n"
53 " a write from the future past the expected number of\n"
54 " actions. Default: %d\n"
55 "-S Future value expiration sloppiness. Default: %u\n"
56 "-f Specify a fairness window in which actions that are\n"
57 " enabled sufficiently many times should receive\n"
58 " priority for execution. Default: %d\n"
59 "-y Turn on CHESS yield-based fairness support.\n"
61 "-Y Prohibit an execution from running a yield.\n"
63 "-e Enabled count. Default: %d\n"
64 "-b Upper length bound. Default: %d\n"
65 "-v Print verbose execution information.\n"
66 "-u Value for uninitialized reads. Default: %u\n"
67 "-c Use SC Trace Analysis.\n"
68 "-- Program arguments follow.\n\n",
69 params->maxreads, params->maxfuturevalues, params->maxfuturedelay, params->expireslop, params->fairwindow, params->yieldon, params->yieldblock, params->enabledcount, params->bound, params->uninitvalue);
73 static void parse_options(struct model_params *params, int argc, char **argv)
75 const char *shortopts = "hyYcm:M:s:S:f:e:b:u:v";
78 while (!error && (opt = getopt(argc, argv, shortopts)) != -1) {
84 params->maxfuturedelay = atoi(optarg);
87 params->expireslop = atoi(optarg);
90 params->fairwindow = atoi(optarg);
93 params->enabledcount = atoi(optarg);
96 params->bound = atoi(optarg);
99 params->maxreads = atoi(optarg);
102 params->maxfuturevalues = atoi(optarg);
108 params->uninitvalue = atoi(optarg);
111 params->sc_trace_analysis = true;
114 params->yieldon = true;
117 params->yieldblock = true;
125 /* Pass remaining arguments to user program */
126 params->argc = argc - (optind - 1);
127 params->argv = argv + (optind - 1);
129 /* Reset program name */
130 params->argv[0] = argv[0];
132 /* Reset (global) optind for potential use by user program */
142 static void install_trace_analyses(const ModelExecution *execution)
144 if (model->params.sc_trace_analysis)
145 model->add_trace_analysis(new SCAnalysis(execution));
148 /** The model_main function contains the main model checking loop. */
149 static void model_main()
151 struct model_params params;
153 param_defaults(¶ms);
155 parse_options(¶ms, main_argc, main_argv);
157 //Initialize race detector
160 snapshot_stack_init();
162 model = new ModelChecker(params);
163 install_trace_analyses(model->get_execution());
173 * Main function. Just initializes snapshotting library and the
174 * snapshotting library calls the model_main function.
176 int main(int argc, char **argv)
181 /* Configure output redirection for the model-checker */
184 /* Let's jump in quickly and start running stuff */
185 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);