~drizzle-trunk/drizzle/development

0.67.481 by John H. Embretsen
New file (pb2gentest-new.pl) that is mostly a copy of pb2gentest.pl. The difference is that this file uses runall-new.pl instead of runall.pl.
1
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 
2
# Use is subject to license terms.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
7
#
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16
# USA
17
18
use lib 'lib';
19
use lib "$ENV{RQG_HOME}/lib";
20
use lib 'randgen/lib';
21
22
use strict;
23
use Carp;
24
use Cwd;
25
use DBI;
26
use File::Find;
27
use GenTest;
28
use GenTest::Random;
29
use GenTest::BzrInfo;
30
use POSIX;
31
use Sys::Hostname;
32
33
my ($basedir, $vardir, $tree, $test) = @ARGV;
34
35
#
36
# For further details about tests and recommended RQG options, see
37
# http://forge.mysql.com/wiki/RandomQueryGeneratorTests
38
#
39
40
print("==================== Starting $0 ====================\n");
41
# Print MTR-style output saying which test suite/mode this is for PB2 reporting.
42
# So far we only support running one test at a time.
43
print("##############################################################################\n");
44
print("# $test\n");
45
print("##############################################################################\n");
46
47
# Autoflush output buffers (needed when using POSIX::_exit())
48
$| = 1;
49
50
#
51
# Prepare ENV variables and other settings.
52
#
53
54
# Local "installation" of MySQL 5.0. Default is for Unix hosts. See below for Windows.
55
my $basedirRelease50 = '/export/home/mysql-releases/mysql-5.0';
56
57
# Location of grammars and other test configuration files.
58
# Will use env variable RQG_CONF if set.
59
# Default is currently "conf" while using legacy setup.
60
# If not absolute path, it is relative to cwd at run time, which is the randgen directory.
61
my $conf = $ENV{RQG_CONF};
62
$conf = 'conf' if not defined $conf;
63
64
if (osWindows()) {
65
	# For tail, cdb, pscp.
66
	$ENV{PATH} = 'G:\pb2\scripts\randgen\bin;G:\pb2\scripts\bin;C:\Program Files\Debugging Tools for Windows (x86);'.$ENV{PATH};
67
	$ENV{_NT_SYMBOL_PATH} = 'srv*c:\\cdb_symbols*http://msdl.microsoft.com/download/symbols;cache*c:\\cdb_symbols';
68
69
	# For vlad
70
	#ENV{MYSQL_FULL_MINIDUMP} = 1;
71
72
	#system("date /T");
73
	#system("time /T");
74
75
	# Path to MySQL releases used for comparison runs.
76
	$basedirRelease50 = 'G:\mysql-releases\mysql-5.0.87-win32'; # loki06
77
} elsif (osSolaris()) {
78
	# For libmysqlclient
79
	$ENV{LD_LIBRARY_PATH}=$ENV{LD_LIBRARY_PATH}.':/export/home/pb2/scripts/lib/';
80
81
	# For DBI and DBD::mysql and XML::Writer on hosts with local setup.
82
	$ENV{PERL5LIB}=$ENV{PERL5LIB}.
83
		':/export/home/pb2/scripts/DBI-1.607/'.
84
		':/export/home/pb2/scripts/DBI-1.607/lib'.
85
		':/export/home/pb2/scripts/DBI-1.607/blib/arch/'.
86
		':/export/home/pb2/scripts/DBD-mysql-4.008/lib/'.
87
		':/export/home/pb2/scripts/DBD-mysql-4.008/blib/arch/'.
88
		':/export/home/pb2/scripts/XML-Writer-0.610/lib/site_perl/';
89
	
90
	# For c++filt
91
	$ENV{PATH} = $ENV{PATH}.':/opt/studio12/SUNWspro/bin';
92
93
	#system("uname -a");
94
	#system("date");
95
96
}
97
98
################################################################################
99
##
100
## subroutines
101
##
102
################################################################################
103
104
#
105
# Skips the test, displays reason (argument to the routine) quasi-MTR-style and
106
# exits with exit code 0.
107
#
108
# Example usage:
109
#   # This feature is not yet supported on Windows, so skip this test
110
#   skip_test("This feature/test does not support the Windows platform at this time");
111
#
112
# will appear in output as:
113
#   rpl_semisync                             [ skipped ] This feature/test does not support the Windows platform at this time
114
#
115
sub skip_test {
116
	my $reason = @_[0];
117
	my $message = "$test";
118
	# Using MTR-style output for the readers' convenience.
119
	# (at least 41 chars before "[ skipped ]")
120
	while (length $message < 40)
121
	{
122
		$message = $message.' ';
123
	}
124
	$message = $message." [ skipped ] ".$reason;
125
	print "$message\n";
126
	print localtime()." [$$] $0 will exit with exit status 0.\n";
127
	POSIX::_exit (0);
128
}
129
130
#
131
# Returns a random number between 1 and 499.
132
#
133
sub pick_random_port_range_id {
134
	my $prng = GenTest::Random->new( seed => time );
135
	return $prng->uint16(1,499);
136
}
137
138
#
139
# Searches recursively for a given file name under the given directory.
140
# Default top search directory is $basedir.
141
#
142
# Arg1 (mandatory): file name (excluding path)
143
# Arg2 (optional) : directory where search will start
144
#
145
# Returns full path to the directory where the file resides, if found.
146
# If more than one matching file is found, the directory of the first one found
147
# in a depth-first search will be returned.
148
# Returns undef if none is found.
149
#
150
sub findDirectory {
151
	my ($plugin_name, $dir) = @_;
152
	if (not defined $plugin_name) {
153
		carp("File name required as argument to subroutine findDirectory()");
154
	}
155
	if (not defined $dir) {
156
		$dir = $basedir;
157
	}
158
	my $fullPath;	# the result
159
	find(sub {
160
			# This subroutine is called for each file and dir it finds.
161
			# According to docs it does depth-first search.
162
			if ($_ eq $plugin_name) {
163
				$fullPath = $File::Find::dir if not defined $fullPath;
164
			}
165
			# any return value is ignored
166
		}, $dir);
167
	return $fullPath;
168
}
169
170
#
171
# Get the bzr branch ID from the pushbuild2 database (internal), based on the
172
# branch name ($tree variable).
173
#
174
# If the branch name (tree) is not found in the database, or we are unable to
175
# connect to the database, undef is returned.
176
#
177
sub get_pb2_branch_id {
178
179
	# First, check if the environment variable BRANCH_ID is set.
180
	if (defined $ENV{BRANCH_ID}) {
181
		return $ENV{BRANCH_ID};
182
	} else {
183
		# Disable db lookup for the time being due to issues on sparc32.
184
		# Remove this "else" block to enable
185
		return;
186
	}
187
	# Lookup by branch name. Get branch name from tree, which could be url.
188
	my $branch_name = $tree;
189
	if ($tree =~ m{/}) {
190
		# Found '/', assuming tree is URL.
191
		# Find last substring that is between a '/' and either end-of-string or a '/' followed by end of string.
192
		$tree =~ m{.*/([^/]+)($|/$)};
193
		$branch_name=$1;
194
	}
195
196
	my $dsn_pb2 = 'dbi:mysql:host=trollheim.norway.sun.com:port=3306:user=readonly:database=pushbuild2';
197
	my $SQL_getBranchId = "SELECT branch_id FROM branches WHERE branch_name = '$branch_name'";
198
199
	say("Using branch name $branch_name\n");
200
	say("Trying to connect to pushbuild2 database...\n");
201
202
	my $dbh = DBI->connect($dsn_pb2, undef, undef, {
203
		mysql_connect_timeout => 5,
204
		PrintError => 0,
205
		RaiseError => 0,
206
		AutoCommit => 0,
207
	} );
208
209
	if (not defined $dbh) {
210
		say("connect() to pushbuild2 database failed: ".$DBI::errstr."\n");
211
		return;
212
	}
213
214
	my $id = $dbh->selectrow_array($SQL_getBranchId);
215
	$dbh->disconnect;
216
	return $id;
217
}
218
219
#### end subroutines ###########################################################
220
221
# Find out active user name and mention it in the output to ease debugging.
222
my $username;
223
if (osLinux() || osSolaris()) {
224
    $username = $ENV{'LOGNAME'};
225
} else {
226
    $username = $ENV{'USERNAME'};
227
}
228
229
chdir('randgen');
230
231
say("Gathering info from the environment...");
232
# calling bzr usually takes a few seconds...
233
my $bzrinfo = GenTest::BzrInfo->new(
234
            dir => cwd()
235
);
236
237
say("===== Information on the host system: =====\n");
238
say(" - Local time  : ".localtime()."\n");
239
say(" - Hostname    : ".hostname()."\n");
240
say(" - Username    : ".$username."\n");
241
say(" - PID         : $$\n");
242
say(" - Working dir : ".cwd()."\n");
243
say(" - PATH        : ".$ENV{'PATH'}."\n");
244
say(" - Script arguments:\n");
245
say("       basedir = $basedir\n");
246
say("       vardir  = $vardir\n");
247
say("       tree    = $tree\n");
248
say("       test    = $test\n");
249
say("\n");
250
say("===== Information on the tested binaries (PB2): =====\n");
251
say(" - Branch URL  : ".$ENV{'BRANCH_SOURCE'});
252
say(" - Branch name : ".$ENV{'BRANCH_NAME'});
253
say(" - Revision    : ".$ENV{'PUSH_REVISION'});
254
say(" - Source      : ".$ENV{'SOURCE'});
255
say("===== Information on Random Query Generator version (bzr): =====\n");
256
say(" - Date (rev)  : ".$bzrinfo->bzrDate());
257
#say(" - Date (now) : ".$bzrinfo->bzrBuildDate());  # Shows current date, we already have that.
258
say(" - Revno       : ".$bzrinfo->bzrRevno());
259
say(" - Revision ID : ".$bzrinfo->bzrRevisionId());
260
say(" - Branch nick : ".$bzrinfo->bzrBranchNick());
261
say(" - Clean copy? : ". ($bzrinfo->bzrClean()? "Yes" : "No"));
262
say("\n");
263
264
# Test name:
265
#   In PB2, tests run via this script are prefixed with "rqg_" so that it is
266
#   easy to distinguish these tests from other "external" tests.
267
#   For a while we will support test names both with and without the prefix.
268
#   For this reason we strip off the "rqg_" prefix before continuing.
269
#   This also means that you cannot try to match against "rqg_" prefix in test
270
#   "definitions" (if statements) below.
271
my $test_name = $test;
272
my $test_suite_name = 'serverqa'; # used for xref reporting
273
$test =~ s/^rqg_//;	# test_name without prefix
274
275
# Server port numbers:
276
#
277
# If several instances of this script may run at the same time on the same
278
# host, port number conflicts may occur.
279
#
280
# If needed, use use a port range ID (integer) that is unique for this host at
281
# this time.
282
# This ID is used by the RQG framework to designate a port range to use for the
283
# test run. Passed to RQG using the MTR_BUILD_THREAD environment variable
284
# (this naming is a legacy from MTR, which is used by RQG to start the MySQL
285
# server).
286
#
287
# Solution: Use unique port range id per branch. Use "branch_id" as recorded
288
#           in PB2 database (guaranteed unique per branch).
289
# Potential issue 1: Unable to connect to pb2 database.
290
# Solution 1: Pick a random ID between 1 and some sensible number (e.g. 500).
291
# Potential issue 2: Clashing resources when running multiple pushes in same branch?
292
# Potential solution 2: Keep track of used ids in local file(s). Pick unused id.
293
#                       (not implemented yet)
294
#
295
# Currently (December 2009) PB2 RQG host should be running only one test at a
296
# time, so this should not be an issue, hence no need to set MTR_BUILD_THREAD.
297
298
#print("===== Determining port base id: =====\n");
299
my $port_range_id; # Corresponding to MTR_BUILD_THREAD in the MySQL MTR world.
300
# First, see if user has supplied us with a value for MTR_BUILD_THREAD:
301
$port_range_id = $ENV{MTR_BUILD_THREAD};
302
if (defined $port_range_id) {
303
	say("Environment variable MTR_BUILD_THREAD was already set.\n");
304
}
305
#else {
306
#	# try to obtain branch id, somehow
307
#	$port_range_id = get_pb2_branch_id();
308
#	if (not defined $port_range_id) {
309
#		print("Unable to get branch id. Picking a 'random' port base id...\n");
310
#		$port_range_id = pick_random_port_range_id();
311
#	} else {
312
#		print("Using pb2 branch ID as port base ID.\n");
313
#	}
314
#}
315
316
say("Configuring test...\n");
317
318
# Guess MySQL version. Some options we set later depend on this.
319
my $version50 = 0;      # 1 if 5.0.x, 0 otherwise. 
320
if( ($ENV{'BRANCH_SOURCE'} =~ m{-5\.0}io) || ($basedir =~ m{-5\.0}io) ) {
321
    say("Detected version 5.0.x, adjusting server options accordingly.");
322
    $version50 = 1;
323
}
324
325
my $cwd = cwd();
326
327
my $command;
328
my $engine;
329
my $rpl_mode;
330
331
if (($engine) = $test =~ m{(maria|falcon|innodb|myisam|pbxt)}io) {
332
	say("Detected that this test is about the $engine engine.");
333
}
334
335
if (($rpl_mode) = $test =~ m{(rbr|sbr|mbr|statement|mixed|row)}io) {
336
	say("Detected that this test is about replication mode $rpl_mode.");
337
	$rpl_mode = 'mixed' if $rpl_mode eq 'mbr';
338
	$rpl_mode = 'statement' if $rpl_mode eq 'sbr';
339
	$rpl_mode = 'row' if $rpl_mode eq 'rbr';
340
}
341
342
#
343
# Start defining tests. Test name can be whatever matches the regex in the if().
344
# TODO: Define less ambiguous test names to avoid accidental misconfiguration.
345
#
346
# Starting out with "legacy" Falcon tests.
347
#
348
if ($test =~ m{falcon_.*transactions}io ) {
349
	$command = '
350
		--grammar='.$conf.'/transactions/transactions.yy
351
		--gendata='.$conf.'/transactions/transactions.zz
352
		--mysqld=--falcon-consistent-read=1
353
		--mysqld=--transaction-isolation=REPEATABLE-READ
354
		--validator=DatabaseConsistency
355
		--mem
356
	';
357
} elsif ($test =~ m{falcon_.*durability}io ) {
358
	$command = '
359
		--grammar='.$conf.'/transactions/transaction_durability.yy
360
		--vardir1='.$vardir.'/vardir-'.$engine.'
361
		--vardir2='.$vardir.'/vardir-innodb
362
		--mysqld=--default-storage-engine='.$engine.'
363
		--mysqld=--falcon-checkpoint-schedule=\'1 1 1 1 1\'
364
		--mysqld2=--default-storage-engine=Innodb
365
		--validator=ResultsetComparator
366
	';
367
} elsif ($test =~ m{falcon_repeatable_read}io ) {
368
	$command = '
369
		--grammar='.$conf.'/transactions/repeatable_read.yy
370
		--gendata='.$conf.'/transactions/transactions.zz
371
		--mysqld=--falcon-consistent-read=1
372
		--mysqld=--transaction-isolation=REPEATABLE-READ
373
		--validator=RepeatableRead
374
		--mysqld=--falcon-consistent-read=1
375
		--mem
376
	';
377
} elsif ($test =~ m{falcon_chill_thaw_compare}io) {
378
	$command = '
379
	        --grammar='.$conf.'/engines/falcon/falcon_chill_thaw.yy
380
		--gendata='.$conf.'/engines/falcon/falcon_chill_thaw.zz
381
	        --mysqld=--falcon-record-chill-threshold=1K
382
	        --mysqld=--falcon-index-chill-threshold=1K 
383
		--threads=1
384
		--vardir1='.$vardir.'/chillthaw-vardir
385
		--vardir2='.$vardir.'/default-vardir
386
		--reporters=Deadlock,ErrorLog,Backtrace
387
	';
388
} elsif ($test =~ m{falcon_chill_thaw}io) {
389
	$command = '
390
	        --grammar='.$conf.'/engines/falcon/falcon_chill_thaw.yy
391
	        --mysqld=--falcon-index-chill-threshold=4K 
392
	        --mysqld=--falcon-record-chill-threshold=4K
393
	';
394
} elsif ($test =~ m{falcon_online_alter}io) {
395
	$command = '
396
	        --grammar='.$conf.'/engines/falcon/falcon_online_alter.yy
397
	';
398
} elsif ($test =~ m{falcon_ddl}io) {
399
	$command = '
400
	        --grammar='.$conf.'/engines/falcon/falcon_ddl.yy
401
	';
402
} elsif ($test =~ m{falcon_limit_compare_self}io ) {
403
	$command = '
404
		--grammar='.$conf.'/engines/falcon/falcon_nolimit.yy
405
		--threads=1
406
		--validator=Limit
407
	';
408
} elsif ($test =~ m{falcon_limit_compare_innodb}io ) {
409
	$command = '
410
		--grammar='.$conf.'/engines/falcon/limit_compare.yy
411
		--vardir1='.$vardir.'/vardir-falcon
412
		--vardir2='.$vardir.'/vardir-innodb
413
		--mysqld=--default-storage-engine=Falcon
414
		--mysqld2=--default-storage-engine=Innodb
415
		--threads=1
416
		--reporters=
417
	';
418
} elsif ($test =~ m{falcon_limit}io ) {
419
	$command = '
420
	        --grammar='.$conf.'/engines/falcon/falcon_limit.yy
421
		--mysqld=--loose-maria-pagecache-buffer-size=64M
422
	';
423
} elsif ($test =~ m{falcon_recovery}io ) {
424
	$command = '
425
	        --grammar='.$conf.'/engines/falcon/falcon_recovery.yy
426
		--gendata='.$conf.'/engines/falcon/falcon_recovery.zz
427
		--mysqld=--falcon-checkpoint-schedule="1 1 1 1 1"
428
	';
429
} elsif ($test =~ m{falcon_pagesize_32K}io ) {
430
	$command = '
431
		--grammar='.$conf.'/engines/falcon/falcon_pagesize.yy
432
		--mysqld=--falcon-page-size=32K
433
		--gendata='.$conf.'/engines/falcon/falcon_pagesize32K.zz
434
	';
435
} elsif ($test =~ m{falcon_pagesize_2K}io) {
436
	$command = '
437
		--grammar='.$conf.'/engines/falcon/falcon_pagesize.yy
438
		--mysqld=--falcon-page-size=2K
439
		--gendata='.$conf.'/engines/falcon/falcon_pagesize2K.zz
440
	';
441
} elsif ($test =~ m{falcon_select_autocommit}io) {
442
	$command = '
443
		--grammar='.$conf.'/engines/falcon/falcon_select_autocommit.yy
444
		--queries=10000000
445
	';
446
} elsif ($test =~ m{falcon_backlog}io ) {
447
	$command = '
448
		--grammar='.$conf.'/engines/falcon/falcon_backlog.yy
449
		--gendata='.$conf.'/engines/falcon/falcon_backlog.zz
450
		--mysqld=--transaction-isolation=REPEATABLE-READ
451
		--mysqld=--falcon-record-memory-max=10M
452
		--mysqld=--falcon-record-chill-threshold=1K
453
		--mysqld=--falcon-page-cache-size=128M
454
	';
455
} elsif ($test =~ m{falcon_compare_innodb}io ) {
456
        # Datatypes YEAR and TIME disabled in grammars due to Bug#45499 (InnoDB). 
457
        # Revert to falcon_data_types.{yy|zz} when that bug is resolved in relevant branches.
458
	$command = '
459
		--grammar='.$conf.'/engines/falcon/falcon_data_types_no_year_time.yy
460
		--gendata='.$conf.'/engines/falcon/falcon_data_types_no_year_time.zz
461
		--vardir1='.$vardir.'/vardir-falcon
462
		--vardir2='.$vardir.'/vardir-innodb
463
		--mysqld=--default-storage-engine=Falcon
464
		--mysqld2=--default-storage-engine=Innodb
465
		--threads=1
466
		--reporters=
467
	';
468
} elsif ($test =~ m{falcon_compare_self}io ) {
469
	$command = '
470
		--grammar='.$conf.'/engines/falcon/falcon_data_types.yy
471
		--gendata='.$conf.'/engines/falcon/falcon_data_types.zz
472
		--vardir1='.$vardir.'/'.$engine.'-vardir1
473
		--vardir2='.$vardir.'/'.$engine.'-vardir2
474
		--threads=1
475
		--reporters=
476
	';
477
#
478
# END OF FALCON-ONLY TESTS
479
#
480
} elsif ($test =~ m{innodb_repeatable_read}io ) {
481
	# Transactional test. See also falcon_repeatable_read.
482
	$command = '
483
		--grammar='.$conf.'/transactions/repeatable_read.yy
484
		--gendata='.$conf.'/transactions/transactions.zz
485
		--mysqld=--transaction-isolation=REPEATABLE-READ
486
		--validator=RepeatableRead
487
	';
488
} elsif ($test =~ m{(falcon|myisam)_blob_recovery}io ) {
489
	$command = '
490
		--grammar='.$conf.'/engines/falcon/falcon_blobs.yy
491
		--gendata='.$conf.'/engines/falcon/falcon_blobs.zz
492
		--duration=130
493
		--threads=1
494
		--reporters=Deadlock,ErrorLog,Backtrace,Recovery
495
	';
496
	if ($test =~ m{falcon}io) {
497
		# this option works with Falcon-enabled builds only
498
		$command = $command.'
499
			--mysqld=--falcon-page-cache-size=128M
500
		';
501
	}
502
} elsif ($test =~ m{(falcon|innodb|myisam)_many_indexes}io ) {
503
	$command = '
504
		--grammar='.$conf.'/engines/many_indexes.yy
505
		--gendata='.$conf.'/engines/many_indexes.zz
506
	';
507
} elsif ($test =~ m{(falcon|innodb|myisam)_tiny_inserts}io) {
508
	$command = '
509
		--gendata='.$conf.'/engines/tiny_inserts.zz
510
		--grammar='.$conf.'/engines/tiny_inserts.yy
511
		--queries=10000000
512
	';
513
} elsif ($test =~ m{innodb_transactions}io) {
514
	$command = '
515
		--grammar='.$conf.'/transactions/transactions.yy
516
		--gendata='.$conf.'/transactions/transactions.zz
517
		--mysqld=--transaction-isolation=REPEATABLE-READ
518
		--validator=DatabaseConsistency
519
	';
520
#
521
# END OF STORAGE ENGINE TESTS
522
#
523
# Keep the following tests in alphabetical order (based on letters in regex)
524
# for easy lookup.
525
#
526
} elsif ($test =~ m{^backup_.*?_simple}io) {
527
	$command = '
528
		--grammar='.$conf.'/backup/backup_simple.yy
529
		--reporters=Deadlock,ErrorLog,Backtrace
530
		--mysqld=--mysql-backup
531
	';
532
} elsif ($test =~ m{^backup_.*?_consistency}io) {
533
	$command = '
534
		--gendata='.$conf.'/backup/invariant.zz
535
		--grammar='.$conf.'/backup/invariant.yy
536
		--validator=Invariant
537
		--reporters=Deadlock,ErrorLog,Backtrace,BackupAndRestoreInvariant
538
		--mysqld=--mysql-backup
539
		--duration=600
540
		--threads=25
541
	';
542
} elsif ($test =~ m{dml_alter}io ) {
543
	$command = '
544
		--gendata='.$conf.'/engines/maria/maria.zz
545
		--grammar='.$conf.'/engines/maria/maria_dml_alter.yy
546
	';
547
} elsif ($test =~ m{^info_schema}io ) {
548
	$command = '
549
		--grammar='.$conf.'/runtime/information_schema.yy
550
		--threads=10
551
		--duration=300
552
		--mysqld=--log-output=file
553
	';
554
} elsif ($test =~ m{^mdl_stability}io ) {
555
	$command = '
556
		--grammar='.$conf.'/runtime/metadata_stability.yy
557
		--gendata='.$conf.'/runtime/metadata_stability.zz
558
		--validator=SelectStability,QueryProperties
559
		--engine=Innodb
560
		--mysqld=--innodb
561
		--mysqld=--default-storage-engine=Innodb
562
		--mysqld=--transaction-isolation=SERIALIZABLE
563
		--mysqld=--innodb-flush-log-at-trx-commit=2
564
		--mysqld=--loose-table-lock-wait-timeout=1
565
		--mysqld=--innodb-lock-wait-timeout=1
566
		--mysqld=--log-output=file
567
		--queries=1M
568
		--duration=600
569
	';
570
} elsif ($test =~ m{^mdl_deadlock}io ) {
571
    #
572
    # Should be same as mdl_stress (or mdl_stability, whichever has produced
573
    # the most deadlocks), except with higher (~default) lock_wait_timeouts.
574
    # The other variants have very low wait timeouts, making it difficult to
575
    # detect invalid deadlocks.
576
    # As per Feb-26-2010 default innodb-lock-wait-timeout=50 and
577
    # lock-wait-timeout=31536000 (bug#45225).
578
    # We may want to switch to real (implicit) defaults later.
579
    #
580
    $command = '
581
        --grammar=conf/runtime/WL5004_sql.yy
582
        --threads=10
583
        --queries=1M
584
        --duration=1200
585
        --mysqld=--innodb
586
        --mysqld=--innodb-lock-wait-timeout=50
587
        --mysqld=--lock-wait-timeout=31536000
588
        --mysqld=--log-output=file
589
    ';
590
} elsif ($test =~ m{^mdl_stress}io ) {
591
	# Seems like --gendata=conf/WL5004_data.zz unexplicably causes more test
592
	# failures, so let's leave this out of PB2 for the time being (pstoev).
593
	#
594
	# InnoDB should be loaded but the test is not per se for InnoDB, hence
595
	# no "innodb" in test name.
596
	$command = '
597
		--grammar=conf/runtime/WL5004_sql.yy
598
		--threads=10
599
		--queries=1M
600
		--duration=1800
601
		--mysqld=--innodb
602
	';
603
#
604
# opt: Optimizer tests, primarily used for 5.1 regression testing...
605
#
606
#
607
} elsif ($test =~ m{^opt_access_exp}io ) {
608
    # More queries drastically increases runtime.
609
    # We use a larger than default duration to allow even slower machines to do 
610
    # useful testing.
611
    # This test is for hitting as many table access methods as possible.
612
	$command = '
613
        --threads=1
614
        --queries=10K
615
        --gendata='.$conf.'/optimizer/range_access.zz
616
        --grammar='.$conf.'/optimizer/optimizer_access_exp.yy
617
        --duration=1200
618
	';
619
} elsif ($test =~ m{^opt_no_subquery$}io ) {
620
	$command = '
621
        --threads=1
622
        --queries=100K
623
        --grammar='.$conf.'/optimizer/optimizer_no_subquery.yy
624
        --duration=1200
625
	';
626
} elsif ($test =~ m{^opt_no_subquery_compare_50}io ) {
627
    # Compares query results from 5.1 to those from 5.0.
628
    # We do not want the Shutdown reporter (default) here, in order to be able to compare dumps, so specify --reporters.
629
	$command = '
630
        --basedir1='.$basedir.'
631
        --basedir2='.$basedirRelease50.'
632
        --vardir1='.$vardir.'/vardir-bzr
633
        --vardir2='.$vardir.'/vardir-5.0
634
        --threads=1
635
        --queries=20K
636
        --grammar='.$conf.'/optimizer/optimizer_no_subquery_portable.yy
637
        --validator=ResultsetComparatorSimplify
638
        --reporters=Deadlock,ErrorLog,Backtrace
639
        --views
640
        --duration=1200
641
	';
642
} elsif ($test =~ m{^opt_range_access}io ) {
643
    # We should use a larger than default duration to allow even slower machines to do
644
    # useful testing.
645
    # 15K queries means runtime of ~40 mins on standard desktop hardware of Apr2010.
646
    # Used to allow 45 mins (2700s) of runtime.
647
    # This caused PB2 timeouts (30 min), so duration is now set to 25 minutes.
648
    # TODO: Adjust after implementing https://blueprints.launchpad.net/randgen/+spec/heartbeat-in-output
649
	$command = '
650
        --threads=1
651
        --queries=15K
652
        --gendata='.$conf.'/optimizer/range_access.zz
653
        --grammar='.$conf.'/optimizer/range_access.yy
654
        --duration=1500
655
	';
656
} elsif ($test =~ m{^opt_subquery}io ) {
657
    # Produces large and time consuming queries, so we use a larger than default 
658
    # duration to allow even slower machines to do useful testing.
659
	$command = '
660
        --threads=1
661
        --queries=75K
662
        --grammar='.$conf.'/optimizer/optimizer_subquery.yy
663
        --duration=1200
664
	';
665
} elsif ($test =~ m{^outer_join}io ) {
666
    # Any larger queries value than 30k will cause a known/documented crash (5.1).
667
    # Produces large and time consuming queries, so we use a larger than default
668
    # duration to allow even slower machines to do useful testing.
669
	$command = '
670
        --threads=1
671
        --queries=30K
672
        --gendata='.$conf.'/optimizer/outer_join.zz
673
        --grammar='.$conf.'/optimizer/outer_join.yy
674
        --duration=1200
675
	';
676
#
677
# End of optimizer tests.
678
#
679
} elsif ($test =~ m{^partition_ddl}io ) {
680
	$command = '
681
		--grammar='.$conf.'/partitioning/partitions-ddl.yy
682
		--mysqld=--innodb
683
		--threads=1
684
		--queries=100K
685
	';
686
} elsif ($test =~ m{partn_pruning(|.valgrind)$}io ) {
687
	# reduced duration to half since gendata phase takes longer in this case
688
	$command = '
689
		--gendata='.$conf.'/partitioning/partition_pruning.zz
690
		--grammar='.$conf.'/partitioning/partition_pruning.yy
691
		--mysqld=--innodb
692
		--threads=1
693
		--queries=100000
694
		--duration=300
695
	';
696
} elsif ($test =~ m{^partn_pruning_compare_50}io) {
697
	$command = '
698
	--gendata='.$conf.'/partitioning/partition_pruning.zz
699
	--grammar='.$conf.'/partitioning/partition_pruning.yy
700
	--basedir1='.$basedir.'
701
	--basedir2='.$basedirRelease50.'
702
	--vardir1='.$vardir.'/vardir-bzr
703
	--vardir2='.$vardir.'/vardir-5.0
704
	--mysqld=--innodb
705
	--validators=ResultsetComparator
706
	--reporters=Deadlock,ErrorLog,Backtrace
707
	--threads=1
708
	--queries=10000
709
	--duration=300
710
	';
711
} elsif ($test =~ m{^rpl_.*?_simple}io) {
712
	# Not used; rpl testing needs adjustments (some of the failures this
713
	# produces are known replication issues documented in the manual).
714
	$command = '
715
		--gendata='.$conf.'/replication/replication_single_engine.zz
716
		--grammar='.$conf.'/replication/replication_simple.yy
717
		--mysqld=--log-output=table,file
718
	';
719
} elsif ($test =~ m{^rpl_.*?_complex}io) {
720
	# Not used; rpl testing needs adjustments (some of the failures this
721
	# produces are known replication issues documented in the manual).
722
	$command = '
723
		--gendata='.$conf.'/replication/replication_single_engine_pk.zz
724
		--grammar='.$conf.'/replication/replication.yy
725
		--mysqld=--log-output=table,file
726
		--mysqld=--innodb
727
	';
728
} elsif ($test =~ m{^rpl_semisync}io) {
729
	# --rpl_mode=default is used because the .YY file changes the binary log format dynamically.
730
	# --threads=1 is used to avoid any replication failures due to concurrent DDL.
731
	# --validator= line will remove the default replication Validator, which would otherwise
732
	#   report test failure when the slave I/O thread is stopped, which is OK in the context
733
	#   of this particular test.
734
735
	# Plugin file names and location vary between platforms.
736
	# See http://bugs.mysql.com/bug.php?id=49170 for details.
737
	# We search for the respective file names under basedir (recursively).
738
	# The first matching file that is found is used.
739
	# We assume that both master and slave plugins are in the same dir.
740
	# Unix file name extenstions other than .so may exist, but support for this
741
	# is not yet implemented here.
742
	my $plugin_dir;
743
	my $plugins;
744
	if (osWindows()) {
745
		my $master_plugin_name = "semisync_master.dll";
746
		$plugin_dir=findDirectory($master_plugin_name);
747
		if (not defined $plugin_dir) {
748
			carp "Unable to find semisync plugin $master_plugin_name!";
749
		}
750
		$plugins = 'rpl_semi_sync_master='.$master_plugin_name.';rpl_semi_sync_slave=semisync_slave.dll';
751
	} else {
752
		# tested on Linux and Solaris
753
		my $prefix;	# for Bug#48351
754
		my $master_plugin_name = "semisync_master.so";
755
		$plugin_dir=findDirectory($master_plugin_name);
756
		if (not defined $plugin_dir) {
757
			# Until fix for Bug#48351 is widespread it may happen
758
			# that the Unix plugin names are prefixed with "lib".
759
			# Remove this when no longer needed.
760
			$prefix = 'lib';
761
			$plugin_dir=findDirectory($prefix.$master_plugin_name);
762
			if (not defined $plugin_dir) {
763
				carp "Unable to find semisync plugin! ($master_plugin_name or $prefix$master_plugin_name)";
764
			}
765
		}
766
		$plugins = 'rpl_semi_sync_master='.$prefix.$master_plugin_name.':rpl_semi_sync_slave='.$prefix.'semisync_slave.so';
767
	}
768
	$command = '
769
		--gendata='.$conf.'/replication/replication_single_engine.zz
770
		--engine=InnoDB
771
		--grammar='.$conf.'/replication/replication_simple.yy
772
		--rpl_mode=default
773
		--mysqld=--plugin-dir='.$plugin_dir.'
774
		--mysqld=--plugin-load='.$plugins.'
775
		--mysqld=--rpl_semi_sync_master_enabled=1
776
		--mysqld=--rpl_semi_sync_slave_enabled=1
777
		--mysqld=--innodb
778
		--reporters=ReplicationSemiSync,Deadlock,Backtrace,ErrorLog
779
		--validators=None
780
		--threads=1
781
		--duration=300
782
		--queries=1M
783
	';
784
} elsif ($test =~ m{signal_resignal}io ) {
785
	$command = '
786
		--threads=10
787
		--queries=1M
788
		--duration=300
789
		--grammar='.$conf.'/runtime/signal_resignal.yy
790
		--mysqld=--max-sp-recursion-depth=10
791
	';
792
} elsif ($test =~ m{(innodb|maria|myisam)_stress}io ) {
793
	$command = '
794
		--grammar='.$conf.'/engines/maria/maria_stress.yy
795
	';
796
} elsif ($test =~ m{example}io ) {
797
    # this is here for the purpose testing this script
798
	$command = '
799
		--grammar='.$conf.'/examples/example.yy
800
        --threads=1
801
        --duration=40
802
        --queries=10000
803
	';
804
}else {
805
	say("[ERROR]: Test configuration for test name '$test' is not ".
806
		"defined in this script.\n");
807
	my $exitCode = 1;
808
	say("Will exit $0 with exit code $exitCode.\n");
809
	POSIX::_exit ($exitCode);
810
}
811
812
#
813
# Specify some "default" Reporters if none have been specified already.
814
# The RQG itself also specifies some default values for some options if not set.
815
#
816
if ($command =~ m{--reporters}io) {
817
	# Reporters have already been specified	
818
} elsif ($test =~ m{rpl}io ) {
819
	# Don't include Recovery for replication tests, because
820
	$command = $command.' --reporters=Deadlock,ErrorLog,Backtrace';
821
} elsif ($test =~ m{falcon}io ) {
822
	# Include the Recovery reporter for Falcon tests in order to test
823
	# recovery by default after each such test.
824
	$command = $command.' --reporters=Deadlock,ErrorLog,Backtrace,Recovery,Shutdown';
825
	# Falcon-only options (avoid "unknown variable" warnings in non-Falcon builds)
826
	$command = $command.' --mysqld=--loose-falcon-lock-wait-timeout=5 --mysqld=--loose-falcon-debug-mask=2';
827
} else {
828
	# Default reporters for tests whose name does not contain "rpl" or "falcon"
829
	# Not using Shutdown reporter as it is not compatible with runall-new.pl (which shuts down its own server).
830
	$command = $command.' --reporters=Deadlock,ErrorLog,Backtrace';
831
}
832
833
#
834
# Other defaults...
835
#
836
837
if ($command !~ m{--duration}io ) {
838
	# Set default duration for tests where duration is not specified.
839
	# In PB2 we cannot run tests for too long since there are many branches
840
	# and many pushes (or other test triggers).
841
	# Setting it to 10 minutes for now.
842
	$command = $command.' --duration=600';
843
}
844
845
if ($command !~ m{--basedir}io ) {
846
	$command = $command." --basedir=\"$basedir\"";
847
}
848
849
if ($command !~ m{--vardir}io && $command !~ m{--mem}io ) {
850
	$command = $command." --vardir=\"$vardir\"";
851
}
852
853
# Logging to file is faster than table. And we want some form of logging.
854
# This option is not present in versions prior to 5.1.6, so skipping for 5.0.
855
if ($command !~ m{--log-output}io) {
856
	if (!$version50) {
857
		$command = $command.' --mysqld=--log-output=file';
858
	} 
859
}
860
861
# 1s to enable increased concurrency. NOTE: Removed in MySQL 5.5, Feb 2010.
862
if ($command !~ m{table-lock-wait-timeout}io) {
863
    $command = $command.' --mysqld=--loose-table-lock-wait-timeout=1';
864
}
865
866
# 1s to enable increased concurrency. NOTE: Added in MySQL 5.5, Feb 2010 (bug#45225).
867
# Default value in the server is 1 year.
868
if ($command !~ m{(--|--loose-)lock-wait-timeout}io) {
869
    $command = $command.' --mysqld=--loose-lock-wait-timeout=1';
870
}
871
872
# Decrease from default (50s) to 1s to enable increased concurrency.
873
if ($command !~ m{innodb-lock-wait-timeout}io) {
874
    $command = $command.' --mysqld=--loose-innodb-lock-wait-timeout=1';
875
}
876
877
if ($command !~ m{--queries}io) {
878
	$command = $command.' --queries=100000';
879
}
880
881
if (($command !~ m{--(engine|default-storage-engine)}io) && (defined $engine)) {
882
	$command = $command." --engine=$engine";
883
}
884
885
# if test name contains "innodb", add the --mysqld=--innodb and --engine=innodb 
886
# options if they are not there already.
887
if ( ($test =~ m{innodb}io) ){
888
	if ($command !~ m{mysqld=--innodb}io){
889
		$command = $command.' --mysqld=--innodb';
890
	}
891
	if ($command !~ m{engine=innodb}io){
892
		$command = $command.' --engine=innodb';
893
	}
894
}
895
896
if (($command !~ m{--rpl_mode}io)  && ($rpl_mode ne '')) {
897
	$command = $command." --rpl_mode=$rpl_mode";
898
}
899
900
# if test name contains (usually ends with) "valgrind", add the valgrind option to runall.pl
901
if ($test =~ m{valgrind}io){
902
	say("Detected that this test should enable valgrind instrumentation.\n");
903
	if (system("valgrind --version")) {
904
		say("  *** valgrind executable not found! Not setting --valgrind flag.\n");
905
	} else {
906
		$command = $command.' --valgrind';
907
	}
908
}
909
	
910
$command = "perl runall-new.pl --mysqld=--loose-skip-safemalloc ".$command;
911
912
### XML reporting setup START
913
914
# Pass test name to RQG, for reporting purposes
915
$command = $command." --testname=".$test_name;
916
917
# Enable XML reporting to TestTool.
918
# For now only on given hosts...
919
my %report_xml_from_hosts = (
920
    'loki06'   => '',
921
    'nanna21'  => '',
922
    'techra22' => '',
923
    'tor06-z1' => '',
924
    'tyr41'    => ''
925
);
926
my $hostname = hostname();
927
my $xmlfile;
928
my $delete_xmlfile = 0; # boolean indicator whether to delete local XML file.
929
if (exists $report_xml_from_hosts{$hostname}) {
930
    # We should enable XML reporting on this host...
931
    say("XML reporting to TestTool automatically enabled based on hostname.");
932
    # We need to write the XML to a file before sending to reporting framework.
933
    # This is done by specifying xml-output option.
934
    # TMPDIR should be set by Pushbuild to indicate a suitable location for temp files.
935
    # GenTest looks for other tmpdir alternatives.
936
    my $tmpdir = $ENV{'TMPDIR'} || tmpdir();
937
    if (length($tmpdir) > 1) {
938
        # tmpdir may or may not end with a file separator. Make sure it does.
939
        $tmpdir = $tmpdir.'/' if ($tmpdir =~ m{[^\/\\]+$});
940
        $xmlfile = $tmpdir.$test_name.'.xml';
941
    } else {
942
        # tmpdir not found. Write report to current directory.
943
        say("A suitable tmpdir was not found. Writing temporary files to current directory");
944
        # This file should be deleted after test end so that disks won't fill up.
945
        $delete_xmlfile = 1;
946
        $xmlfile = $test_name.'.xml';
947
    }
948
    # Enable XML reporting to TT (assuming this is not already enabled):
949
    $command = $command.' --xml-output='.$xmlfile.' --report-xml-tt';
950
    # Specify XML reporting transport type (not relying on defaults):
951
    # We assume SSH keys have been properly set up to enable seamless scp use.
952
    $command = $command.' --report-xml-tt-type=scp';
953
    # Specify destination for XML reports (not relying on defaults):
954
    $command = $command.' --report-xml-tt-dest=regin.norway.sun.com:/raid/xml_results/TestTool/xml/';
955
}
956
### XML reporting setup END
957
958
959
# Add env variable to specify unique port range to use to avoid conflicts.
960
# Trying not to do this unless actually needed.
961
if (defined $port_range_id) {
962
	say("MTR_BUILD_THREAD=$port_range_id\n");
963
	if (osWindows()) {
964
		$command = "set MTR_BUILD_THREAD=$port_range_id && ".$command;
965
	} else {
966
		$command = "MTR_BUILD_THREAD=$port_range_id ".$command;
967
	}
968
}
969
970
$command =~ s{[\r\n\t]}{ }sgio;
971
say("Running runall-new.pl...\n");
972
my $command_result = system($command);
973
# shift result code to the right to obtain the code returned from the called script
974
my $command_result_shifted = ($command_result >> 8);
975
976
# Report test result in an MTR fashion so that PB2 will see it and add to
977
# xref database etc.
978
# Format: TESTSUITE.TESTCASE 'TESTMODE' [ RESULT ]
979
# Example: ndb.ndb_dd_alter 'InnoDB plugin'     [ fail ]
980
# Not using TESTMODE for now.
981
982
my $full_test_name = $test_suite_name.'.'.$test_name;
983
# keep test statuses more or less vertically aligned
984
while (length $full_test_name < 40)
985
{
986
	$full_test_name = $full_test_name.' ';
987
}
988
989
if ($command_result_shifted > 0) {
990
	# test failed
991
	# Trying out marking a test as "experimental" by reporting exp-fail:
992
	# Mark all failures in next-mr-johnemb as experimental (temporary).
993
	if ($ENV{BRANCH_NAME} =~ m{mysql-next-mr-johnemb}) {
994
		print($full_test_name." [ exp-fail ]\n");
995
	} else {
996
		print($full_test_name." [ fail ]\n");
997
	}
998
	say('runall.pl failed with exit code '.$command_result_shifted."\n");
999
	say("Look above this message in the test log for failure details.\n");
1000
} else {
1001
	print($full_test_name." [ pass ]\n");
1002
}
1003
1004
if ($delete_xmlfile && -e $xmlfile) {
1005
    unlink $xmlfile;
1006
    say("Temporary XML file $xmlfile deleted");
1007
}
1008
1009
# Kill remaining mysqld processes.
1010
# Assuming only one test run going on at the same time, and that all mysqld
1011
# processes are ours.
1012
say("Checking for remaining mysqld processes...\n");
1013
if (osWindows()) {
1014
	# assumes MS Sysinternals PsTools is installed in C:\bin
1015
	# If you need to run pslist or pskill as non-Admin user, some adjustments
1016
	# may be needed. See:
1017
	#   http://blogs.technet.com/markrussinovich/archive/2007/07/09/1449341.aspx
1018
	if (system('C:\bin\pslist mysqld') == 0) {
1019
		say(" ^--- Found running mysqld process(es), to be killed if possible.\n");
1020
		system('C:\bin\pskill mysqld > '.$vardir.'/pskill_mysqld.out 2>&1');
1021
		system('C:\bin\pskill mysqld-nt > '.$vardir.'/pskill_mysqld-nt.out 2>&1');
1022
	} else { say("  None found.\n"); }
1023
	
1024
} else {
1025
	# Unix/Linux.
1026
	# Avoid "bad argument count" messages from kill by checking if process exists first.
1027
	if (system("pgrep mysqld") == 0) {
1028
		say(" ^--- Found running mysqld process(es), to be killed if possible.\n");
1029
		system("pgrep mysqld | xargs kill -15"); # "soft" kill
1030
		sleep(5);
1031
		if (system("pgrep mysqld > /dev/null") == 0) {
1032
			# process is still around...
1033
			system("pgrep mysqld | xargs kill -9"); # "hard" kill
1034
		}
1035
	} else { say("  None found.\n"); }
1036
}
1037
1038
say(" [$$] $0 will exit with exit status ".$command_result_shifted."\n");
1039
POSIX::_exit ($command_result_shifted);