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 /* Reset defaults before printing */
39 param_defaults(params);
42 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
43 "Distributed under the GPLv2\n"
44 "Written by Brian Norris and Brian Demsky\n"
46 "Usage: %s [MODEL-CHECKER OPTIONS] -- [PROGRAM ARGS]\n"
48 "MODLE-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
49 "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
51 "Model-checker options:\n"
52 "-h, --help Display this help message and exit\n"
53 "-m, --liveness=NUM Maximum times a thread can read from the same write\n"
54 " while other writes exist.\n"
56 "-M, --maxfv=NUM Maximum number of future values that can be sent to\n"
59 "-s, --maxfvdelay=NUM Maximum actions that the model checker will wait for\n"
60 " a write from the future past the expected number\n"
63 "-S, --fvslop=NUM Future value expiration sloppiness.\n"
65 "-y, --yield Enable CHESS-like yield-based fairness support.\n"
67 "-Y, --yieldblock Prohibit an execution from running a yield.\n"
69 "-f, --fairness=WINDOW Specify a fairness window in which actions that are\n"
70 " enabled sufficiently many times should receive\n"
71 " priority for execution (not recommended).\n"
73 "-e, --enabled=COUNT Enabled count.\n"
75 "-b, --bound=MAX Upper length bound.\n"
77 "-v, --verbose Print verbose execution information.\n"
78 "-u, --uninitialized=VALUE Return VALUE any load which may read from an\n"
79 " uninitialized atomic.\n"
81 "-t, --analysis=NAME Use Trace Analysis.\n"
82 "-o, --options=NAME Options.\n"
83 " -- Program arguments follow.\n\n",
86 params->maxfuturevalues,
87 params->maxfuturedelay,
89 params->yieldon ? "enabled" : "disabled",
90 params->yieldblock ? "enabled" : "disabled",
98 bool install_plugin(char * name) {
99 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
100 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
102 for(unsigned int i=0;i<registeredanalysis->size();i++) {
103 TraceAnalysis * analysis=(*registeredanalysis)[i];
104 if (strcmp(name, analysis->name())==0) {
105 installedanalysis->push_back(analysis);
109 model_print("Analysis %s Not Found\n", name);
113 static void parse_options(struct model_params *params, int argc, char **argv)
115 const char *shortopts = "hyYt:o:m:M:s:S:f:e:b:u:v::";
116 const struct option longopts[] = {
117 {"help", no_argument, NULL, 'h'},
118 {"liveness", required_argument, NULL, 'm'},
119 {"maxfv", required_argument, NULL, 'M'},
120 {"maxfvdelay", required_argument, NULL, 's'},
121 {"fvslop", required_argument, NULL, 'S'},
122 {"fairness", required_argument, NULL, 'f'},
123 {"yield", no_argument, NULL, 'y'},
124 {"yieldblock", no_argument, NULL, 'Y'},
125 {"enabled", required_argument, NULL, 'e'},
126 {"bound", required_argument, NULL, 'b'},
127 {"verbose", optional_argument, NULL, 'v'},
128 {"uninitialized", optional_argument, NULL, 'u'},
129 {"analysis", optional_argument, NULL, 't'},
130 {"options", optional_argument, NULL, 'o'},
131 {0, 0, 0, 0} /* Terminator */
135 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
138 print_usage(argv[0], params);
141 params->maxfuturedelay = atoi(optarg);
144 params->expireslop = atoi(optarg);
147 params->fairwindow = atoi(optarg);
150 params->enabledcount = atoi(optarg);
153 params->bound = atoi(optarg);
156 params->maxreads = atoi(optarg);
159 params->maxfuturevalues = atoi(optarg);
162 params->verbose = optarg ? atoi(optarg) : 1;
165 params->uninitvalue = atoi(optarg);
168 params->yieldon = true;
171 if (install_plugin(optarg))
176 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
177 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
182 params->yieldblock = true;
190 /* Pass remaining arguments to user program */
191 params->argc = argc - (optind - 1);
192 params->argv = argv + (optind - 1);
194 /* Reset program name */
195 params->argv[0] = argv[0];
197 /* Reset (global) optind for potential use by user program */
201 print_usage(argv[0], params);
207 static void install_trace_analyses(ModelExecution *execution)
209 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
210 for(unsigned int i=0;i<installedanalysis->size();i++) {
211 TraceAnalysis * ta=(*installedanalysis)[i];
212 ta->setExecution(execution);
213 model->add_trace_analysis(ta);
217 /** The model_main function contains the main model checking loop. */
218 static void model_main()
220 struct model_params params;
222 param_defaults(¶ms);
225 parse_options(¶ms, main_argc, main_argv);
227 //Initialize race detector
230 snapshot_stack_init();
232 model = new ModelChecker(params);
233 install_trace_analyses(model->get_execution());
243 * Main function. Just initializes snapshotting library and the
244 * snapshotting library calls the model_main function.
246 int main(int argc, char **argv)
251 /* Configure output redirection for the model-checker */
254 /* Let's jump in quickly and start running stuff */
255 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);