3
# Copyright (c) 2008, 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
21
# This script executes the following sequence
23
# $ mysql-test-run.pl --start-and-exit with replication
24
# $ gentest.pl --gendata
30
use lib "$ENV{RQG_HOME}/lib";
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, $grammar_file,
57
$redefine_file, $seed, $mask, $mask_level, $no_mask, $mem, $rows,
58
$varchar_len, $xml_output, $valgrind, $valgrind_xml, $views, $start_dirty,
59
$filter, $build_thread, $testname, $report_xml_tt, $report_xml_tt_type,
60
$report_xml_tt_dest, $notnull, $sqltrace, $lcov, $transformers, $querytimeout);
62
my $threads = my $default_threads = 10;
63
my $queries = my $default_queries = 1000;
64
my $duration = my $default_duration = 3600;
66
my @ARGV_saved = @ARGV;
68
my $opt_result = GetOptions(
69
'mysqld=s@' => \$mysqld_options[0],
70
'mysqld1=s@' => \$mysqld_options[0],
71
'mysqld2=s@' => \$mysqld_options[1],
72
'basedir=s' => \$basedirs[0],
73
'basedir1=s' => \$basedirs[0],
74
'basedir2=s' => \$basedirs[1],
75
'vardir=s' => \$vardirs[0],
76
'vardir1=s' => \$vardirs[0],
77
'vardir2=s' => \$vardirs[1],
78
'rpl_mode=s' => \$rpl_mode,
79
'engine=s' => \$engine,
80
'grammar=s' => \$grammar_file,
81
'redefine=s' => \$redefine_file,
82
'threads=i' => \$threads,
83
'queries=s' => \$queries,
84
'duration=i' => \$duration,
87
'validators:s@' => \$validators,
88
'transformers:s@' =>\$transformers,
89
'reporters:s@' => \$reporters,
90
'report-xml-tt' => \$report_xml_tt,
91
'report-xml-tt-type=s' => \$report_xml_tt_type,
92
'report-xml-tt-dest=s' => \$report_xml_tt_dest,
93
'gendata:s' => \$gendata,
94
'notnull' => \$notnull,
97
'mask-level=i' => \$mask_level,
98
'no-mask' => \$no_mask,
101
'varchar-length=i' => \$varchar_len,
102
'xml-output=s' => \$xml_output,
103
'valgrind' => \$valgrind,
104
'valgrind-xml' => \$valgrind_xml,
106
'sqltrace' => \$sqltrace,
107
'start-dirty' => \$start_dirty,
108
'filter=s' => \$filter,
109
'mtr-build-thread=i' => \$build_thread,
110
'testname=s' => \$testname,
112
'querytimeout=i' => \$querytimeout
115
$ENV{RQG_DEBUG} = 1 if defined $debug;
117
$validators = join(',', @$validators) if defined $validators;
118
$reporters = join(',', @$reporters) if defined $reporters;
119
$transformers = join(',', @$transformers) if defined $transformers;
126
} elsif ($basedirs[0] eq '') {
127
say("No basedir provided via --basedir.");
129
} elsif (not defined $grammar_file) {
130
say("No grammar file provided via --grammar");
134
say("Copyright (c) 2008,2011 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.");
135
say("Please see http://forge.mysql.com/wiki/Category:RandomQueryGenerator for more information on this test framework.");
136
say("Starting: $0 ".join(" ", @ARGV_saved));
139
# Calculate master and slave ports based on MTR_BUILD_THREAD (MTR
140
# Version 1 behaviour)
143
if (not defined $build_thread) {
144
if (defined $ENV{MTR_BUILD_THREAD}) {
145
$build_thread = $ENV{MTR_BUILD_THREAD}
147
$build_thread = DEFAULT_MTR_BUILD_THREAD;
151
if ( $build_thread eq 'auto' ) {
152
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.") ");
153
exit (STATUS_ENVIRONMENT_FAILURE);
156
my $master_port = 10000 + 10 * $build_thread;
157
my $slave_port = 10000 + 10 * $build_thread + 2;
158
my @master_ports = ($master_port,$slave_port);
160
say("master_port : $master_port slave_port : $slave_port master_ports : @master_ports MTR_BUILD_THREAD : $build_thread ");
162
$ENV{MTR_BUILD_THREAD} = $build_thread;
165
# If the user has provided two vardirs and one basedir, start second
166
# server using the same basedir
171
($vardirs[1] ne '') &&
174
$basedirs[1] = $basedirs[0];
179
($mysqld_options[1] ne '') &&
182
$basedirs[1] = $basedirs[0];
186
# If the user has provided identical basedirs and vardirs, warn of a potential overlap.
190
($basedirs[0] eq $basedirs[1]) &&
191
($vardirs[0] eq $vardirs[1]) &&
194
die("Please specify either different --basedir[12] or different --vardir[12] in order to start two MySQL servers");
198
# If RQG_HOME is set, prepend it to config files if they can not be found without it
201
$gendata = $ENV{RQG_HOME}.'/'.$gendata if defined $gendata && defined $ENV{RQG_HOME} && ! -e $gendata;
202
$grammar_file = $ENV{RQG_HOME}.'/'.$grammar_file if defined $grammar_file && defined $ENV{RQG_HOME} && ! -e $grammar_file;
203
$redefine_file = $ENV{RQG_HOME}.'/'.$redefine_file if defined $redefine_file && defined $ENV{RQG_HOME} && ! -e $redefine_file;
208
unlink(tmpdir()."/lcov-rqg.info");
209
system("lcov --directory $basedirs[0] --zerocounters");
213
# Start servers. Use rpl_alter if replication is needed.
216
foreach my $server_id (0..1) {
217
next if $basedirs[$server_id] eq '';
223
$master_dsns[$server_id] = "dbi:mysql:host=127.0.0.1:port=".$master_ports[$server_id].":user=root:database=".$database;
227
push @mtr_options, lc("--mysqld=--$engine") if defined $engine && $engine !~ m{myisam|memory|heap}sio;
229
push @mtr_options, "--mem" if defined $mem;
230
if ((defined $valgrind) || (defined $valgrind_xml)) {
231
push @mtr_options, "--valgrind";
232
if (defined $valgrind_xml) {
233
push @mtr_options, "--valgrind-option='--xml=yes'";
234
if (defined $vardirs[$server_id]) {
235
push @mtr_options, "--valgrind-option='--xml-file=".$vardirs[$server_id]."/log/valgrind.xml'";
237
push @mtr_options, "--valgrind-option='--xml-file=".$basedirs[$server_id]."/mysql-test/var/log/valgrind.xml'";
242
push @mtr_options, "--skip-ndb";
243
push @mtr_options, "--mysqld=--core-file";
244
push @mtr_options, "--mysqld=--loose-new";
245
# push @mtr_options, "--mysqld=--default-storage-engine=$engine" if defined $engine;
246
push @mtr_options, "--mysqld=--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
247
push @mtr_options, "--mysqld=--relay-log=slave-relay-bin";
248
push @mtr_options, "--mysqld=--loose-innodb";
249
push @mtr_options, "--mysqld=--loose-falcon-debug-mask=2";
250
push @mtr_options, "--mysqld=--secure-file-priv="; # Disable secure-file-priv that mtr enables.
251
push @mtr_options, "--mysqld=--max-allowed-packet=16Mb"; # Allow loading bigger blobs
252
push @mtr_options, "--mysqld=--loose-innodb-status-file=1";
253
push @mtr_options, "--mysqld=--master-retry-count=65535";
255
push @mtr_options, "--start-dirty" if defined $start_dirty;
256
push @mtr_options, "--gcov" if $lcov;
258
if (($rpl_mode ne '') && ($server_id != 0)) {
259
# If we are running in replication, and we start the slave separately (because it is a different binary)
260
# add a few options that allow the slave and the master to be distinguished and SHOW SLAVE HOSTS to work
261
push @mtr_options, "--mysqld=--server-id=".($server_id + 1);
262
push @mtr_options, "--mysqld=--report-host=127.0.0.1";
263
push @mtr_options, "--mysqld=--report-port=".$master_ports[$server_id];
266
my $mtr_path = $basedirs[$server_id].'/mysql-test/';
267
chdir($mtr_path) or die "unable to chdir() to $mtr_path: $!";
269
push @mtr_options, "--vardir=$vardirs[$server_id]" if defined $vardirs[$server_id];
270
push @mtr_options, "--master_port=".$master_ports[$server_id];
272
if (defined $mysqld_options[$server_id]) {
273
foreach my $mysqld_option (@{$mysqld_options[$server_id]}) {
274
push @mtr_options, '--mysqld="'.$mysqld_option.'"';
281
(not defined $vardirs[1]) &&
282
(not defined $mysqld_options[1])
284
push @mtr_options, 'rpl_alter';
285
push @mtr_options, "--slave_port=".$slave_port;
286
} elsif ($basedirs[$server_id] =~ m{(^|[-/ ])5\.0}sgio) {
287
say("Basedir implies server version 5.0. Will not use --start-and-exit 1st");
288
# Do nothing, test name "1st" does not exist in 5.0
290
push @mtr_options, '1st';
293
$ENV{MTR_VERSION} = 1;
294
# my $out_file = "/tmp/mtr-".$$."-".$server_id.".out";
295
my $mtr_command = "perl mysql-test-run.pl --start-and-exit ".join(' ', @mtr_options)." 2>&1";
296
say("Running $mtr_command .");
298
my $vardir = $vardirs[$server_id] || $basedirs[$server_id].'/mysql-test/var';
300
open (MTR_COMMAND, '>'.$mtr_path.'/mtr_command') or say("Unable to open mtr_command: $!");
301
print MTR_COMMAND $mtr_command;
304
my $mtr_status = system($mtr_command);
306
if ($mtr_status != 0) {
307
# system("cat $out_file");
308
system("cat \"$vardir/log/master.err\"");
309
exit_test(STATUS_ENVIRONMENT_FAILURE);
313
if ((defined $master_dsns[$server_id]) && (defined $engine)) {
314
my $dbh = DBI->connect($master_dsns[$server_id], undef, undef, { RaiseError => 1 } );
315
$dbh->do("SET GLOBAL storage_engine = '$engine'");
321
my $master_dbh = DBI->connect($master_dsns[0], undef, undef, { RaiseError => 1 } );
324
my $slave_dsn = "dbi:mysql:host=127.0.0.1:port=".$slave_port.":user=root:database=".$database;
325
my $slave_dbh = DBI->connect($slave_dsn, undef, undef, { RaiseError => 1 } );
327
say("Establishing replication, mode $rpl_mode ...");
329
my ($foo, $master_version) = $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version'");
331
if (($master_version !~ m{^5\.0}sio) && ($rpl_mode ne 'default')) {
332
$master_dbh->do("SET GLOBAL BINLOG_FORMAT = '$rpl_mode'");
333
$slave_dbh->do("SET GLOBAL BINLOG_FORMAT = '$rpl_mode'");
336
$slave_dbh->do("STOP SLAVE");
338
$slave_dbh->do("SET GLOBAL storage_engine = '$engine'") if defined $engine;
340
$slave_dbh->do("CHANGE MASTER TO
341
MASTER_PORT = $master_ports[0],
342
MASTER_HOST = '127.0.0.1',
343
MASTER_USER = 'root',
344
MASTER_CONNECT_RETRY = 1
347
$slave_dbh->do("START SLAVE");
356
push @gentest_options, "--start-dirty" if defined $start_dirty;
357
push @gentest_options, "--gendata=$gendata";
358
push @gentest_options, "--notnull" if defined $notnull;
359
push @gentest_options, "--engine=$engine" if defined $engine;
360
push @gentest_options, "--rpl_mode=$rpl_mode" if defined $rpl_mode;
361
push @gentest_options, map {'--validator='.$_} split(/,/,$validators) if defined $validators;
362
push @gentest_options, map {'--reporter='.$_} split(/,/,$reporters) if defined $reporters;
363
push @gentest_options, map {'--transformer='.$_} split(/,/,$transformers) if defined $transformers;
364
push @gentest_options, "--threads=$threads" if defined $threads;
365
push @gentest_options, "--queries=$queries" if defined $queries;
366
push @gentest_options, "--duration=$duration" if defined $duration;
367
push @gentest_options, "--dsn=$master_dsns[0]" if defined $master_dsns[0];
368
push @gentest_options, "--dsn=$master_dsns[1]" if defined $master_dsns[1];
369
push @gentest_options, "--grammar=$grammar_file";
370
push @gentest_options, "--redefine=$redefine_file" if defined $redefine_file;
371
push @gentest_options, "--seed=$seed" if defined $seed;
372
push @gentest_options, "--mask=$mask" if ((defined $mask) && (not defined $no_mask));
373
push @gentest_options, "--mask-level=$mask_level" if defined $mask_level;
374
push @gentest_options, "--rows=$rows" if defined $rows;
375
push @gentest_options, "--views" if defined $views;
376
push @gentest_options, "--varchar-length=$varchar_len" if defined $varchar_len;
377
push @gentest_options, "--xml-output=$xml_output" if defined $xml_output;
378
push @gentest_options, "--report-xml-tt" if defined $report_xml_tt;
379
push @gentest_options, "--report-xml-tt-type=$report_xml_tt_type" if defined $report_xml_tt_type;
380
push @gentest_options, "--report-xml-tt-dest=$report_xml_tt_dest" if defined $report_xml_tt_dest;
381
push @gentest_options, "--debug" if defined $debug;
382
push @gentest_options, "--filter=$filter" if defined $filter;
383
push @gentest_options, "--valgrind" if defined $valgrind;
384
push @gentest_options, "--valgrind-xml" if defined $valgrind_xml;
385
push @gentest_options, "--testname=$testname" if defined $testname;
386
push @gentest_options, "--sqltrace" if defined $sqltrace;
387
push @gentest_options, "--querytimeout=$querytimeout" if defined $querytimeout;
389
# Push the number of "worker" threads into the environment.
390
# lib/GenTest/Generator/FromGrammar.pm will generate a corresponding grammar element.
391
$ENV{RQG_THREADS}= $threads;
393
my $gentest_result = system("perl $ENV{RQG_HOME}gentest.pl ".join(' ', @gentest_options)) >> 8;
394
say("gentest.pl exited with exit status ".status2text($gentest_result). " ($gentest_result)");
397
say("Trying to generate a genhtml lcov report in ".tmpdir()."/rqg-lcov-$$ ...");
398
system("lcov --quiet --directory $basedirs[0] --capture --output-file ".tmpdir()."/lcov-rqg.info");
399
system("genhtml --quiet --no-sort --output-directory=".tmpdir()."/rqg-lcov-$$ ".tmpdir()."/lcov-rqg.info");
400
say("genhtml lcov report may have been generated in ".tmpdir()."/rqg-lcov-$$ .");
404
exit_test($gentest_result);
409
Copyright (c) 2008,2011 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.
411
$0 - Run a complete random query generation test, including server start with replication and master/slave verification
413
Options related to one standalone MySQL server:
415
--basedir : Specifies the base directory of the stand-alone MySQL installation;
416
--mysqld : Options passed to the MySQL server
417
--vardir : Optional. (default \$basedir/mysql-test/var);
419
Options related to two MySQL servers
421
--basedir1 : Specifies the base directory of the first MySQL installation;
422
--basedir2 : Specifies the base directory of the second MySQL installation;
423
--mysqld1 : Options passed to the first MySQL server
424
--mysqld2 : Options passed to the second MySQL server
425
--vardir1 : Optional. (default \$basedir1/mysql-test/var);
426
--vardir2 : Optional. (default \$basedir2/mysql-test/var);
430
--grammar : Grammar file to use when generating queries (REQUIRED);
431
--redefine : Grammar file to redefine and/or add rules to the given grammar
432
--rpl_mode : Replication type to use (statement|row|mixed) (default: no replication);
433
--vardir1 : Optional.
434
--vardir2 : Optional.
435
--engine : Table engine to use when creating tables with gendata (default no ENGINE in CREATE TABLE);
436
--threads : Number of threads to spawn (default $default_threads);
437
--queries : Number of queries to execute per thread (default $default_queries);
438
--duration : Duration of the test in seconds (default $default_duration seconds);
439
--validator : The validators to use
440
--reporter : The reporters to use
441
--transformer: The transformers to use (turns on --validator=transformer). Accepts comma separated list
442
--querytimeout: The timeout to use for the QueryTimeout reporter
443
--gendata : Generate data option. Passed to gentest.pl
444
--seed : PRNG seed. Passed to gentest.pl
445
--mask : Grammar mask. Passed to gentest.pl
446
--mask-level: Grammar mask level. Passed to gentest.pl
447
--rows : No of rows. Passed to gentest.pl
448
--varchar-length: length of strings. passed to gentest.pl
449
--xml-output: Passed to gentest.pl
450
--report-xml-tt: Passed to gentest.pl
451
--report-xml-tt-type: Passed to gentest.pl
452
--report-xml-tt-dest: Passed to gentest.pl
453
--testname : Name of test, used for reporting purposes
454
--sqltrace : Print all generated SQL statements
455
--views : Generate views. Passed to gentest.pl
456
--valgrind : Passed to gentest.pl
457
--filter : Passed to gentest.pl
458
--mem : Passed to mtr
459
--mtr-build-thread: Value used for MTR_BUILD_THREAD when servers are started and accessed
461
--help : This help message
463
If you specify --basedir1 and --basedir2 or --vardir1 and --vardir2, two servers will be started and the results from the queries
464
will be compared between them.
467
print "$0 arguments were: ".join(' ', @ARGV_saved)."\n";
468
exit_test(STATUS_UNKNOWN_ERROR);
474
print isoTimestamp()." [$$] $0 will exit with exit status ".status2text($status)." ($status)\n";