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->sc_trace_analysis = false;
25 params->enabledcount = 1;
27 params->maxfuturevalues = 0;
28 params->expireslop = 4;
29 params->verbose = !!DBG_ENABLED();
30 params->uninitvalue = 0;
33 static void print_usage(struct model_params *params)
35 /* Reset defaults before printing */
36 param_defaults(params);
39 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
40 "Distributed under the GPLv2\n"
41 "Written by Brian Norris and Brian Demsky\n"
43 "Usage: <program name> [MC_OPTIONS] -- [PROGRAM ARGUMENTS]\n"
46 "-h Display this help message and exit\n"
47 "-m Maximum times a thread can read from the same write\n"
48 " while other writes exist. Default: %d\n"
49 "-M Maximum number of future values that can be sent to\n"
50 " the same read. Default: %d\n"
51 "-s Maximum actions that the model checker will wait for\n"
52 " a write from the future past the expected number of\n"
53 " actions. Default: %d\n"
54 "-S Future value expiration sloppiness. Default: %u\n"
55 "-f Specify a fairness window in which actions that are\n"
56 " enabled sufficiently many times should receive\n"
57 " priority for execution. Default: %d\n"
58 "-y Turn on CHESS yield-based fairness support.\n"
60 "-e Enabled count. Default: %d\n"
61 "-b Upper length bound. Default: %d\n"
62 "-v Print verbose execution information.\n"
63 "-u Value for uninitialized reads. Default: %u\n"
64 "-c Use SC Trace Analysis.\n"
65 "-- Program arguments follow.\n\n",
66 params->maxreads, params->maxfuturevalues, params->maxfuturedelay, params->expireslop, params->fairwindow, params->yieldon, params->enabledcount, params->bound, params->uninitvalue);
70 static void parse_options(struct model_params *params, int argc, char **argv)
72 const char *shortopts = "hycm:M:s:S:f:e:b:u:v";
75 while (!error && (opt = getopt(argc, argv, shortopts)) != -1) {
81 params->maxfuturedelay = atoi(optarg);
84 params->expireslop = atoi(optarg);
87 params->fairwindow = atoi(optarg);
90 params->enabledcount = atoi(optarg);
93 params->bound = atoi(optarg);
96 params->maxreads = atoi(optarg);
99 params->maxfuturevalues = atoi(optarg);
105 params->uninitvalue = atoi(optarg);
108 params->sc_trace_analysis = true;
111 params->yieldon = true;
119 /* Pass remaining arguments to user program */
120 params->argc = argc - (optind - 1);
121 params->argv = argv + (optind - 1);
123 /* Reset program name */
124 params->argv[0] = argv[0];
126 /* Reset (global) optind for potential use by user program */
136 void install_trace_analyses() {
137 if (model->params.sc_trace_analysis)
138 model->add_trace_analysis(new SCAnalysis());
141 /** The model_main function contains the main model checking loop. */
142 static void model_main()
144 struct model_params params;
146 param_defaults(¶ms);
148 parse_options(¶ms, main_argc, main_argv);
150 //Initialize race detector
153 snapshot_stack_init();
155 model = new ModelChecker(params);
156 install_trace_analyses();
166 * Main function. Just initializes snapshotting library and the
167 * snapshotting library calls the model_main function.
169 int main(int argc, char **argv)
174 /* Configure output redirection for the model-checker */
177 /* Let's jump in quickly and start running stuff */
178 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);