~drizzle-trunk/drizzle/development

0.67.1 by Philip Stoev
initial import from internal tree
1
#!/usr/bin/perl
0.67.305 by Bernt M. Johnsen
Copyright headres and license added
2
3
# Copyright (C) 2008-2010 Sun Microsystems, Inc. All rights reserved.
4
# Use is subject to license terms.
5
#
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.
9
#
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.
14
#
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
18
# USA
19
0.67.1 by Philip Stoev
initial import from internal tree
20
use lib 'lib';
21
use lib "$ENV{RQG_HOME}/lib";
22
use strict;
0.67.160 by Bernt M. Johnsen
Changes + merge
23
use Carp;
0.67.350 by Bernt M. Johnsen
gentest.pl made a wrapper of new module GenTest::App::GenTest.pm
24
use Getopt::Long;
0.67.160 by Bernt M. Johnsen
Changes + merge
25
0.67.1 by Philip Stoev
initial import from internal tree
26
use GenTest;
0.67.160 by Bernt M. Johnsen
Changes + merge
27
use GenTest::Properties;
0.67.55 by Bernt M. Johnsen
Fixed status check in gentest.pl
28
use GenTest::Constants;
0.67.350 by Bernt M. Johnsen
gentest.pl made a wrapper of new module GenTest::App::GenTest.pm
29
use GenTest::App::GenTest;
0.67.1 by Philip Stoev
initial import from internal tree
30
0.67.160 by Bernt M. Johnsen
Changes + merge
31
my $DEFAULT_THREADS = 10;
32
my $DEFAULT_QUERIES = 1000;
33
my $DEFAULT_DURATION = 3600;
2465.1.4 by Brian Aker
Move from using 127.0.0.1, to localhost.
34
my $DEFAULT_DSN = 'dbi:mysql:host=localhost:port=9306:user=root:database=test';
0.67.1 by Philip Stoev
initial import from internal tree
35
36
my @ARGV_saved = @ARGV;
37
0.67.160 by Bernt M. Johnsen
Changes + merge
38
my $options = {};
39
my $opt_result = GetOptions($options,
40
                            'config=s',
41
                            'dsn=s@',
42
                            'dsn1=s',
43
                            'dsn2=s',
44
                            'dsn3=s',
45
                            'engine=s',
0.67.736 by eve
First fixes towards making RQG indepentent of a particular Generator, in particular random query generation from grammars
46
                            'generator=s',
0.67.160 by Bernt M. Johnsen
Changes + merge
47
                            'gendata:s',
48
                            'grammar=s',
49
                            'redefine=s',
0.101.35 by John H. Embretsen
XML: Option --testname requires a value. Also add its usage docs to runall, gentest.
50
                            'testname=s',
0.67.160 by Bernt M. Johnsen
Changes + merge
51
                            'threads=i',
52
                            'queries=s',
53
                            'duration=s',
54
                            'help',
55
                            'debug',
56
                            'rpl_mode=s',
0.67.185 by Bernt M. Johnsen
Fix for Bug#49167
57
                            'validators:s@',
58
                            'reporters:s@',
0.67.768 by Bernt M. Johnsen
--transformers option added to use explicit list of transformers
59
                            'transformers:s@',
0.101.29 by John H. Embretsen
XML: Add new options to support XML report delivery.
60
                            'report-xml-tt',
61
                            'report-xml-tt-type=s',
62
                            'report-xml-tt-dest=s',
0.67.160 by Bernt M. Johnsen
Changes + merge
63
                            'seed=s',
64
                            'mask=i',
65
                            'mask-level=i',
66
                            'rows=i',
67
                            'varchar-length=i',
0.101.18 by John H. Embretsen
Fix issues with XML reporting after latest merge (gentest.pl).
68
                            'xml-output=s',
0.109.2 by John H. Embretsen
Support --sqltrace option with classic runall.pl and gentest.pl. Add to usage texts.
69
                            'sqltrace',
0.67.629 by Patrick Crews
Added no-err-filter option to turn off randgen suppression of error messages. There are cases where we want to see all error output from the randgen. Code only added to Drizzle Executor, but can be added to other Executors if desired
70
                            'no-err-filter',
0.67.160 by Bernt M. Johnsen
Changes + merge
71
                            'views',
72
                            'start-dirty',
73
                            'filter=s',
0.67.497 by eve
added --notnull option to all scripts
74
                            'valgrind',
0.67.575 by eve
new --valgrind-xml option that reports Valgrind failures at the end of the test
75
                            'valgrind-xml',
0.67.521 by eve
provide textual exit codes for various scripts and not jus numbers
76
                            'notnull',
0.67.771 by Bernt M. Johnsen
--querytimeout added to parameterize QueryTimeout.pm reporter
77
                            'debug',
78
                            'querytimeout=i');
0.67.160 by Bernt M. Johnsen
Changes + merge
79
backwardCompatability($options);
80
my $config = GenTest::Properties->new(
81
    options => $options,
82
    defaults => {dsn=>[$DEFAULT_DSN],
83
                 seed => 1,
84
                 queries => $DEFAULT_QUERIES,
85
                 duration => $DEFAULT_DURATION,
86
                 threads => $DEFAULT_THREADS},
87
    legal => ['dsn',
88
              'engine',
89
              'gendata',
0.67.736 by eve
First fixes towards making RQG indepentent of a particular Generator, in particular random query generation from grammars
90
              'generator',
91
              'grammar',
0.67.160 by Bernt M. Johnsen
Changes + merge
92
              'redefine',
0.101.26 by John H. Embretsen
Merge from lp:randgen, revno 366, 2010-03-26.
93
              'testname',
0.67.160 by Bernt M. Johnsen
Changes + merge
94
              'threads',
95
              'queries',
96
              'duration',
97
              'help',
98
              'debug',
99
              'rpl_mode',
0.67.185 by Bernt M. Johnsen
Fix for Bug#49167
100
              'validators',
101
              'reporters',
0.67.768 by Bernt M. Johnsen
--transformers option added to use explicit list of transformers
102
              'transformers',
0.101.29 by John H. Embretsen
XML: Add new options to support XML report delivery.
103
              'report-xml-tt',
104
              'report-xml-tt-type',
105
              'report-xml-tt-dest',
0.67.160 by Bernt M. Johnsen
Changes + merge
106
              'seed',
107
              'mask',
108
              'mask-level',
109
              'rows',
110
              'varchar-length',
111
              'xml-output',
112
              'views',
0.109.2 by John H. Embretsen
Support --sqltrace option with classic runall.pl and gentest.pl. Add to usage texts.
113
              'sqltrace',
0.67.629 by Patrick Crews
Added no-err-filter option to turn off randgen suppression of error messages. There are cases where we want to see all error output from the randgen. Code only added to Drizzle Executor, but can be added to other Executors if desired
114
              'no-err-filter',
0.67.160 by Bernt M. Johnsen
Changes + merge
115
              'start-dirty',
116
              'filter',
0.103.2 by Bernt M. Johnsen
Sqltrace option for re-runs
117
              'valgrind',
0.67.575 by eve
new --valgrind-xml option that reports Valgrind failures at the end of the test
118
              'valgrind-xml',
0.67.497 by eve
added --notnull option to all scripts
119
              'sqltrace',
0.67.771 by Bernt M. Johnsen
--querytimeout added to parameterize QueryTimeout.pm reporter
120
              'notnull',
121
              'querytimeout'],
0.67.160 by Bernt M. Johnsen
Changes + merge
122
    help => \&help);
0.67.1 by Philip Stoev
initial import from internal tree
123
0.67.160 by Bernt M. Johnsen
Changes + merge
124
help() if !$opt_result || $config->help;
0.67.1 by Philip Stoev
initial import from internal tree
125
0.67.736 by eve
First fixes towards making RQG indepentent of a particular Generator, in particular random query generation from grammars
126
say("Starting: $0 ".join(" ", @ARGV_saved));
0.67.1 by Philip Stoev
initial import from internal tree
127
0.67.521 by eve
provide textual exit codes for various scripts and not jus numbers
128
$ENV{RQG_DEBUG} = 1 if defined $config->debug;
0.67.350 by Bernt M. Johnsen
gentest.pl made a wrapper of new module GenTest::App::GenTest.pm
129
my $gentest = GenTest::App::GenTest->new(config => $config);
130
0.67.355 by Bernt M. Johnsen
return instead of exit from GenTest::App::GenTest
131
my $status = $gentest->run();
0.67.350 by Bernt M. Johnsen
gentest.pl made a wrapper of new module GenTest::App::GenTest.pm
132
0.67.355 by Bernt M. Johnsen
return instead of exit from GenTest::App::GenTest
133
safe_exit($status);
0.67.1 by Philip Stoev
initial import from internal tree
134
135
sub help {
136
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
137
    print <<EOF
138
$0 - Testing via random query generation. Options:
139
0.67.160 by Bernt M. Johnsen
Changes + merge
140
        --dsn      : DBI resources to connect to (default $DEFAULT_DSN).
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
141
                      Supported databases are MySQL, Drizzle, PostgreSQL, JavaDB
0.67.160 by Bernt M. Johnsen
Changes + merge
142
                      first --dsn must be to MySQL or Drizzle
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
143
        --gendata   : Execute gendata-old.pl in order to populate tables with simple data (default NO)
144
        --gendata=s : Execute gendata.pl in order to populate tables with data 
0.67.160 by Bernt M. Johnsen
Changes + merge
145
                      using the argument as specification file to gendata.pl
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
146
        --engine    : Table engine to use when creating tables with gendata (default: no ENGINE for CREATE TABLE)
0.67.160 by Bernt M. Johnsen
Changes + merge
147
        --threads   : Number of threads to spawn (default $DEFAULT_THREADS)
148
        --queries   : Numer of queries to execute per thread (default $DEFAULT_QUERIES);
149
        --duration  : Duration of the test in seconds (default $DEFAULT_DURATION seconds);
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
150
        --grammar   : Grammar file to use for generating the queries (REQUIRED);
0.67.52 by Bernt M. Johnsen
Added --redefine option to gentest.pl
151
        --redefine  : Grammar file to redefine and/or add rules to the given grammar
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
152
        --seed      : PRNG seed (default 1). If --seed=time, the current time will be used.
153
        --rpl_mode  : Replication mode
0.67.160 by Bernt M. Johnsen
Changes + merge
154
        --validator : Validator classes to be used. Defaults
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
155
                           ErrorMessageCorruption if one or two MySQL dsns
156
                           ResultsetComparator3 if 3 dsns
157
                           ResultsetComparartor if 2 dsns
0.67.160 by Bernt M. Johnsen
Changes + merge
158
        --reporter  : ErrorLog, Backtrace if one or two MySQL dsns
159
        --mask      : A seed to a random mask used to mask (reduce) the grammar.
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
160
        --mask-level: How many levels deep the mask is applied (default 1)
161
        --rows      : Number of rows to generate for each table in gendata.pl, unless specified in the ZZ file
162
        --varchar-length: maximum length of strings (deault 1) in gendata.pl
163
        --views     : Pass --views to gendata-old.pl or gendata.pl
164
        --filter    : ......
0.109.2 by John H. Embretsen
Support --sqltrace option with classic runall.pl and gentest.pl. Add to usage texts.
165
        --sqltrace  : Print all generated SQL statements.
0.67.629 by Patrick Crews
Added no-err-filter option to turn off randgen suppression of error messages. There are cases where we want to see all error output from the randgen. Code only added to Drizzle Executor, but can be added to other Executors if desired
166
        --no-err-filter:  Do not suppress error messages.  Output all error messages encountered.
0.67.49 by Bernt M. Johnsen
Refactored gendata.pl and gendata-old.pl to modules. The scripts are kept as wrappers
167
        --start-dirty: Do not generate data (use existing database(s))
0.101.18 by John H. Embretsen
Fix issues with XML reporting after latest merge (gentest.pl).
168
        --xml-output: Name of a file to which an XML report will be written if this option is set.
0.101.29 by John H. Embretsen
XML: Add new options to support XML report delivery.
169
        --report-xml-tt: Report test results in XML-format to the Test Tool (TT) reporting framework.
170
        --report-xml-tt-type: Type of TT XML transport to use (e.g. scp)
171
        --report-xml-tt-dest: Destination of TT XML report (e.g. user\@host:/path/to/location (for type scp))
0.101.35 by John H. Embretsen
XML: Option --testname requires a value. Also add its usage docs to runall, gentest.
172
        --testname  : Name of test, used for reporting purposes.
0.67.31 by Bernt M. Johnsen
Updated some help function (more to do here)
173
        --valgrind  : ......
174
        --filter    : ......
175
        --help      : This help message
176
        --debug     : Provide debug output
0.67.1 by Philip Stoev
initial import from internal tree
177
EOF
178
	;
179
	safe_exit(1);
180
}
0.67.160 by Bernt M. Johnsen
Changes + merge
181
182
sub backwardCompatability {
183
    my ($options) = @_;
184
    if (defined $options->{dsn}) {
185
        croak ("Do not combine --dsn and --dsnX") 
186
            if defined $options->{dsn1} or
187
            defined $options->{dsn2} or
188
            defined $options->{dsn3};
189
        
190
    } else {
191
        my @dsns;
192
        foreach my $i (1..3) {
193
            if (defined $options->{'dsn'.$i}) {
194
                push @dsns, $options->{'dsn'.$i};
195
                delete $options->{'dsn'.$i};
196
            }
197
        }
198
        $options->{dsn} = \@dsns;
199
    }
0.67.736 by eve
First fixes towards making RQG indepentent of a particular Generator, in particular random query generation from grammars
200
        
0.67.185 by Bernt M. Johnsen
Fix for Bug#49167
201
    if (grep (/,/,@{$options->{reporters}})) {
202
        my $newreporters = [];
203
        map {push(@$newreporters,split(/,/,$_))} @{$options->{reporters}};
204
        $options->{reporters}=$newreporters ;
0.67.160 by Bernt M. Johnsen
Changes + merge
205
    }
0.67.736 by eve
First fixes towards making RQG indepentent of a particular Generator, in particular random query generation from grammars
206
0.67.768 by Bernt M. Johnsen
--transformers option added to use explicit list of transformers
207
    if (grep (/,/,@{$options->{transformers}})) {
208
        my $newtransformers = [];
209
        map {push(@$newtransformers,split(/,/,$_))} @{$options->{transformers}};
210
        $options->{transformers}=$newtransformers ;
211
    }
212
0.67.185 by Bernt M. Johnsen
Fix for Bug#49167
213
    if (grep (/,/,@{$options->{validators}})) {
214
        my $newvalidators = [];
215
        map {push(@$newvalidators,split(/,/,$_))} @{$options->{validators}};
216
        $options->{validators}=$newvalidators ;
0.67.160 by Bernt M. Johnsen
Changes + merge
217
    }
0.67.736 by eve
First fixes towards making RQG indepentent of a particular Generator, in particular random query generation from grammars
218
219
    if (not defined $options->{generator}) {
220
        $options->{generator} = 'FromGrammar';
221
    }
0.67.160 by Bernt M. Johnsen
Changes + merge
222
}
223