2 * @brief Entry point for the model checker.
12 /* global "model" object */
14 #include "snapshot-interface.h"
15 #include "scanalysis.h"
17 static void param_defaults(struct model_params *params)
20 params->maxfuturedelay = 6;
21 params->fairwindow = 0;
22 params->yieldon = false;
23 params->sc_trace_analysis = false;
24 params->enabledcount = 1;
26 params->maxfuturevalues = 0;
27 params->expireslop = 4;
28 params->verbose = !!DBG_ENABLED();
29 params->uninitvalue = 0;
32 static void print_usage(struct model_params *params)
34 /* Reset defaults before printing */
35 param_defaults(params);
38 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
39 "Distributed under the GPLv2\n"
40 "Written by Brian Norris and Brian Demsky\n"
42 "Usage: <program name> [MC_OPTIONS] -- [PROGRAM ARGUMENTS]\n"
45 "-h Display this help message and exit\n"
46 "-m Maximum times a thread can read from the same write\n"
47 " while other writes exist. Default: %d\n"
48 "-M Maximum number of future values that can be sent to\n"
49 " the same read. Default: %d\n"
50 "-s Maximum actions that the model checker will wait for\n"
51 " a write from the future past the expected number of\n"
52 " actions. Default: %d\n"
53 "-S Future value expiration sloppiness. Default: %u\n"
54 "-f Specify a fairness window in which actions that are\n"
55 " enabled sufficiently many times should receive\n"
56 " priority for execution. Default: %d\n"
57 "-y Turn on CHESS yield-based fairness support.\n"
59 "-e Enabled count. Default: %d\n"
60 "-b Upper length bound. Default: %d\n"
61 "-v Print verbose execution information.\n"
62 "-u Value for uninitialized reads. Default: %u\n"
63 "-c Use SC Trace Analysis.\n"
64 "-- Program arguments follow.\n\n",
65 params->maxreads, params->maxfuturevalues, params->maxfuturedelay, params->expireslop, params->fairwindow, params->yieldon, params->enabledcount, params->bound, params->uninitvalue);
69 static void parse_options(struct model_params *params, int argc, char **argv)
71 const char *shortopts = "hycm:M:s:S:f:e:b:u:v";
74 while (!error && (opt = getopt(argc, argv, shortopts)) != -1) {
80 params->maxfuturedelay = atoi(optarg);
83 params->expireslop = atoi(optarg);
86 params->fairwindow = atoi(optarg);
89 params->enabledcount = atoi(optarg);
92 params->bound = atoi(optarg);
95 params->maxreads = atoi(optarg);
98 params->maxfuturevalues = atoi(optarg);
104 params->uninitvalue = atoi(optarg);
107 params->sc_trace_analysis = true;
110 params->yieldon = true;
118 /* Pass remaining arguments to user program */
119 params->argc = argc - (optind - 1);
120 params->argv = argv + (optind - 1);
122 /* Reset program name */
123 params->argv[0] = argv[0];
125 /* Reset (global) optind for potential use by user program */
135 void install_trace_analyses() {
136 if (model->params.sc_trace_analysis)
137 model->add_trace_analysis(new SCAnalysis());
140 /** The model_main function contains the main model checking loop. */
141 static void model_main()
143 struct model_params params;
145 param_defaults(¶ms);
147 parse_options(¶ms, main_argc, main_argv);
149 //Initialize race detector
152 snapshot_stack_init();
154 model = new ModelChecker(params);
155 install_trace_analyses();
165 * Main function. Just initializes snapshotting library and the
166 * snapshotting library calls the model_main function.
168 int main(int argc, char **argv)
173 /* Configure output redirection for the model-checker */
176 /* Let's jump in quickly and start running stuff */
177 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);