3
# Copyright (c) 2010,2011 Oracle and/or its affiliates. All rights reserved.
4
# Use is subject to license terms.
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
20
#################### FOR THE MOMENT THIS SCRIPT IS FOR TESTING PURPOSES
23
use lib "$ENV{RQG_HOME}/lib";
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;
36
$SIG{CHLD} = "IGNORE";
39
if (defined $ENV{RQG_HOME}) {
41
$ENV{RQG_HOME} = $ENV{RQG_HOME}.'\\';
43
$ENV{RQG_HOME} = $ENV{RQG_HOME}.'/';
48
use GenTest::Constants;
52
my $database = 'test';
55
my ($gendata, @basedirs, @mysqld_options, @vardirs, $rpl_mode,
56
$engine, $help, $debug, @validators, @reporters, @transformers,
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);
64
my $gendata=''; ## default simple gendata
66
my $threads = my $default_threads = 10;
67
my $queries = my $default_queries = 1000;
68
my $duration = my $default_duration = 3600;
70
my @ARGV_saved = @ARGV;
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,
93
'validators=s@' => \@validators,
94
'reporters=s@' => \@reporters,
95
'transformers=s@' => \@transformers,
96
'gendata:s' => \$gendata,
97
'notnull' => \$notnull,
100
'mask-level=i' => \$mask_level,
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,
112
'start-dirty' => \$start_dirty,
113
'filter=s' => \$filter,
114
'mtr-build-thread=i' => \$build_thread,
115
'sqltrace' => \$sqltrace,
116
'querytimeout=i' => \$querytimeout
119
if (!$opt_result || $help || $basedirs[0] eq '' || not defined $grammar_file) {
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));
129
# Calculate master and slave ports based on MTR_BUILD_THREAD (MTR
130
# Version 1 behaviour)
133
if (not defined $build_thread) {
134
if (defined $ENV{MTR_BUILD_THREAD}) {
135
$build_thread = $ENV{MTR_BUILD_THREAD}
137
$build_thread = DEFAULT_MTR_BUILD_THREAD;
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);
146
my @ports = (10000 + 10 * $build_thread, 10000 + 10 * $build_thread + 2);
148
say("master_port : $ports[0] slave_port : $ports[1] ports : @ports MTR_BUILD_THREAD : $build_thread ");
151
# If the user has provided two vardirs and one basedir, start second
152
# server using the same basedir
156
($vardirs[1] ne '') &&
159
$basedirs[1] = $basedirs[0];
164
($mysqld_options[1] ne '') &&
167
$basedirs[1] = $basedirs[0];
171
# If the user has provided identical basedirs and vardirs, warn of a
176
($basedirs[0] eq $basedirs[1]) &&
177
($vardirs[0] eq $vardirs[1]) &&
180
croak("Please specify either different --basedir[12] or different --vardir[12] in order to start two MySQL servers");
185
foreach my $path ("$basedirs[0]/client/RelWithDebInfo", "$basedirs[0]/client/Debug", "$basedirs[0]/client", "$basedirs[0]/bin") {
187
$client_basedir = $path;
193
# Start servers. Use rpl_alter if replication is needed.
199
if ($rpl_mode ne '') {
201
push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
203
push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
205
if (defined $mysqld_options[0]) {
206
push @options, @{$mysqld_options[0]};
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],
215
server_options => \@options,
216
valgrind => $valgrind,
217
valgrind_options => \@valgrind_options,
218
start_dirty => $start_dirty);
220
my $status = $rplsrv->startServer();
222
if ($status > DBSTATUS_OK) {
225
say(system("dir ".unix2winPath($rplsrv->master->datadir)));
226
say(system("dir ".unix2winPath($rplsrv->slave->datadir)));
228
say(system("ls -l ".$rplsrv->master->datadir));
229
say(system("ls -l ".$rplsrv->slave->datadir));
231
croak("Could not start replicating server pair");
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;
240
if ($#basedirs != $#vardirs) {
241
croak ("The number of basedirs and vardirs must match $#basedirs != $#vardirs")
243
foreach my $server_id (0..1) {
244
next if $basedirs[$server_id] eq '';
247
push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
249
push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
251
if (defined $mysqld_options[$server_id]) {
252
push @options, @{$mysqld_options[$server_id]};
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);
263
my $status = $server[$server_id]->startServer;
265
if ($status > DBSTATUS_OK) {
268
say(system("dir ".unix2winPath($server[$server_id]->datadir)));
270
say(system("ls -l ".$server[$server_id]->datadir));
272
croak("Could not start all servers");
279
$dsns[$server_id] = $server[$server_id]->dsn($database);
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'");
293
my $gentestProps = GenTest::Properties->new(
326
'report-xml-tt-type',
327
'report-xml-tt-dest']
332
## For backward compatability
333
if ($#validators == 0 and $validators[0] =~ m/,/) {
334
@validators = split(/,/,$validators[0]);
337
## For backward compatability
338
if ($#reporters == 0 and $reporters[0] =~ m/,/) {
339
@reporters = split(/,/,$reporters[0]);
342
## For backward compatability
343
if ($#transformers == 0 and $transformers[0] =~ m/,/) {
344
@transformers = split(/,/,$transformers[0]);
347
$gentestProps->property('generator','FromGrammar') if not defined $gentestProps->property('generator');
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;
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;
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;
390
# Compare master and slave, or two masters
393
if ($rpl_mode || (defined $basedirs[1])) {
394
if ($rpl_mode ne '') {
395
$rplsrv->waitForSlaveSync;
400
foreach my $i (0..$#server) {
401
$dump_files[$i] = tmpdir()."server_".$$."_".$i.".dump";
403
my $dump_result = $server[$i]->dumpdb($database,$dump_files[$i]);
404
exit_test($dump_result >> 8) if $dump_result > 0;
407
say("Comparing SQL dumps...");
408
my $diff_result = system("diff -u $dump_files[0] $dump_files[1]");
409
$diff_result = $diff_result >> 8;
411
if ($diff_result == 0) {
412
say("No differences were found between servers.");
415
foreach my $dump_file (@dump_files) {
419
exit_test($diff_result);
426
if ($rpl_mode ne '') {
427
$rplsrv->stopServer();
429
foreach my $srv (@server) {
441
Copyright (c) 2010,2011 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.
443
$0 - Run a complete random query generation test, including server start with replication and master/slave verification
445
Options related to one standalone MySQL server:
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);
451
Options related to two MySQL servers
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);
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
490
--help : This help message
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.
496
print "$0 arguments were: ".join(' ', @ARGV_saved)."\n";
497
exit_test(STATUS_UNKNOWN_ERROR);
503
say("[$$] $0 will exit with exit status ".status2text($status). " ($status)");