110
110
my $opt_tmpdir; # Path to use for tmp/ dir
111
111
my $opt_tmpdir_pid;
114
119
if ( defined $opt_tmpdir_pid and $opt_tmpdir_pid == $$ )
116
# Remove the tempdir this process has created
117
mtr_verbose("Removing tmpdir '$opt_tmpdir");
121
if (!$opt_start_exit)
123
# Remove the tempdir this process has created
124
mtr_verbose("Removing tmpdir $opt_tmpdir");
129
mtr_warning("tmpdir $opt_tmpdir should be removed after the server has finished");
187
199
my $config; # The currently running config
188
200
my $current_config_name; # The currently running config file template
190
our $opt_experimental;
191
our $experimental_test_cases;
202
our @opt_experimentals;
203
our $experimental_test_cases= [];
194
206
# $opt_build_thread may later be set from $opt_port_base
212
224
my $opt_shutdown_timeout= $ENV{MTR_SHUTDOWN_TIMEOUT} || 10; # seconds
213
225
my $opt_start_timeout = $ENV{MTR_START_TIMEOUT} || 180; # seconds
215
sub testcase_timeout { return $opt_testcase_timeout * 60; };
216
227
sub suite_timeout { return $opt_suite_timeout * 60; };
217
228
sub check_timeout { return $opt_testcase_timeout * 6; };
222
230
my $opt_wait_all;
223
232
my $opt_repeat= 1;
224
233
my $opt_retry= 3;
225
234
my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2);
226
235
my $opt_reorder= 1;
236
my $opt_force_restart= 0;
228
238
my $opt_strace_client;
240
250
my $opt_debug_sync_timeout= 300; # Default timeout for WAIT_FOR actions.
252
sub testcase_timeout ($) {
254
if (exists $tinfo->{'case-timeout'}) {
255
# Return test specific timeout if *longer* that the general timeout
256
my $test_to= $tinfo->{'case-timeout'};
257
$test_to*= 10 if $opt_valgrind;
258
return $test_to * 60 if $test_to > $opt_testcase_timeout;
260
return $opt_testcase_timeout * 60;
242
263
our $opt_warnings= 1;
244
our $opt_skip_ndbcluster= 0;
265
our $opt_include_ndbcluster= 0;
266
our $opt_skip_ndbcluster= 1;
247
269
my $exe_ndb_mgmd;
345
367
mtr_report("Using parallel: $opt_parallel");
370
if ($opt_parallel > 1 && $opt_start_exit) {
371
mtr_warning("Parallel and --start-and-exit cannot be combined\n" .
372
"Setting parallel to 1");
348
376
# Create server socket on any free port
349
377
my $server = new IO::Socket::INET
385
413
my $completed= run_test_server($server, $tests, $opt_parallel);
415
exit(0) if $opt_start_exit;
387
417
# Send Ctrl-C to any children still running
388
418
kill("INT", keys(%children));
557
587
if ($test_has_failed and $retries <= $opt_retry){
558
588
# Test should be run one more time unless it has failed
559
589
# too many times already
590
my $tname= $result->{name};
560
591
my $failures= $result->{failures};
561
592
if ($opt_retry > 1 and $failures >= $opt_retry_failure){
562
mtr_report("\nTest has failed $failures times,",
593
mtr_report("\nTest $tname has failed $failures times,",
563
594
"no more retries!\n");
566
mtr_report("\nRetrying test, attempt($retries/$opt_retry)...\n");
597
mtr_report("\nRetrying test $tname, ".
598
"attempt($retries/$opt_retry)...\n");
567
599
delete($result->{result});
568
600
$result->{retries}= $retries+1;
569
601
$result->write_test($sock, 'TESTCASE');
634
# Prefer same configuration, or just use next if --noreorder
635
if (!$opt_reorder or (defined $result and
636
$result->{template_path} eq $t->{template_path}))
638
#mtr_report("Test uses same config => good match");
639
# Test uses same config => good match
640
$next= splice(@$tests, $i, 1);
644
666
# Second best choice is the first that does not fulfill
645
667
# any of the above conditions
646
668
if (!defined $second_best){
647
669
#mtr_report("Setting second_best to $i");
648
670
$second_best= $i;
673
# Smart allocation of next test within this thread.
675
if ($opt_reorder and $opt_parallel > 1 and defined $result)
677
my $wid= $result->{worker};
678
# Reserved for other thread, try next
679
next if (defined $t->{reserved} and $t->{reserved} != $wid);
680
if (! defined $t->{reserved})
682
# Force-restart not relevant when comparing *next* test
683
$t->{criteria} =~ s/force-restart$/no-restart/;
684
my $criteria= $t->{criteria};
685
# Reserve similar tests for this worker, but not too many
686
my $maxres= (@$tests - $i) / $opt_parallel + 1;
687
for (my $j= $i+1; $j <= $i + $maxres; $j++)
689
my $tt= $tests->[$j];
690
last unless defined $tt;
691
last if $tt->{criteria} ne $criteria;
692
$tt->{reserved}= $wid;
697
# At this point we have found next suitable test
698
$next= splice(@$tests, $i, 1);
652
702
# Use second best choice if no other test has been found
655
705
mtr_error("Internal error, second best too large($second_best)")
656
706
if $second_best > $#$tests;
657
707
$next= splice(@$tests, $second_best, 1);
708
delete $next->{reserved};
661
#$next->print_test();
712
# We don't need this any more
713
delete $next->{criteria};
662
714
$next->write_test($sock, 'TESTCASE');
663
715
$running{$next->key()}= $next;
664
716
$num_ndb_tests++ if ($next->{ndb_test});
741
793
delete($test->{'comment'});
742
794
delete($test->{'logfile'});
796
# A sanity check. Should this happen often we need to look at it.
797
if (defined $test->{reserved} && $test->{reserved} != $thread_num) {
798
my $tres= $test->{reserved};
799
mtr_warning("Test reserved for w$tres picked up by w$thread_num");
744
801
$test->{worker} = $thread_num if $opt_parallel > 1;
746
803
run_testcase($test);
828
885
# Control what test suites or cases to run
829
886
'force' => \$opt_force,
830
887
'with-ndbcluster-only' => \&collect_option,
888
'include-ndbcluster' => \$opt_include_ndbcluster,
831
889
'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster,
832
890
'suite|suites=s' => \$opt_suites,
833
891
'skip-rpl' => \&collect_option,
837
895
'big-test' => \$opt_big_test,
838
896
'combination=s' => \@opt_combinations,
839
897
'skip-combinations' => \&collect_option,
840
'experimental=s' => \$opt_experimental,
898
'experimental=s' => \@opt_experimentals,
841
899
'skip-im' => \&ignore_option,
904
962
'report-features' => \$opt_report_features,
905
963
'comment=s' => \$opt_comment,
906
964
'fast' => \$opt_fast,
965
'force-restart' => \$opt_force_restart,
907
966
'reorder!' => \$opt_reorder,
908
967
'enable-disabled' => \&collect_option,
909
968
'verbose+' => \$opt_verbose,
910
969
'verbose-restart' => \&report_option,
911
970
'sleep=i' => \$opt_sleep,
912
971
'start-dirty' => \$opt_start_dirty,
972
'start-and-exit' => \$opt_start_exit,
913
973
'start' => \$opt_start,
974
'user-args' => \$opt_user_args,
914
975
'wait-all' => \$opt_wait_all,
915
976
'print-testcases' => \&collect_option,
916
977
'repeat=i' => \$opt_repeat,
1018
1079
mtr_print_thick_line('#');
1021
if ( $opt_experimental )
1082
if ( @opt_experimentals )
1023
1084
# $^O on Windows considered not generic enough
1024
1085
my $plat= (IS_WINDOWS) ? 'windows' : $^O;
1026
# read the list of experimental test cases from the file specified on
1087
# read the list of experimental test cases from the files specified on
1027
1088
# the command line
1028
open(FILE, "<", $opt_experimental) or mtr_error("Can't read experimental file: $opt_experimental");
1029
mtr_report("Using experimental file: $opt_experimental");
1030
1089
$experimental_test_cases = [];
1033
# remove comments (# foo) at the beginning of the line, or after a
1034
# blank at the end of the line
1036
# If @ platform specifier given, use this entry only if it contains
1037
# @<platform> or @!<xxx> where xxx != platform
1040
next if (/\@!$plat/);
1041
next unless (/\@$plat/ or /\@!/);
1042
# Then remove @ and everything after it
1048
# if nothing left, don't need to remember this line
1052
# remember what is left as the name of another test case that should be
1053
# treated as experimental
1055
push @$experimental_test_cases, $_;
1090
foreach my $exp_file (@opt_experimentals)
1092
open(FILE, "<", $exp_file)
1093
or mtr_error("Can't read experimental file: $exp_file");
1094
mtr_report("Using experimental file: $exp_file");
1097
# remove comments (# foo) at the beginning of the line, or after a
1098
# blank at the end of the line
1100
# If @ platform specifier given, use this entry only if it contains
1101
# @<platform> or @!<xxx> where xxx != platform
1104
next if (/\@!$plat/);
1105
next unless (/\@$plat/ or /\@!/);
1106
# Then remove @ and everything after it
1112
# if nothing left, don't need to remember this line
1116
# remember what is left as the name of another test case that should be
1117
# treated as experimental
1119
push @$experimental_test_cases, $_;
1060
1125
foreach my $arg ( @ARGV )
1316
1381
# --------------------------------------------------------------------------
1317
1382
# Modified behavior with --start options
1318
1383
# --------------------------------------------------------------------------
1319
if ($opt_start or $opt_start_dirty) {
1384
if ($opt_start or $opt_start_dirty or $opt_start_exit) {
1320
1385
collect_option ('quick-collect', 1);
1321
1386
$start_only= 1;
1324
1389
# --------------------------------------------------------------------------
1390
# Check use of user-args
1391
# --------------------------------------------------------------------------
1393
if ($opt_user_args) {
1394
mtr_error("--user-args only valid with --start options")
1396
mtr_error("--user-args cannot be combined with named suites or tests")
1397
if $opt_suites || @opt_cases;
1400
# --------------------------------------------------------------------------
1325
1401
# Check use of wait-all
1326
1402
# --------------------------------------------------------------------------
1328
1404
if ($opt_wait_all && ! $start_only)
1330
mtr_error("--wait-all can only be used with --start or --start-dirty");
1406
mtr_error("--wait-all can only be used with --start options");
1333
1409
# --------------------------------------------------------------------------
2060
2136
# to detect that valgrind is being used from test cases
2061
2137
$ENV{'VALGRIND_TEST'}= $opt_valgrind;
2139
# Add dir of this perl to aid mysqltest in finding perl
2140
my $perldir= dirname($^X);
2142
$pathsep= ";" if IS_WINDOWS && ! IS_CYGWIN;
2143
$ENV{'PATH'}= "$ENV{'PATH'}".$pathsep.$perldir;
2335
2416
sub check_ndbcluster_support ($) {
2336
2417
my $mysqld_variables= shift;
2419
if ($opt_include_ndbcluster)
2421
$opt_skip_ndbcluster= 0;
2338
2424
if ($opt_skip_ndbcluster)
2340
2426
mtr_report(" - skipping ndbcluster");
2988
3075
foreach my $mysqld ( mysqlds() )
2990
if ( defined $mysqld->{'proc'} )
3077
# Skip if server has been restarted with additional options
3078
if ( defined $mysqld->{'proc'} && ! exists $mysqld->{'restart_opts'} )
2992
3080
my $proc= start_check_testcase($tinfo, $mode, $mysqld);
2993
3081
$started{$proc->pid()}= $proc;
3040
3128
"\nMTR's internal check of the test case '$tname' failed.
3041
3129
This means that the test case does not preserve the state that existed
3042
3130
before the test case was executed. Most likely the test case did not
3043
do a proper clean-up.
3131
do a proper clean-up. It could also be caused by the previous test run
3132
by this thread, if the server wasn't restarted.
3044
3133
This is the diff of the states of the servers before and after the
3045
3134
test case was executed:\n";
3046
3135
$tinfo->{check}.= $report;
3082
3171
# Kill any check processes still running
3083
3172
map($_->kill(), values(%started));
3174
mtr_warning("Check-testcase failed, this could also be caused by the" .
3175
" previous test run by this worker thread")
3176
if $result > 1 && $mode eq "before";
3085
3178
return $result;
3349
3442
$config= My::ConfigFactory->new_config
3351
3444
basedir => $basedir,
3445
testdir => $glob_mysql_test_dir,
3352
3446
template_path => $tinfo->{template_path},
3353
3447
extra_template_path => $tinfo->{extra_template_path},
3354
3448
vardir => $opt_vardir,
3409
3503
mtr_print ($mysqld->name() . " " . $mysqld->value('port') .
3410
3504
" " . $mysqld->value('socket'));
3506
if ( $opt_start_exit )
3508
mtr_print("Server(s) started, not waiting for them to finish");
3511
POSIX::_exit(0); # exit hangs here in ActiveState Perl
3412
3518
mtr_print("Waiting for server(s) to exit...");
3413
3519
if ( $opt_wait_all ) {
3414
3520
My::SafeProcess->wait_all();
3521
3627
# Try to get reason from test log file
3522
3628
find_testcase_skipped_reason($tinfo);
3523
3629
mtr_report_test_skipped($tinfo);
3630
# Restart if skipped due to missing perl, it may have had side effects
3631
stop_all_servers($opt_shutdown_timeout)
3632
if ($tinfo->{'comment'} =~ /^perl not found/);
3525
3634
elsif ( $res == 65 )
3636
3745
"== $log_file_name == \n".
3637
3746
mtr_lastlinesfromfile($log_file_name, 20)."\n";
3639
$tinfo->{'timeout'}= testcase_timeout(); # Mark as timeout
3748
$tinfo->{'timeout'}= testcase_timeout($tinfo); # Mark as timeout
3640
3749
run_on_all($tinfo, 'analyze-timeout');
3642
3751
report_failure_and_restart($tinfo);
3719
3828
foreach my $mysqld (mysqlds()) {
3720
3829
if ($mysqld->{proc} eq $proc) {
3721
3830
my @srv_lines= extract_server_log($mysqld->value('#log-error'), $name);
3722
$srv_log= "\nServer log from this test:\n" . join ("", @srv_lines);
3831
$srv_log= "\nServer log from this test:\n" .
3832
"----------SERVER LOG START-----------\n". join ("", @srv_lines) .
3833
"----------SERVER LOG END-------------\n";
3759
3870
if ($opt_valgrind_mysqld) {
3760
3871
# Skip valgrind summary from tests where server has been restarted
3761
3872
# Should this contain memory leaks, the final report will find it
3762
$skip_valgrind= 1 if $line =~ /^==\d+== ERROR SUMMARY:/;
3873
# Use a generic pattern for summaries
3874
$skip_valgrind= 1 if $line =~ /^==\d+== [A-Z ]+ SUMMARY:/;
3763
3875
$skip_valgrind= 0 unless $line =~ /^==\d+==/;
3764
3876
next if $skip_valgrind;
4084
# If last line begins "restart:", the rest of the line is read as
4085
# extra command line options to add to the restarted mysqld.
4086
# Anything other than 'wait' or 'restart:' (with a colon) will
4087
# result in a restart with original mysqld options.
4088
if ($last_line =~ /restart:(.+)/) {
4089
my @rest_opt= split(' ', $1);
4090
$mysqld->{'restart_opts'}= \@rest_opt;
4092
delete $mysqld->{'restart_opts'};
3972
4094
unlink($expect_file);
3974
4096
# Start server with same settings as last time
4285
4407
# Enable the debug sync facility, set default wait timeout.
4286
4408
# Facility stays disabled if timeout value is zero.
4287
4409
mtr_add_arg($args, "--loose-debug-sync-timeout=%s",
4288
$opt_debug_sync_timeout);
4410
$opt_debug_sync_timeout) unless $opt_user_args;
4315
4437
mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
4316
mysqld_arguments($args,$mysqld,$extra_opts);
4439
# Add any additional options from an in-test restart
4440
my @all_opts= @$extra_opts;
4441
if (exists $mysqld->{'restart_opts'}) {
4442
push (@all_opts, @{$mysqld->{'restart_opts'}});
4444
mysqld_arguments($args,$mysqld,\@all_opts);
4318
4446
if ( $opt_debug )
4574
if ( $opt_force_restart ) {
4575
mtr_verbose_restart($server, "forced restart turned on");
4446
4579
if ( $tinfo->{template_path} ne $current_config_name)
4448
4581
mtr_verbose_restart($server, "using different config file");
4477
# Temporary re-enable the "always restart slave" hack
4478
# this should be removed asap, but will require that each rpl
4479
# testcase cleanup better after itself - ie. stop and reset
4481
# Use the "#!use-slave-opt" marker to detect that this is a "slave"
4483
if ( $server->option("#!use-slave-opt") ){
4484
mtr_verbose_restart($server, "Always restart slave(s)");
4488
4610
my $is_mysqld= grep ($server eq $_, mysqlds());
4489
4611
if ($is_mysqld)
4494
4616
my $extra_opts= get_extra_opts($server, $tinfo);
4495
4617
my $started_opts= $server->{'started_opts'};
4497
if (!My::Options::same($started_opts, $extra_opts) )
4619
# Also, always restart if server had been restarted with additional
4620
# options within test.
4621
if (!My::Options::same($started_opts, $extra_opts) ||
4622
exists $server->{'restart_opts'})
4499
4624
my $use_dynamic_option_switch= 0;
4500
4625
if (!$use_dynamic_option_switch)
5346
5480
force Continue to run the suite after failure
5347
5481
with-ndbcluster-only Run only tests that include "ndb" in the filename
5348
skip-ndb[cluster] Skip all tests that need cluster
5482
skip-ndb[cluster] Skip all tests that need cluster. Default.
5483
include-ndb[cluster] Enable all tests that need cluster
5349
5484
do-test=PREFIX or REGEX
5350
5485
Run test cases which name are prefixed with PREFIX
5351
5486
or fulfills REGEX
5449
5584
startup settings for the first specified test case
5451
5586
$0 --start alias &
5587
start-and-exit Same as --start, but mysql-test-run terminates and
5588
leaves just the server running
5452
5589
start-dirty Only start the servers (without initialization) for
5453
5590
the first specified test case
5591
user-args In combination with start* and no test name, drops
5592
arguments to mysqld except those speficied with
5454
5594
wait-all If --start or --start-dirty option is used, wait for all
5455
5595
servers to exit before finishing the process
5456
5596
fast Run as fast as possible, dont't wait for servers
5457
5597
to shutdown etc.
5598
force-restart Always restart servers between tests
5458
5599
parallel=N Run tests in N parallel threads (default=1)
5459
5600
Use parallel=auto for auto-setting of N
5460
5601
repeat=N Run each test N number of times