~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/gentest.pl

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights
 
4
# reserved.
 
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
 
 
20
use lib 'lib';
 
21
use lib "$ENV{RQG_HOME}/lib";
 
22
use strict;
 
23
use Carp;
 
24
use Getopt::Long;
 
25
 
 
26
use GenTest;
 
27
use GenTest::Properties;
 
28
use GenTest::Constants;
 
29
use GenTest::App::GenTest;
 
30
 
 
31
my $logger;
 
32
eval
 
33
{
 
34
    require Log::Log4perl;
 
35
    Log::Log4perl->import();
 
36
    $logger = Log::Log4perl->get_logger('randgen.gentest');
 
37
};
 
38
 
 
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';
 
43
 
 
44
my @ARGV_saved = @ARGV;
 
45
 
 
46
my $options = {};
 
47
my $opt_result = GetOptions($options,
 
48
                            'config=s',
 
49
                            'dsn=s@',
 
50
                            'dsn1=s',
 
51
                            'dsn2=s',
 
52
                            'dsn3=s',
 
53
                            'engine=s',
 
54
                            'generator=s',
 
55
                            'gendata:s',
 
56
                            'grammar=s',
 
57
                            'skip-recursive-rules',
 
58
                            'redefine=s',
 
59
                            'testname=s',
 
60
                            'threads=i',
 
61
                            'queries=s',
 
62
                            'duration=s',
 
63
                            'help',
 
64
                            'debug',
 
65
                            'rpl_mode=s',
 
66
                            'validators:s@',
 
67
                            'reporters:s@',
 
68
                            'transformers:s@',
 
69
                            'report-xml-tt',
 
70
                            'report-xml-tt-type=s',
 
71
                            'report-xml-tt-dest=s',
 
72
                            'seed=s',
 
73
                            'mask=i',
 
74
                            'mask-level=i',
 
75
                            'rows=s',
 
76
                            'varchar-length=i',
 
77
                            'xml-output=s',
 
78
                            'sqltrace:s',
 
79
                            'no-err-filter',
 
80
                            'views:s',
 
81
                            'start-dirty',
 
82
                            'filter=s',
 
83
                            'valgrind',
 
84
                            'valgrind-xml',
 
85
                            'notnull',
 
86
                            'short_column_names',
 
87
                            'strict_fields',
 
88
                            'freeze_time',
 
89
                            'debug',
 
90
                            'logfile=s',
 
91
                            'logconf=s',
 
92
                            'report-tt-logdir=s',
 
93
                            'querytimeout=i');
 
94
backwardCompatability($options);
 
95
my $config = GenTest::Properties->new(
 
96
    options => $options,
 
97
    defaults => {dsn=>[$DEFAULT_DSN],
 
98
                 seed => 1,
 
99
                 queries => $DEFAULT_QUERIES,
 
100
                 duration => $DEFAULT_DURATION,
 
101
                 threads => $DEFAULT_THREADS},
 
102
    legal => ['dsn',
 
103
              'engine',
 
104
              'gendata',
 
105
              'generator',
 
106
              'grammar',
 
107
              'skip-recursive-rules',
 
108
              'redefine',
 
109
              'testname',
 
110
              'threads',
 
111
              'queries',
 
112
              'duration',
 
113
              'help',
 
114
              'debug',
 
115
              'rpl_mode',
 
116
              'validators',
 
117
              'reporters',
 
118
              'transformers',
 
119
              'report-xml-tt',
 
120
              'report-xml-tt-type',
 
121
              'report-xml-tt-dest',
 
122
              'seed',
 
123
              'mask',
 
124
              'mask-level',
 
125
              'rows',
 
126
              'varchar-length',
 
127
              'xml-output',
 
128
              'views',
 
129
              'sqltrace',
 
130
              'no-err-filter',
 
131
              'start-dirty',
 
132
              'filter',
 
133
              'valgrind',
 
134
              'valgrind-xml',
 
135
              'sqltrace',
 
136
              'notnull',
 
137
              'short_column_names',
 
138
              'freeze_time',
 
139
              'strict_fields',
 
140
              'logfile',
 
141
              'logconf',
 
142
              'report-tt-logdir',
 
143
              'querytimeout'],
 
144
    help => \&help);
 
145
 
 
146
help() if !$opt_result || $config->help;
 
147
 
 
148
if (defined $config->logfile && defined $logger) {
 
149
    setLoggingToFile($config->logfile);
 
150
} else {
 
151
    if (defined $config->logconf && defined $logger) {
 
152
        setLogConf($config->logconf);
 
153
    }
 
154
}
 
155
 
 
156
say("Starting: $0 ".join(" ", @ARGV_saved));
 
157
 
 
158
$ENV{RQG_DEBUG} = 1 if defined $config->debug;
 
159
my $gentest = GenTest::App::GenTest->new(config => $config);
 
160
 
 
161
my $status = $gentest->run();
 
162
 
 
163
safe_exit($status);
 
164
 
 
165
sub help {
 
166
 
 
167
    print <<EOF
 
168
$0 - Testing via random query generation. Options:
 
169
 
 
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. 
 
194
        --filter    : ......
 
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.
 
204
        --valgrind  : ......
 
205
        --filter    : ......
 
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
 
211
EOF
 
212
        ;
 
213
        safe_exit(1);
 
214
}
 
215
 
 
216
sub backwardCompatability {
 
217
    my ($options) = @_;
 
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};
 
223
        
 
224
    } else {
 
225
        my @dsns;
 
226
        foreach my $i (1..3) {
 
227
            if (defined $options->{'dsn'.$i}) {
 
228
                push @dsns, $options->{'dsn'.$i};
 
229
                delete $options->{'dsn'.$i};
 
230
            }
 
231
        }
 
232
        $options->{dsn} = \@dsns;
 
233
    }
 
234
        
 
235
    if (grep (/,/,@{$options->{reporters}})) {
 
236
        my $newreporters = [];
 
237
        map {push(@$newreporters,split(/,/,$_))} @{$options->{reporters}};
 
238
        $options->{reporters}=$newreporters ;
 
239
    }
 
240
 
 
241
    if (grep (/,/,@{$options->{transformers}})) {
 
242
        my $newtransformers = [];
 
243
        map {push(@$newtransformers,split(/,/,$_))} @{$options->{transformers}};
 
244
        $options->{transformers}=$newtransformers ;
 
245
    }
 
246
 
 
247
    if (grep (/,/,@{$options->{validators}})) {
 
248
        my $newvalidators = [];
 
249
        map {push(@$newvalidators,split(/,/,$_))} @{$options->{validators}};
 
250
        $options->{validators}=$newvalidators ;
 
251
    }
 
252
 
 
253
    if (not defined $options->{generator}) {
 
254
        $options->{generator} = 'FromGrammar';
 
255
    }
 
256
    
 
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
 
264
        );
 
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");
 
271
                help();
 
272
            }
 
273
        } else {
 
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;
 
278
        }
 
279
    }
 
280
 
 
281
}
 
282