3
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; version 2 of the License.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21
use lib "$ENV{RQG_HOME}/lib";
27
use GenTest::Properties;
28
use GenTest::Constants;
29
use GenTest::App::GenTest;
34
require Log::Log4perl;
35
Log::Log4perl->import();
36
$logger = Log::Log4perl->get_logger('randgen.gentest');
39
my $DEFAULT_THREADS = 10;
40
my $DEFAULT_QUERIES = 1000;
41
my $DEFAULT_DURATION = 3600;
42
my $DEFAULT_DSN = 'dbi:mysql:host=127.0.0.1:port=9306:user=root:database=test';
44
my @ARGV_saved = @ARGV;
47
my $opt_result = GetOptions($options,
57
'skip-recursive-rules',
70
'report-xml-tt-type=s',
71
'report-xml-tt-dest=s',
94
backwardCompatability($options);
95
my $config = GenTest::Properties->new(
97
defaults => {dsn=>[$DEFAULT_DSN],
99
queries => $DEFAULT_QUERIES,
100
duration => $DEFAULT_DURATION,
101
threads => $DEFAULT_THREADS},
107
'skip-recursive-rules',
120
'report-xml-tt-type',
121
'report-xml-tt-dest',
137
'short_column_names',
146
help() if !$opt_result || $config->help;
148
if (defined $config->logfile && defined $logger) {
149
setLoggingToFile($config->logfile);
151
if (defined $config->logconf && defined $logger) {
152
setLogConf($config->logconf);
156
say("Starting: $0 ".join(" ", @ARGV_saved));
158
$ENV{RQG_DEBUG} = 1 if defined $config->debug;
159
my $gentest = GenTest::App::GenTest->new(config => $config);
161
my $status = $gentest->run();
168
$0 - Testing via random query generation. Options:
170
--dsn : DBI resources to connect to (default $DEFAULT_DSN).
171
Supported databases are MySQL, Drizzle, PostgreSQL, JavaDB
172
first --dsn must be to MySQL or Drizzle
173
--gendata : Execute gendata-old.pl in order to populate tables with simple data (default NO)
174
--gendata=s : Execute gendata.pl in order to populate tables with data
175
using the argument as specification file to gendata.pl
176
--engine : Table engine to use when creating tables with gendata (default: no ENGINE for CREATE TABLE)
177
--threads : Number of threads to spawn (default $DEFAULT_THREADS)
178
--queries : Numer of queries to execute per thread (default $DEFAULT_QUERIES);
179
--duration : Duration of the test in seconds (default $DEFAULT_DURATION seconds);
180
--grammar : Grammar file to use for generating the queries (REQUIRED);
181
--redefine : Grammar file to redefine and/or add rules to the given grammar
182
--seed : PRNG seed (default 1). If --seed=time, the current time will be used.
183
--rpl_mode : Replication mode
184
--validator : Validator classes to be used. Defaults
185
ErrorMessageCorruption if one or two MySQL dsns
186
ResultsetComparator3 if 3 dsns
187
ResultsetComparartor if 2 dsns
188
--reporter : ErrorLog, Backtrace if one or two MySQL dsns
189
--mask : A seed to a random mask used to mask (reduce) the grammar.
190
--mask-level: How many levels deep the mask is applied (default 1)
191
--rows : Number of rows to generate for each table in gendata.pl, unless specified in the ZZ file
192
--varchar-length: maximum length of strings (deault 1) in gendata.pl
193
--views : Pass --views to gendata-old.pl or gendata.pl. Optionally specify view type (algorithm) as option value.
195
--sqltrace : Print all generated SQL statements.
196
Optional: Specify --sqltrace=MarkErrors to mark invalid statements.
197
--no-err-filter: Do not suppress error messages. Output all error messages encountered.
198
--start-dirty: Do not generate data (use existing database(s))
199
--xml-output: Name of a file to which an XML report will be written if this option is set.
200
--report-xml-tt: Report test results in XML-format to the Test Tool (TT) reporting framework.
201
--report-xml-tt-type: Type of TT XML transport to use (e.g. scp)
202
--report-xml-tt-dest: Destination of TT XML report (e.g. user\@host:/path/to/location (for type scp))
203
--testname : Name of test, used for reporting purposes.
206
--freeze_time: Freeze time for each query so that CURRENT_TIMESTAMP gives the same result for all transformers/validators
207
--strict_fields: Disable all AI applied to columns defined in \$fields in the gendata file. Allows for very specific column definitions
208
--short_column_names: use short column names in gendata (c<number>)
209
--help : This help message
210
--debug : Provide debug output
216
sub backwardCompatability {
218
if (defined $options->{dsn}) {
219
croak ("Do not combine --dsn and --dsnX")
220
if defined $options->{dsn1} or
221
defined $options->{dsn2} or
222
defined $options->{dsn3};
226
foreach my $i (1..3) {
227
if (defined $options->{'dsn'.$i}) {
228
push @dsns, $options->{'dsn'.$i};
229
delete $options->{'dsn'.$i};
232
$options->{dsn} = \@dsns;
235
if (grep (/,/,@{$options->{reporters}})) {
236
my $newreporters = [];
237
map {push(@$newreporters,split(/,/,$_))} @{$options->{reporters}};
238
$options->{reporters}=$newreporters ;
241
if (grep (/,/,@{$options->{transformers}})) {
242
my $newtransformers = [];
243
map {push(@$newtransformers,split(/,/,$_))} @{$options->{transformers}};
244
$options->{transformers}=$newtransformers ;
247
if (grep (/,/,@{$options->{validators}})) {
248
my $newvalidators = [];
249
map {push(@$newvalidators,split(/,/,$_))} @{$options->{validators}};
250
$options->{validators}=$newvalidators ;
253
if (not defined $options->{generator}) {
254
$options->{generator} = 'FromGrammar';
257
if (defined $options->{sqltrace}) {
258
my $sqltrace = $options->{sqltrace};
259
# --sqltrace may have a string value (optional).
260
# To retain backwards compatibility we set value 1 when no value is given.
261
# Allowed values for --sqltrace:
262
my %sqltrace_legal_values = (
263
'MarkErrors' => 1 # Prefixes invalid SQL statements for easier post-processing
265
if (length($sqltrace) > 0) {
266
# A value is given, check if it is legal.
267
if (not exists $sqltrace_legal_values{$sqltrace}) {
268
say("Invalid value for --sqltrace option: '".$sqltrace."'");
269
say("Valid values are: ".join(', ', keys(%sqltrace_legal_values)));
270
say("No value means that default/plain sqltrace will be used.\n");
274
# If no value is given, GetOpt will assign the value '' (empty string).
275
# We interpret this as plain tracing (no marking of errors, prefixing etc.).
276
# Better to use 1 instead of empty string for comparisons later.
277
$options->{sqltrace} = 1;