2 * @brief Entry point for the model checker.
14 /* global "model" object */
17 #include "snapshot-interface.h"
19 static void param_defaults(struct model_params *params)
22 params->maxfuturedelay = 6;
23 params->fairwindow = 0;
24 params->yieldon = false;
25 params->yieldblock = false;
26 params->enabledcount = 1;
28 params->maxfuturevalues = 0;
29 params->expireslop = 4;
30 params->verbose = !!DBG_ENABLED();
31 params->uninitvalue = 0;
32 params->maxexecutions = 0;
35 static void print_usage(const char *program_name, struct model_params *params)
37 /* Reset defaults before printing */
38 param_defaults(params);
41 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
42 "Distributed under the GPLv2\n"
43 "Written by Brian Norris and Brian Demsky\n"
45 "Usage: %s [MODEL-CHECKER OPTIONS] -- [PROGRAM ARGS]\n"
47 "MODEL-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
48 "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
50 "Model-checker options:\n"
51 "-h, --help Display this help message and exit\n"
52 "-m, --liveness=NUM Maximum times a thread can read from the same write\n"
53 " while other writes exist.\n"
55 "-M, --maxfv=NUM Maximum number of future values that can be sent to\n"
58 "-s, --maxfvdelay=NUM Maximum actions that the model checker will wait for\n"
59 " a write from the future past the expected number\n"
62 "-S, --fvslop=NUM Future value expiration sloppiness.\n"
64 "-y, --yield Enable CHESS-like yield-based fairness support\n"
65 " (requires thrd_yield() in test program).\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[NUM], --verbose[=NUM] Print verbose execution information. NUM is optional:\n"
78 " 0 is quiet; 1 shows valid executions; 2 is noisy;\n"
81 "-u, --uninitialized=VALUE Return VALUE any load which may read from an\n"
82 " uninitialized atomic.\n"
84 "-t, --analysis=NAME Use Analysis Plugin.\n"
85 "-o, --options=NAME Option for previous analysis plugin. \n"
86 "-x, --maxexec=NUM Maximum number of executions.\n"
88 " -o help for a list of options\n"
89 " -- Program arguments follow.\n\n",
92 params->maxfuturevalues,
93 params->maxfuturedelay,
95 params->yieldon ? "enabled" : "disabled",
96 params->yieldblock ? "enabled" : "disabled",
102 params->maxexecutions);
107 static void parse_options(struct model_params *params, int argc, char **argv)
109 const char *shortopts = "hyYt:o:m:M:s:S:f:e:b:u:x:v::";
110 const struct option longopts[] = {
111 {"help", no_argument, NULL, 'h'},
112 {"liveness", required_argument, NULL, 'm'},
113 {"maxfv", required_argument, NULL, 'M'},
114 {"maxfvdelay", required_argument, NULL, 's'},
115 {"fvslop", required_argument, NULL, 'S'},
116 {"fairness", required_argument, NULL, 'f'},
117 {"yield", no_argument, NULL, 'y'},
118 {"yieldblock", no_argument, NULL, 'Y'},
119 {"enabled", required_argument, NULL, 'e'},
120 {"bound", required_argument, NULL, 'b'},
121 {"verbose", optional_argument, NULL, 'v'},
122 {"uninitialized", required_argument, NULL, 'u'},
123 {"analysis", required_argument, NULL, 't'},
124 {"options", required_argument, NULL, 'o'},
125 {"maxexecutions", required_argument, NULL, 'x'},
126 {0, 0, 0, 0} /* Terminator */
130 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
133 print_usage(argv[0], params);
136 params->maxexecutions = atoi(optarg);
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))
174 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
175 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
181 params->yieldblock = true;
189 /* Pass remaining arguments to user program */
190 params->argc = argc - (optind - 1);
191 params->argv = argv + (optind - 1);
193 /* Reset program name */
194 params->argv[0] = argv[0];
196 /* Reset (global) optind for potential use by user program */
200 print_usage(argv[0], params);
206 /** The model_main function contains the main model checking loop. */
207 static void model_main()
209 struct model_params params;
211 param_defaults(¶ms);
213 parse_options(¶ms, main_argc, main_argv);
215 //Initialize race detector
218 snapshot_stack_init();
220 model = new ModelChecker(params); // L: Model thread is created
221 // install_trace_analyses(model->get_execution()); L: disable plugin
231 * Main function. Just initializes snapshotting library and the
232 * snapshotting library calls the model_main function.
234 int main(int argc, char **argv)
240 * If this printf statement is removed, CDSChecker will fail on an
241 * assert on some versions of glibc. The first time printf is
242 * called, it allocated internal buffers. We can't easily snapshot
243 * libc since we also use it.
246 printf("CDSChecker\n"
247 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
248 "Distributed under the GPLv2\n"
249 "Written by Brian Norris and Brian Demsky\n\n");
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);