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"
68 "-Y, --yieldblock Prohibit an execution from running a yield.\n"
70 "-f, --fairness=WINDOW Specify a fairness window in which actions that are\n"
71 " enabled sufficiently many times should receive\n"
72 " priority for execution (not recommended).\n"
74 "-e, --enabled=COUNT Enabled count.\n"
76 "-b, --bound=MAX Upper length bound.\n"
78 "-v, --verbose Print verbose execution information.\n"
79 "-u, --uninitialized=VALUE Return VALUE any load which may read from an\n"
80 " uninitialized atomic.\n"
82 "-t, --analysis=NAME Use Analysis Plugin.\n"
83 "-o, --options=NAME Option for previous analysis plugin. \n"
84 " -o help for a list of options\n"
85 " -- Program arguments follow.\n\n",
88 params->maxfuturevalues,
89 params->maxfuturedelay,
91 params->yieldon ? "enabled" : "disabled",
92 params->yieldblock ? "enabled" : "disabled",
97 model_print("Analysis plugins:\n");
98 for(unsigned int i=0;i<registeredanalysis->size();i++) {
99 TraceAnalysis * analysis=(*registeredanalysis)[i];
100 model_print("%s\n", analysis->name());
105 bool install_plugin(char * name) {
106 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
107 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
109 for(unsigned int i=0;i<registeredanalysis->size();i++) {
110 TraceAnalysis * analysis=(*registeredanalysis)[i];
111 if (strcmp(name, analysis->name())==0) {
112 installedanalysis->push_back(analysis);
116 model_print("Analysis %s Not Found\n", name);
120 static void parse_options(struct model_params *params, int argc, char **argv)
122 const char *shortopts = "hyYt:o:m:M:s:S:f:e:b:u:v::";
123 const struct option longopts[] = {
124 {"help", no_argument, NULL, 'h'},
125 {"liveness", required_argument, NULL, 'm'},
126 {"maxfv", required_argument, NULL, 'M'},
127 {"maxfvdelay", required_argument, NULL, 's'},
128 {"fvslop", required_argument, NULL, 'S'},
129 {"fairness", required_argument, NULL, 'f'},
130 {"yield", no_argument, NULL, 'y'},
131 {"yieldblock", no_argument, NULL, 'Y'},
132 {"enabled", required_argument, NULL, 'e'},
133 {"bound", required_argument, NULL, 'b'},
134 {"verbose", optional_argument, NULL, 'v'},
135 {"uninitialized", optional_argument, NULL, 'u'},
136 {"analysis", optional_argument, NULL, 't'},
137 {"options", optional_argument, NULL, 'o'},
138 {0, 0, 0, 0} /* Terminator */
142 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
145 print_usage(argv[0], params);
148 params->maxfuturedelay = atoi(optarg);
151 params->expireslop = atoi(optarg);
154 params->fairwindow = atoi(optarg);
157 params->enabledcount = atoi(optarg);
160 params->bound = atoi(optarg);
163 params->maxreads = atoi(optarg);
166 params->maxfuturevalues = atoi(optarg);
169 params->verbose = optarg ? atoi(optarg) : 1;
172 params->uninitvalue = atoi(optarg);
175 params->yieldon = true;
178 if (install_plugin(optarg))
183 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
184 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
189 params->yieldblock = true;
197 /* Pass remaining arguments to user program */
198 params->argc = argc - (optind - 1);
199 params->argv = argv + (optind - 1);
201 /* Reset program name */
202 params->argv[0] = argv[0];
204 /* Reset (global) optind for potential use by user program */
208 print_usage(argv[0], params);
214 static void install_trace_analyses(ModelExecution *execution)
216 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
217 for(unsigned int i=0;i<installedanalysis->size();i++) {
218 TraceAnalysis * ta=(*installedanalysis)[i];
219 ta->setExecution(execution);
220 model->add_trace_analysis(ta);
224 /** The model_main function contains the main model checking loop. */
225 static void model_main()
227 struct model_params params;
229 param_defaults(¶ms);
232 parse_options(¶ms, main_argc, main_argv);
234 //Initialize race detector
237 snapshot_stack_init();
239 model = new ModelChecker(params);
240 install_trace_analyses(model->get_execution());
250 * Main function. Just initializes snapshotting library and the
251 * snapshotting library calls the model_main function.
253 int main(int argc, char **argv)
258 /* Configure output redirection for the model-checker */
261 /* Let's jump in quickly and start running stuff */
262 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);