2 * @brief Entry point for the model checker.
14 /* global "model" object */
17 #include "snapshot-interface.h"
20 void param_defaults(struct model_params *params)
22 params->verbose = !!DBG_ENABLED();
23 params->maxexecutions = 10;
24 params->traceminsize = 0;
25 params->checkthreshold = 500000;
26 params->removevisible = false;
27 params->nofork = false;
30 static void print_usage(struct model_params *params)
32 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
33 /* Reset defaults before printing */
34 param_defaults(params);
37 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
38 "Distributed under the GPLv2\n"
39 "Written by Brian Norris and Brian Demsky\n"
41 "Usage: C11TESTER=[MODEL-CHECKER OPTIONS]\n"
43 "MODEL-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
44 "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
46 "Model-checker options:\n"
47 "-h, --help Display this help message and exit\n"
48 "-v[NUM], --verbose[=NUM] Print verbose execution information. NUM is optional:\n"
49 " 0 is quiet; 1 shows valid executions; 2 is noisy;\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"
58 "-m, --minsize=NUM Minimum number of actions to keep\n"
60 "-f, --freqfree=NUM Frequency to free actions\n"
62 "-r, --removevisible Free visible writes\n",
64 params->maxexecutions,
66 params->checkthreshold);
67 model_print("Analysis plugins:\n");
68 for(unsigned int i=0;i<registeredanalysis->size();i++) {
69 TraceAnalysis * analysis=(*registeredanalysis)[i];
70 model_print("%s\n", analysis->name());
75 bool install_plugin(char * name) {
76 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
77 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
79 for(unsigned int i=0;i<registeredanalysis->size();i++) {
80 TraceAnalysis * analysis=(*registeredanalysis)[i];
81 if (strcmp(name, analysis->name())==0) {
82 installedanalysis->push_back(analysis);
86 model_print("Analysis %s Not Found\n", name);
90 void parse_options(struct model_params *params) {
91 const char *shortopts = "hrnt:o:x:v:m:f:";
92 const struct option longopts[] = {
93 {"help", no_argument, NULL, 'h'},
94 {"removevisible", no_argument, NULL, 'r'},
95 {"analysis", required_argument, NULL, 't'},
96 {"options", required_argument, NULL, 'o'},
97 {"maxexecutions", required_argument, NULL, 'x'},
98 {"verbose", optional_argument, NULL, 'v'},
99 {"minsize", required_argument, NULL, 'm'},
100 {"freqfree", required_argument, NULL, 'f'},
101 {0, 0, 0, 0} /* Terminator */
105 char * options = getenv("C11TESTER");
111 for(index = 0;options[index]!=0;index++) {
112 if (options[index] == ' ')
115 argc++; //first parameter is executable name
116 char optcpy[index + 1];
117 memcpy(optcpy, options, index+1);
118 char * argv[argc + 1];
122 for(index = 0;optcpy[index]!=0;index++) {
123 if (optcpy[index] == ' ') {
124 argv[count++] = &optcpy[index+1];
129 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
135 params->nofork = true;
138 params->maxexecutions = atoi(optarg);
141 params->verbose = optarg ? atoi(optarg) : 1;
144 if (install_plugin(optarg))
148 params->traceminsize = atoi(optarg);
151 params->checkthreshold = atoi(optarg);
154 params->removevisible = true;
158 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
159 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
169 /* Special value to reset implementation as described by Linux man page. */
176 void install_trace_analyses(ModelExecution *execution) {
177 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
178 for(unsigned int i=0;i<installedanalysis->size();i++) {
179 TraceAnalysis * ta=(*installedanalysis)[i];
180 ta->setExecution(execution);
181 model->add_trace_analysis(ta);
182 /** Call the installation event for each installed plugin */
183 ta->actionAtInstallation();