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)
21 params->enabledcount = 1;
23 params->verbose = !!DBG_ENABLED();
24 params->uninitvalue = 0;
25 params->maxexecutions = 0;
28 static void print_usage(const char *program_name, struct model_params *params)
30 /* Reset defaults before printing */
31 param_defaults(params);
34 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
35 "Distributed under the GPLv2\n"
36 "Written by Brian Norris and Brian Demsky\n"
38 "Usage: %s [MODEL-CHECKER OPTIONS] -- [PROGRAM ARGS]\n"
40 "MODEL-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
41 "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
43 "Model-checker options:\n"
44 "-h, --help Display this help message and exit\n"
45 "-e, --enabled=COUNT Enabled count.\n"
47 "-b, --bound=MAX Upper length bound.\n"
49 "-v[NUM], --verbose[=NUM] Print verbose execution information. NUM is optional:\n"
50 " 0 is quiet; 1 shows valid executions; 2 is noisy;\n"
53 "-u, --uninitialized=VALUE Return VALUE any load which may read from an\n"
54 " uninitialized atomic.\n"
56 "-t, --analysis=NAME Use Analysis Plugin.\n"
57 "-o, --options=NAME Option for previous analysis plugin. \n"
58 "-x, --maxexec=NUM Maximum number of executions.\n"
60 " -o help for a list of options\n"
61 " -- Program arguments follow.\n\n",
67 params->maxexecutions);
72 static void parse_options(struct model_params *params, int argc, char **argv)
74 const char *shortopts = "ht:o:e:b:u:x:v::";
75 const struct option longopts[] = {
76 {"help", no_argument, NULL, 'h'},
77 {"enabled", required_argument, NULL, 'e'},
78 {"bound", required_argument, NULL, 'b'},
79 {"verbose", optional_argument, NULL, 'v'},
80 {"uninitialized", required_argument, NULL, 'u'},
81 {"analysis", required_argument, NULL, 't'},
82 {"options", required_argument, NULL, 'o'},
83 {"maxexecutions", required_argument, NULL, 'x'},
84 {0, 0, 0, 0} /* Terminator */
88 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
91 print_usage(argv[0], params);
94 params->maxexecutions = atoi(optarg);
97 params->enabledcount = atoi(optarg);
100 params->bound = atoi(optarg);
103 params->verbose = optarg ? atoi(optarg) : 1;
106 params->uninitvalue = atoi(optarg);
109 if (install_plugin(optarg))
114 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
115 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
126 /* Pass remaining arguments to user program */
127 params->argc = argc - (optind - 1);
128 params->argv = argv + (optind - 1);
130 /* Reset program name */
131 params->argv[0] = argv[0];
133 /* Reset (global) optind for potential use by user program */
137 print_usage(argv[0], params);
143 /** The model_main function contains the main model checking loop. */
144 static void model_main()
146 struct model_params params;
148 param_defaults(¶ms);
150 parse_options(¶ms, main_argc, main_argv);
152 //Initialize race detector
155 snapshot_stack_init();
157 model = new ModelChecker(params); // L: Model thread is created
158 // install_trace_analyses(model->get_execution()); L: disable plugin
168 * Main function. Just initializes snapshotting library and the
169 * snapshotting library calls the model_main function.
171 int main(int argc, char **argv)
177 * If this printf statement is removed, CDSChecker will fail on an
178 * assert on some versions of glibc. The first time printf is
179 * called, it allocated internal buffers. We can't easily snapshot
180 * libc since we also use it.
183 printf("CDSChecker\n"
184 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
185 "Distributed under the GPLv2\n"
186 "Written by Brian Norris and Brian Demsky\n\n");
188 /* Configure output redirection for the model-checker */
191 /* Let's jump in quickly and start running stuff */
192 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);