2 * @brief Entry point for the model checker.
14 /* global "model" object */
17 #include "snapshot-interface.h"
20 static void param_defaults(struct model_params *params)
23 params->maxfuturedelay = 6;
24 params->fairwindow = 0;
25 params->yieldon = false;
26 params->yieldblock = false;
27 params->enabledcount = 1;
29 params->maxfuturevalues = 0;
30 params->expireslop = 4;
31 params->verbose = !!DBG_ENABLED();
32 params->uninitvalue = 0;
33 params->maxexecutions = 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 shows valid executions; 2 is noisy;\n"
83 "-u, --uninitialized=VALUE Return VALUE any load which may read from an\n"
84 " uninitialized atomic.\n"
86 "-t, --analysis=NAME Use Analysis Plugin.\n"
87 "-o, --options=NAME Option for previous analysis plugin. \n"
88 "-x, --maxexec=NUM Maximum number of executions.\n"
90 " -o help for a list of options\n"
91 " -- Program arguments follow.\n\n",
94 params->maxfuturevalues,
95 params->maxfuturedelay,
97 params->yieldon ? "enabled" : "disabled",
98 params->yieldblock ? "enabled" : "disabled",
100 params->enabledcount,
104 params->maxexecutions);
105 model_print("Analysis plugins:\n");
106 for(unsigned int i=0;i<registeredanalysis->size();i++) {
107 TraceAnalysis * analysis=(*registeredanalysis)[i];
108 model_print("%s\n", analysis->name());
113 bool install_plugin(char * name) {
114 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
115 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
117 for(unsigned int i=0;i<registeredanalysis->size();i++) {
118 TraceAnalysis * analysis=(*registeredanalysis)[i];
119 if (strcmp(name, analysis->name())==0) {
120 installedanalysis->push_back(analysis);
124 model_print("Analysis %s Not Found\n", name);
128 static void parse_options(struct model_params *params, int argc, char **argv)
130 const char *shortopts = "hyYt:o:m:M:s:S:f:e:b:u:x:v::";
131 const struct option longopts[] = {
132 {"help", no_argument, NULL, 'h'},
133 {"liveness", required_argument, NULL, 'm'},
134 {"maxfv", required_argument, NULL, 'M'},
135 {"maxfvdelay", required_argument, NULL, 's'},
136 {"fvslop", required_argument, NULL, 'S'},
137 {"fairness", required_argument, NULL, 'f'},
138 {"yield", no_argument, NULL, 'y'},
139 {"yieldblock", no_argument, NULL, 'Y'},
140 {"enabled", required_argument, NULL, 'e'},
141 {"bound", required_argument, NULL, 'b'},
142 {"verbose", optional_argument, NULL, 'v'},
143 {"uninitialized", required_argument, NULL, 'u'},
144 {"analysis", required_argument, NULL, 't'},
145 {"options", required_argument, NULL, 'o'},
146 {"maxexecutions", required_argument, NULL, 'x'},
147 {0, 0, 0, 0} /* Terminator */
151 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
154 print_usage(argv[0], params);
157 params->maxexecutions = atoi(optarg);
160 params->maxfuturedelay = atoi(optarg);
163 params->expireslop = atoi(optarg);
166 params->fairwindow = atoi(optarg);
169 params->enabledcount = atoi(optarg);
172 params->bound = atoi(optarg);
175 params->maxreads = atoi(optarg);
178 params->maxfuturevalues = atoi(optarg);
181 params->verbose = optarg ? atoi(optarg) : 1;
184 params->uninitvalue = atoi(optarg);
187 params->yieldon = true;
190 if (install_plugin(optarg))
195 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
196 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
201 params->yieldblock = true;
209 /* Pass remaining arguments to user program */
210 params->argc = argc - (optind - 1);
211 params->argv = argv + (optind - 1);
213 /* Reset program name */
214 params->argv[0] = argv[0];
216 /* Reset (global) optind for potential use by user program */
220 print_usage(argv[0], params);
226 static void install_trace_analyses(ModelExecution *execution)
228 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
229 for(unsigned int i=0;i<installedanalysis->size();i++) {
230 TraceAnalysis * ta=(*installedanalysis)[i];
231 ta->setExecution(execution);
232 model->add_trace_analysis(ta);
233 /** Call the installation event for each installed plugin */
234 ta->actionAtInstallation();
238 /** The model_main function contains the main model checking loop. */
239 static void model_main()
241 struct model_params params;
243 param_defaults(¶ms);
246 parse_options(¶ms, main_argc, main_argv);
248 //Initialize race detector
251 snapshot_stack_init();
253 model = new ModelChecker(params);
254 install_trace_analyses(model->get_execution());
264 * Main function. Just initializes snapshotting library and the
265 * snapshotting library calls the model_main function.
267 int main(int argc, char **argv)
273 * If this printf statement is removed, CDSChecker will fail on an
274 * assert on some versions of glibc. The first time printf is
275 * called, it allocated internal buffers. We can't easily snapshot
276 * libc since we also use it.
279 printf("CDSChecker\n"
280 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
281 "Distributed under the GPLv2\n"
282 "Written by Brian Norris and Brian Demsky\n\n");
284 /* Configure output redirection for the model-checker */
287 /* Let's jump in quickly and start running stuff */
288 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);