6 #ifndef HAVE_BOOST_REGEX
9 #include <boost/regex.hpp>
12 using boost::regex_match;
29 #ifdef HAVE_LIBSQLITE3
41 using namespace std::chrono;
53 extern "C" void cerr_log_handler(
int)
55 if (global_cerr_logger)
56 global_cerr_logger->report();
60 int main(
int argc,
char *argv[])
62 cerr << PACKAGE_NAME
" " GITREV << endl;
64 map<string,string> options;
65 regex optregex(
"--(help|log-to|verbose|target|sqlite|monetdb|version|dump-all-graphs|dump-all-queries|seed|dry-run|max-queries|rng-state|exclude-catalog)(?:=((?:.|\n)*))?");
67 for(
char **opt = argv+1 ;opt < argv+argc; opt++) {
70 if (regex_match(s, match, optregex)) {
71 options[string(match[1])] = match[2];
73 cerr <<
"Cannot parse option: " << *opt << endl;
78 if (options.count(
"help")) {
80 " --target=connstr postgres database to send queries to" << endl <<
81 #ifdef HAVE_LIBSQLITE3
82 " --sqlite=URI SQLite database to send queries to" << endl <<
85 " --monetdb=connstr MonetDB database to send queries to" <<endl <<
87 " --log-to=connstr log errors to postgres database" << endl <<
88 " --seed=int seed RNG with specified int instead of PID" << endl <<
89 " --dump-all-queries print queries as they are generated" << endl <<
90 " --dump-all-graphs dump generated ASTs" << endl <<
91 " --dry-run print queries instead of executing them" << endl <<
92 " --exclude-catalog don't generate queries using catalog relations" << endl <<
93 " --max-queries=long terminate after generating this many queries" << endl <<
94 " --rng-state=string deserialize dumped rng state" << endl <<
95 " --verbose emit progress output" << endl <<
96 " --version print version information and exit" << endl <<
97 " --help print available command line options and exit" << endl;
99 }
else if (options.count(
"version")) {
105 shared_ptr<schema>
schema;
106 if (options.count(
"sqlite")) {
107 #ifdef HAVE_LIBSQLITE3
108 schema = make_shared<schema_sqlite>(options[
"sqlite"], options.count(
"exclude-catalog"));
110 cerr <<
"Sorry, " PACKAGE_NAME
" was compiled without SQLite support." << endl;
114 else if(options.count(
"monetdb")) {
116 schema = make_shared<schema_monetdb>(options[
"monetdb"]);
118 cerr <<
"Sorry, " PACKAGE_NAME
" was compiled without MonetDB support." << endl;
123 schema = make_shared<schema_pqxx>(options[
"target"], options.count(
"exclude-catalog"));
126 long queries_generated = 0;
129 if (options.count(
"rng-state")) {
130 istringstream(options[
"rng-state"]) >> smith::rng;
132 smith::rng.seed(options.count(
"seed") ? stoi(options[
"seed"]) : getpid());
135 vector<shared_ptr<logger> > loggers;
137 loggers.push_back(make_shared<impedance_feedback>());
139 if (options.count(
"log-to"))
140 loggers.push_back(make_shared<pqxx_logger>(
141 options.count(
"sqlite") ? options[
"sqlite"] : options[
"target"],
142 options[
"log-to"], *
schema));
144 if (options.count(
"verbose")) {
145 auto l = make_shared<cerr_logger>();
146 global_cerr_logger = &*l;
147 loggers.push_back(l);
148 signal(SIGINT, cerr_log_handler);
151 if (options.count(
"dump-all-graphs"))
152 loggers.push_back(make_shared<ast_logger>());
154 if (options.count(
"dump-all-queries"))
155 loggers.push_back(make_shared<query_dumper>());
157 if (options.count(
"dry-run")) {
159 shared_ptr<prod> gen = statement_factory(&
scope);
161 for (
auto l : loggers)
166 if (options.count(
"max-queries")
167 && (queries_generated >= stol(options[
"max-queries"])))
172 shared_ptr<dut_base> dut;
174 if (options.count(
"sqlite")) {
175 #ifdef HAVE_LIBSQLITE3
176 dut = make_shared<dut_sqlite>(options[
"sqlite"]);
178 cerr <<
"Sorry, " PACKAGE_NAME
" was compiled without SQLite support." << endl;
182 else if(options.count(
"monetdb")) {
184 dut = make_shared<dut_monetdb>(options[
"monetdb"]);
186 cerr <<
"Sorry, " PACKAGE_NAME
" was compiled without MonetDB support." << endl;
191 dut = make_shared<dut_libpq>(options[
"target"]);
198 if (options.count(
"max-queries")
199 && (++queries_generated > stol(options[
"max-queries"]))) {
200 if (global_cerr_logger)
201 global_cerr_logger->report();
206 shared_ptr<prod> gen = statement_factory(&
scope);
208 for (
auto l : loggers)
218 for (
auto l : loggers)
221 for (
auto l : loggers)
224 }
catch (runtime_error &e) {
225 cerr << endl <<
"log failed: " <<
typeid(*l).name() <<
": "
237 this_thread::sleep_for(milliseconds(1000));
241 catch (
const exception &e) {
242 cerr << e.what() << endl;
Dump syntax trees as GraphML.
Base class for device under test.
grammar: Top-level and unsorted grammar productions
feedback to the grammar about failed productions
schema and dut classes for MonetDB
schema and dut classes for PostgreSQL
supporting classes for the grammar
Base class providing schema information to grammar.
schema and dut classes for SQLite 3