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

« back to all changes in this revision

Viewing changes to tests/randgen/runall-new.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) 2010,2011 Oracle and/or its affiliates. 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
 
 
20
#################### FOR THE MOMENT THIS SCRIPT IS FOR TESTING PURPOSES
 
21
 
 
22
use lib 'lib';
 
23
use lib "$ENV{RQG_HOME}/lib";
 
24
use Carp;
 
25
use strict;
 
26
use GenTest;
 
27
use GenTest::Constants;
 
28
use GenTest::Properties;
 
29
use GenTest::App::GenTest;
 
30
use DBServer::DBServer;
 
31
use DBServer::MySQL::MySQLd;
 
32
use DBServer::MySQL::ReplMySQLd;
 
33
 
 
34
$| = 1;
 
35
if (osWindows()) {
 
36
        $SIG{CHLD} = "IGNORE";
 
37
}
 
38
 
 
39
if (defined $ENV{RQG_HOME}) {
 
40
    if (osWindows()) {
 
41
        $ENV{RQG_HOME} = $ENV{RQG_HOME}.'\\';
 
42
    } else {
 
43
        $ENV{RQG_HOME} = $ENV{RQG_HOME}.'/';
 
44
    }
 
45
}
 
46
 
 
47
use Getopt::Long;
 
48
use GenTest::Constants;
 
49
use DBI;
 
50
use Cwd;
 
51
 
 
52
my $database = 'test';
 
53
my @dsns;
 
54
 
 
55
my ($gendata, @basedirs, @mysqld_options, @vardirs, $rpl_mode,
 
56
    $engine, $help, $debug, @validators, @reporters, @transformers, 
 
57
    $grammar_file,
 
58
    $redefine_file, $seed, $mask, $mask_level, $mem, $rows,
 
59
    $varchar_len, $xml_output, $valgrind, @valgrind_options, $views,
 
60
    $start_dirty, $filter, $build_thread, $sqltrace, $testname,
 
61
    $report_xml_tt, $report_xml_tt_type, $report_xml_tt_dest,
 
62
    $notnull, $querytimeout);
 
63
 
 
64
my $gendata=''; ## default simple gendata
 
65
 
 
66
my $threads = my $default_threads = 10;
 
67
my $queries = my $default_queries = 1000;
 
68
my $duration = my $default_duration = 3600;
 
69
 
 
70
my @ARGV_saved = @ARGV;
 
71
 
 
72
my $opt_result = GetOptions(
 
73
        'mysqld=s@' => \$mysqld_options[0],
 
74
        'mysqld1=s@' => \$mysqld_options[0],
 
75
        'mysqld2=s@' => \$mysqld_options[1],
 
76
    'basedir=s' => \$basedirs[0],
 
77
    'basedir1=s' => \$basedirs[0],
 
78
    'basedir2=s' => \$basedirs[1],
 
79
        #'basedir=s@' => \@basedirs,
 
80
        'vardir=s' => \$vardirs[0],
 
81
        'vardir1=s' => \$vardirs[0],
 
82
        'vardir2=s' => \$vardirs[1],
 
83
        #'vardir=s@' => \@vardirs,
 
84
        'rpl_mode=s' => \$rpl_mode,
 
85
        'engine=s' => \$engine,
 
86
        'grammar=s' => \$grammar_file,
 
87
        'redefine=s' => \$redefine_file,
 
88
        'threads=i' => \$threads,
 
89
        'queries=s' => \$queries,
 
90
        'duration=i' => \$duration,
 
91
        'help' => \$help,
 
92
        'debug' => \$debug,
 
93
        'validators=s@' => \@validators,
 
94
        'reporters=s@' => \@reporters,
 
95
        'transformers=s@' => \@transformers,
 
96
        'gendata:s' => \$gendata,
 
97
        'notnull' => \$notnull,
 
98
        'seed=s' => \$seed,
 
99
        'mask=i' => \$mask,
 
100
    'mask-level=i' => \$mask_level,
 
101
        'mem' => \$mem,
 
102
        'rows=i' => \$rows,
 
103
        'varchar-length=i' => \$varchar_len,
 
104
        'xml-output=s'  => \$xml_output,
 
105
        'report-xml-tt' => \$report_xml_tt,
 
106
        'report-xml-tt-type=s' => \$report_xml_tt_type,
 
107
        'report-xml-tt-dest=s' => \$report_xml_tt_dest,
 
108
        'testname=s'            => \$testname,
 
109
        'valgrind!'     => \$valgrind,
 
110
        'valgrind_options=s@'   => \@valgrind_options,
 
111
        'views'         => \$views,
 
112
        'start-dirty'   => \$start_dirty,
 
113
        'filter=s'      => \$filter,
 
114
    'mtr-build-thread=i' => \$build_thread,
 
115
    'sqltrace' => \$sqltrace,
 
116
    'querytimeout=i' => \$querytimeout
 
117
    );
 
118
 
 
119
if (!$opt_result || $help || $basedirs[0] eq '' || not defined $grammar_file) {
 
120
        help();
 
121
        exit($help ? 0 : 1);
 
122
}
 
123
 
 
124
say("Copyright (c) 2010,2011 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.");
 
125
say("Please see http://forge.mysql.com/wiki/Category:RandomQueryGenerator for more information on this test framework.");
 
126
say("Starting \n# $0 \\ \n# ".join(" \\ \n# ", @ARGV_saved));
 
127
 
 
128
#
 
129
# Calculate master and slave ports based on MTR_BUILD_THREAD (MTR
 
130
# Version 1 behaviour)
 
131
#
 
132
 
 
133
if (not defined $build_thread) {
 
134
    if (defined $ENV{MTR_BUILD_THREAD}) {
 
135
        $build_thread = $ENV{MTR_BUILD_THREAD}
 
136
    } else {
 
137
        $build_thread = DEFAULT_MTR_BUILD_THREAD;
 
138
    }
 
139
}
 
140
 
 
141
if ( $build_thread eq 'auto' ) {
 
142
    say ("Please set the environment variable MTR_BUILD_THREAD to a value <> 'auto' (recommended) or unset it (will take the value ".DEFAULT_MTR_BUILD_THREAD.") ");
 
143
    exit (STATUS_ENVIRONMENT_FAILURE);
 
144
}
 
145
 
 
146
my @ports = (10000 + 10 * $build_thread, 10000 + 10 * $build_thread + 2);
 
147
 
 
148
say("master_port : $ports[0] slave_port : $ports[1] ports : @ports MTR_BUILD_THREAD : $build_thread ");
 
149
 
 
150
#
 
151
# If the user has provided two vardirs and one basedir, start second
 
152
# server using the same basedir
 
153
#
 
154
 
 
155
if (
 
156
        ($vardirs[1] ne '') && 
 
157
        ($basedirs[1] eq '')
 
158
    ) {
 
159
        $basedirs[1] = $basedirs[0];    
 
160
}
 
161
 
 
162
 
 
163
if (
 
164
        ($mysqld_options[1] ne '') && 
 
165
        ($basedirs[1] eq '')
 
166
    ) {
 
167
        $basedirs[1] = $basedirs[0];    
 
168
}
 
169
 
 
170
#
 
171
# If the user has provided identical basedirs and vardirs, warn of a
 
172
# potential overlap.
 
173
#
 
174
 
 
175
if (
 
176
        ($basedirs[0] eq $basedirs[1]) &&
 
177
        ($vardirs[0] eq $vardirs[1]) &&
 
178
        ($rpl_mode eq '')
 
179
    ) {
 
180
        croak("Please specify either different --basedir[12] or different --vardir[12] in order to start two MySQL servers");
 
181
}
 
182
 
 
183
my $client_basedir;
 
184
 
 
185
foreach my $path ("$basedirs[0]/client/RelWithDebInfo", "$basedirs[0]/client/Debug", "$basedirs[0]/client", "$basedirs[0]/bin") {
 
186
        if (-e $path) {
 
187
                $client_basedir = $path;
 
188
                last;
 
189
        }
 
190
}
 
191
 
 
192
#
 
193
# Start servers. Use rpl_alter if replication is needed.
 
194
#
 
195
 
 
196
my @server;
 
197
my $rplsrv;
 
198
 
 
199
if ($rpl_mode ne '') {
 
200
    my @options;
 
201
    push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
 
202
    
 
203
    push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
 
204
    
 
205
    if (defined $mysqld_options[0]) {
 
206
        push @options, @{$mysqld_options[0]};
 
207
    }
 
208
    
 
209
    $rplsrv = DBServer::MySQL::ReplMySQLd->new(basedir => $basedirs[0],
 
210
                                               master_vardir => $vardirs[0],
 
211
                                               master_port => $ports[0],
 
212
                                               slave_vardir => $vardirs[1],
 
213
                                               slave_port => $ports[1],
 
214
                                               mode => $rpl_mode,
 
215
                                               server_options => \@options,
 
216
                                               valgrind => $valgrind,
 
217
                                               valgrind_options => \@valgrind_options,
 
218
                                               start_dirty => $start_dirty);
 
219
    
 
220
    my $status = $rplsrv->startServer();
 
221
    
 
222
    if ($status > DBSTATUS_OK) {
 
223
        stopServers();
 
224
        if (osWindows()) {
 
225
            say(system("dir ".unix2winPath($rplsrv->master->datadir)));
 
226
            say(system("dir ".unix2winPath($rplsrv->slave->datadir)));
 
227
        } else {
 
228
            say(system("ls -l ".$rplsrv->master->datadir));
 
229
            say(system("ls -l ".$rplsrv->slave->datadir));
 
230
        }
 
231
        croak("Could not start replicating server pair");
 
232
    }
 
233
    
 
234
    $dsns[0] = $rplsrv->master->dsn($database);
 
235
    $dsns[1] = undef; ## passed to gentest. No dsn for slave!
 
236
    $server[0] = $rplsrv->master;
 
237
    $server[1] = $rplsrv->slave;
 
238
    
 
239
} else {
 
240
    if ($#basedirs != $#vardirs) {
 
241
        croak ("The number of basedirs and vardirs must match $#basedirs != $#vardirs")
 
242
    }
 
243
    foreach my $server_id (0..1) {
 
244
        next if $basedirs[$server_id] eq '';
 
245
        
 
246
        my @options;
 
247
        push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
 
248
        
 
249
        push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
 
250
        
 
251
        if (defined $mysqld_options[$server_id]) {
 
252
            push @options, @{$mysqld_options[$server_id]};
 
253
        }
 
254
        
 
255
        $server[$server_id] = DBServer::MySQL::MySQLd->new(basedir => $basedirs[$server_id],
 
256
                                                           vardir => $vardirs[$server_id],
 
257
                                                           port => $ports[$server_id],
 
258
                                                           start_dirty => $start_dirty,
 
259
                                                           valgrind => $valgrind,
 
260
                                                           valgrind_options => \@valgrind_options,
 
261
                                                           server_options => \@options);
 
262
        
 
263
        my $status = $server[$server_id]->startServer;
 
264
        
 
265
        if ($status > DBSTATUS_OK) {
 
266
            stopServers();
 
267
            if (osWindows()) {
 
268
                say(system("dir ".unix2winPath($server[$server_id]->datadir)));
 
269
            } else {
 
270
                say(system("ls -l ".$server[$server_id]->datadir));
 
271
            }
 
272
            croak("Could not start all servers");
 
273
        }
 
274
        
 
275
        if (
 
276
            ($server_id == 0) ||
 
277
            ($rpl_mode eq '') 
 
278
            ) {
 
279
            $dsns[$server_id] = $server[$server_id]->dsn($database);
 
280
        }
 
281
    
 
282
        if ((defined $dsns[$server_id]) && (defined $engine)) {
 
283
            my $dbh = DBI->connect($dsns[$server_id], undef, undef, { RaiseError => 1 } );
 
284
            $dbh->do("SET GLOBAL storage_engine = '$engine'");
 
285
        }
 
286
    }
 
287
}
 
288
 
 
289
#
 
290
# Run actual queries
 
291
#
 
292
 
 
293
my $gentestProps = GenTest::Properties->new(
 
294
    legal => ['grammar',
 
295
              'dsn',
 
296
              'engine',
 
297
              'gendata',
 
298
              'generator',
 
299
              'redefine',
 
300
              'threads',
 
301
              'queries',
 
302
              'duration',
 
303
              'help',
 
304
              'debug',
 
305
              'rpl_mode',
 
306
              'validators',
 
307
              'reporters',
 
308
              'reporters',
 
309
              'transformers',
 
310
              'seed',
 
311
              'mask',
 
312
              'mask-level',
 
313
              'rows',
 
314
              'varchar-length',
 
315
              'xml-output',
 
316
              'views',
 
317
              'start-dirty',
 
318
              'filter',
 
319
              'notnull',
 
320
              'valgrind',
 
321
              'valgrind-xml',
 
322
              'testname',
 
323
              'sqltrace',
 
324
              'querytimeout',
 
325
              'report-xml-tt',
 
326
              'report-xml-tt-type',
 
327
              'report-xml-tt-dest']
 
328
    );
 
329
 
 
330
my @gentest_options;
 
331
 
 
332
## For backward compatability
 
333
if ($#validators == 0 and $validators[0] =~ m/,/) {
 
334
    @validators = split(/,/,$validators[0]);
 
335
}
 
336
 
 
337
## For backward compatability
 
338
if ($#reporters == 0 and $reporters[0] =~ m/,/) {
 
339
    @reporters = split(/,/,$reporters[0]);
 
340
}
 
341
 
 
342
## For backward compatability
 
343
if ($#transformers == 0 and $transformers[0] =~ m/,/) {
 
344
    @transformers = split(/,/,$transformers[0]);
 
345
}
 
346
 
 
347
$gentestProps->property('generator','FromGrammar') if not defined $gentestProps->property('generator');
 
348
 
 
349
$gentestProps->property('start-dirty',1) if defined $start_dirty;
 
350
$gentestProps->gendata($gendata);
 
351
$gentestProps->engine($engine) if defined $engine;
 
352
$gentestProps->rpl_mode($rpl_mode) if defined $rpl_mode;
 
353
$gentestProps->validators(\@validators) if defined @validators;
 
354
$gentestProps->reporters(\@reporters) if defined @reporters;
 
355
$gentestProps->transformers(\@transformers) if defined @transformers;
 
356
$gentestProps->threads($threads) if defined $threads;
 
357
$gentestProps->queries($queries) if defined $queries;
 
358
$gentestProps->duration($duration) if defined $duration;
 
359
$gentestProps->dsn(\@dsns) if defined @dsns;
 
360
$gentestProps->grammar($grammar_file);
 
361
$gentestProps->redefine($redefine_file) if defined $redefine_file;
 
362
$gentestProps->seed($seed) if defined $seed;
 
363
$gentestProps->mask($mask) if defined $mask;
 
364
$gentestProps->property('mask-level',$mask_level) if defined $mask_level;
 
365
$gentestProps->rows($rows) if defined $rows;
 
366
$gentestProps->views(1) if defined $views;
 
367
$gentestProps->property('varchar-length',$varchar_len) if defined $varchar_len;
 
368
$gentestProps->property('xml-output',$xml_output) if defined $xml_output;
 
369
$gentestProps->debug(1) if defined $debug;
 
370
$gentestProps->filter($filter) if defined $filter;
 
371
$gentestProps->notnull($notnull) if defined $notnull;
 
372
$gentestProps->valgrind(1) if $valgrind;
 
373
$gentestProps->sqltrace(1) if $sqltrace;
 
374
$gentestProps->querytimeout($querytimeout) if defined $querytimeout;
 
375
$gentestProps->testname($testname) if $testname;
 
376
$gentestProps->property('report-xml-tt', 1) if defined $report_xml_tt;
 
377
$gentestProps->property('report-xml-tt-type', $report_xml_tt_type) if defined $report_xml_tt_type;
 
378
$gentestProps->property('report-xml-tt-dest', $report_xml_tt_dest) if defined $report_xml_tt_dest;
 
379
 
 
380
# Push the number of "worker" threads into the environment.
 
381
# lib/GenTest/Generator/FromGrammar.pm will generate a corresponding grammar element.
 
382
$ENV{RQG_THREADS}= $threads;
 
383
 
 
384
my $gentest = GenTest::App::GenTest->new(config => $gentestProps);
 
385
my $gentest_result = $gentest->run();
 
386
say("GenTest exited with exit status ".status2text($gentest_result)." ($gentest_result)");
 
387
exit_test($gentest_result) if $gentest_result > 0;
 
388
 
 
389
#
 
390
# Compare master and slave, or two masters
 
391
#
 
392
 
 
393
if ($rpl_mode || (defined $basedirs[1])) {
 
394
    if ($rpl_mode ne '') {
 
395
        $rplsrv->waitForSlaveSync;
 
396
    }
 
397
 
 
398
    my @dump_files;
 
399
    
 
400
        foreach my $i (0..$#server) {
 
401
                $dump_files[$i] = tmpdir()."server_".$$."_".$i.".dump";
 
402
        
 
403
                my $dump_result = $server[$i]->dumpdb($database,$dump_files[$i]);
 
404
                exit_test($dump_result >> 8) if $dump_result > 0;
 
405
        }
 
406
    
 
407
        say("Comparing SQL dumps...");
 
408
        my $diff_result = system("diff -u $dump_files[0] $dump_files[1]");
 
409
        $diff_result = $diff_result >> 8;
 
410
    
 
411
        if ($diff_result == 0) {
 
412
                say("No differences were found between servers.");
 
413
        }
 
414
    
 
415
        foreach my $dump_file (@dump_files) {
 
416
                unlink($dump_file);
 
417
        }
 
418
    
 
419
        exit_test($diff_result);
 
420
}
 
421
 
 
422
 
 
423
stopServers();
 
424
 
 
425
sub stopServers {
 
426
    if ($rpl_mode ne '') {
 
427
        $rplsrv->stopServer();
 
428
    } else {
 
429
        foreach my $srv (@server) {
 
430
            if ($srv) {
 
431
                $srv->stopServer;
 
432
            }
 
433
        }
 
434
    }
 
435
}
 
436
 
 
437
 
 
438
sub help {
 
439
    
 
440
        print <<EOF
 
441
Copyright (c) 2010,2011 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.
 
442
 
 
443
$0 - Run a complete random query generation test, including server start with replication and master/slave verification
 
444
    
 
445
    Options related to one standalone MySQL server:
 
446
 
 
447
    --basedir   : Specifies the base directory of the stand-alone MySQL installation;
 
448
    --mysqld    : Options passed to the MySQL server
 
449
    --vardir    : Optional. (default \$basedir/mysql-test/var);
 
450
 
 
451
    Options related to two MySQL servers
 
452
 
 
453
    --basedir1  : Specifies the base directory of the first MySQL installation;
 
454
    --basedir2  : Specifies the base directory of the second MySQL installation;
 
455
    --mysqld1   : Options passed to the first MySQL server
 
456
    --mysqld2   : Options passed to the second MySQL server
 
457
    --vardir1   : Optional. (default \$basedir1/mysql-test/var);
 
458
    --vardir2   : Optional. (default \$basedir2/mysql-test/var);
 
459
 
 
460
    General options
 
461
 
 
462
    --grammar   : Grammar file to use when generating queries (REQUIRED);
 
463
    --redefine  : Grammar file to redefine and/or add rules to the given grammar
 
464
    --rpl_mode  : Replication type to use (statement|row|mixed) (default: no replication);
 
465
    --vardir1   : Optional.
 
466
    --vardir2   : Optional. 
 
467
    --engine    : Table engine to use when creating tables with gendata (default no ENGINE in CREATE TABLE);
 
468
    --threads   : Number of threads to spawn (default $default_threads);
 
469
    --queries   : Number of queries to execute per thread (default $default_queries);
 
470
    --duration  : Duration of the test in seconds (default $default_duration seconds);
 
471
    --validator : The validators to use
 
472
    --reporter  : The reporters to use
 
473
    --transformer: The transformers to use (turns on --validator=transformer). Accepts comma separated list
 
474
    --querytimeout: The timeout to use for the QueryTimeout reporter 
 
475
    --gendata   : Generate data option. Passed to gentest.pl
 
476
    --seed      : PRNG seed. Passed to gentest.pl
 
477
    --mask      : Grammar mask. Passed to gentest.pl
 
478
    --mask-level: Grammar mask level. Passed to gentest.pl
 
479
    --notnull   : Generate all fields with NOT NULL
 
480
    --rows      : No of rows. Passed to gentest.pl
 
481
    --sqltrace  : Print all generated SQL statements
 
482
    --varchar-length: length of strings. passed to gentest.pl
 
483
    --xml-outputs: Passed to gentest.pl
 
484
    --views     : Generate views. Passed to gentest.pl
 
485
    --valgrind  : Passed to gentest.pl
 
486
    --filter    : Passed to gentest.pl
 
487
    --mem       : Passed to mtr
 
488
    --mtr-build-thread:  Value used for MTR_BUILD_THREAD when servers are started and accessed
 
489
    --debug     : Debug mode
 
490
    --help      : This help message
 
491
 
 
492
    If you specify --basedir1 and --basedir2 or --vardir1 and --vardir2, two servers will be started and the results from the queries
 
493
    will be compared between them.
 
494
EOF
 
495
        ;
 
496
        print "$0 arguments were: ".join(' ', @ARGV_saved)."\n";
 
497
        exit_test(STATUS_UNKNOWN_ERROR);
 
498
}
 
499
 
 
500
sub exit_test {
 
501
        my $status = shift;
 
502
    stopServers();
 
503
        say("[$$] $0 will exit with exit status ".status2text($status). " ($status)");
 
504
        safe_exit($status);
 
505
}