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)
22 params->verbose = !!DBG_ENABLED();
23 params->uninitvalue = 0;
24 params->maxexecutions = 10;
27 static void print_usage(const char *program_name, struct model_params *params)
29 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
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 "-v[NUM], --verbose[=NUM] Print verbose execution information. NUM is optional:\n"
46 " 0 is quiet; 1 shows valid executions; 2 is noisy;\n"
49 "-u, --uninitialized=VALUE Return VALUE any load which may read from an\n"
50 " uninitialized atomic.\n"
52 "-t, --analysis=NAME Use Analysis Plugin.\n"
53 "-o, --options=NAME Option for previous analysis plugin. \n"
54 "-x, --maxexec=NUM Maximum number of executions.\n"
56 " -o help for a list of options\n"
57 " -- Program arguments follow.\n\n",
61 params->maxexecutions);
62 model_print("Analysis plugins:\n");
63 for(unsigned int i=0;i<registeredanalysis->size();i++) {
64 TraceAnalysis * analysis=(*registeredanalysis)[i];
65 model_print("%s\n", analysis->name());
70 bool install_plugin(char * name) {
71 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
72 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
74 for(unsigned int i=0;i<registeredanalysis->size();i++) {
75 TraceAnalysis * analysis=(*registeredanalysis)[i];
76 if (strcmp(name, analysis->name())==0) {
77 installedanalysis->push_back(analysis);
81 model_print("Analysis %s Not Found\n", name);
85 static void parse_options(struct model_params *params, int argc, char **argv)
87 const char *shortopts = "ht:o:u:x:v::";
88 const struct option longopts[] = {
89 {"help", no_argument, NULL, 'h'},
90 {"verbose", optional_argument, NULL, 'v'},
91 {"uninitialized", required_argument, NULL, 'u'},
92 {"analysis", required_argument, NULL, 't'},
93 {"options", required_argument, NULL, 'o'},
94 {"maxexecutions", required_argument, NULL, 'x'},
95 {0, 0, 0, 0} /* Terminator */
99 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
102 print_usage(argv[0], params);
105 params->maxexecutions = atoi(optarg);
108 params->verbose = optarg ? atoi(optarg) : 1;
111 params->uninitvalue = atoi(optarg);
114 if (install_plugin(optarg))
119 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
120 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
130 /* Pass remaining arguments to user program */
131 params->argc = argc - (optind - 1);
132 params->argv = argv + (optind - 1);
134 /* Reset program name */
135 params->argv[0] = argv[0];
137 /* Reset (global) optind for potential use by user program */
141 print_usage(argv[0], params);
147 static void install_trace_analyses(ModelExecution *execution)
149 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
150 for(unsigned int i=0;i<installedanalysis->size();i++) {
151 TraceAnalysis * ta=(*installedanalysis)[i];
152 ta->setExecution(execution);
153 model->add_trace_analysis(ta);
154 /** Call the installation event for each installed plugin */
155 ta->actionAtInstallation();
159 /** The model_main function contains the main model checking loop. */
160 static void model_main()
162 struct model_params params;
164 param_defaults(¶ms);
167 parse_options(¶ms, main_argc, main_argv);
169 //Initialize race detector
172 snapshot_stack_init();
175 model = new ModelChecker();
176 model->setParams(params);
177 install_trace_analyses(model->get_execution());
187 * Main function. Just initializes snapshotting library and the
188 * snapshotting library calls the model_main function.
190 int main(int argc, char **argv)
196 * If this printf statement is removed, CDSChecker will fail on an
197 * assert on some versions of glibc. The first time printf is
198 * called, it allocated internal buffers. We can't easily snapshot
199 * libc since we also use it.
202 printf("CDSChecker\n"
203 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
204 "Distributed under the GPLv2\n"
205 "Written by Brian Norris and Brian Demsky\n\n");
207 /* Configure output redirection for the model-checker */
210 /* Let's jump in quickly and start running stuff */
211 snapshot_system_init(10000, 1024, 1024, 4000, &model_main);