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->tracebound = 0;
25 params->nofork = false;
28 static void print_usage(struct model_params *params)
30 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
31 /* Reset defaults before printing */
32 param_defaults(params);
35 "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
36 "Distributed under the GPLv2\n"
37 "Written by Brian Norris and Brian Demsky\n"
39 "Usage: C11TESTER=[MODEL-CHECKER OPTIONS]\n"
41 "MODEL-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
42 "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
44 "Model-checker options:\n"
45 "-h, --help Display this help message and exit\n"
46 "-v[NUM], --verbose[=NUM] Print verbose execution information. NUM is optional:\n"
47 " 0 is quiet; 1 shows valid executions; 2 is noisy;\n"
50 "-t, --analysis=NAME Use Analysis Plugin.\n"
51 "-o, --options=NAME Option for previous analysis plugin. \n"
52 "-x, --maxexec=NUM Maximum number of executions.\n"
54 " -o help for a list of options\n"
57 params->maxexecutions);
58 model_print("Analysis plugins:\n");
59 for(unsigned int i=0;i<registeredanalysis->size();i++) {
60 TraceAnalysis * analysis=(*registeredanalysis)[i];
61 model_print("%s\n", analysis->name());
66 bool install_plugin(char * name) {
67 ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
68 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
70 for(unsigned int i=0;i<registeredanalysis->size();i++) {
71 TraceAnalysis * analysis=(*registeredanalysis)[i];
72 if (strcmp(name, analysis->name())==0) {
73 installedanalysis->push_back(analysis);
77 model_print("Analysis %s Not Found\n", name);
81 void parse_options(struct model_params *params) {
82 const char *shortopts = "hnt:o:x:v::";
83 const struct option longopts[] = {
84 {"help", no_argument, NULL, 'h'},
85 {"verbose", optional_argument, NULL, 'v'},
86 {"analysis", required_argument, NULL, 't'},
87 {"options", required_argument, NULL, 'o'},
88 {"maxexecutions", required_argument, NULL, 'x'},
89 {0, 0, 0, 0} /* Terminator */
92 int tmpoptind = optind;
94 char * options = getenv("C11TESTER");
100 for(index = 0;options[index]!=0;index++) {
101 if (options[index] == ' ')
104 argc++; //first parameter is executable name
105 char optcpy[index + 1];
106 memcpy(optcpy, options, index+1);
107 char * argv[argc + 1];
111 for(index = 0;optcpy[index]!=0;index++) {
112 if (optcpy[index] == ' ') {
113 argv[count++] = &optcpy[index+1];
118 while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
124 params->nofork = true;
127 params->maxexecutions = atoi(optarg);
130 params->verbose = optarg ? atoi(optarg) : 1;
133 if (install_plugin(optarg))
138 ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
139 if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
149 /* Restore (global) optind for potential use by user program */
156 void install_trace_analyses(ModelExecution *execution) {
157 ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
158 for(unsigned int i=0;i<installedanalysis->size();i++) {
159 TraceAnalysis * ta=(*installedanalysis)[i];
160 ta->setExecution(execution);
161 model->add_trace_analysis(ta);
162 /** Call the installation event for each installed plugin */
163 ta->actionAtInstallation();