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 " -- Program arguments follow.\n\n",
85 params->maxfuturevalues,
86 params->maxfuturedelay,
88 params->yieldon ? "enabled" : "disabled",
89 params->yieldblock ? "enabled" : "disabled",
97 bool install_plugin(char * name) {
98 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
99 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
101 for(unsigned int i=0;i<registeredanalysis->size();i++) {
102 TraceAnalysis * analysis=(*registeredanalysis)[i];
103 if (strcmp(name, analysis->name())==0) {
104 installedanalysis->push_back(analysis);
108 model_print("Analysis %s Not Found\n", name);
112 static void parse_options(struct model_params *params, int argc, char **argv)
114 const char *shortopts = "hyYt:m:M:s:S:f:e:b:u:v::";
115 const struct option longopts[] = {
116 {"help", no_argument, NULL, 'h'},
117 {"liveness", required_argument, NULL, 'm'},
118 {"maxfv", required_argument, NULL, 'M'},
119 {"maxfvdelay", required_argument, NULL, 's'},
120 {"fvslop", required_argument, NULL, 'S'},
121 {"fairness", required_argument, NULL, 'f'},
122 {"yield", no_argument, NULL, 'y'},
123 {"yieldblock", no_argument, NULL, 'Y'},
124 {"enabled", required_argument, NULL, 'e'},
125 {"bound", required_argument, NULL, 'b'},
126 {"verbose", optional_argument, NULL, 'v'},
127 {"uninitialized", optional_argument, NULL, 'u'},
128 {"analysis", optional_argument, NULL, 't'},
129 {0, 0, 0, 0} /* Terminator */
133 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
136 print_usage(argv[0], params);
139 params->maxfuturedelay = atoi(optarg);
142 params->expireslop = atoi(optarg);
145 params->fairwindow = atoi(optarg);
148 params->enabledcount = atoi(optarg);
151 params->bound = atoi(optarg);
154 params->maxreads = atoi(optarg);
157 params->maxfuturevalues = atoi(optarg);
160 params->verbose = optarg ? atoi(optarg) : 1;
163 params->uninitvalue = atoi(optarg);
166 params->yieldon = true;
169 if (install_plugin(optarg))
173 params->yieldblock = true;
181 /* Pass remaining arguments to user program */
182 params->argc = argc - (optind - 1);
183 params->argv = argv + (optind - 1);
185 /* Reset program name */
186 params->argv[0] = argv[0];
188 /* Reset (global) optind for potential use by user program */
192 print_usage(argv[0], params);
198 static void install_trace_analyses(ModelExecution *execution)
200 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
201 for(unsigned int i=0;i<installedanalysis->size();i++) {
202 TraceAnalysis * ta=(*installedanalysis)[i];
203 ta->setExecution(execution);
204 model->add_trace_analysis(ta);
208 /** The model_main function contains the main model checking loop. */
209 static void model_main()
211 struct model_params params;
213 param_defaults(¶ms);
216 parse_options(¶ms, main_argc, main_argv);
218 //Initialize race detector
221 snapshot_stack_init();
223 model = new ModelChecker(params);
224 install_trace_analyses(model->get_execution());
234 * Main function. Just initializes snapshotting library and the
235 * snapshotting library calls the model_main function.
237 int main(int argc, char **argv)
242 /* Configure output redirection for the model-checker */
245 /* Let's jump in quickly and start running stuff */
246 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);