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";
38
require Log::Log4perl;
39
Log::Log4perl->import();
40
$logger = Log::Log4perl->get_logger('randgen.gentest');
47
$SIG{CHLD} = "IGNORE";
50
if (defined $ENV{RQG_HOME}) {
52
$ENV{RQG_HOME} = $ENV{RQG_HOME}.'\\';
54
$ENV{RQG_HOME} = $ENV{RQG_HOME}.'/';
59
use GenTest::Constants;
63
my $database = 'test';
66
my ($gendata, $skip_gendata, @basedirs, @mysqld_options, @vardirs, $rpl_mode,
67
$engine, $help, $debug, $validators, $reporters, $grammar_file, $skip_recursive_rules,
68
$redefine_file, $seed, $mask, $mask_level, $no_mask, $mem, $rows,
69
$varchar_len, $xml_output, $valgrind, $valgrind_xml, $views,
70
$start_dirty, $filter, $build_thread, $testname, $report_xml_tt,
71
$report_xml_tt_type, $report_xml_tt_dest, $notnull, $sqltrace,
72
$lcov, $transformers, $logfile, $logconf, $report_tt_logdir,$querytimeout,
73
$short_column_names, $strict_fields, $freeze_time);
75
my $threads = my $default_threads = 10;
76
my $queries = my $default_queries = 1000;
77
my $duration = my $default_duration = 3600;
79
my @ARGV_saved = @ARGV;
81
my $opt_result = GetOptions(
82
'mysqld=s@' => \$mysqld_options[0],
83
'mysqld1=s@' => \$mysqld_options[0],
84
'mysqld2=s@' => \$mysqld_options[1],
85
'basedir=s' => \$basedirs[0],
86
'basedir1=s' => \$basedirs[0],
87
'basedir2=s' => \$basedirs[1],
88
'vardir=s' => \$vardirs[0],
89
'vardir1=s' => \$vardirs[0],
90
'vardir2=s' => \$vardirs[1],
91
'rpl_mode=s' => \$rpl_mode,
92
'engine=s' => \$engine,
93
'grammar=s' => \$grammar_file,
94
'skip-recursive-rules' => \$skip_recursive_rules,
95
'redefine=s' => \$redefine_file,
96
'threads=i' => \$threads,
97
'queries=s' => \$queries,
98
'duration=i' => \$duration,
101
'validators:s@' => \$validators,
102
'transformers:s@' =>\$transformers,
103
'reporters:s@' => \$reporters,
104
'report-xml-tt' => \$report_xml_tt,
105
'report-xml-tt-type=s' => \$report_xml_tt_type,
106
'report-xml-tt-dest=s' => \$report_xml_tt_dest,
107
'gendata:s' => \$gendata,
108
'skip-gendata' => \$skip_gendata,
109
'notnull' => \$notnull,
110
'short_column_names' => \$short_column_names,
111
'strict_fields' => \$strict_fields,
112
'freeze_time' => \$freeze_time,
115
'mask-level=i' => \$mask_level,
116
'no-mask' => \$no_mask,
119
'varchar-length=i' => \$varchar_len,
120
'xml-output=s' => \$xml_output,
121
'valgrind' => \$valgrind,
122
'valgrind-xml' => \$valgrind_xml,
123
'views:s' => \$views,
124
'sqltrace:s' => \$sqltrace,
125
'start-dirty' => \$start_dirty,
126
'filter=s' => \$filter,
127
'mtr-build-thread=i' => \$build_thread,
128
'testname=s' => \$testname,
130
'logfile=s' => \$logfile,
131
'logconf=s' => \$logconf,
132
'report-tt-logdir=s' => \$report_tt_logdir,
133
'querytimeout=i' => \$querytimeout
136
if (defined $logfile && defined $logger) {
137
setLoggingToFile($logfile);
139
if (defined $logconf && defined $logger) {
140
setLogConf($logconf);
144
$ENV{RQG_DEBUG} = 1 if defined $debug;
146
$validators = join(',', @$validators) if defined $validators;
147
$reporters = join(',', @$reporters) if defined $reporters;
148
$transformers = join(',', @$transformers) if defined $transformers;
155
} elsif ($basedirs[0] eq '') {
156
say("No basedir provided via --basedir.");
158
} elsif (not defined $grammar_file) {
159
say("No grammar file provided via --grammar");
163
# --sqltrace may have a string value (optional).
164
# Allowed values for --sqltrace:
165
my %sqltrace_legal_values = (
166
'MarkErrors' => 1 # Prefixes invalid SQL statements for easier post-processing
169
# If no value is given, GetOpt will assign the value '' (empty string).
170
if (length($sqltrace) > 0) {
171
# A value is given, check if it is legal.
172
if (not exists $sqltrace_legal_values{$sqltrace}) {
173
say("Invalid value for --sqltrace option: '$sqltrace'");
174
say("Valid values are: ".join(', ', keys(%sqltrace_legal_values)));
175
say("No value means that default/plain sqltrace will be used.");
176
exit(STATUS_ENVIRONMENT_FAILURE);
180
say("Copyright (c) 2008,2011 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.");
181
say("Please see http://forge.mysql.com/wiki/Category:RandomQueryGenerator for more information on this test framework.");
182
say("Starting: $0 ".join(" ", @ARGV_saved));
185
# Calculate master and slave ports based on MTR_BUILD_THREAD (MTR
186
# Version 1 behaviour)
189
if (not defined $build_thread) {
190
if (defined $ENV{MTR_BUILD_THREAD}) {
191
$build_thread = $ENV{MTR_BUILD_THREAD}
193
$build_thread = DEFAULT_MTR_BUILD_THREAD;
197
if ( $build_thread eq 'auto' ) {
198
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.") ");
199
exit (STATUS_ENVIRONMENT_FAILURE);
202
my $master_port = 10000 + 10 * $build_thread;
203
my $slave_port = 10000 + 10 * $build_thread + 2;
204
my @master_ports = ($master_port,$slave_port);
206
say("master_port : $master_port slave_port : $slave_port master_ports : @master_ports MTR_BUILD_THREAD : $build_thread ");
208
$ENV{MTR_BUILD_THREAD} = $build_thread;
211
# If the user has provided two vardirs and one basedir, start second
212
# server using the same basedir
217
($vardirs[1] ne '') &&
220
$basedirs[1] = $basedirs[0];
223
foreach my $dir (cwd(), @basedirs) {
224
# calling bzr usually takes a few seconds...
226
my $bzrinfo = GenTest::BzrInfo->new(
229
my $revno = $bzrinfo->bzrRevno();
230
my $revid = $bzrinfo->bzrRevisionId();
232
if ((defined $revno) && (defined $revid)) {
233
say("$dir Revno: $revno");
234
say("$dir Revision-Id: $revid");
236
say($dir.' does not look like a bzr branch, cannot get revision info.');
244
($mysqld_options[1] ne '') &&
247
$basedirs[1] = $basedirs[0];
251
# If the user has provided identical basedirs and vardirs, warn of a potential overlap.
255
($basedirs[0] eq $basedirs[1]) &&
256
($vardirs[0] eq $vardirs[1]) &&
259
die("Please specify either different --basedir[12] or different --vardir[12] in order to start two MySQL servers");
263
# If RQG_HOME is set, prepend it to config files if they can not be found without it
266
$gendata = $ENV{RQG_HOME}.'/'.$gendata if defined $gendata && defined $ENV{RQG_HOME} && ! -e $gendata;
267
$grammar_file = $ENV{RQG_HOME}.'/'.$grammar_file if defined $grammar_file && defined $ENV{RQG_HOME} && ! -e $grammar_file;
268
$redefine_file = $ENV{RQG_HOME}.'/'.$redefine_file if defined $redefine_file && defined $ENV{RQG_HOME} && ! -e $redefine_file;
273
unlink(tmpdir()."/lcov-rqg.info");
274
system("lcov --directory $basedirs[0] --zerocounters");
278
# Start servers. Use rpl_alter if replication is needed.
281
foreach my $server_id (0..1) {
282
next if $basedirs[$server_id] eq '';
288
$master_dsns[$server_id] = "dbi:mysql:host=127.0.0.1:port=".$master_ports[$server_id].":user=root:database=".$database;
292
push @mtr_options, lc("--mysqld=--$engine") if defined $engine && $engine !~ m{myisam|memory|heap|aria}sio;
294
push @mtr_options, "--mem" if defined $mem;
295
if ((defined $valgrind) || (defined $valgrind_xml)) {
296
push @mtr_options, "--valgrind";
297
if (defined $valgrind_xml) {
298
push @mtr_options, "--valgrind-option='--xml=yes'";
299
if (defined $vardirs[$server_id]) {
300
push @mtr_options, "--valgrind-option='--xml-file=".$vardirs[$server_id]."/log/valgrind.xml'";
302
push @mtr_options, "--valgrind-option='--xml-file=".$basedirs[$server_id]."/mysql-test/var/log/valgrind.xml'";
307
push @mtr_options, "--skip-ndb";
308
push @mtr_options, "--mysqld=--core-file";
309
push @mtr_options, "--mysqld=--loose-new";
310
push @mtr_options, "--mysqld=--default-storage-engine=$engine" if defined $engine;
311
push @mtr_options, "--mysqld=--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
312
push @mtr_options, "--mysqld=--relay-log=slave-relay-bin";
313
push @mtr_options, "--mysqld=--loose-innodb";
314
push @mtr_options, "--mysqld=--loose-falcon-debug-mask=2";
315
push @mtr_options, "--mysqld=--secure-file-priv="; # Disable secure-file-priv that mtr enables.
316
push @mtr_options, "--mysqld=--max-allowed-packet=16Mb"; # Allow loading bigger blobs
317
push @mtr_options, "--mysqld=--loose-innodb-status-file=1";
318
push @mtr_options, "--mysqld=--master-retry-count=65535";
319
push @mtr_options, "--mysqld=--loose-debug-assert-if-crashed-table";
320
push @mtr_options, "--mysqld=--loose-debug-assert-on-error";
321
push @mtr_options, "--mysqld=--skip-name-resolve";
323
push @mtr_options, "--start-dirty" if defined $start_dirty;
324
push @mtr_options, "--gcov" if $lcov;
326
if (($rpl_mode ne '') && ($server_id != 0)) {
327
# If we are running in replication, and we start the slave separately (because it is a different binary)
328
# add a few options that allow the slave and the master to be distinguished and SHOW SLAVE HOSTS to work
329
push @mtr_options, "--mysqld=--server-id=".($server_id + 1);
330
push @mtr_options, "--mysqld=--report-host=127.0.0.1";
331
push @mtr_options, "--mysqld=--report-port=".$master_ports[$server_id];
334
my $mtr_path = $basedirs[$server_id].'/mysql-test/';
335
chdir($mtr_path) or croak "unable to chdir() to $mtr_path: $!";
337
push @mtr_options, "--vardir=$vardirs[$server_id]" if defined $vardirs[$server_id];
338
push @mtr_options, "--master_port=".$master_ports[$server_id];
340
if (defined $mysqld_options[$server_id]) {
341
foreach my $mysqld_option (@{$mysqld_options[$server_id]}) {
342
push @mtr_options, '--mysqld="'.$mysqld_option.'"';
349
(not defined $vardirs[1]) &&
350
(not defined $mysqld_options[1])
352
push @mtr_options, 'rpl_alter';
353
push @mtr_options, "--slave_port=".$slave_port;
354
} elsif ($basedirs[$server_id] =~ m{(^|[-/ ])5\.0}sgio) {
355
say("Basedir implies server version 5.0. Will not use --start-and-exit 1st");
356
# Do nothing, test name "1st" does not exist in 5.0
358
push @mtr_options, '1st';
361
$ENV{MTR_VERSION} = 1;
362
# my $out_file = "/tmp/mtr-".$$."-".$server_id.".out";
363
my $mtr_command = "perl mysql-test-run.pl --start-and-exit ".join(' ', @mtr_options)." 2>&1";
364
say("Running $mtr_command .");
366
my $vardir = $vardirs[$server_id] || $basedirs[$server_id].'/mysql-test/var';
368
open (MTR_COMMAND, '>'.$mtr_path.'/mtr_command') or say("Unable to open mtr_command: $!");
369
print MTR_COMMAND $mtr_command;
372
my $mtr_status = system($mtr_command);
374
if ($mtr_status != 0) {
375
# system("cat $out_file");
376
system("cat \"$vardir/log/master.err\"");
377
exit_test(STATUS_ENVIRONMENT_FAILURE);
381
if ((defined $master_dsns[$server_id]) && (defined $engine)) {
382
my $dbh = DBI->connect($master_dsns[$server_id], undef, undef, { RaiseError => 1 } );
383
$dbh->do("SET GLOBAL storage_engine = '$engine'");
389
my $master_dbh = DBI->connect($master_dsns[0], undef, undef, { RaiseError => 1 } );
392
my $slave_dsn = "dbi:mysql:host=127.0.0.1:port=".$slave_port.":user=root:database=".$database;
393
my $slave_dbh = DBI->connect($slave_dsn, undef, undef, { RaiseError => 1 } );
395
say("Establishing replication, mode $rpl_mode ...");
397
my ($foo, $master_version) = $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version'");
399
if (($master_version !~ m{^5\.0}sio) && ($rpl_mode ne 'default')) {
400
$master_dbh->do("SET GLOBAL BINLOG_FORMAT = '$rpl_mode'");
401
$slave_dbh->do("SET GLOBAL BINLOG_FORMAT = '$rpl_mode'");
404
$slave_dbh->do("STOP SLAVE");
406
$slave_dbh->do("SET GLOBAL storage_engine = '$engine'") if defined $engine;
408
$slave_dbh->do("CHANGE MASTER TO
409
MASTER_PORT = $master_ports[0],
410
MASTER_HOST = '127.0.0.1',
411
MASTER_USER = 'root',
412
MASTER_CONNECT_RETRY = 1
415
$slave_dbh->do("START SLAVE");
424
push @gentest_options, "--start-dirty" if defined $start_dirty;
425
push @gentest_options, "--gendata=$gendata" if not defined $skip_gendata;
426
push @gentest_options, "--notnull" if defined $notnull;
427
push @gentest_options, "--short_column_names" if defined $short_column_names;
428
push @gentest_options, "--strict_fields" if defined $strict_fields;
429
push @gentest_options, "--freeze_time" if defined $freeze_time;
430
push @gentest_options, "--engine=$engine" if defined $engine;
431
push @gentest_options, "--rpl_mode=$rpl_mode" if defined $rpl_mode;
432
push @gentest_options, map {'--validator='.$_} split(/,/,$validators) if defined $validators;
433
push @gentest_options, map {'--reporter='.$_} split(/,/,$reporters) if defined $reporters;
434
push @gentest_options, map {'--transformer='.$_} split(/,/,$transformers) if defined $transformers;
435
push @gentest_options, "--threads=$threads" if defined $threads;
436
push @gentest_options, "--queries=$queries" if defined $queries;
437
push @gentest_options, "--duration=$duration" if defined $duration;
438
push @gentest_options, "--dsn=$master_dsns[0]" if defined $master_dsns[0];
439
push @gentest_options, "--dsn=$master_dsns[1]" if defined $master_dsns[1];
440
push @gentest_options, "--grammar=$grammar_file";
441
push @gentest_options, "--skip-recursive-rules" if defined $skip_recursive_rules;
442
push @gentest_options, "--redefine=$redefine_file" if defined $redefine_file;
443
push @gentest_options, "--seed=$seed" if defined $seed;
444
push @gentest_options, "--mask=$mask" if ((defined $mask) && (not defined $no_mask));
445
push @gentest_options, "--mask-level=$mask_level" if defined $mask_level;
446
push @gentest_options, "--rows=$rows" if defined $rows;
447
push @gentest_options, "--views=$views" if defined $views;
448
push @gentest_options, "--varchar-length=$varchar_len" if defined $varchar_len;
449
push @gentest_options, "--xml-output=$xml_output" if defined $xml_output;
450
push @gentest_options, "--report-xml-tt" if defined $report_xml_tt;
451
push @gentest_options, "--report-xml-tt-type=$report_xml_tt_type" if defined $report_xml_tt_type;
452
push @gentest_options, "--report-xml-tt-dest=$report_xml_tt_dest" if defined $report_xml_tt_dest;
453
push @gentest_options, "--debug" if defined $debug;
454
push @gentest_options, "--filter=$filter" if defined $filter;
455
push @gentest_options, "--valgrind" if defined $valgrind;
456
push @gentest_options, "--valgrind-xml" if defined $valgrind_xml;
457
push @gentest_options, "--testname=$testname" if defined $testname;
458
push @gentest_options, "--sqltrace".(length($sqltrace)>0 ? "=$sqltrace" : '' ) if defined $sqltrace;
459
push @gentest_options, "--logfile=$logfile" if defined $logfile;
460
push @gentest_options, "--logconf=$logconf" if defined $logconf;
461
push @gentest_options, "--report-tt-logdir=$report_tt_logdir" if defined $report_tt_logdir;
462
push @gentest_options, "--querytimeout=$querytimeout" if defined $querytimeout;
464
# Push the number of "worker" threads into the environment.
465
# lib/GenTest/Generator/FromGrammar.pm will generate a corresponding grammar element.
466
$ENV{RQG_THREADS}= $threads;
468
my $gentest_result = system("perl ".($Carp::Verbose?"-MCarp=verbose ":"").
469
"$ENV{RQG_HOME}gentest.pl ".join(' ', @gentest_options)) >> 8;
470
say("gentest.pl exited with exit status ".status2text($gentest_result). " ($gentest_result)");
473
say("Trying to generate a genhtml lcov report in ".tmpdir()."/rqg-lcov-$$ ...");
474
system("lcov --quiet --directory $basedirs[0] --capture --output-file ".tmpdir()."/lcov-rqg.info");
475
system("genhtml --quiet --no-sort --output-directory=".tmpdir()."/rqg-lcov-$$ ".tmpdir()."/lcov-rqg.info");
476
say("genhtml lcov report may have been generated in ".tmpdir()."/rqg-lcov-$$ .");
480
exit_test($gentest_result);
485
Copyright (c) 2008,2011 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.
487
$0 - Run a complete random query generation test, including server start with replication and master/slave verification
489
Options related to one standalone MySQL server:
491
--basedir : Specifies the base directory of the stand-alone MySQL installation;
492
--mysqld : Options passed to the MySQL server
493
--vardir : Optional. (default \$basedir/mysql-test/var);
495
Options related to two MySQL servers
497
--basedir1 : Specifies the base directory of the first MySQL installation;
498
--basedir2 : Specifies the base directory of the second MySQL installation;
499
--mysqld1 : Options passed to the first MySQL server
500
--mysqld2 : Options passed to the second MySQL server
501
--vardir1 : Optional. (default \$basedir1/mysql-test/var);
502
--vardir2 : Optional. (default \$basedir2/mysql-test/var);
506
--grammar : Grammar file to use when generating queries (REQUIRED);
507
--redefine : Grammar file to redefine and/or add rules to the given grammar
508
--rpl_mode : Replication type to use (statement|row|mixed) (default: no replication);
509
--vardir1 : Optional.
510
--vardir2 : Optional.
511
--engine : Table engine to use when creating tables with gendata (default no ENGINE in CREATE TABLE);
512
--threads : Number of threads to spawn (default $default_threads);
513
--queries : Number of queries to execute per thread (default $default_queries);
514
--duration : Duration of the test in seconds (default $default_duration seconds);
515
--validator : The validators to use
516
--reporter : The reporters to use
517
--transformer: The transformers to use (turns on --validator=transformer). Accepts comma separated list
518
--querytimeout: The timeout to use for the QueryTimeout reporter
519
--gendata : Generate data option. Passed to gentest.pl
520
--seed : PRNG seed. Passed to gentest.pl
521
--mask : Grammar mask. Passed to gentest.pl
522
--mask-level: Grammar mask level. Passed to gentest.pl
523
--rows : No of rows. Passed to gentest.pl
524
--varchar-length: length of strings. passed to gentest.pl
525
--xml-output: Passed to gentest.pl
526
--report-xml-tt: Passed to gentest.pl
527
--report-xml-tt-type: Passed to gentest.pl
528
--report-xml-tt-dest: Passed to gentest.pl
529
--testname : Name of test, used for reporting purposes
530
--sqltrace : Print all generated SQL statements.
531
Optional: Specify --sqltrace=MarkErrors to mark invalid statements.
532
--views : Generate views. Optionally specify view type (algorithm) as option value. Passed to gentest.pl
533
--valgrind : Passed to gentest.pl
534
--filter : Passed to gentest.pl
535
--mem : Passed to mtr
536
--mtr-build-thread: Value used for MTR_BUILD_THREAD when servers are started and accessed
537
--short_column_names: Use short column names in gendata (c<number>)
538
--strict_fields: Disable all AI applied to columns defined in \$fields in the gendata file. Allows for very specific column definitions
539
--freeze_time: Freeze time for each query so that CURRENT_TIMESTAMP gives the same result for all transformers/validators
541
--help : This help message
543
If you specify --basedir1 and --basedir2 or --vardir1 and --vardir2, two servers will be started and the results from the queries
544
will be compared between them.
547
print "$0 arguments were: ".join(' ', @ARGV_saved)."\n";
548
exit_test(STATUS_UNKNOWN_ERROR);
554
print isoTimestamp()." [$$] $0 will exit with exit status ".status2text($status)." ($status)\n";