2 * @brief Entry point for the model checker.
14 /* global "model" object */
17 #include "snapshot-interface.h"
18 #include "scanalysis.h"
21 static void param_defaults(struct model_params *params)
24 params->maxfuturedelay = 6;
25 params->fairwindow = 0;
26 params->yieldon = false;
27 params->yieldblock = false;
28 params->enabledcount = 1;
30 params->maxfuturevalues = 0;
31 params->expireslop = 4;
32 params->verbose = !!DBG_ENABLED();
33 params->uninitvalue = 0;
36 static void print_usage(const char *program_name, struct model_params *params)
38 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
39 /* Reset defaults before printing */
40 param_defaults(params);
43 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
44 "Distributed under the GPLv2\n"
45 "Written by Brian Norris and Brian Demsky\n"
47 "Usage: %s [MODEL-CHECKER OPTIONS] -- [PROGRAM ARGS]\n"
49 "MODEL-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
50 "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
52 "Model-checker options:\n"
53 "-h, --help Display this help message and exit\n"
54 "-m, --liveness=NUM Maximum times a thread can read from the same write\n"
55 " while other writes exist.\n"
57 "-M, --maxfv=NUM Maximum number of future values that can be sent to\n"
60 "-s, --maxfvdelay=NUM Maximum actions that the model checker will wait for\n"
61 " a write from the future past the expected number\n"
64 "-S, --fvslop=NUM Future value expiration sloppiness.\n"
66 "-y, --yield Enable CHESS-like yield-based fairness support\n"
67 " (requires thrd_yield() in test program).\n"
69 "-Y, --yieldblock Prohibit an execution from running a yield.\n"
71 "-f, --fairness=WINDOW Specify a fairness window in which actions that are\n"
72 " enabled sufficiently many times should receive\n"
73 " priority for execution (not recommended).\n"
75 "-e, --enabled=COUNT Enabled count.\n"
77 "-b, --bound=MAX Upper length bound.\n"
79 "-v[NUM], --verbose[=NUM] Print verbose execution information. NUM is optional:\n"
80 " 0 is quiet; 1 is noisy; 2 is noisier.\n"
82 "-u, --uninitialized=VALUE Return VALUE any load which may read from an\n"
83 " uninitialized atomic.\n"
85 "-t, --analysis=NAME Use Analysis Plugin.\n"
86 "-o, --options=NAME Option for previous analysis plugin. \n"
87 " -o help for a list of options\n"
88 " -- Program arguments follow.\n\n",
91 params->maxfuturevalues,
92 params->maxfuturedelay,
94 params->yieldon ? "enabled" : "disabled",
95 params->yieldblock ? "enabled" : "disabled",
100 params->uninitvalue);
101 model_print("Analysis plugins:\n");
102 for(unsigned int i=0;i<registeredanalysis->size();i++) {
103 TraceAnalysis * analysis=(*registeredanalysis)[i];
104 model_print("%s\n", analysis->name());
109 bool install_plugin(char * name) {
110 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
111 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
113 for(unsigned int i=0;i<registeredanalysis->size();i++) {
114 TraceAnalysis * analysis=(*registeredanalysis)[i];
115 if (strcmp(name, analysis->name())==0) {
116 installedanalysis->push_back(analysis);
120 model_print("Analysis %s Not Found\n", name);
124 static void parse_options(struct model_params *params, int argc, char **argv)
126 const char *shortopts = "hyYt:o:m:M:s:S:f:e:b:u:v::";
127 const struct option longopts[] = {
128 {"help", no_argument, NULL, 'h'},
129 {"liveness", required_argument, NULL, 'm'},
130 {"maxfv", required_argument, NULL, 'M'},
131 {"maxfvdelay", required_argument, NULL, 's'},
132 {"fvslop", required_argument, NULL, 'S'},
133 {"fairness", required_argument, NULL, 'f'},
134 {"yield", no_argument, NULL, 'y'},
135 {"yieldblock", no_argument, NULL, 'Y'},
136 {"enabled", required_argument, NULL, 'e'},
137 {"bound", required_argument, NULL, 'b'},
138 {"verbose", optional_argument, NULL, 'v'},
139 {"uninitialized", optional_argument, NULL, 'u'},
140 {"analysis", optional_argument, NULL, 't'},
141 {"options", optional_argument, NULL, 'o'},
142 {0, 0, 0, 0} /* Terminator */
146 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
149 print_usage(argv[0], params);
152 params->maxfuturedelay = atoi(optarg);
155 params->expireslop = atoi(optarg);
158 params->fairwindow = atoi(optarg);
161 params->enabledcount = atoi(optarg);
164 params->bound = atoi(optarg);
167 params->maxreads = atoi(optarg);
170 params->maxfuturevalues = atoi(optarg);
173 params->verbose = optarg ? atoi(optarg) : 1;
176 params->uninitvalue = atoi(optarg);
179 params->yieldon = true;
182 if (install_plugin(optarg))
187 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
188 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
193 params->yieldblock = true;
201 /* Pass remaining arguments to user program */
202 params->argc = argc - (optind - 1);
203 params->argv = argv + (optind - 1);
205 /* Reset program name */
206 params->argv[0] = argv[0];
208 /* Reset (global) optind for potential use by user program */
212 print_usage(argv[0], params);
218 static void install_trace_analyses(ModelExecution *execution)
220 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
221 for(unsigned int i=0;i<installedanalysis->size();i++) {
222 TraceAnalysis * ta=(*installedanalysis)[i];
223 ta->setExecution(execution);
224 model->add_trace_analysis(ta);
228 /** The model_main function contains the main model checking loop. */
229 static void model_main()
231 struct model_params params;
233 param_defaults(¶ms);
236 parse_options(¶ms, main_argc, main_argv);
238 //Initialize race detector
241 snapshot_stack_init();
243 model = new ModelChecker(params);
244 install_trace_analyses(model->get_execution());
254 * Main function. Just initializes snapshotting library and the
255 * snapshotting library calls the model_main function.
257 int main(int argc, char **argv)
262 /* Configure output redirection for the model-checker */
265 /* Let's jump in quickly and start running stuff */
266 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);