5
##############################################################################
9
# Tool used for executing a suite of .test file
11
# See the "MySQL Test framework manual" for more information
12
# http://dev.mysql.com/doc/mysqltest/en/index.html
14
# Please keep the test framework tools identical in all versions!
16
##############################################################################
18
# Coding style directions for this perl script
20
# - To make this Perl script easy to alter even for those that not
21
# code Perl that often, keeep the coding style as close as possible to
22
# the C/C++ MySQL coding standard.
24
# - All lists of arguments to send to commands are Perl lists/arrays,
25
# not strings we append args to. Within reason, most string
26
# concatenation for arguments should be avoided.
28
# - Functions defined in the main program are not to be prefixed,
29
# functions in "library files" are to be prefixed with "mtr_" (for
30
# Mysql-Test-Run). There are some exceptions, code that fits best in
31
# the main program, but are put into separate files to avoid
32
# clutter, may be without prefix.
34
# - All stat/opendir/-f/ is to be kept in collect_test_cases(). It
35
# will create a struct that the rest of the program can use to get
36
# the information. This separates the "find information" from the
37
# "do the work" and makes the program more easy to maintain.
39
# - The rule when it comes to the logic of this program is
41
# command_line_setup() - is to handle the logic between flags
42
# collect_test_cases() - is to do its best to select what tests
43
# to run, dig out options, if needs restart etc.
44
# run_testcase() - is to run a single testcase, and follow the
45
# logic set in both above. No, or rare file
46
# system operations. If a test seems complex,
47
# it should probably not be here.
49
# A nice way to trace the execution of this script while debugging
50
# is to use the Devel::Trace package found at
51
# "http://www.plover.com/~mjd/perl/Trace/" and run this script like
52
# "perl -d:Trace mysql-test-run.pl"
58
$Devel::Trace::TRACE= 0; # Don't trace boring init stuff
64
use File::Temp qw /tempdir/;
65
use File::Spec::Functions qw /splitdir/;
74
$| = 1; # Automatically flush STDOUT
76
our $glob_win32_perl= ($^O eq "MSWin32"); # ActiveState Win32 Perl
77
our $glob_cygwin_perl= ($^O eq "cygwin"); # Cygwin Perl
78
our $glob_win32= ($glob_win32_perl or $glob_cygwin_perl);
79
our $glob_netware= ($^O eq "NetWare"); # NetWare
81
require "lib/mtr_cases.pl";
82
require "lib/mtr_process.pl";
83
require "lib/mtr_timer.pl";
84
require "lib/mtr_io.pl";
85
require "lib/mtr_gcov.pl";
86
require "lib/mtr_gprof.pl";
87
require "lib/mtr_report.pl";
88
require "lib/mtr_match.pl";
89
require "lib/mtr_misc.pl";
90
require "lib/mtr_stress.pl";
91
require "lib/mtr_unique.pl";
93
$Devel::Trace::TRACE= 1;
95
##############################################################################
99
##############################################################################
101
# Misc global variables
102
our $mysql_version_id;
103
our $glob_mysql_test_dir= undef;
104
our $glob_mysql_bench_dir= undef;
105
our $glob_scriptname= undef;
106
our $glob_timers= undef;
107
our $glob_use_embedded_server= 0;
112
our $path_charsetsdir;
113
our $path_client_bindir;
118
our $path_mysqltest_log;
119
our $path_current_test_log;
120
our $path_my_basedir;
122
our $opt_vardir; # A path but set directly on cmd line
123
our $path_vardir_trace; # unix formatted opt_vardir for trace files
124
our $opt_tmpdir; # A path but set directly on cmd line
126
# Visual Studio produces executables in different sub-directories based on the
127
# configuration used to build them. To make life easier, an environment
128
# variable or command-line option may be specified to control which set of
129
# executables will be used by the test suite.
130
our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
136
our $opt_suites_default= "main,binlog,rpl"; # Default suites to run
137
our $opt_script_debug= 0; # Script debugging, enable with --script-debug
138
our $opt_verbose= 0; # Verbose output, enable with --verbose
140
our $exe_master_mysqld;
143
our $exe_mysql_upgrade;
144
our $exe_mysqlbinlog;
145
our $exe_mysql_client_test;
151
our $exe_mysqlimport;
153
our $exe_mysql_fix_system_tables;
154
our $file_mysql_fix_privilege_tables;
158
our $exe_slave_mysqld;
159
our $exe_my_print_defaults;
161
our $lib_udf_example;
162
our $lib_example_plugin;
166
our $opt_small_bench= 0;
167
our $opt_big_test= 0;
169
our @opt_combinations;
170
our $opt_skip_combination;
172
our @opt_extra_mysqld_opt;
177
our $opt_ssl_supported;
178
our $opt_ps_protocol;
179
our $opt_sp_protocol;
180
our $opt_cursor_protocol;
181
our $opt_view_protocol;
185
our @opt_cases; # The test cases names in argv
186
our $opt_embedded_server;
194
our $opt_enable_disabled;
195
our $opt_mem= $ENV{'MTR_MEM'};
201
our $glob_debugger= 0;
208
our $opt_manual_debug;
209
our $opt_mtr_build_thread=0;
211
our $opt_client_debugger;
215
our $opt_gprof_master;
216
our $opt_gprof_slave;
222
our $opt_master_myport;
223
our $opt_slave_myport;
224
our $opt_ndbcluster_port;
225
our $opt_ndbconnectstring;
226
our $opt_ndbcluster_port_slave;
227
our $opt_ndbconnectstring_slave;
230
my $opt_report_features;
231
our $opt_check_testcases;
232
our $opt_mark_progress;
235
our $max_slave_num= 0;
236
our $max_master_num= 1;
242
our $opt_testcase_timeout;
243
our $opt_suite_timeout;
244
my $default_testcase_timeout= 15; # 15 min max
245
my $default_suite_timeout= 180; # 3 hours max
247
our $opt_start_and_exit;
248
our $opt_start_dirty;
251
our $opt_strace_client;
258
my $opt_valgrind_mysqld= 0;
259
my $opt_valgrind_mysqltest= 0;
260
my @default_valgrind_args= ("--show-reachable=yes");
262
my $opt_valgrind_path;
266
our $opt_stress_suite= "main";
267
our $opt_stress_mode= "random";
268
our $opt_stress_threads= 5;
269
our $opt_stress_test_count= 0;
270
our $opt_stress_loop_count= 0;
271
our $opt_stress_test_duration= 0;
272
our $opt_stress_init_file= "";
273
our $opt_stress_test_file= "";
277
our $opt_skip_ndbcluster= 0;
278
our $opt_skip_ndbcluster_slave= 0;
279
our $opt_with_ndbcluster= 0;
280
our $opt_with_ndbcluster_only= 0;
281
our $glob_ndbcluster_supported= 0;
282
our $opt_ndb_extra_test= 0;
283
our $opt_skip_master_binlog= 0;
284
our $opt_skip_slave_binlog= 0;
288
our $path_ndb_tools_dir;
289
our $path_ndb_examples_dir;
290
our $exe_ndb_example;
291
our $path_ndb_testrun_log;
297
our $used_binlog_format;
298
our $used_default_engine;
299
our $debug_compiled_binaries;
301
our %mysqld_variables;
305
our $opt_max_save_core= 5;
306
my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far.
308
######################################################################
310
# Function declarations
312
######################################################################
315
sub initial_setup ();
316
sub command_line_setup ();
317
sub set_mtr_build_thread_ports($);
318
sub datadir_list_setup ();
319
sub executable_setup ();
320
sub environment_setup ();
321
sub kill_running_servers ();
322
sub remove_stale_vardir ();
324
sub check_ssl_support ($);
325
sub check_running_as_root();
326
sub check_ndbcluster_support ($);
327
sub rm_ndbcluster_tables ($);
328
sub ndbcluster_start_install ($);
329
sub ndbcluster_start ($$);
330
sub ndbcluster_wait_started ($$);
331
sub mysqld_wait_started($);
332
sub run_benchmarks ($);
333
sub initialize_servers ();
334
sub mysql_install_db ();
336
sub copy_install_db ($$);
337
sub run_testcase ($);
338
sub run_testcase_stop_servers ($$$);
339
sub run_testcase_start_servers ($);
340
sub run_testcase_check_skip_test($);
341
sub report_failure_and_restart ($);
342
sub do_before_start_master ($);
343
sub do_before_start_slave ($);
344
sub ndbd_start ($$$);
345
sub ndb_mgmd_start ($);
346
sub mysqld_start ($$$);
347
sub mysqld_arguments ($$$$);
348
sub stop_all_servers ();
349
sub run_mysqltest ($);
353
######################################################################
357
######################################################################
363
command_line_setup();
365
check_ndbcluster_support(\%mysqld_variables);
366
check_ssl_support(\%mysqld_variables);
367
check_debug_support(\%mysqld_variables);
386
initialize_servers();
387
run_benchmarks(shift); # Shift what? Extra arguments?!
389
elsif ( $opt_stress )
391
initialize_servers();
396
# Figure out which tests we are going to run
399
$opt_suites= $opt_suites_default;
401
# Check for any extra suites to enable based on the path name
404
"mysql-5.1-new-ndb" => "ndb_team",
405
"mysql-5.1-new-ndb-merge" => "ndb_team",
406
"mysql-5.1-telco-6.2" => "ndb_team",
407
"mysql-5.1-telco-6.2-merge" => "ndb_team",
408
"mysql-5.1-telco-6.3" => "ndb_team",
409
"mysql-6.0-ndb" => "ndb_team",
412
foreach my $dir ( reverse splitdir($glob_basedir) )
414
my $extra_suite= $extra_suites{$dir};
415
if (defined $extra_suite){
416
mtr_report("Found extra suite: $extra_suite");
417
$opt_suites= "$extra_suite,$opt_suites";
423
my $tests= collect_test_cases($opt_suites);
425
# Turn off NDB and other similar options if no tests use it
426
my ($need_ndbcluster);
427
foreach my $test (@$tests)
429
next if $test->{skip};
433
$need_ndbcluster||= $test->{ndb_test};
435
# Count max number of slaves used by a test case
436
if ( $test->{slave_num} > $max_slave_num) {
437
$max_slave_num= $test->{slave_num};
438
mtr_error("Too many slaves") if $max_slave_num > 3;
441
# Count max number of masters used by a test case
442
if ( $test->{master_num} > $max_master_num) {
443
$max_master_num= $test->{master_num};
444
mtr_error("Too many masters") if $max_master_num > 2;
445
mtr_error("Too few masters") if $max_master_num < 1;
448
$use_innodb||= $test->{'innodb_test'};
451
# Check if cluster can be skipped
452
if ( !$need_ndbcluster )
454
$opt_skip_ndbcluster= 1;
455
$opt_skip_ndbcluster_slave= 1;
458
# Check if slave cluster can be skipped
459
if ($max_slave_num == 0)
461
$opt_skip_ndbcluster_slave= 1;
464
initialize_servers();
466
if ( $opt_report_features ) {
467
run_report_features();
476
##############################################################################
480
##############################################################################
483
# When an option is no longer used by this program, it must be explicitly
484
# ignored or else it will be passed through to mysqld. GetOptions will call
485
# this subroutine once for each such option on the command line. See
486
# Getopt::Long documentation.
489
sub warn_about_removed_option {
490
my ($option, $value, $hash_value) = @_;
492
warn "WARNING: This option is no longer used, and is ignored: --$option\n";
495
sub command_line_setup () {
497
# These are defaults for things that are set on the command line
501
# Magic number -69.4 results in traditional test ports starting from 9306.
502
set_mtr_build_thread_ports(-69.4);
504
# If so requested, we try to avail ourselves of a unique build thread number.
505
if ( $ENV{'MTR_BUILD_THREAD'} ) {
506
if ( lc($ENV{'MTR_BUILD_THREAD'}) eq 'auto' ) {
507
print "Requesting build thread... ";
508
$ENV{'MTR_BUILD_THREAD'} = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
509
print "got ".$ENV{'MTR_BUILD_THREAD'}."\n";
513
if ( $ENV{'MTR_BUILD_THREAD'} )
515
set_mtr_build_thread_ports($ENV{'MTR_BUILD_THREAD'});
518
# This is needed for test log evaluation in "gen-build-status-page"
519
# in all cases where the calling tool does not log the commands
520
# directly before it executes them, like "make test-force-pl" in RPM builds.
521
print "Logging: $0 ", join(" ", @ARGV), "\n";
523
# Read the command line
524
# Note: Keep list, and the order, in sync with usage at end of this file
526
# Options that are no longer used must still be processed, because all
527
# unprocessed options are passed directly to mysqld. The user will be
528
# warned that the option is being ignored.
530
# Put the complete option string here. For example, to remove the --suite
531
# option, remove it from GetOptions() below and put 'suite|suites=s' here.
532
my @removed_options = (
533
'skip-im', # WL#4085 "Discontinue the instance manager"
536
Getopt::Long::Configure("pass_through");
538
# Control what engine/variation to run
539
'embedded-server' => \$opt_embedded_server,
540
'ps-protocol' => \$opt_ps_protocol,
541
'sp-protocol' => \$opt_sp_protocol,
542
'view-protocol' => \$opt_view_protocol,
543
'cursor-protocol' => \$opt_cursor_protocol,
544
'ssl|with-openssl' => \$opt_ssl,
545
'skip-ssl' => \$opt_skip_ssl,
546
'compress' => \$opt_compress,
547
'bench' => \$opt_bench,
548
'small-bench' => \$opt_small_bench,
549
'with-ndbcluster|ndb' => \$opt_with_ndbcluster,
550
'vs-config' => \$opt_vs_config,
552
# Control what test suites or cases to run
553
'force' => \$opt_force,
554
'with-ndbcluster-only' => \$opt_with_ndbcluster_only,
555
'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster,
556
'skip-ndbcluster-slave|skip-ndb-slave'
557
=> \$opt_skip_ndbcluster_slave,
558
'ndb-extra-test' => \$opt_ndb_extra_test,
559
'skip-master-binlog' => \$opt_skip_master_binlog,
560
'skip-slave-binlog' => \$opt_skip_slave_binlog,
561
'do-test=s' => \$opt_do_test,
562
'start-from=s' => \$opt_start_from,
563
'suite|suites=s' => \$opt_suites,
564
'skip-rpl' => \$opt_skip_rpl,
565
'skip-test=s' => \$opt_skip_test,
566
'big-test' => \$opt_big_test,
567
'combination=s' => \@opt_combinations,
568
'skip-combination' => \$opt_skip_combination,
571
'master_port=i' => \$opt_master_myport,
572
'slave_port=i' => \$opt_slave_myport,
573
'ndbcluster-port|ndbcluster_port=i' => \$opt_ndbcluster_port,
574
'ndbcluster-port-slave=i' => \$opt_ndbcluster_port_slave,
575
'mtr-build-thread=i' => \$opt_mtr_build_thread,
577
# Test case authoring
578
'record' => \$opt_record,
579
'check-testcases' => \$opt_check_testcases,
580
'mark-progress' => \$opt_mark_progress,
582
# Extra options used when starting mysqld
583
'mysqld=s' => \@opt_extra_mysqld_opt,
585
# Run test on running server
586
'extern' => \$opt_extern,
587
'ndb-connectstring=s' => \$opt_ndbconnectstring,
588
'ndb-connectstring-slave=s' => \$opt_ndbconnectstring_slave,
592
'client-gdb' => \$opt_client_gdb,
593
'manual-gdb' => \$opt_manual_gdb,
594
'manual-debug' => \$opt_manual_debug,
596
'client-ddd' => \$opt_client_ddd,
597
'manual-ddd' => \$opt_manual_ddd,
598
'debugger=s' => \$opt_debugger,
599
'client-debugger=s' => \$opt_client_debugger,
600
'strace-client' => \$opt_strace_client,
601
'master-binary=s' => \$exe_master_mysqld,
602
'slave-binary=s' => \$exe_slave_mysqld,
603
'max-save-core=i' => \$opt_max_save_core,
605
# Coverage, profiling etc
606
'gcov' => \$opt_gcov,
607
'gprof' => \$opt_gprof,
608
'valgrind|valgrind-all' => \$opt_valgrind,
609
'valgrind-mysqltest' => \$opt_valgrind_mysqltest,
610
'valgrind-mysqld' => \$opt_valgrind_mysqld,
611
'valgrind-options=s' => sub {
612
my ($opt, $value)= @_;
613
# Deprecated option unless it's what we know pushbuild uses
614
if ($value eq "--gen-suppressions=all --show-reachable=yes") {
615
push(@valgrind_args, $_) for (split(' ', $value));
618
die("--valgrind-options=s is deprecated. Use ",
619
"--valgrind-option=s, to be specified several",
620
" times if necessary");
622
'valgrind-option=s' => \@valgrind_args,
623
'valgrind-path=s' => \$opt_valgrind_path,
624
'callgrind' => \$opt_callgrind,
627
'stress' => \$opt_stress,
628
'stress-suite=s' => \$opt_stress_suite,
629
'stress-threads=i' => \$opt_stress_threads,
630
'stress-test-file=s' => \$opt_stress_test_file,
631
'stress-init-file=s' => \$opt_stress_init_file,
632
'stress-mode=s' => \$opt_stress_mode,
633
'stress-loop-count=i' => \$opt_stress_loop_count,
634
'stress-test-count=i' => \$opt_stress_test_count,
635
'stress-test-duration=i' => \$opt_stress_test_duration,
638
'tmpdir=s' => \$opt_tmpdir,
639
'vardir=s' => \$opt_vardir,
640
'benchdir=s' => \$glob_mysql_bench_dir,
644
'report-features' => \$opt_report_features,
645
'comment=s' => \$opt_comment,
646
'debug' => \$opt_debug,
647
'fast' => \$opt_fast,
648
'reorder' => \$opt_reorder,
649
'enable-disabled' => \$opt_enable_disabled,
650
'script-debug' => \$opt_script_debug,
651
'verbose' => \$opt_verbose,
652
'sleep=i' => \$opt_sleep,
653
'socket=s' => \$opt_socket,
654
'start-dirty' => \$opt_start_dirty,
655
'start-and-exit' => \$opt_start_and_exit,
656
'timer!' => \$opt_timer,
657
'user=s' => \$opt_user,
658
'testcase-timeout=i' => \$opt_testcase_timeout,
659
'suite-timeout=i' => \$opt_suite_timeout,
660
'warnings|log-warnings' => \$opt_warnings,
662
# Options which are no longer used
663
(map { $_ => \&warn_about_removed_option } @removed_options),
665
'help|h' => \$opt_usage,
666
) or usage("Can't read options");
668
usage("") if $opt_usage;
670
$glob_scriptname= basename($0);
672
if ($opt_mtr_build_thread != 0)
674
set_mtr_build_thread_ports($opt_mtr_build_thread)
676
elsif ($ENV{'MTR_BUILD_THREAD'})
678
$opt_mtr_build_thread= $ENV{'MTR_BUILD_THREAD'};
681
# We require that we are in the "mysql-test" directory
682
# to run mysql-test-run
683
if (! -f $glob_scriptname)
685
mtr_error("Can't find the location for the mysql-test-run script\n" .
686
"Go to to the mysql-test directory and execute the script " .
687
"as follows:\n./$glob_scriptname");
695
# Find the absolute path to the test directory
696
$glob_mysql_test_dir= cwd();
697
if ( $glob_cygwin_perl )
699
# Windows programs like 'mysqld' needs Windows paths
700
$glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`;
701
chomp($glob_mysql_test_dir);
703
$default_vardir= "$glob_mysql_test_dir/var";
705
# In most cases, the base directory we find everything relative to,
706
# is the parent directory of the "mysql-test" directory. For source
707
# distributions, TAR binary distributions and some other packages.
708
$glob_basedir= dirname($glob_mysql_test_dir);
710
# In the RPM case, binaries and libraries are installed in the
711
# default system locations, instead of having our own private base
712
# directory. And we install "/usr/share/mysql-test". Moving up one
713
# more directory relative to "mysql-test" gives us a usable base
714
# directory for RPM installs.
715
if ( ! $source_dist and ! -d "$glob_basedir/bin" )
717
$glob_basedir= dirname($glob_basedir);
720
# Expect mysql-bench to be located adjacent to the source tree, by default
721
$glob_mysql_bench_dir= "$glob_basedir/../mysql-bench"
722
unless defined $glob_mysql_bench_dir;
723
$glob_mysql_bench_dir= undef
724
unless -d $glob_mysql_bench_dir;
727
$source_dist ? $glob_mysql_test_dir : $glob_basedir;
729
$glob_timers= mtr_init_timers();
731
# --------------------------------------------------------------------------
732
# Embedded server flag
733
# --------------------------------------------------------------------------
734
if ( $opt_embedded_server )
736
$glob_use_embedded_server= 1;
737
# Add the location for libmysqld.dll to the path.
741
mtr_path_exists(vs_config_dirs('libmysqld',''));
742
$lib_mysqld= $glob_cygwin_perl ? ":".`cygpath "$lib_mysqld"`
745
$ENV{'PATH'}="$ENV{'PATH'}".$lib_mysqld;
748
push(@glob_test_mode, "embedded");
749
$opt_skip_rpl= 1; # We never run replication with embedded
750
$opt_skip_ndbcluster= 1; # Turn off use of NDB cluster
751
$opt_skip_ssl= 1; # Turn off use of SSL
753
# Turn off use of bin log
754
push(@opt_extra_mysqld_opt, "--skip-log-bin");
758
mtr_error("Can't use --extern with --embedded-server");
763
# Find the mysqld executable to be able to find the mysqld version
764
# number as early as possible
767
# Look for the client binaries directory
768
$path_client_bindir= mtr_path_exists("$glob_basedir/client_release",
769
"$glob_basedir/client_debug",
770
vs_config_dirs('client', ''),
771
"$glob_basedir/client",
772
"$glob_basedir/bin");
774
# Look for language files and charsetsdir, use same share
775
$path_share= mtr_path_exists("$glob_basedir/share/mysql",
776
"$glob_basedir/sql/share",
777
"$glob_basedir/share");
779
$path_language= mtr_path_exists("$path_share/english");
780
$path_charsetsdir= mtr_path_exists("$path_share/charsets");
785
$exe_mysqld= mtr_exe_exists (vs_config_dirs('sql', 'mysqld'),
786
vs_config_dirs('sql', 'mysqld-debug'),
787
"$glob_basedir/sql/mysqld",
788
"$path_client_bindir/mysqld-max-nt",
789
"$path_client_bindir/mysqld-max",
790
"$path_client_bindir/mysqld-nt",
791
"$path_client_bindir/mysqld",
792
"$path_client_bindir/mysqld-debug",
793
"$path_client_bindir/mysqld-max",
794
"$glob_basedir/libexec/mysqld",
795
"$glob_basedir/bin/mysqld",
796
"$glob_basedir/sbin/mysqld");
798
# Use the mysqld found above to find out what features are available
799
collect_mysqld_features();
803
$mysqld_variables{'port'}= 3306;
809
print '#' x 78, "\n";
810
print "# $opt_comment\n";
811
print '#' x 78, "\n\n";
814
foreach my $arg ( @ARGV )
816
if ( $arg =~ /^--skip-/ )
818
push(@opt_extra_mysqld_opt, $arg);
820
elsif ( $arg =~ /^--$/ )
822
# It is an effect of setting 'pass_through' in option processing
823
# that the lone '--' separating options from arguments survives,
826
elsif ( $arg =~ /^-/ )
828
usage("Invalid option \"$arg\"");
832
push(@opt_cases, $arg);
836
# --------------------------------------------------------------------------
837
# Find out type of logging that are being used
838
# --------------------------------------------------------------------------
839
if (!$opt_extern && $mysql_version_id >= 50100 )
841
foreach my $arg ( @opt_extra_mysqld_opt )
843
if ( $arg =~ /binlog[-_]format=(\S+)/ )
845
$used_binlog_format= $1;
848
if (defined $used_binlog_format)
850
mtr_report("Using binlog format '$used_binlog_format'");
854
mtr_report("Using dynamic switching of binlog format");
859
# --------------------------------------------------------------------------
860
# Find out default storage engine being used(if any)
861
# --------------------------------------------------------------------------
862
if ( $opt_with_ndbcluster )
864
# --ndb or --with-ndbcluster turns on --default-storage-engine=ndbcluster
865
push(@opt_extra_mysqld_opt, "--default-storage-engine=ndbcluster");
868
foreach my $arg ( @opt_extra_mysqld_opt )
870
if ( $arg =~ /default-storage-engine=(\S+)/ )
872
$used_default_engine= $1;
875
mtr_report("Using default engine '$used_default_engine'")
876
if defined $used_default_engine;
878
# --------------------------------------------------------------------------
879
# Check if we should speed up tests by trying to run on tmpfs
880
# --------------------------------------------------------------------------
881
if ( defined $opt_mem )
883
mtr_error("Can't use --mem and --vardir at the same time ")
885
mtr_error("Can't use --mem and --tmpdir at the same time ")
888
# Search through list of locations that are known
889
# to be "fast disks" to list to find a suitable location
890
# Use --mem=<dir> as first location to look.
891
my @tmpfs_locations= ($opt_mem, "/dev/shm", "/tmp");
893
foreach my $fs (@tmpfs_locations)
897
mtr_report("Using tmpfs in $fs");
899
$opt_mem .= $opt_mtr_build_thread if $opt_mtr_build_thread;
905
# --------------------------------------------------------------------------
906
# Set the "var/" directory, as it is the base for everything else
907
# --------------------------------------------------------------------------
910
$opt_vardir= $default_vardir;
912
elsif ( $mysql_version_id < 50000 and
913
$opt_vardir ne $default_vardir)
915
# Version 4.1 and --vardir was specified
916
# Only supported as a symlink from var/
917
# by setting up $opt_mem that symlink will be created
920
# Only platforms that have native symlinks can use the vardir trick
921
$opt_mem= $opt_vardir;
922
mtr_report("Using 4.1 vardir trick");
925
$opt_vardir= $default_vardir;
928
$path_vardir_trace= $opt_vardir;
929
# Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
930
$path_vardir_trace=~ s/^\w://;
932
# We make the path absolute, as the server will do a chdir() before usage
933
unless ( $opt_vardir =~ m,^/, or
934
($glob_win32 and $opt_vardir =~ m,^[a-z]:/,i) )
936
# Make absolute path, relative test dir
937
$opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
940
# --------------------------------------------------------------------------
942
# --------------------------------------------------------------------------
943
$opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir;
944
$opt_tmpdir =~ s,/+$,,; # Remove ending slash if any
946
# --------------------------------------------------------------------------
948
# --------------------------------------------------------------------------
949
if ( $opt_record and ! @opt_cases )
951
mtr_error("Will not run in record mode without a specific test case");
956
$opt_skip_combination = 1;
959
# --------------------------------------------------------------------------
961
# --------------------------------------------------------------------------
962
if ( $opt_ps_protocol )
964
push(@glob_test_mode, "ps-protocol");
967
# --------------------------------------------------------------------------
969
# --------------------------------------------------------------------------
970
if ( $opt_small_bench )
975
# --------------------------------------------------------------------------
977
# --------------------------------------------------------------------------
983
# --------------------------------------------------------------------------
985
# --------------------------------------------------------------------------
986
if ( $opt_gcov and ! $source_dist )
988
mtr_error("Coverage test needs the source - please use source dist");
991
# --------------------------------------------------------------------------
992
# Check debug related options
993
# --------------------------------------------------------------------------
994
if ( $opt_gdb || $opt_client_gdb || $opt_ddd || $opt_client_ddd ||
995
$opt_manual_gdb || $opt_manual_ddd || $opt_manual_debug ||
996
$opt_debugger || $opt_client_debugger )
998
# Indicate that we are using debugger
1002
mtr_error("Can't use --extern when using debugger");
1006
# --------------------------------------------------------------------------
1007
# Check if special exe was selected for master or slave
1008
# --------------------------------------------------------------------------
1009
$exe_master_mysqld= $exe_master_mysqld || $exe_mysqld;
1010
$exe_slave_mysqld= $exe_slave_mysqld || $exe_mysqld;
1012
# --------------------------------------------------------------------------
1013
# Check valgrind arguments
1014
# --------------------------------------------------------------------------
1015
if ( $opt_valgrind or $opt_valgrind_path or @valgrind_args)
1017
mtr_report("Turning on valgrind for all executables");
1019
$opt_valgrind_mysqld= 1;
1020
$opt_valgrind_mysqltest= 1;
1022
elsif ( $opt_valgrind_mysqld )
1024
mtr_report("Turning on valgrind for mysqld(s) only");
1027
elsif ( $opt_valgrind_mysqltest )
1029
mtr_report("Turning on valgrind for mysqltest and mysql_client_test only");
1033
if ( $opt_callgrind )
1035
mtr_report("Turning on valgrind with callgrind for mysqld(s)");
1037
$opt_valgrind_mysqld= 1;
1039
# Set special valgrind options unless options passed on command line
1040
push(@valgrind_args, "--trace-children=yes")
1041
unless @valgrind_args;
1044
if ( $opt_valgrind )
1046
# Set valgrind_options to default unless already defined
1047
push(@valgrind_args, @default_valgrind_args)
1048
unless @valgrind_args;
1050
mtr_report("Running valgrind with options \"",
1051
join(" ", @valgrind_args), "\"");
1054
if ( ! $opt_testcase_timeout )
1056
$opt_testcase_timeout= $default_testcase_timeout;
1057
$opt_testcase_timeout*= 10 if $opt_valgrind;
1058
$opt_testcase_timeout*= 10 if ($opt_debug and $glob_win32);
1061
if ( ! $opt_suite_timeout )
1063
$opt_suite_timeout= $default_suite_timeout;
1064
$opt_suite_timeout*= 6 if $opt_valgrind;
1065
$opt_suite_timeout*= 6 if ($opt_debug and $glob_win32);
1076
$opt_user= "root"; # We want to do FLUSH xxx commands
1080
# On QNX, /tmp/dir/master.sock and /tmp/dir//master.sock seem to be
1081
# considered different, so avoid the extra slash (/) in the socket
1083
my $sockdir = $opt_tmpdir;
1084
$sockdir =~ s|/+$||;
1086
# On some operating systems, there is a limit to the length of a
1087
# UNIX domain socket's path far below PATH_MAX, so try to avoid long
1088
# socket path names.
1089
$sockdir = tempdir(CLEANUP => 0) if ( length($sockdir) >= 70 );
1096
path_myddir => "$opt_vardir/master-data",
1097
path_myerr => "$opt_vardir/log/master.err",
1098
path_pid => "$opt_vardir/run/master.pid",
1099
path_sock => "$sockdir/master.sock",
1100
port => $opt_master_myport,
1101
start_timeout => 400, # enough time create innodb tables
1102
cluster => 0, # index in clusters list
1111
path_myddir => "$opt_vardir/master1-data",
1112
path_myerr => "$opt_vardir/log/master1.err",
1113
path_pid => "$opt_vardir/run/master1.pid",
1114
path_sock => "$sockdir/master1.sock",
1115
port => $opt_master_myport + 1,
1116
start_timeout => 400, # enough time create innodb tables
1117
cluster => 0, # index in clusters list
1126
path_myddir => "$opt_vardir/slave-data",
1127
path_myerr => "$opt_vardir/log/slave.err",
1128
path_pid => "$opt_vardir/run/slave.pid",
1129
path_sock => "$sockdir/slave.sock",
1130
port => $opt_slave_myport,
1131
start_timeout => 400,
1133
cluster => 1, # index in clusters list
1142
path_myddir => "$opt_vardir/slave1-data",
1143
path_myerr => "$opt_vardir/log/slave1.err",
1144
path_pid => "$opt_vardir/run/slave1.pid",
1145
path_sock => "$sockdir/slave1.sock",
1146
port => $opt_slave_myport + 1,
1147
start_timeout => 300,
1148
cluster => -1, # index in clusters list
1157
path_myddir => "$opt_vardir/slave2-data",
1158
path_myerr => "$opt_vardir/log/slave2.err",
1159
path_pid => "$opt_vardir/run/slave2.pid",
1160
path_sock => "$sockdir/slave2.sock",
1161
port => $opt_slave_myport + 2,
1162
start_timeout => 300,
1163
cluster => -1, # index in clusters list
1168
my $data_dir= "$opt_vardir/ndbcluster-$opt_ndbcluster_port";
1173
port => "$opt_ndbcluster_port",
1174
data_dir => "$data_dir",
1175
connect_string => "host=localhost:$opt_ndbcluster_port",
1176
path_pid => "$data_dir/ndb_3.pid", # Nodes + 1
1177
pid => 0, # pid of ndb_mgmd
1181
$data_dir= "$opt_vardir/ndbcluster-$opt_ndbcluster_port_slave";
1186
port => "$opt_ndbcluster_port_slave",
1187
data_dir => "$data_dir",
1188
connect_string => "host=localhost:$opt_ndbcluster_port_slave",
1189
path_pid => "$data_dir/ndb_2.pid", # Nodes + 1
1190
pid => 0, # pid of ndb_mgmd
1194
# Init pids of ndbd's
1195
foreach my $cluster ( @{$clusters} )
1197
for ( my $idx= 0; $idx < $cluster->{'nodes'}; $idx++ )
1200
$cluster->{'ndbds'}->[$idx]=
1204
path_pid => "$cluster->{'data_dir'}/ndb_${nodeid}.pid",
1205
path_fs => "$cluster->{'data_dir'}/ndb_${nodeid}_fs",
1210
# --------------------------------------------------------------------------
1212
# --------------------------------------------------------------------------
1215
# Turn off features not supported when running with extern server
1217
$opt_skip_ndbcluster= 1;
1218
warn("Currenty broken --extern");
1220
# Setup master->[0] with the settings for the extern server
1221
$master->[0]->{'path_sock'}= $opt_socket ? $opt_socket : "/tmp/mysql.sock";
1222
mtr_report("Using extern server at '$master->[0]->{path_sock}'");
1226
mtr_error("--socket can only be used in combination with --extern")
1231
# --------------------------------------------------------------------------
1232
# ndbconnectstring and ndbconnectstring_slave
1233
# --------------------------------------------------------------------------
1234
if ( $opt_ndbconnectstring )
1236
# ndbconnectstring was supplied by user, the tests shoudl be run
1237
# against an already started cluster, change settings
1238
my $cluster= $clusters->[0]; # Master cluster
1239
$cluster->{'connect_string'}= $opt_ndbconnectstring;
1240
$cluster->{'use_running'}= 1;
1242
mtr_error("Can't specify --ndb-connectstring and --skip-ndbcluster")
1243
if $opt_skip_ndbcluster;
1245
$ENV{'NDB_CONNECTSTRING'}= $clusters->[0]->{'connect_string'};
1248
if ( $opt_ndbconnectstring_slave )
1250
# ndbconnectstring-slave was supplied by user, the tests should be run
1251
# agains an already started slave cluster, change settings
1252
my $cluster= $clusters->[1]; # Slave cluster
1253
$cluster->{'connect_string'}= $opt_ndbconnectstring_slave;
1254
$cluster->{'use_running'}= 1;
1256
mtr_error("Can't specify ndb-connectstring_slave and " .
1257
"--skip-ndbcluster-slave")
1258
if $opt_skip_ndbcluster_slave;
1262
$path_timefile= "$opt_vardir/log/mysqltest-time";
1263
$path_mysqltest_log= "$opt_vardir/log/mysqltest.log";
1264
$path_current_test_log= "$opt_vardir/log/current_test";
1265
$path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log";
1267
$path_snapshot= "$opt_tmpdir/snapshot_$opt_master_myport/";
1269
if ( $opt_valgrind and $opt_debug )
1271
# When both --valgrind and --debug is selected, send
1272
# all output to the trace file, making it possible to
1273
# see the exact location where valgrind complains
1274
foreach my $mysqld (@{$master}, @{$slave})
1276
my $sidx= $mysqld->{idx} ? "$mysqld->{idx}" : "";
1277
$mysqld->{path_myerr}=
1278
"$opt_vardir/log/" . $mysqld->{type} . "$sidx.trace";
1284
# To make it easier for different devs to work on the same host,
1285
# an environment variable can be used to control all ports. A small
1286
# number is to be used, 0 - 16 or similar.
1288
# Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
1289
# versions of this script, else a 4.0 test run might conflict with a
1290
# 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
1291
# all port numbers might not be used in this version of the script.
1293
# Also note the limitation of ports we are allowed to hand out. This
1294
# differs between operating systems and configuration, see
1295
# http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
1296
# But a fairly safe range seems to be 5001 - 32767
1299
sub set_mtr_build_thread_ports($) {
1300
my $mtr_build_thread= shift;
1302
if ( lc($mtr_build_thread) eq 'auto' ) {
1303
print "Requesting build thread... ";
1304
$ENV{'MTR_BUILD_THREAD'} = $mtr_build_thread = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
1305
print "got ".$mtr_build_thread."\n";
1308
# Up to two masters, up to three slaves
1309
# A magic value in command_line_setup depends on these equations.
1310
$opt_master_myport= $mtr_build_thread * 10 + 10000; # and 1
1311
$opt_slave_myport= $opt_master_myport + 2; # and 3 4
1312
$opt_ndbcluster_port= $opt_master_myport + 5;
1313
$opt_ndbcluster_port_slave= $opt_master_myport + 6;
1315
if ( $opt_master_myport < 5001 or $opt_master_myport + 10 >= 32767 )
1317
mtr_error("MTR_BUILD_THREAD number results in a port",
1318
"outside 5001 - 32767",
1319
"($opt_master_myport - $opt_master_myport + 10)");
1324
sub datadir_list_setup () {
1326
# Make a list of all data_dirs
1327
for (my $idx= 0; $idx < $max_master_num; $idx++)
1329
push(@data_dir_lst, $master->[$idx]->{'path_myddir'});
1332
for (my $idx= 0; $idx < $max_slave_num; $idx++)
1334
push(@data_dir_lst, $slave->[$idx]->{'path_myddir'});
1339
##############################################################################
1341
# Set paths to various executable programs
1343
##############################################################################
1346
sub collect_mysqld_features () {
1347
my $found_variable_list_start= 0;
1348
my $tmpdir= tempdir(CLEANUP => 0); # Directory removed by this function
1351
# Execute "mysqld --help --verbose" to get a list
1352
# list of all features and settings
1354
# --no-defaults and --skip-grant-tables are to avoid loading
1355
# system-wide configs and plugins
1357
# --datadir must exist, mysqld will chdir into it
1359
my $list= `$exe_mysqld --no-defaults --datadir=$tmpdir --language=$path_language --skip-grant-tables --verbose --help`;
1361
foreach my $line (split('\n', $list))
1363
# First look for version
1364
if ( !$mysql_version_id )
1367
my $exe_name= basename($exe_mysqld);
1368
mtr_verbose("exe_name: $exe_name");
1369
if ( $line =~ /^\S*$exe_name\s\sVer\s([0-9]*)\.([0-9]*)\.([0-9]*)/ )
1371
#print "Major: $1 Minor: $2 Build: $3\n";
1372
$mysql_version_id= $1*10000 + $2*100 + $3;
1373
#print "mysql_version_id: $mysql_version_id\n";
1374
mtr_report("MySQL Version $1.$2.$3");
1379
if (!$found_variable_list_start)
1381
# Look for start of variables list
1382
if ( $line =~ /[\-]+\s[\-]+/ )
1384
$found_variable_list_start= 1;
1389
# Put variables into hash
1390
if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
1392
# print "$1=\"$2\"\n";
1393
$mysqld_variables{$1}= $2;
1397
# The variable list is ended with a blank line
1398
if ( $line =~ /^[\s]*$/ )
1404
# Send out a warning, we should fix the variables that has no
1405
# space between variable name and it's value
1406
# or should it be fixed width column parsing? It does not
1407
# look like that in function my_print_variables in my_getopt.c
1408
mtr_warning("Could not parse variable list line : $line");
1415
mtr_error("Could not find version of MySQL") unless $mysql_version_id;
1416
mtr_error("Could not find variabes list") unless $found_variable_list_start;
1422
my ($mysqld, $query)= @_;
1425
mtr_init_args(\$args);
1427
mtr_add_arg($args, "--no-defaults");
1428
mtr_add_arg($args, "--user=%s", $opt_user);
1429
mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
1430
mtr_add_arg($args, "--silent"); # Tab separated output
1431
mtr_add_arg($args, "-e '%s'", $query);
1433
my $cmd= "$exe_mysql " . join(' ', @$args);
1434
mtr_verbose("cmd: $cmd");
1439
sub collect_mysqld_features_from_running_server ()
1441
my $list= run_query($master->[0], "use mysql; SHOW VARIABLES");
1443
foreach my $line (split('\n', $list))
1445
# Put variables into hash
1446
if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
1448
print "$1=\"$2\"\n";
1449
$mysqld_variables{$1}= $2;
1455
sub executable_setup_ndb () {
1457
# Look for ndb tols and binaries
1458
my $ndb_path= mtr_file_exists("$glob_basedir/ndb",
1459
"$glob_basedir/storage/ndb",
1460
"$glob_basedir/bin");
1463
mtr_exe_maybe_exists("$ndb_path/src/kernel/ndbd",
1466
mtr_exe_maybe_exists("$ndb_path/src/mgmclient/ndb_mgm",
1467
"$ndb_path/ndb_mgm");
1469
mtr_exe_maybe_exists("$ndb_path/src/mgmsrv/ndb_mgmd",
1470
"$ndb_path/ndb_mgmd");
1472
mtr_exe_maybe_exists("$ndb_path/tools/ndb_waiter",
1473
"$ndb_path/ndb_waiter");
1476
$path_ndb_tools_dir= mtr_file_exists("$ndb_path/tools",
1479
$path_ndb_examples_dir=
1480
mtr_file_exists("$ndb_path/ndbapi-examples",
1481
"$ndb_path/examples");
1484
mtr_file_exists("$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple");
1486
return ( $exe_ndbd eq "" or
1487
$exe_ndb_mgm eq "" or
1488
$exe_ndb_mgmd eq "" or
1489
$exe_ndb_waiter eq "");
1492
sub executable_setup () {
1495
# Check if libtool is available in this distribution/clone
1496
# we need it when valgrinding or debugging non installed binary
1497
# Otherwise valgrind will valgrind the libtool wrapper or bash
1498
# and gdb will not find the real executable to debug
1500
if ( -x "../libtool")
1502
$exe_libtool= "../libtool";
1503
if ($opt_valgrind or $glob_debugger)
1505
mtr_report("Using \"$exe_libtool\" when running valgrind or debugger");
1509
# Look for my_print_defaults
1510
$exe_my_print_defaults=
1511
mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
1512
"$path_client_bindir/my_print_defaults",
1513
"$glob_basedir/extra/my_print_defaults");
1516
$exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
1517
"$glob_basedir/extra/perror",
1518
"$path_client_bindir/perror");
1520
# Look for the client binaries
1521
$exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck");
1522
$exe_mysqldump= mtr_exe_exists("$path_client_bindir/mysqldump");
1523
$exe_mysqlimport= mtr_exe_exists("$path_client_bindir/mysqlimport");
1524
$exe_mysqlshow= mtr_exe_exists("$path_client_bindir/mysqlshow");
1525
$exe_mysqlbinlog= mtr_exe_exists("$path_client_bindir/mysqlbinlog");
1526
$exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin");
1527
$exe_mysql= mtr_exe_exists("$path_client_bindir/mysql");
1531
# Look for SQL scripts directory
1532
if ( mtr_file_exists("$path_share/mysql_system_tables.sql") ne "")
1534
# The SQL scripts are in path_share
1535
$path_sql_dir= $path_share;
1539
$path_sql_dir= mtr_path_exists("$glob_basedir/share",
1540
"$glob_basedir/scripts");
1543
if ( $mysql_version_id >= 50100 )
1545
$exe_mysqlslap= mtr_exe_exists("$path_client_bindir/mysqlslap");
1547
if ( $mysql_version_id >= 50000 and !$glob_use_embedded_server )
1549
$exe_mysql_upgrade= mtr_exe_exists("$path_client_bindir/mysql_upgrade")
1553
$exe_mysql_upgrade= "";
1556
if ( ! $glob_win32 )
1558
# Look for mysql_fix_system_table script
1559
$exe_mysql_fix_system_tables=
1560
mtr_script_exists("$glob_basedir/scripts/mysql_fix_privilege_tables",
1561
"$path_client_bindir/mysql_fix_privilege_tables");
1564
# Look for mysql_fix_privilege_tables.sql script
1565
$file_mysql_fix_privilege_tables=
1566
mtr_file_exists("$glob_basedir/scripts/mysql_fix_privilege_tables.sql",
1567
"$glob_basedir/share/mysql_fix_privilege_tables.sql");
1569
if ( ! $opt_skip_ndbcluster and executable_setup_ndb())
1571
mtr_warning("Could not find all required ndb binaries, " .
1572
"all ndb tests will fail, use --skip-ndbcluster to " .
1573
"skip testing it.");
1575
foreach my $cluster (@{$clusters})
1577
$cluster->{"executable_setup_failed"}= 1;
1582
# Look for the udf_example library
1584
mtr_file_exists(vs_config_dirs('sql', 'udf_example.dll'),
1585
"$glob_basedir/sql/.libs/udf_example.so",);
1587
# Look for the ha_example library
1588
$lib_example_plugin=
1589
mtr_file_exists(vs_config_dirs('storage/example', 'ha_example.dll'),
1590
"$glob_basedir/storage/example/.libs/ha_example.so",);
1594
# Look for mysqltest executable
1595
if ( $glob_use_embedded_server )
1598
mtr_exe_exists(vs_config_dirs('libmysqld/examples','mysqltest_embedded'),
1599
"$glob_basedir/libmysqld/examples/mysqltest_embedded",
1600
"$path_client_bindir/mysqltest_embedded");
1604
$exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest");
1607
# Look for mysql_client_test executable which may _not_ exist in
1608
# some versions, test using it should be skipped
1609
if ( $glob_use_embedded_server )
1611
$exe_mysql_client_test=
1612
mtr_exe_maybe_exists(
1613
vs_config_dirs('libmysqld/examples', 'mysql_client_test_embedded'),
1614
"$glob_basedir/libmysqld/examples/mysql_client_test_embedded");
1618
$exe_mysql_client_test=
1619
mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'),
1620
"$glob_basedir/tests/mysql_client_test",
1621
"$glob_basedir/bin/mysql_client_test");
1624
# Look for bug25714 executable which may _not_ exist in
1625
# some versions, test using it should be skipped
1627
mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'),
1628
"$glob_basedir/tests/bug25714");
1632
sub generate_cmdline_mysqldump ($) {
1635
mtr_native_path($exe_mysqldump) .
1636
" --no-defaults -uroot --debug-check " .
1637
"--port=$mysqld->{'port'} ";
1641
##############################################################################
1643
# Set environment to be used by childs of this process for
1644
# things that are constant duting the whole lifetime of mysql-test-run.pl
1646
##############################################################################
1648
sub mysql_client_test_arguments()
1650
my $exe= $exe_mysql_client_test;
1653
mtr_init_args(\$args);
1654
if ( $opt_valgrind_mysqltest )
1656
valgrind_arguments($args, \$exe);
1659
mtr_add_arg($args, "--no-defaults");
1660
mtr_add_arg($args, "--testcase");
1661
mtr_add_arg($args, "--user=root");
1662
mtr_add_arg($args, "--port=$master->[0]->{'port'}");
1664
if ( $opt_extern || $mysql_version_id >= 50000 )
1666
mtr_add_arg($args, "--vardir=$opt_vardir")
1672
"--debug=d:t:A,$path_vardir_trace/log/mysql_client_test.trace");
1675
if ( $glob_use_embedded_server )
1678
" -A --language=$path_language");
1680
" -A --datadir=$slave->[0]->{'path_myddir'}");
1682
" -A --character-sets-dir=$path_charsetsdir");
1685
return join(" ", $exe, @$args);
1688
sub mysql_upgrade_arguments()
1690
my $exe= $exe_mysql_upgrade;
1693
mtr_init_args(\$args);
1694
# if ( $opt_valgrind_mysql_ugrade )
1696
# valgrind_arguments($args, \$exe);
1699
mtr_add_arg($args, "--no-defaults");
1700
mtr_add_arg($args, "--user=root");
1701
mtr_add_arg($args, "--port=$master->[0]->{'port'}");
1702
mtr_add_arg($args, "--datadir=$master->[0]->{'path_myddir'}");
1703
mtr_add_arg($args, "--basedir=$glob_basedir");
1708
"--debug=d:t:A,$path_vardir_trace/log/mysql_upgrade.trace");
1711
return join(" ", $exe, @$args);
1714
# Note that some env is setup in spawn/run, in "mtr_process.pl"
1716
sub environment_setup () {
1720
my @ld_library_paths;
1722
# --------------------------------------------------------------------------
1723
# Setup LD_LIBRARY_PATH so the libraries from this distro/clone
1724
# are used in favor of the system installed ones
1725
# --------------------------------------------------------------------------
1728
push(@ld_library_paths, "$glob_basedir/libmysql/.libs/",
1729
"$glob_basedir/libmysql_r/.libs/",
1730
"$glob_basedir/zlib.libs/");
1734
push(@ld_library_paths, "$glob_basedir/lib");
1737
# --------------------------------------------------------------------------
1738
# Add the path where libndbclient can be found
1739
# --------------------------------------------------------------------------
1740
if ( $glob_ndbcluster_supported )
1742
push(@ld_library_paths, "$glob_basedir/storage/ndb/src/.libs");
1745
# --------------------------------------------------------------------------
1746
# Valgrind need to be run with debug libraries otherwise it's almost
1747
# impossible to add correct supressions, that means if "/usr/lib/debug"
1748
# is available, it should be added to
1751
# But pthread is broken in libc6-dbg on Debian <= 3.1 (see Debian
1752
# bug 399035, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=399035),
1753
# so don't change LD_LIBRARY_PATH on that platform.
1754
# --------------------------------------------------------------------------
1755
my $debug_libraries_path= "/usr/lib/debug";
1757
if ( $opt_valgrind and -d $debug_libraries_path and
1758
(! -e '/etc/debian_version' or
1759
($deb_version= mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
1760
$deb_version > 3.1 ) )
1762
push(@ld_library_paths, $debug_libraries_path);
1765
$ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths,
1766
$ENV{'LD_LIBRARY_PATH'} ?
1767
split(':', $ENV{'LD_LIBRARY_PATH'}) : ());
1768
mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
1770
$ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
1771
$ENV{'DYLD_LIBRARY_PATH'} ?
1772
split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ());
1773
mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
1775
# The environment variable used for shared libs on AIX
1776
$ENV{'SHLIB_PATH'}= join(":", @ld_library_paths,
1777
$ENV{'SHLIB_PATH'} ?
1778
split(':', $ENV{'SHLIB_PATH'}) : ());
1779
mtr_debug("SHLIB_PATH: $ENV{'SHLIB_PATH'}");
1781
# The environment variable used for shared libs on hp-ux
1782
$ENV{'LIBPATH'}= join(":", @ld_library_paths,
1784
split(':', $ENV{'LIBPATH'}) : ());
1785
mtr_debug("LIBPATH: $ENV{'LIBPATH'}");
1787
# --------------------------------------------------------------------------
1788
# Also command lines in .opt files may contain env vars
1789
# --------------------------------------------------------------------------
1791
$ENV{'CHARSETSDIR'}= $path_charsetsdir;
1792
$ENV{'UMASK'}= "0660"; # The octal *string*
1793
$ENV{'UMASK_DIR'}= "0770"; # The octal *string*
1796
# MySQL tests can produce output in various character sets
1797
# (especially, ctype_xxx.test). To avoid confusing Perl
1798
# with output which is incompatible with the current locale
1799
# settings, we reset the current values of LC_ALL and LC_CTYPE to "C".
1800
# For details, please see
1801
# Bug#27636 tests fails if LC_* variables set to *_*.UTF-8
1803
$ENV{'LC_ALL'}= "C";
1804
$ENV{'LC_CTYPE'}= "C";
1806
$ENV{'LC_COLLATE'}= "C";
1807
$ENV{'USE_RUNNING_SERVER'}= $opt_extern;
1808
$ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
1809
$ENV{'MYSQLTEST_VARDIR'}= $opt_vardir;
1810
$ENV{'MYSQL_TMP_DIR'}= $opt_tmpdir;
1811
$ENV{'MASTER_MYSOCK'}= $master->[0]->{'path_sock'};
1812
$ENV{'MASTER_MYSOCK1'}= $master->[1]->{'path_sock'};
1813
$ENV{'MASTER_MYPORT'}= $master->[0]->{'port'};
1814
$ENV{'MASTER_MYPORT1'}= $master->[1]->{'port'};
1815
$ENV{'SLAVE_MYSOCK'}= $slave->[0]->{'path_sock'};
1816
$ENV{'SLAVE_MYPORT'}= $slave->[0]->{'port'};
1817
$ENV{'SLAVE_MYPORT1'}= $slave->[1]->{'port'};
1818
$ENV{'SLAVE_MYPORT2'}= $slave->[2]->{'port'};
1819
$ENV{'MYSQL_TCP_PORT'}= $mysqld_variables{'port'};
1821
$ENV{MTR_BUILD_THREAD}= $opt_mtr_build_thread;
1823
$ENV{'EXE_MYSQL'}= $exe_mysql;
1826
# ----------------------------------------------------
1828
# ----------------------------------------------------
1829
if ( ! $opt_skip_ndbcluster )
1831
$ENV{'NDB_MGM'}= $exe_ndb_mgm;
1833
$ENV{'NDBCLUSTER_PORT'}= $opt_ndbcluster_port;
1834
$ENV{'NDBCLUSTER_PORT_SLAVE'}= $opt_ndbcluster_port_slave;
1836
$ENV{'NDB_EXTRA_TEST'}= $opt_ndb_extra_test;
1838
$ENV{'NDB_BACKUP_DIR'}= $clusters->[0]->{'data_dir'};
1839
$ENV{'NDB_DATA_DIR'}= $clusters->[0]->{'data_dir'};
1840
$ENV{'NDB_TOOLS_DIR'}= $path_ndb_tools_dir;
1841
$ENV{'NDB_TOOLS_OUTPUT'}= $path_ndb_testrun_log;
1843
if ( $mysql_version_id >= 50000 )
1845
$ENV{'NDB_EXAMPLES_DIR'}= $path_ndb_examples_dir;
1846
$ENV{'MY_NDB_EXAMPLES_BINARY'}= $exe_ndb_example;
1848
$ENV{'NDB_EXAMPLES_OUTPUT'}= $path_ndb_testrun_log;
1851
# ----------------------------------------------------
1852
# Setup env so childs can execute mysqlcheck
1853
# ----------------------------------------------------
1854
my $cmdline_mysqlcheck=
1855
mtr_native_path($exe_mysqlcheck) .
1856
" --no-defaults --debug-check -uroot " .
1857
"--port=$master->[0]->{'port'} ";
1861
$cmdline_mysqlcheck .=
1862
" --debug=d:t:A,$path_vardir_trace/log/mysqlcheck.trace";
1864
$ENV{'MYSQL_CHECK'}= $cmdline_mysqlcheck;
1866
# ----------------------------------------------------
1867
# Setup env to childs can execute myqldump
1868
# ----------------------------------------------------
1869
my $cmdline_mysqldump= generate_cmdline_mysqldump($master->[0]);
1870
my $cmdline_mysqldumpslave= generate_cmdline_mysqldump($slave->[0]);
1874
$cmdline_mysqldump .=
1875
" --debug=d:t:A,$path_vardir_trace/log/mysqldump-master.trace";
1876
$cmdline_mysqldumpslave .=
1877
" --debug=d:t:A,$path_vardir_trace/log/mysqldump-slave.trace";
1879
$ENV{'MYSQL_DUMP'}= $cmdline_mysqldump;
1880
$ENV{'MYSQL_DUMP_SLAVE'}= $cmdline_mysqldumpslave;
1883
# ----------------------------------------------------
1884
# Setup env so childs can execute mysqlslap
1885
# ----------------------------------------------------
1886
if ( $exe_mysqlslap )
1888
my $cmdline_mysqlslap=
1889
mtr_native_path($exe_mysqlslap) .
1891
"--port=$master->[0]->{'port'} ";
1895
$cmdline_mysqlslap .=
1896
" --debug=d:t:A,$path_vardir_trace/log/mysqlslap.trace";
1898
$ENV{'MYSQL_SLAP'}= $cmdline_mysqlslap;
1901
# ----------------------------------------------------
1902
# Setup env so childs can execute mysqlimport
1903
# ----------------------------------------------------
1904
my $cmdline_mysqlimport=
1905
mtr_native_path($exe_mysqlimport) .
1906
" -uroot --debug-check " .
1907
"--port=$master->[0]->{'port'} ";
1911
$cmdline_mysqlimport .=
1912
" --debug=d:t:A,$path_vardir_trace/log/mysqlimport.trace";
1914
$ENV{'MYSQL_IMPORT'}= $cmdline_mysqlimport;
1917
# ----------------------------------------------------
1918
# Setup env so childs can execute mysqlshow
1919
# ----------------------------------------------------
1920
my $cmdline_mysqlshow=
1921
mtr_native_path($exe_mysqlshow) .
1922
" -uroot --debug-check " .
1923
"--port=$master->[0]->{'port'} ";
1927
$cmdline_mysqlshow .=
1928
" --debug=d:t:A,$path_vardir_trace/log/mysqlshow.trace";
1930
$ENV{'MYSQL_SHOW'}= $cmdline_mysqlshow;
1932
# ----------------------------------------------------
1933
# Setup env so childs can execute mysqlbinlog
1934
# ----------------------------------------------------
1935
my $cmdline_mysqlbinlog=
1936
mtr_native_path($exe_mysqlbinlog) .
1937
" --no-defaults --disable-force-if-open --debug-check";
1938
if ( !$opt_extern && $mysql_version_id >= 50000 )
1940
$cmdline_mysqlbinlog .=" --character-sets-dir=$path_charsetsdir";
1945
$cmdline_mysqlbinlog .=
1946
" --debug=d:t:A,$path_vardir_trace/log/mysqlbinlog.trace";
1948
$ENV{'MYSQL_BINLOG'}= $cmdline_mysqlbinlog;
1950
# ----------------------------------------------------
1951
# Setup env so childs can execute mysql
1952
# ----------------------------------------------------
1954
mtr_native_path($exe_mysql) .
1955
" --no-defaults --debug-check --host=localhost --user=root --password= " .
1956
"--port=$master->[0]->{'port'} " .
1957
"--character-sets-dir=$path_charsetsdir";
1959
$ENV{'MYSQL'}= $cmdline_mysql;
1961
# ----------------------------------------------------
1962
# Setup env so childs can execute bug25714
1963
# ----------------------------------------------------
1964
$ENV{'MYSQL_BUG25714'}= $exe_bug25714;
1966
# ----------------------------------------------------
1967
# Setup env so childs can execute mysql_client_test
1968
# ----------------------------------------------------
1969
$ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments();
1971
# ----------------------------------------------------
1972
# Setup env so childs can execute mysql_upgrade
1973
# ----------------------------------------------------
1974
if ( !$opt_extern && $mysql_version_id >= 50000 )
1976
$ENV{'MYSQL_UPGRADE'}= mysql_upgrade_arguments();
1979
# ----------------------------------------------------
1980
# Setup env so childs can execute mysql_fix_system_tables
1981
# ----------------------------------------------------
1982
if ( !$opt_extern && ! $glob_win32 )
1984
my $cmdline_mysql_fix_system_tables=
1985
"$exe_mysql_fix_system_tables --no-defaults --host=localhost " .
1986
"--user=root --password= " .
1987
"--basedir=$glob_basedir --bindir=$path_client_bindir --verbose " .
1988
"--port=$master->[0]->{'port'} ";
1989
$ENV{'MYSQL_FIX_SYSTEM_TABLES'}= $cmdline_mysql_fix_system_tables;
1992
$ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}= $file_mysql_fix_privilege_tables;
1994
# ----------------------------------------------------
1995
# Setup env so childs can execute my_print_defaults
1996
# ----------------------------------------------------
1997
$ENV{'MYSQL_MY_PRINT_DEFAULTS'}= mtr_native_path($exe_my_print_defaults);
1999
# ----------------------------------------------------
2000
# Setup env so childs can execute mysqladmin
2001
# ----------------------------------------------------
2002
$ENV{'MYSQLADMIN'}= mtr_native_path($exe_mysqladmin);
2004
# ----------------------------------------------------
2005
# Setup env so childs can execute perror
2006
# ----------------------------------------------------
2007
$ENV{'MY_PERROR'}= mtr_native_path($exe_perror);
2009
# ----------------------------------------------------
2010
# Add the path where mysqld will find udf_example.so
2011
# ----------------------------------------------------
2012
$ENV{'UDF_EXAMPLE_LIB'}=
2013
($lib_udf_example ? basename($lib_udf_example) : "");
2014
$ENV{'UDF_EXAMPLE_LIB_OPT'}=
2015
($lib_udf_example ? "--plugin_dir=" . dirname($lib_udf_example) : "");
2017
# ----------------------------------------------------
2018
# Add the path where mysqld will find ha_example.so
2019
# ----------------------------------------------------
2020
$ENV{'EXAMPLE_PLUGIN'}=
2021
($lib_example_plugin ? basename($lib_example_plugin) : "");
2022
$ENV{'EXAMPLE_PLUGIN_OPT'}=
2023
($lib_example_plugin ? "--plugin_dir=" . dirname($lib_example_plugin) : "");
2025
# ----------------------------------------------------
2026
# Setup env so childs can execute myisampack and myisamchk
2027
# ----------------------------------------------------
2028
$ENV{'MYISAMCHK'}= mtr_native_path(mtr_exe_exists(
2029
vs_config_dirs('storage/myisam', 'myisamchk'),
2030
vs_config_dirs('myisam', 'myisamchk'),
2031
"$path_client_bindir/myisamchk",
2032
"$glob_basedir/storage/myisam/myisamchk",
2033
"$glob_basedir/myisam/myisamchk"));
2034
$ENV{'MYISAMPACK'}= mtr_native_path(mtr_exe_exists(
2035
vs_config_dirs('storage/myisam', 'myisampack'),
2036
vs_config_dirs('myisam', 'myisampack'),
2037
"$path_client_bindir/myisampack",
2038
"$glob_basedir/storage/myisam/myisampack",
2039
"$glob_basedir/myisam/myisampack"));
2041
# ----------------------------------------------------
2042
# We are nice and report a bit about our settings
2043
# ----------------------------------------------------
2046
print "Using MTR_BUILD_THREAD = $ENV{MTR_BUILD_THREAD}\n";
2047
print "Using MASTER_MYPORT = $ENV{MASTER_MYPORT}\n";
2048
print "Using MASTER_MYPORT1 = $ENV{MASTER_MYPORT1}\n";
2049
print "Using SLAVE_MYPORT = $ENV{SLAVE_MYPORT}\n";
2050
print "Using SLAVE_MYPORT1 = $ENV{SLAVE_MYPORT1}\n";
2051
print "Using SLAVE_MYPORT2 = $ENV{SLAVE_MYPORT2}\n";
2052
if ( ! $opt_skip_ndbcluster )
2054
print "Using NDBCLUSTER_PORT = $ENV{NDBCLUSTER_PORT}\n";
2055
if ( ! $opt_skip_ndbcluster_slave )
2057
print "Using NDBCLUSTER_PORT_SLAVE = $ENV{NDBCLUSTER_PORT_SLAVE}\n";
2062
# Create an environment variable to make it possible
2063
# to detect that valgrind is being used from test cases
2064
$ENV{'VALGRIND_TEST'}= $opt_valgrind;
2069
##############################################################################
2071
# If we get a ^C, we try to clean up before termination
2073
##############################################################################
2074
# FIXME check restrictions what to do in a signal handler
2076
sub signal_setup () {
2077
$SIG{INT}= \&handle_int_signal;
2081
sub handle_int_signal () {
2082
$SIG{INT}= 'DEFAULT'; # If we get a ^C again, we die...
2083
mtr_warning("got INT signal, cleaning up.....");
2085
mtr_error("We die from ^C signal from user");
2089
##############################################################################
2091
# Handle left overs from previous runs
2093
##############################################################################
2095
sub kill_running_servers () {
2097
if ( $opt_fast or $glob_use_embedded_server )
2099
# FIXME is embedded server really using PID files?!
2100
unlink($master->[0]->{'path_pid'});
2101
unlink($master->[1]->{'path_pid'});
2102
unlink($slave->[0]->{'path_pid'});
2103
unlink($slave->[1]->{'path_pid'});
2104
unlink($slave->[2]->{'path_pid'});
2108
# Ensure that no old mysqld test servers are running
2109
# This is different from terminating processes we have
2110
# started from this run of the script, this is terminating
2111
# leftovers from previous runs.
2112
mtr_kill_leftovers();
2117
# Remove var and any directories in var/ created by previous
2120
sub remove_stale_vardir () {
2122
mtr_report("Removing Stale Files");
2125
mtr_error("No, don't remove the vardir when running with --extern")
2128
mtr_verbose("opt_vardir: $opt_vardir");
2129
if ( $opt_vardir eq $default_vardir )
2132
# Running with "var" in mysql-test dir
2134
if ( -l $opt_vardir)
2138
if ( $opt_mem and readlink($opt_vardir) eq $opt_mem )
2140
# Remove the directory which the link points at
2141
mtr_verbose("Removing " . readlink($opt_vardir));
2142
mtr_rmtree(readlink($opt_vardir));
2144
# Remove the "var" symlink
2145
mtr_verbose("unlink($opt_vardir)");
2146
unlink($opt_vardir);
2150
# Just remove the "var" symlink
2151
mtr_report("WARNING: Removing '$opt_vardir' symlink it's wrong");
2153
mtr_verbose("unlink($opt_vardir)");
2154
unlink($opt_vardir);
2158
# Some users creates a soft link in mysql-test/var to another area
2159
# - allow it, but remove all files in it
2161
mtr_report("WARNING: Using the 'mysql-test/var' symlink");
2163
# Make sure the directory where it points exist
2164
mtr_error("The destination for symlink $opt_vardir does not exist")
2165
if ! -d readlink($opt_vardir);
2167
foreach my $bin ( glob("$opt_vardir/*") )
2169
mtr_verbose("Removing bin $bin");
2176
# Remove the entire "var" dir
2177
mtr_verbose("Removing $opt_vardir/");
2178
mtr_rmtree("$opt_vardir/");
2183
# A symlink from var/ to $opt_mem will be set up
2184
# remove the $opt_mem dir to assure the symlink
2185
# won't point at an old directory
2186
mtr_verbose("Removing $opt_mem");
2187
mtr_rmtree($opt_mem);
2194
# Running with "var" in some other place
2197
# Remove the var/ dir in mysql-test dir if any
2198
# this could be an old symlink that shouldn't be there
2199
mtr_verbose("Removing $default_vardir");
2200
mtr_rmtree($default_vardir);
2202
# Remove the "var" dir
2203
mtr_verbose("Removing $opt_vardir/");
2204
mtr_rmtree("$opt_vardir/");
2209
# Create var and the directories needed in var
2211
sub setup_vardir() {
2212
mtr_report("Creating Directories");
2214
if ( $opt_vardir eq $default_vardir )
2217
# Running with "var" in mysql-test dir
2219
if ( -l $opt_vardir )
2223
# Make sure the directory where it points exist
2224
mtr_error("The destination for symlink $opt_vardir does not exist")
2225
if ! -d readlink($opt_vardir);
2229
# Runinng with "var" as a link to some "memory" location, normally tmpfs
2230
mtr_verbose("Creating $opt_mem");
2233
mtr_report("Symlinking 'var' to '$opt_mem'");
2234
symlink($opt_mem, $opt_vardir);
2238
if ( ! -d $opt_vardir )
2240
mtr_verbose("Creating $opt_vardir");
2241
mkpath($opt_vardir);
2244
# Ensure a proper error message if vardir couldn't be created
2245
unless ( -d $opt_vardir and -w $opt_vardir )
2247
mtr_error("Writable 'var' directory is needed, use the " .
2248
"'--vardir=<path>' option");
2251
mkpath("$opt_vardir/log");
2252
mkpath("$opt_vardir/run");
2253
mkpath("$opt_vardir/tmp");
2254
mkpath($opt_tmpdir) if $opt_tmpdir ne "$opt_vardir/tmp";
2256
# Create new data dirs
2257
foreach my $data_dir (@data_dir_lst)
2259
mkpath("$data_dir/mysql");
2260
mkpath("$data_dir/test");
2263
# Make a link std_data_ln in var/ that points to std_data
2264
if ( ! $glob_win32 )
2266
symlink("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data_ln");
2270
# on windows, copy all files from std_data into var/std_data_ln
2271
mkpath("$opt_vardir/std_data_ln");
2272
opendir(DIR, "$glob_mysql_test_dir/std_data")
2273
or mtr_error("Can't find the std_data directory: $!");
2275
next if -d "$glob_mysql_test_dir/std_data/$_";
2276
copy("$glob_mysql_test_dir/std_data/$_", "$opt_vardir/std_data_ln/$_");
2281
# Remove old log files
2282
foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
2289
sub check_running_as_root () {
2290
# Check if running as root
2291
# i.e a file can be read regardless what mode we set it to
2292
my $test_file= "$opt_vardir/test_running_as_root.txt";
2293
mtr_tofile($test_file, "MySQL");
2294
chmod(oct("0000"), $test_file);
2297
if (open(FILE,"<",$test_file))
2299
$result= join('', <FILE>);
2303
# Some filesystems( for example CIFS) allows reading a file
2304
# although mode was set to 0000, but in that case a stat on
2305
# the file will not return 0000
2306
my $file_mode= (stat($test_file))[2] & 07777;
2308
$ENV{'MYSQL_TEST_ROOT'}= "NO";
2309
mtr_verbose("result: $result, file_mode: $file_mode");
2310
if ($result eq "MySQL" && $file_mode == 0)
2312
mtr_warning("running this script as _root_ will cause some " .
2313
"tests to be skipped");
2314
$ENV{'MYSQL_TEST_ROOT'}= "YES";
2317
chmod(oct("0755"), $test_file);
2323
sub check_ssl_support ($) {
2324
my $mysqld_variables= shift;
2326
if ($opt_skip_ssl || $opt_extern)
2330
mtr_report("Skipping SSL");
2332
$opt_ssl_supported= 0;
2337
if ( ! $mysqld_variables->{'ssl'} )
2341
mtr_error("Couldn't find support for SSL");
2344
mtr_report("Skipping SSL, mysqld not compiled with SSL");
2345
$opt_ssl_supported= 0;
2349
mtr_report("Setting mysqld to support SSL connections");
2350
$opt_ssl_supported= 1;
2354
sub check_debug_support ($) {
2355
my $mysqld_variables= shift;
2357
if ( ! $mysqld_variables->{'debug'} )
2359
#mtr_report("Binaries are not debug compiled");
2360
$debug_compiled_binaries= 0;
2364
mtr_error("Can't use --debug, binaries does not support it");
2368
mtr_report("Binaries are debug compiled");
2369
$debug_compiled_binaries= 1;
2372
##############################################################################
2374
# Helper function to handle configuration-based subdirectories which Visual
2375
# Studio uses for storing binaries. If opt_vs_config is set, this returns
2376
# a path based on that setting; if not, it returns paths for the default
2377
# /release/ and /debug/ subdirectories.
2379
# $exe can be undefined, if the directory itself will be used
2381
###############################################################################
2383
sub vs_config_dirs ($$) {
2384
my ($path_part, $exe) = @_;
2386
$exe = "" if not defined $exe;
2390
return ("$glob_basedir/$path_part/$opt_vs_config/$exe");
2393
return ("$glob_basedir/$path_part/release/$exe",
2394
"$glob_basedir/$path_part/relwithdebinfo/$exe",
2395
"$glob_basedir/$path_part/debug/$exe");
2398
##############################################################################
2400
# Start the ndb cluster
2402
##############################################################################
2404
sub check_ndbcluster_support ($) {
2405
my $mysqld_variables= shift;
2407
if ($opt_skip_ndbcluster || $opt_extern)
2411
mtr_report("Skipping ndbcluster");
2413
$opt_skip_ndbcluster_slave= 1;
2417
if ( ! $mysqld_variables->{'ndb-connectstring'} )
2419
mtr_report("Skipping ndbcluster, mysqld not compiled with ndbcluster");
2420
$opt_skip_ndbcluster= 1;
2421
$opt_skip_ndbcluster_slave= 1;
2424
$glob_ndbcluster_supported= 1;
2425
mtr_report("Using ndbcluster when necessary, mysqld supports it");
2427
if ( $mysql_version_id < 50100 )
2429
# Slave cluster is not supported until 5.1
2430
$opt_skip_ndbcluster_slave= 1;
2438
sub ndbcluster_start_install ($) {
2441
mtr_report("Installing $cluster->{'name'} Cluster");
2443
mkdir($cluster->{'data_dir'});
2445
# Create a config file from template
2447
my $ndb_no_attr=2048;
2448
my $ndb_con_op=105000;
2451
my $ndb_pbmem="32M";
2452
my $nodes= $cluster->{'nodes'};
2453
my $ndb_host= "localhost";
2454
my $ndb_diskless= 0;
2458
# Use a smaller configuration
2459
if ( $mysql_version_id < 50100 )
2461
# 4.1 and 5.0 is using a "larger" --small configuration
2477
my $config_file_template= "ndb/ndb_config_${nodes}_node.ini";
2478
my $config_file= "$cluster->{'data_dir'}/config.ini";
2480
open(IN, $config_file_template)
2481
or mtr_error("Can't open $config_file_template: $!");
2482
open(OUT, ">", $config_file)
2483
or mtr_error("Can't write to $config_file: $!");
2488
s/CHOOSE_MaxNoOfAttributes/$ndb_no_attr/;
2489
s/CHOOSE_MaxNoOfOrderedIndexes/$ndb_no_ord/;
2490
s/CHOOSE_MaxNoOfConcurrentOperations/$ndb_con_op/;
2491
s/CHOOSE_DataMemory/$ndb_dmem/;
2492
s/CHOOSE_IndexMemory/$ndb_imem/;
2493
s/CHOOSE_Diskless/$ndb_diskless/;
2494
s/CHOOSE_HOSTNAME_.*/$ndb_host/;
2495
s/CHOOSE_FILESYSTEM/$cluster->{'data_dir'}/;
2496
s/CHOOSE_PORT_MGM/$cluster->{'port'}/;
2497
if ( $mysql_version_id < 50000 )
2499
my $base_port= $cluster->{'port'} + 1;
2500
s/CHOOSE_PORT_TRANSPORTER/$base_port/;
2502
s/CHOOSE_DiskPageBufferMemory/$ndb_pbmem/;
2510
# Start cluster with "--initial"
2512
ndbcluster_start($cluster, "--initial");
2518
sub ndbcluster_wait_started($$){
2520
my $ndb_waiter_extra_opt= shift;
2521
my $path_waiter_log= "$cluster->{'data_dir'}/ndb_waiter.log";
2524
mtr_init_args(\$args);
2526
mtr_add_arg($args, "--no-defaults");
2527
mtr_add_arg($args, "--core");
2528
mtr_add_arg($args, "--ndb-connectstring=%s", $cluster->{'connect_string'});
2529
mtr_add_arg($args, "--timeout=60");
2531
if ($ndb_waiter_extra_opt)
2533
mtr_add_arg($args, "$ndb_waiter_extra_opt");
2536
# Start the ndb_waiter which will connect to the ndb_mgmd
2537
# and poll it for state of the ndbd's, will return when
2538
# all nodes in the cluster is started
2539
my $res= mtr_run($exe_ndb_waiter, $args,
2540
"", $path_waiter_log, $path_waiter_log, "");
2541
mtr_verbose("ndbcluster_wait_started, returns: $res") if $res;
2547
sub mysqld_wait_started($){
2550
if (sleep_until_file_created($mysqld->{'path_pid'},
2551
$mysqld->{'start_timeout'},
2552
$mysqld->{'pid'}) == 0)
2554
# Failed to wait for pid file
2558
# Get the "real pid" of the process, it will be used for killing
2559
# the process in ActiveState's perl on windows
2560
$mysqld->{'real_pid'}= mtr_get_pid_from_file($mysqld->{'path_pid'});
2566
sub ndb_mgmd_wait_started($) {
2570
while (ndbcluster_wait_started($cluster, "--no-contact") and
2573
# Millisceond sleep emulated with select
2574
select(undef, undef, undef, (0.1));
2579
return $retries == 0;
2583
sub ndb_mgmd_start ($) {
2586
my $args; # Arg vector
2589
mtr_init_args(\$args);
2590
mtr_add_arg($args, "--no-defaults");
2591
mtr_add_arg($args, "--core");
2592
mtr_add_arg($args, "--nodaemon");
2593
mtr_add_arg($args, "--config-file=%s", "$cluster->{'data_dir'}/config.ini");
2596
my $path_ndb_mgmd_log= "$cluster->{'data_dir'}/\l$cluster->{'name'}_ndb_mgmd.log";
2597
$pid= mtr_spawn($exe_ndb_mgmd, $args, "",
2601
{ append_log_file => 1 });
2603
# FIXME Should not be needed
2604
# Unfortunately the cluster nodes will fail to start
2605
# if ndb_mgmd has not started properly
2606
if (ndb_mgmd_wait_started($cluster))
2608
mtr_error("Failed to wait for start of ndb_mgmd");
2611
# Remember pid of ndb_mgmd
2612
$cluster->{'pid'}= $pid;
2614
mtr_verbose("ndb_mgmd_start, pid: $pid");
2620
sub ndbd_start ($$$) {
2623
my $extra_args= shift;
2625
my $args; # Arg vector
2628
mtr_init_args(\$args);
2629
mtr_add_arg($args, "--no-defaults");
2630
mtr_add_arg($args, "--core");
2631
mtr_add_arg($args, "--ndb-connectstring=%s", "$cluster->{'connect_string'}");
2632
if ( $mysql_version_id >= 50000)
2634
mtr_add_arg($args, "--character-sets-dir=%s", "$path_charsetsdir");
2636
mtr_add_arg($args, "--nodaemon");
2637
mtr_add_arg($args, "$extra_args");
2639
my $nodeid= $cluster->{'ndbds'}->[$idx]->{'nodeid'};
2640
my $path_ndbd_log= "$cluster->{'data_dir'}/ndb_${nodeid}.log";
2641
$pid= mtr_spawn($exe_ndbd, $args, "",
2645
{ append_log_file => 1 });
2647
# Add pid to list of pids for this cluster
2648
$cluster->{'ndbds'}->[$idx]->{'pid'}= $pid;
2650
# Rememeber options used when starting
2651
$cluster->{'ndbds'}->[$idx]->{'start_extra_args'}= $extra_args;
2652
$cluster->{'ndbds'}->[$idx]->{'idx'}= $idx;
2654
mtr_verbose("ndbd_start, pid: $pid");
2660
sub ndbcluster_start ($$) {
2662
my $extra_args= shift;
2664
mtr_verbose("ndbcluster_start '$cluster->{'name'}'");
2666
if ( $cluster->{'use_running'} )
2671
if ( $cluster->{'pid'} )
2673
mtr_error("Cluster '$cluster->{'name'}' already started");
2676
ndb_mgmd_start($cluster);
2678
for ( my $idx= 0; $idx < $cluster->{'nodes'}; $idx++ )
2680
ndbd_start($cluster, $idx, $extra_args);
2687
sub rm_ndbcluster_tables ($) {
2689
foreach my $bin ( glob("$dir/mysql/ndb_apply_status*"),
2690
glob("$dir/mysql/ndb_schema*"))
2697
##############################################################################
2699
# Run the benchmark suite
2701
##############################################################################
2703
sub run_benchmarks ($) {
2704
my $benchmark= shift;
2708
if ( ! $glob_use_embedded_server )
2710
mysqld_start($master->[0],[],[]);
2711
if ( ! $master->[0]->{'pid'} )
2713
mtr_error("Can't start the mysqld server");
2717
mtr_init_args(\$args);
2719
mtr_add_arg($args, "--user=%s", $opt_user);
2721
if ( $opt_small_bench )
2723
mtr_add_arg($args, "--small-test");
2724
mtr_add_arg($args, "--small-tables");
2727
if ( $opt_with_ndbcluster )
2729
mtr_add_arg($args, "--create-options=TYPE=ndb");
2732
chdir($glob_mysql_bench_dir)
2733
or mtr_error("Couldn't chdir to '$glob_mysql_bench_dir': $!");
2737
mtr_add_arg($args, "--log");
2738
mtr_run("$glob_mysql_bench_dir/run-all-tests", $args, "", "", "", "");
2739
# FIXME check result code?!
2741
elsif ( -x $benchmark )
2743
mtr_run("$glob_mysql_bench_dir/$benchmark", $args, "", "", "", "");
2744
# FIXME check result code?!
2748
mtr_error("Benchmark $benchmark not found");
2751
chdir($glob_mysql_test_dir); # Go back
2753
if ( ! $glob_use_embedded_server )
2760
##############################################################################
2764
##############################################################################
2769
mtr_print_thick_line();
2771
mtr_timer_start($glob_timers,"suite", 60 * $opt_suite_timeout);
2773
mtr_report_tests_not_skipped_though_disabled($tests);
2777
foreach my $tinfo ( @$tests )
2779
if (run_testcase_check_skip_test($tinfo))
2784
mtr_timer_start($glob_timers,"testcase", 60 * $opt_testcase_timeout);
2785
run_testcase($tinfo);
2786
mtr_timer_stop($glob_timers,"testcase");
2791
if ( ! $glob_debugger and
2793
! $glob_use_embedded_server )
2800
gcov_collect(); # collect coverage information
2804
gprof_collect(); # collect coverage information
2807
mtr_report_stats($tests);
2809
mtr_timer_stop($glob_timers,"suite");
2813
##############################################################################
2815
# Initiate the test databases
2817
##############################################################################
2819
sub initialize_servers () {
2821
datadir_list_setup();
2825
# Running against an already started server, if the specified
2826
# vardir does not already exist it should be created
2827
if ( ! -d $opt_vardir )
2829
mtr_report("Creating '$opt_vardir'");
2834
mtr_verbose("No need to create '$opt_vardir' it already exists");
2839
kill_running_servers();
2841
if ( ! $opt_start_dirty )
2843
remove_stale_vardir();
2849
# Save a snapshot of the freshly installed db
2850
# to make it possible to restore to a known point in time
2851
save_installed_db();
2855
check_running_as_root();
2857
mtr_log_init("$opt_vardir/log/mysql-test-run.log");
2861
sub mysql_install_db () {
2863
install_db('master', $master->[0]->{'path_myddir'});
2865
if ($max_master_num > 1)
2867
copy_install_db('master', $master->[1]->{'path_myddir'});
2870
# Install the number of slave databses needed
2871
for (my $idx= 0; $idx < $max_slave_num; $idx++)
2873
copy_install_db("slave".($idx+1), $slave->[$idx]->{'path_myddir'});
2876
my $cluster_started_ok= 1; # Assume it can be started
2878
my $cluster= $clusters->[0]; # Master cluster
2879
if ($opt_skip_ndbcluster ||
2880
$cluster->{'use_running'} ||
2881
$cluster->{executable_setup_failed})
2883
# Don't install master cluster
2885
elsif (ndbcluster_start_install($cluster))
2887
mtr_warning("Failed to start install of $cluster->{name}");
2888
$cluster_started_ok= 0;
2891
$cluster= $clusters->[1]; # Slave cluster
2892
if ($max_slave_num == 0 ||
2893
$opt_skip_ndbcluster_slave ||
2894
$cluster->{'use_running'} ||
2895
$cluster->{executable_setup_failed})
2897
# Don't install slave cluster
2899
elsif (ndbcluster_start_install($cluster))
2901
mtr_warning("Failed to start install of $cluster->{name}");
2902
$cluster_started_ok= 0;
2905
foreach $cluster (@{$clusters})
2908
next if !$cluster->{'pid'};
2910
$cluster->{'installed_ok'}= 1; # Assume install suceeds
2912
if (ndbcluster_wait_started($cluster, ""))
2914
# failed to install, disable usage and flag that its no ok
2915
mtr_report("ndbcluster_install of $cluster->{'name'} failed");
2916
$cluster->{"installed_ok"}= 0;
2918
$cluster_started_ok= 0;
2922
if ( ! $cluster_started_ok )
2926
# Continue without cluster
2930
mtr_error("To continue, re-run with '--force'.");
2938
sub copy_install_db ($$) {
2940
my $data_dir= shift;
2942
mtr_report("Installing \u$type Database");
2944
# Just copy the installed db from first master
2945
mtr_copy_dir($master->[0]->{'path_myddir'}, $data_dir);
2950
sub install_db ($$) {
2952
my $data_dir= shift;
2954
mtr_report("Installing \u$type Database");
2958
mtr_init_args(\$args);
2959
mtr_add_arg($args, "--no-defaults");
2960
mtr_add_arg($args, "--bootstrap");
2961
mtr_add_arg($args, "--basedir=%s", $path_my_basedir);
2962
mtr_add_arg($args, "--datadir=%s", $data_dir);
2963
mtr_add_arg($args, "--loose-skip-innodb");
2964
mtr_add_arg($args, "--tmpdir=.");
2965
mtr_add_arg($args, "--core-file");
2969
mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap_%s.trace",
2970
$path_vardir_trace, $type);
2973
if ( ! $glob_netware )
2975
mtr_add_arg($args, "--language=%s", $path_language);
2976
mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
2979
# If DISABLE_GRANT_OPTIONS is defined when the server is compiled (e.g.,
2980
# configure --disable-grant-options), mysqld will not recognize the
2981
# --bootstrap or --skip-grant-tables options. The user can set
2982
# MYSQLD_BOOTSTRAP to the full path to a mysqld which does accept
2983
# --bootstrap, to accommodate this.
2984
my $exe_mysqld_bootstrap = $ENV{'MYSQLD_BOOTSTRAP'} || $exe_mysqld;
2986
# ----------------------------------------------------------------------
2987
# export MYSQLD_BOOTSTRAP_CMD variable containing <path>/mysqld <args>
2988
# ----------------------------------------------------------------------
2989
$ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args);
2991
# ----------------------------------------------------------------------
2992
# Create the bootstrap.sql file
2993
# ----------------------------------------------------------------------
2994
my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql";
2996
# Use the mysql database for system tables
2997
mtr_tofile($bootstrap_sql_file, "use mysql");
2999
# Add the offical mysql system tables
3000
# for a production system
3001
mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables.sql",
3002
$bootstrap_sql_file);
3004
# Add the mysql system tables initial data
3005
# for a production system
3006
mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables_data.sql",
3007
$bootstrap_sql_file);
3009
# Add test data for timezone - this is just a subset, on a real
3010
# system these tables will be populated either by mysql_tzinfo_to_sql
3011
# or by downloading the timezone table package from our website
3012
mtr_appendfile_to_file("$path_sql_dir/mysql_test_data_timezone.sql",
3013
$bootstrap_sql_file);
3015
# Remove anonymous users
3016
mtr_tofile($bootstrap_sql_file,
3017
"DELETE FROM mysql.user where user= '';");
3019
# Log bootstrap command
3020
my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
3021
mtr_tofile($path_bootstrap_log,
3022
"$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
3025
if ( mtr_run($exe_mysqld_bootstrap, $args, $bootstrap_sql_file,
3026
$path_bootstrap_log, $path_bootstrap_log,
3027
"", { append_log_file => 1 }) != 0 )
3030
mtr_error("Error executing mysqld --bootstrap\n" .
3031
"Could not install system database from $bootstrap_sql_file\n" .
3032
"see $path_bootstrap_log for errors");
3038
# Restore snapshot of the installed slave databases
3039
# if the snapshot exists
3041
sub restore_slave_databases ($) {
3042
my ($num_slaves)= @_;
3044
if ( -d $path_snapshot)
3046
for (my $idx= 0; $idx < $num_slaves; $idx++)
3048
my $data_dir= $slave->[$idx]->{'path_myddir'};
3049
my $name= basename($data_dir);
3050
mtr_rmtree($data_dir);
3051
mtr_copy_dir("$path_snapshot/$name", $data_dir);
3057
sub run_testcase_check_skip_test($)
3061
# ----------------------------------------------------------------------
3062
# If marked to skip, just print out and return.
3063
# Note that a test case not marked as 'skip' can still be
3064
# skipped later, because of the test case itself in cooperation
3065
# with the mysqltest program tells us so.
3066
# ----------------------------------------------------------------------
3068
if ( $tinfo->{'skip'} )
3070
mtr_report_test_name($tinfo);
3071
mtr_report_test_skipped($tinfo);
3075
if ($tinfo->{'ndb_test'})
3077
foreach my $cluster (@{$clusters})
3079
# Slave cluster is skipped and thus not
3080
# installed, no need to perform checks
3081
last if ($opt_skip_ndbcluster_slave and
3082
$cluster->{'name'} eq 'Slave');
3084
# Using running cluster - no need
3085
# to check if test should be skipped
3086
# will be done by test itself
3087
last if ($cluster->{'use_running'});
3089
# If test needs this cluster, check binaries was found ok
3090
if ( $cluster->{'executable_setup_failed'} )
3092
mtr_report_test_name($tinfo);
3094
"Failed to find cluster binaries";
3095
mtr_report_test_failed($tinfo);
3099
# If test needs this cluster, check it was installed ok
3100
if ( !$cluster->{'installed_ok'} )
3102
mtr_report_test_name($tinfo);
3104
"Cluster $cluster->{'name'} was not installed ok";
3105
mtr_report_test_failed($tinfo);
3116
sub do_before_run_mysqltest($)
3121
# Remove old files produced by mysqltest
3122
my $base_file= mtr_match_extension($tinfo->{'result_file'},
3123
"result"); # Trim extension
3124
unlink("$base_file.reject");
3125
unlink("$base_file.progress");
3126
unlink("$base_file.log");
3127
unlink("$base_file.warnings");
3131
if ( $mysql_version_id < 50000 ) {
3132
# Set environment variable NDB_STATUS_OK to 1
3133
# if script decided to run mysqltest cluster _is_ installed ok
3134
$ENV{'NDB_STATUS_OK'} = "1";
3135
} elsif ( $mysql_version_id < 50100 ) {
3136
# Set environment variable NDB_STATUS_OK to YES
3137
# if script decided to run mysqltest cluster _is_ installed ok
3138
$ENV{'NDB_STATUS_OK'} = "YES";
3140
if (defined $tinfo->{binlog_format} and $mysql_version_id > 50100 )
3142
# Dynamically switch binlog format of
3143
# master, slave is always restarted
3144
foreach my $server ( @$master )
3146
next unless ($server->{'pid'});
3148
mtr_init_args(\$args);
3149
mtr_add_arg($args, "--no-defaults");
3150
mtr_add_arg($args, "--user=root");
3151
mtr_add_arg($args, "--port=$server->{'port'}");
3153
my $sql= "include/set_binlog_format_".$tinfo->{binlog_format}.".sql";
3154
mtr_verbose("Setting binlog format:", $tinfo->{binlog_format});
3155
if (mtr_run($exe_mysql, $args, $sql, "", "", "") != 0)
3157
mtr_error("Failed to switch binlog format");
3164
sub do_after_run_mysqltest($)
3168
# Save info from this testcase run to mysqltest.log
3169
mtr_appendfile_to_file($path_current_test_log, $path_mysqltest_log)
3170
if -f $path_current_test_log;
3171
mtr_appendfile_to_file($path_timefile, $path_mysqltest_log)
3172
if -f $path_timefile;
3176
sub run_testcase_mark_logs($$)
3178
my ($tinfo, $log_msg)= @_;
3180
# Write a marker to all log files
3182
# The file indicating current test name
3183
mtr_tonewfile($path_current_test_log, $log_msg);
3185
# each mysqld's .err file
3186
foreach my $mysqld (@{$master}, @{$slave})
3188
mtr_tofile($mysqld->{path_myerr}, $log_msg);
3191
# ndbcluster log file
3192
mtr_tofile($path_ndb_testrun_log, $log_msg);
3196
sub find_testcase_skipped_reason($)
3200
# Set default message
3201
$tinfo->{'comment'}= "Detected by testcase(no log file)";
3203
# Open mysqltest-time(the mysqltest log file)
3204
my $F= IO::File->new($path_timefile)
3208
while ( my $line= <$F> )
3210
# Look for "reason: <reason for skipping test>"
3211
if ( $line =~ /reason: (.*)/ )
3219
mtr_warning("Could not find reason for skipping test in $path_timefile");
3220
$reason= "Detected by testcase(reason unknown) ";
3222
$tinfo->{'comment'}= $reason;
3226
##############################################################################
3228
# Run a single test case
3230
##############################################################################
3232
# When we get here, we have already filtered out test cases that doesn't
3233
# apply to the current setup, for example if we use a running server, test
3234
# cases that restart the server are dropped. So this function should mostly
3235
# be about doing things, not a lot of logic.
3237
# We don't start and kill the servers for each testcase. But some
3238
# testcases needs a restart, because they specify options to start
3239
# mysqld with. After that testcase, we need to restart again, to set
3240
# back the normal options.
3242
sub run_testcase ($) {
3245
# -------------------------------------------------------
3246
# Init variables that can change between each test case
3247
# -------------------------------------------------------
3249
$ENV{'TZ'}= $tinfo->{'timezone'};
3250
mtr_verbose("Setting timezone: $tinfo->{'timezone'}");
3252
my $master_restart= run_testcase_need_master_restart($tinfo);
3253
my $slave_restart= run_testcase_need_slave_restart($tinfo);
3255
if ($master_restart or $slave_restart)
3257
# Can't restart a running server that may be in use
3260
mtr_report_test_name($tinfo);
3261
$tinfo->{comment}= "Can't restart a running server";
3262
mtr_report_test_skipped($tinfo);
3266
run_testcase_stop_servers($tinfo, $master_restart, $slave_restart);
3269
# Write to all log files to indicate start of testcase
3270
run_testcase_mark_logs($tinfo, "CURRENT_TEST: $tinfo->{name}\n");
3272
my $died= mtr_record_dead_children();
3273
if ($died or $master_restart or $slave_restart)
3275
if (run_testcase_start_servers($tinfo))
3277
mtr_report_test_name($tinfo);
3278
report_failure_and_restart($tinfo);
3282
elsif ($glob_use_embedded_server)
3284
run_master_init_script($tinfo);
3287
# ----------------------------------------------------------------------
3288
# If --start-and-exit or --start-dirty given, stop here to let user manually
3290
# ----------------------------------------------------------------------
3291
if ( $opt_start_and_exit or $opt_start_dirty )
3293
mtr_timer_stop_all($glob_timers);
3294
mtr_report("\nServers started, exiting");
3299
do_before_run_mysqltest($tinfo);
3301
my $res= run_mysqltest($tinfo);
3302
mtr_report_test_name($tinfo);
3304
do_after_run_mysqltest($tinfo);
3308
mtr_report_test_passed($tinfo);
3310
elsif ( $res == 62 )
3312
# Testcase itself tell us to skip this one
3314
# Try to get reason from mysqltest.log
3315
find_testcase_skipped_reason($tinfo);
3316
mtr_report_test_skipped($tinfo);
3318
elsif ( $res == 63 )
3320
$tinfo->{'timeout'}= 1; # Mark as timeout
3321
report_failure_and_restart($tinfo);
3325
# Test case failure reported by mysqltest
3326
report_failure_and_restart($tinfo);
3330
# mysqltest failed, probably crashed
3332
"mysqltest returned unexpected code $res, it has probably crashed";
3333
report_failure_and_restart($tinfo);
3337
# Remove the file that mysqltest writes info to
3338
unlink($path_timefile);
3340
# ----------------------------------------------------------------------
3341
# Stop Instance Manager if we are processing an IM-test case.
3342
# ----------------------------------------------------------------------
3347
# Save a snapshot of the installed test db(s)
3348
# I.e take a snapshot of the var/ dir
3350
sub save_installed_db () {
3352
mtr_report("Saving snapshot of installed databases");
3353
mtr_rmtree($path_snapshot);
3355
foreach my $data_dir (@data_dir_lst)
3357
my $name= basename($data_dir);
3358
mtr_copy_dir("$data_dir", "$path_snapshot/$name");
3364
# Save any interesting files in the data_dir
3365
# before the data dir is removed.
3367
sub save_files_before_restore($$) {
3368
my $test_name= shift;
3369
my $data_dir= shift;
3370
my $save_name= "$opt_vardir/log/$test_name";
3372
# Look for core files
3373
foreach my $core_file ( glob("$data_dir/core*") )
3375
last if $opt_max_save_core > 0 && $num_saved_cores >= $opt_max_save_core;
3376
my $core_name= basename($core_file);
3377
mtr_report("Saving $core_name");
3378
mkdir($save_name) if ! -d $save_name;
3379
rename("$core_file", "$save_name/$core_name");
3386
# Restore snapshot of the installed test db(s)
3387
# if the snapshot exists
3389
sub restore_installed_db ($) {
3390
my $test_name= shift;
3392
if ( -d $path_snapshot)
3394
mtr_report("Restoring snapshot of databases");
3396
foreach my $data_dir (@data_dir_lst)
3398
my $name= basename($data_dir);
3399
save_files_before_restore($test_name, $data_dir);
3400
mtr_rmtree("$data_dir");
3401
mtr_copy_dir("$path_snapshot/$name", "$data_dir");
3404
# Remove the ndb_*_fs dirs for all ndbd nodes
3405
# forcing a clean start of ndb
3406
foreach my $cluster (@{$clusters})
3408
foreach my $ndbd (@{$cluster->{'ndbds'}})
3410
mtr_rmtree("$ndbd->{'path_fs'}" );
3416
# No snapshot existed
3417
mtr_error("No snapshot existed");
3421
sub report_failure_and_restart ($) {
3424
mtr_report_test_failed($tinfo);
3428
# Stop all servers that are known to be running
3431
# Restore the snapshot of the installed test db
3432
restore_installed_db($tinfo->{'name'});
3433
mtr_report("Resuming Tests\n");
3437
my $test_mode= join(" ", @::glob_test_mode) || "default";
3438
mtr_report("Aborting: $tinfo->{'name'} failed in $test_mode mode. ");
3439
mtr_report("To continue, re-run with '--force'.");
3440
if ( ! $glob_debugger and
3442
! $glob_use_embedded_server )
3451
sub run_master_init_script ($) {
3453
my $init_script= $tinfo->{'master_sh'};
3455
# Run master initialization shell script if one exists
3458
my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
3461
# FIXME rewrite those scripts to return 0 if successful
3462
# mtr_warning("$init_script exited with code $ret");
3468
##############################################################################
3470
# Start and stop servers
3472
##############################################################################
3475
sub do_before_start_master ($) {
3478
my $tname= $tinfo->{'name'};
3480
# FIXME what about second master.....
3482
# Don't delete anything if starting dirty
3483
return if ($opt_start_dirty);
3485
foreach my $bin ( glob("$opt_vardir/log/master*-bin*") )
3490
# FIXME only remove the ones that are tied to this master
3491
# Remove old master.info and relay-log.info files
3492
unlink("$master->[0]->{'path_myddir'}/master.info");
3493
unlink("$master->[0]->{'path_myddir'}/relay-log.info");
3494
unlink("$master->[1]->{'path_myddir'}/master.info");
3495
unlink("$master->[1]->{'path_myddir'}/relay-log.info");
3497
run_master_init_script($tinfo);
3501
sub do_before_start_slave ($) {
3504
my $tname= $tinfo->{'name'};
3505
my $init_script= $tinfo->{'master_sh'};
3507
# Don't delete anything if starting dirty
3508
return if ($opt_start_dirty);
3510
foreach my $bin ( glob("$opt_vardir/log/slave*-bin*") )
3515
unlink("$slave->[0]->{'path_myddir'}/master.info");
3516
unlink("$slave->[0]->{'path_myddir'}/relay-log.info");
3518
# Run slave initialization shell script if one exists
3521
my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
3524
# FIXME rewrite those scripts to return 0 if successful
3525
# mtr_warning("$init_script exited with code $ret");
3529
foreach my $bin ( glob("$slave->[0]->{'path_myddir'}/log.*") )
3536
sub mysqld_arguments ($$$$) {
3539
my $extra_opt= shift;
3540
my $slave_master_info= shift;
3542
my $idx= $mysqld->{'idx'};
3543
my $sidx= ""; # Index as string, 0 is empty string
3549
my $prefix= ""; # If mysqltest server arg
3550
if ( $glob_use_embedded_server )
3552
$prefix= "--server-arg=";
3555
mtr_add_arg($args, "%s--no-defaults", $prefix);
3557
mtr_add_arg($args, "%s--basedir=%s", $prefix, $path_my_basedir);
3558
mtr_add_arg($args, "%s--character-sets-dir=%s", $prefix, $path_charsetsdir);
3560
if ( $mysql_version_id >= 50036)
3562
# By default, prevent the started mysqld to access files outside of vardir
3563
mtr_add_arg($args, "%s--secure-file-priv=%s", $prefix, $opt_vardir);
3566
if ( $mysql_version_id >= 50000 )
3568
mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix);
3571
mtr_add_arg($args, "%s--default-character-set=latin1", $prefix);
3572
mtr_add_arg($args, "%s--language=%s", $prefix, $path_language);
3573
mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix);
3575
# Increase default connect_timeout to avoid intermittent
3576
# disconnects when test servers are put under load
3578
mtr_add_arg($args, "%s--connect-timeout=60", $prefix);
3581
# When mysqld is run by a root user(euid is 0), it will fail
3582
# to start unless we specify what user to run as, see BUG#30630
3584
if (!$glob_win32 and $euid == 0 and
3585
grep(/^--user/, @$extra_opt, @opt_extra_mysqld_opt) == 0) {
3586
mtr_add_arg($args, "%s--user=root", $prefix);
3589
mtr_add_arg($args, "%s--pid-file=%s", $prefix,
3590
$mysqld->{'path_pid'});
3592
mtr_add_arg($args, "%s--port=%d", $prefix,
3595
mtr_add_arg($args, "%s--datadir=%s", $prefix,
3596
$mysqld->{'path_myddir'});
3599
if ( $mysql_version_id >= 50106 )
3601
# Turn on logging to bothe tables and file
3602
mtr_add_arg($args, "%s--log-output=table,file", $prefix);
3605
my $log_base_path= "$opt_vardir/log/$mysqld->{'type'}$sidx";
3606
mtr_add_arg($args, "%s--log=%s.log", $prefix, $log_base_path);
3608
"%s--log-slow-queries=%s-slow.log", $prefix, $log_base_path);
3610
# Check if "extra_opt" contains --skip-log-bin
3611
my $skip_binlog= grep(/^--skip-log-bin/, @$extra_opt, @opt_extra_mysqld_opt);
3612
if ( $mysqld->{'type'} eq 'master' )
3614
if (! ($opt_skip_master_binlog || $skip_binlog) )
3616
mtr_add_arg($args, "%s--log-bin=%s/log/master-bin%s", $prefix,
3617
$opt_vardir, $sidx);
3620
mtr_add_arg($args, "%s--server-id=%d", $prefix,
3621
$idx > 0 ? $idx + 101 : 1);
3623
mtr_add_arg($args, "%s--loose-innodb_data_file_path=ibdata1:10M:autoextend",
3626
mtr_add_arg($args, "%s--local-infile", $prefix);
3628
if ( $idx > 0 or !$use_innodb)
3630
mtr_add_arg($args, "%s--loose-skip-innodb", $prefix);
3633
my $cluster= $clusters->[$mysqld->{'cluster'}];
3634
if ( $cluster->{'pid'} || # Cluster is started
3635
$cluster->{'use_running'} ) # Using running cluster
3637
mtr_add_arg($args, "%s--ndbcluster", $prefix);
3638
mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
3639
$cluster->{'connect_string'});
3640
mtr_add_arg($args, "%s--ndb-wait-connected=20", $prefix);
3641
mtr_add_arg($args, "%s--ndb-cluster-connection-pool=3", $prefix);
3642
mtr_add_arg($args, "%s--slave-allow-batching", $prefix);
3643
if ( $mysql_version_id >= 50100 )
3645
mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
3646
mtr_add_arg($args, "%s--ndb-log-orig", $prefix);
3651
mtr_add_arg($args, "%s--loose-skip-ndbcluster", $prefix);
3656
mtr_error("unknown mysqld type")
3657
unless $mysqld->{'type'} eq 'slave';
3659
#mtr_add_arg($args, "%s--init-rpl-role=slave", $prefix);
3660
if (! ( $opt_skip_slave_binlog || $skip_binlog ))
3662
mtr_add_arg($args, "%s--log-bin=%s/log/slave%s-bin", $prefix,
3663
$opt_vardir, $sidx); # FIXME use own dir for binlogs
3664
mtr_add_arg($args, "%s--log-slave-updates", $prefix);
3667
mtr_add_arg($args, "%s--master-retry-count=10", $prefix);
3669
mtr_add_arg($args, "%s--relay-log=%s/log/slave%s-relay-bin", $prefix,
3670
$opt_vardir, $sidx);
3671
mtr_add_arg($args, "%s--report-host=127.0.0.1", $prefix);
3672
mtr_add_arg($args, "%s--report-port=%d", $prefix,
3674
# mtr_add_arg($args, "%s--report-user=root", $prefix);
3675
mtr_add_arg($args, "%s--loose-skip-innodb", $prefix);
3676
mtr_add_arg($args, "%s--skip-slave-start", $prefix);
3678
# Directory where slaves find the dumps generated by "load data"
3679
# on the server. The path need to have constant length otherwise
3680
# test results will vary, thus a relative path is used.
3681
my $slave_load_path= "../tmp";
3682
mtr_add_arg($args, "%s--slave-load-tmpdir=%s", $prefix,
3684
mtr_add_arg($args, "%s--set-variable=slave_net_timeout=120", $prefix);
3686
if ( @$slave_master_info )
3688
foreach my $arg ( @$slave_master_info )
3690
mtr_add_arg($args, "%s%s", $prefix, $arg);
3695
my $slave_server_id= 2 + $idx;
3696
my $slave_rpl_rank= $slave_server_id;
3697
mtr_add_arg($args, "%s--server-id=%d", $prefix, $slave_server_id);
3698
# mtr_add_arg($args, "%s--rpl-recovery-rank=%d", $prefix, $slave_rpl_rank);
3701
my $cluster= $clusters->[$mysqld->{'cluster'}];
3702
if ( $cluster->{'pid'} || # Slave cluster is started
3703
$cluster->{'use_running'} ) # Using running slave cluster
3705
mtr_add_arg($args, "%s--ndbcluster", $prefix);
3706
mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
3707
$cluster->{'connect_string'});
3708
mtr_add_arg($args, "%s--ndb-wait-connected=20", $prefix);
3709
mtr_add_arg($args, "%s--ndb-cluster-connection-pool=3", $prefix);
3710
mtr_add_arg($args, "%s--slave-allow-batching", $prefix);
3711
if ( $mysql_version_id >= 50100 )
3713
mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
3714
mtr_add_arg($args, "%s--ndb-log-orig", $prefix);
3719
mtr_add_arg($args, "%s--loose-skip-ndbcluster", $prefix);
3725
mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/%s%s.trace",
3726
$prefix, $path_vardir_trace, $mysqld->{'type'}, $sidx);
3729
mtr_add_arg($args, "%s--key_buffer_size=1M", $prefix);
3730
mtr_add_arg($args, "%s--sort_buffer=256K", $prefix);
3731
mtr_add_arg($args, "%s--max_heap_table_size=1M", $prefix);
3733
if ( $opt_ssl_supported )
3735
mtr_add_arg($args, "%s--ssl-ca=%s/std_data/cacert.pem", $prefix,
3736
$glob_mysql_test_dir);
3737
mtr_add_arg($args, "%s--ssl-cert=%s/std_data/server-cert.pem", $prefix,
3738
$glob_mysql_test_dir);
3739
mtr_add_arg($args, "%s--ssl-key=%s/std_data/server-key.pem", $prefix,
3740
$glob_mysql_test_dir);
3743
if ( $opt_warnings )
3745
mtr_add_arg($args, "%s--log-warnings", $prefix);
3748
# Indicate to "mysqld" it will be debugged in debugger
3749
if ( $glob_debugger )
3751
mtr_add_arg($args, "%s--gdb", $prefix);
3754
my $found_skip_core= 0;
3755
foreach my $arg ( @opt_extra_mysqld_opt, @$extra_opt )
3757
# Allow --skip-core-file to be set in <testname>-[master|slave].opt file
3758
if ($arg eq "--skip-core-file")
3760
$found_skip_core= 1;
3762
elsif ($skip_binlog and mtr_match_prefix($arg, "--binlog-format"))
3764
; # Dont add --binlog-format when running without binlog
3768
mtr_add_arg($args, "%s%s", $prefix, $arg);
3771
if ( !$found_skip_core )
3773
mtr_add_arg($args, "%s%s", $prefix, "--core-file");
3778
#mtr_add_arg($args, "%s--rpl-recovery-rank=1", $prefix);
3779
#mtr_add_arg($args, "%s--init-rpl-role=master", $prefix);
3781
elsif ( $mysqld->{'type'} eq 'master' )
3783
mtr_add_arg($args, "%s--open-files-limit=1024", $prefix);
3790
##############################################################################
3792
# Start mysqld and return the PID
3794
##############################################################################
3796
sub mysqld_start ($$$) {
3798
my $extra_opt= shift;
3799
my $slave_master_info= shift;
3801
my $args; # Arg vector
3804
my $wait_for_pid_file= 1;
3806
my $type= $mysqld->{'type'};
3807
my $idx= $mysqld->{'idx'};
3809
mtr_error("Internal error: mysqld should never be started for embedded")
3810
if $glob_use_embedded_server;
3812
if ( $type eq 'master' )
3814
$exe= $exe_master_mysqld;
3816
elsif ( $type eq 'slave' )
3818
$exe= $exe_slave_mysqld;
3822
mtr_error("Unknown 'type' \"$type\" passed to mysqld_start");
3825
mtr_init_args(\$args);
3827
if ( $opt_valgrind_mysqld )
3829
valgrind_arguments($args, \$exe);
3832
mysqld_arguments($args,$mysqld,$extra_opt,$slave_master_info);
3834
if ( $opt_gdb || $opt_manual_gdb)
3836
gdb_arguments(\$args, \$exe, "$type"."_$idx");
3838
elsif ( $opt_ddd || $opt_manual_ddd )
3840
ddd_arguments(\$args, \$exe, "$type"."_$idx");
3842
elsif ( $opt_debugger )
3844
debugger_arguments(\$args, \$exe, "$type"."_$idx");
3846
elsif ( $opt_manual_debug )
3848
print "\nStart $type in your debugger\n" .
3849
"dir: $glob_mysql_test_dir\n" .
3851
"args: " . join(" ", @$args) . "\n\n" .
3854
# Indicate the exe should not be started
3859
# Default to not wait until pid file has been created
3860
$wait_for_pid_file= 0;
3863
# Remove the pidfile
3864
unlink($mysqld->{'path_pid'});
3868
$pid= mtr_spawn($exe, $args, "",
3869
$mysqld->{'path_myerr'},
3870
$mysqld->{'path_myerr'},
3872
{ append_log_file => 1 });
3876
if ( $wait_for_pid_file && !sleep_until_file_created($mysqld->{'path_pid'},
3877
$mysqld->{'start_timeout'},
3881
mtr_error("Failed to start mysqld $mysqld->{'type'}");
3885
# Remember pid of the started process
3886
$mysqld->{'pid'}= $pid;
3888
# Remember options used when starting
3889
$mysqld->{'start_opts'}= $extra_opt;
3890
$mysqld->{'start_slave_master_info'}= $slave_master_info;
3892
mtr_verbose("mysqld pid: $pid");
3897
sub stop_all_servers () {
3899
mtr_report("Stopping All Servers");
3901
my %admin_pids; # hash of admin processes that requests shutdown
3902
my @kill_pids; # list of processes to shutdown/kill
3905
# Start shutdown of all started masters
3906
foreach my $mysqld (@{$slave}, @{$master})
3908
if ( $mysqld->{'pid'} )
3910
$pid= mtr_mysqladmin_start($mysqld, "shutdown", 70);
3911
$admin_pids{$pid}= 1;
3914
pid => $mysqld->{'pid'},
3915
real_pid => $mysqld->{'real_pid'},
3916
pidfile => $mysqld->{'path_pid'},
3917
sockfile => $mysqld->{'path_sock'},
3918
port => $mysqld->{'port'},
3919
errfile => $mysqld->{'path_myerr'},
3922
$mysqld->{'pid'}= 0; # Assume we are done with it
3926
# Start shutdown of clusters
3927
foreach my $cluster (@{$clusters})
3929
if ( $cluster->{'pid'} )
3931
$pid= mtr_ndbmgm_start($cluster, "shutdown");
3932
$admin_pids{$pid}= 1;
3935
pid => $cluster->{'pid'},
3936
pidfile => $cluster->{'path_pid'}
3939
$cluster->{'pid'}= 0; # Assume we are done with it
3941
foreach my $ndbd (@{$cluster->{'ndbds'}})
3943
if ( $ndbd->{'pid'} )
3946
pid => $ndbd->{'pid'},
3947
pidfile => $ndbd->{'path_pid'},
3955
# Wait blocking until all shutdown processes has completed
3956
mtr_wait_blocking(\%admin_pids);
3958
# Make sure that process has shutdown else try to kill them
3959
mtr_check_stop_servers(\@kill_pids);
3961
foreach my $mysqld (@{$master}, @{$slave})
3963
rm_ndbcluster_tables($mysqld->{'path_myddir'});
3968
sub run_testcase_need_master_restart($)
3972
# We try to find out if we are to restart the master(s)
3973
my $do_restart= 0; # Assumes we don't have to
3975
if ( $glob_use_embedded_server )
3977
mtr_verbose("Never start or restart for embedded server");
3980
elsif ( $tinfo->{'master_sh'} )
3982
$do_restart= 1; # Always restart if script to run
3983
mtr_verbose("Restart master: Always restart if script to run");
3985
if ( $tinfo->{'force_restart'} )
3987
$do_restart= 1; # Always restart if --force-restart in -opt file
3988
mtr_verbose("Restart master: Restart forced with --force-restart");
3990
elsif ( ! $opt_skip_ndbcluster and
3991
!$tinfo->{'ndb_test'} and
3992
$clusters->[0]->{'pid'} != 0 )
3994
$do_restart= 1; # Restart without cluster
3995
mtr_verbose("Restart master: Test does not need cluster");
3997
elsif ( ! $opt_skip_ndbcluster and
3998
$tinfo->{'ndb_test'} and
3999
$clusters->[0]->{'pid'} == 0 )
4001
$do_restart= 1; # Restart with cluster
4002
mtr_verbose("Restart master: Test need cluster");
4004
elsif( $tinfo->{'component_id'} eq 'im' )
4007
mtr_verbose("Restart master: Always restart for im tests");
4009
elsif ( $master->[0]->{'running_master_options'} and
4010
$master->[0]->{'running_master_options'}->{'timezone'} ne
4011
$tinfo->{'timezone'})
4014
mtr_verbose("Restart master: Different timezone");
4016
# Check that running master was started with same options
4017
# as the current test requires
4018
elsif (! mtr_same_opts($master->[0]->{'start_opts'},
4019
$tinfo->{'master_opt'}) )
4021
# Chech that diff is binlog format only
4022
my $diff_opts= mtr_diff_opts($master->[0]->{'start_opts'},$tinfo->{'master_opt'});
4023
if (scalar(@$diff_opts) eq 2)
4025
$do_restart= 1 unless ($diff_opts->[0] =~/^--binlog-format=/ and $diff_opts->[1] =~/^--binlog-format=/);
4030
mtr_verbose("Restart master: running with different options '" .
4031
join(" ", @{$tinfo->{'master_opt'}}) . "' != '" .
4032
join(" ", @{$master->[0]->{'start_opts'}}) . "'" );
4035
elsif( ! $master->[0]->{'pid'} )
4040
mtr_verbose("No restart: using extern master");
4045
mtr_verbose("Restart master: master is not started");
4051
sub run_testcase_need_slave_restart($)
4055
# We try to find out if we are to restart the slaves
4056
my $do_slave_restart= 0; # Assumes we don't have to
4058
if ( $glob_use_embedded_server )
4060
mtr_verbose("Never start or restart for embedded server");
4061
return $do_slave_restart;
4063
elsif ( $max_slave_num == 0)
4065
mtr_verbose("Skip slave restart: No testcase use slaves");
4070
# Check if any slave is currently started
4071
my $any_slave_started= 0;
4072
foreach my $mysqld (@{$slave})
4074
if ( $mysqld->{'pid'} )
4076
$any_slave_started= 1;
4081
if ($any_slave_started)
4083
mtr_verbose("Restart slave: Slave is started, always restart");
4084
$do_slave_restart= 1;
4086
elsif ( $tinfo->{'slave_num'} )
4088
mtr_verbose("Restart slave: Test need slave");
4089
$do_slave_restart= 1;
4093
return $do_slave_restart;
4097
# ----------------------------------------------------------------------
4098
# If not using a running servers we may need to stop and restart.
4099
# We restart in the case we have initiation scripts, server options
4100
# etc to run. But we also restart again after the test first restart
4101
# and test is run, to get back to normal server settings.
4103
# To make the code a bit more clean, we actually only stop servers
4104
# here, and mark this to be done. Then a generic "start" part will
4105
# start up the needed servers again.
4106
# ----------------------------------------------------------------------
4108
sub run_testcase_stop_servers($$$) {
4109
my ($tinfo, $do_restart, $do_slave_restart)= @_;
4111
my %admin_pids; # hash of admin processes that requests shutdown
4112
my @kill_pids; # list of processes to shutdown/kill
4114
# Remember if we restarted for this test case (count restarts)
4115
$tinfo->{'restarted'}= $do_restart;
4119
delete $master->[0]->{'running_master_options'}; # Forget history
4121
# Start shutdown of all started masters
4122
foreach my $mysqld (@{$master})
4124
if ( $mysqld->{'pid'} )
4126
$pid= mtr_mysqladmin_start($mysqld, "shutdown", 20);
4128
$admin_pids{$pid}= 1;
4131
pid => $mysqld->{'pid'},
4132
real_pid => $mysqld->{'real_pid'},
4133
pidfile => $mysqld->{'path_pid'},
4134
sockfile => $mysqld->{'path_sock'},
4135
port => $mysqld->{'port'},
4136
errfile => $mysqld->{'path_myerr'},
4139
$mysqld->{'pid'}= 0; # Assume we are done with it
4143
# Start shutdown of master cluster
4144
my $cluster= $clusters->[0];
4145
if ( $cluster->{'pid'} )
4147
$pid= mtr_ndbmgm_start($cluster, "shutdown");
4148
$admin_pids{$pid}= 1;
4151
pid => $cluster->{'pid'},
4152
pidfile => $cluster->{'path_pid'}
4155
$cluster->{'pid'}= 0; # Assume we are done with it
4157
foreach my $ndbd (@{$cluster->{'ndbds'}})
4160
pid => $ndbd->{'pid'},
4161
pidfile => $ndbd->{'path_pid'},
4163
$ndbd->{'pid'}= 0; # Assume we are done with it
4168
if ( $do_restart || $do_slave_restart )
4171
delete $slave->[0]->{'running_slave_options'}; # Forget history
4173
# Start shutdown of all started slaves
4174
foreach my $mysqld (@{$slave})
4176
if ( $mysqld->{'pid'} )
4178
$pid= mtr_mysqladmin_start($mysqld, "shutdown", 20);
4180
$admin_pids{$pid}= 1;
4183
pid => $mysqld->{'pid'},
4184
real_pid => $mysqld->{'real_pid'},
4185
pidfile => $mysqld->{'path_pid'},
4186
sockfile => $mysqld->{'path_sock'},
4187
port => $mysqld->{'port'},
4188
errfile => $mysqld->{'path_myerr'},
4192
$mysqld->{'pid'}= 0; # Assume we are done with it
4196
# Start shutdown of slave cluster
4197
my $cluster= $clusters->[1];
4198
if ( $cluster->{'pid'} )
4200
$pid= mtr_ndbmgm_start($cluster, "shutdown");
4202
$admin_pids{$pid}= 1;
4205
pid => $cluster->{'pid'},
4206
pidfile => $cluster->{'path_pid'}
4209
$cluster->{'pid'}= 0; # Assume we are done with it
4211
foreach my $ndbd (@{$cluster->{'ndbds'}} )
4214
pid => $ndbd->{'pid'},
4215
pidfile => $ndbd->{'path_pid'},
4217
$ndbd->{'pid'}= 0; # Assume we are done with it
4222
# ----------------------------------------------------------------------
4223
# Shutdown has now been started and lists for the shutdown processes
4224
# and the processes to be killed has been created
4225
# ----------------------------------------------------------------------
4227
# Wait blocking until all shutdown processes has completed
4228
mtr_wait_blocking(\%admin_pids);
4231
# Make sure that process has shutdown else try to kill them
4232
mtr_check_stop_servers(\@kill_pids);
4234
foreach my $mysqld (@{$master}, @{$slave})
4236
if ( ! $mysqld->{'pid'} )
4238
# Remove ndbcluster tables if server is stopped
4239
rm_ndbcluster_tables($mysqld->{'path_myddir'});
4246
# run_testcase_start_servers
4248
# Start the servers needed by this test case
4255
sub run_testcase_start_servers($) {
4257
my $tname= $tinfo->{'name'};
4259
if ( $tinfo->{'component_id'} eq 'mysqld' )
4261
if ( ! $opt_skip_ndbcluster and
4262
!$clusters->[0]->{'pid'} and
4263
$tinfo->{'ndb_test'} )
4265
# Test need cluster, cluster is not started, start it
4266
ndbcluster_start($clusters->[0], "");
4269
if ( !$master->[0]->{'pid'} )
4271
# Master mysqld is not started
4272
do_before_start_master($tinfo);
4274
mysqld_start($master->[0],$tinfo->{'master_opt'},[]);
4278
if ( $clusters->[0]->{'pid'} || $clusters->[0]->{'use_running'}
4279
and ! $master->[1]->{'pid'} and
4280
$tinfo->{'master_num'} > 1 )
4282
# Test needs cluster, start an extra mysqld connected to cluster
4284
if ( $mysql_version_id >= 50100 )
4286
# First wait for first mysql server to have created ndb system
4287
# tables ok FIXME This is a workaround so that only one mysqld
4289
if ( ! sleep_until_file_created(
4290
"$master->[0]->{'path_myddir'}/mysql/ndb_apply_status.ndb",
4291
$master->[0]->{'start_timeout'},
4292
$master->[0]->{'pid'}))
4295
$tinfo->{'comment'}= "Failed to create 'mysql/ndb_apply_status' table";
4299
mysqld_start($master->[1],$tinfo->{'master_opt'},[]);
4302
# Save this test case information, so next can examine it
4303
$master->[0]->{'running_master_options'}= $tinfo;
4306
# ----------------------------------------------------------------------
4307
# Start slaves - if needed
4308
# ----------------------------------------------------------------------
4309
if ( $tinfo->{'slave_num'} )
4311
restore_slave_databases($tinfo->{'slave_num'});
4313
do_before_start_slave($tinfo);
4315
if ( ! $opt_skip_ndbcluster_slave and
4316
!$clusters->[1]->{'pid'} and
4317
$tinfo->{'ndb_test'} )
4319
# Test need slave cluster, cluster is not started, start it
4320
ndbcluster_start($clusters->[1], "");
4323
for ( my $idx= 0; $idx < $tinfo->{'slave_num'}; $idx++ )
4325
if ( ! $slave->[$idx]->{'pid'} )
4327
mysqld_start($slave->[$idx],$tinfo->{'slave_opt'},
4328
$tinfo->{'slave_mi'});
4333
# Save this test case information, so next can examine it
4334
$slave->[0]->{'running_slave_options'}= $tinfo;
4337
# Wait for clusters to start
4338
foreach my $cluster (@{$clusters})
4341
next if !$cluster->{'pid'};
4343
if (ndbcluster_wait_started($cluster, ""))
4346
$tinfo->{'comment'}= "Start of $cluster->{'name'} cluster failed";
4351
# Wait for mysqld's to start
4352
foreach my $mysqld (@{$master},@{$slave})
4355
next if !$mysqld->{'pid'};
4357
if (mysqld_wait_started($mysqld))
4360
$tinfo->{'comment'}=
4361
"Failed to start $mysqld->{'type'} mysqld $mysqld->{'idx'}";
4369
# Run include/check-testcase.test
4370
# Before a testcase, run in record mode, save result file to var
4371
# After testcase, run and compare with the recorded file, they should be equal!
4377
sub run_check_testcase ($$) {
4382
my $name= "check-" . $mysqld->{'type'} . $mysqld->{'idx'};
4385
mtr_init_args(\$args);
4387
mtr_add_arg($args, "--no-defaults");
4388
mtr_add_arg($args, "--silent");
4389
mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
4390
mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
4392
mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
4393
mtr_add_arg($args, "--database=test");
4394
mtr_add_arg($args, "--user=%s", $opt_user);
4395
mtr_add_arg($args, "--password=");
4397
mtr_add_arg($args, "-R");
4398
mtr_add_arg($args, "$opt_vardir/tmp/$name.result");
4400
if ( $mode eq "before" )
4402
mtr_add_arg($args, "--record");
4405
my $res = mtr_run_test($exe_mysqltest,$args,
4406
"include/check-testcase.test", "", "", "");
4408
if ( $res == 1 and $mode eq "after")
4410
mtr_run("diff",["-u",
4411
"$opt_vardir/tmp/$name.result",
4412
"$opt_vardir/tmp/$name.reject"],
4417
mtr_error("Could not execute 'check-testcase' $mode testcase");
4422
##############################################################################
4424
# Report the features that were compiled in
4426
##############################################################################
4428
sub run_report_features () {
4431
if ( ! $glob_use_embedded_server )
4433
mysqld_start($master->[0],[],[]);
4434
if ( ! $master->[0]->{'pid'} )
4436
mtr_error("Can't start the mysqld server");
4438
mysqld_wait_started($master->[0]);
4442
$tinfo->{'name'} = 'report features';
4443
$tinfo->{'result_file'} = undef;
4444
$tinfo->{'component_id'} = 'mysqld';
4445
$tinfo->{'path'} = 'include/report-features.test';
4446
$tinfo->{'timezone'}= "GMT-3";
4447
$tinfo->{'slave_num'} = 0;
4448
$tinfo->{'master_opt'} = [];
4449
$tinfo->{'slave_opt'} = [];
4450
$tinfo->{'slave_mi'} = [];
4451
$tinfo->{'comment'} = 'report server features';
4452
run_mysqltest($tinfo);
4454
if ( ! $glob_use_embedded_server )
4461
sub run_mysqltest ($) {
4463
my $exe= $exe_mysqltest;
4466
mtr_init_args(\$args);
4468
mtr_add_arg($args, "--no-defaults");
4469
mtr_add_arg($args, "--silent");
4470
mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
4471
mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
4472
mtr_add_arg($args, "--logdir=%s/log", $opt_vardir);
4474
# Log line number and time for each line in .test file
4475
mtr_add_arg($args, "--mark-progress")
4476
if $opt_mark_progress;
4479
mtr_add_arg($args, "--port=%d", $master->[0]->{'port'});
4480
mtr_add_arg($args, "--database=test");
4481
mtr_add_arg($args, "--user=%s", $opt_user);
4482
mtr_add_arg($args, "--password=");
4485
if ( $opt_ps_protocol )
4487
mtr_add_arg($args, "--ps-protocol");
4490
if ( $opt_sp_protocol )
4492
mtr_add_arg($args, "--sp-protocol");
4495
if ( $opt_view_protocol )
4497
mtr_add_arg($args, "--view-protocol");
4500
if ( $opt_cursor_protocol )
4502
mtr_add_arg($args, "--cursor-protocol");
4505
if ( $opt_strace_client )
4507
$exe= "strace"; # FIXME there are ktrace, ....
4508
mtr_add_arg($args, "-o");
4509
mtr_add_arg($args, "%s/log/mysqltest.strace", $opt_vardir);
4510
mtr_add_arg($args, "$exe_mysqltest");
4515
mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
4518
if ( $opt_compress )
4520
mtr_add_arg($args, "--compress");
4525
mtr_add_arg($args, "--sleep=%d", $opt_sleep);
4530
mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace",
4531
$path_vardir_trace);
4534
if ( $opt_ssl_supported )
4536
mtr_add_arg($args, "--ssl-ca=%s/std_data/cacert.pem",
4537
$glob_mysql_test_dir);
4538
mtr_add_arg($args, "--ssl-cert=%s/std_data/client-cert.pem",
4539
$glob_mysql_test_dir);
4540
mtr_add_arg($args, "--ssl-key=%s/std_data/client-key.pem",
4541
$glob_mysql_test_dir);
4546
# Turn on SSL for _all_ test cases if option --ssl was used
4547
mtr_add_arg($args, "--ssl");
4549
elsif ( $opt_ssl_supported )
4551
mtr_add_arg($args, "--skip-ssl");
4554
# ----------------------------------------------------------------------
4555
# If embedded server, we create server args to give mysqltest to pass on
4556
# ----------------------------------------------------------------------
4558
if ( $glob_use_embedded_server )
4560
mysqld_arguments($args,$master->[0],$tinfo->{'master_opt'},[]);
4563
# ----------------------------------------------------------------------
4564
# export MYSQL_TEST variable containing <path>/mysqltest <args>
4565
# ----------------------------------------------------------------------
4567
mtr_native_path($exe_mysqltest) . " " . join(" ", @$args);
4569
# ----------------------------------------------------------------------
4570
# Add arguments that should not go into the MYSQL_TEST env var
4571
# ----------------------------------------------------------------------
4573
if ( $opt_valgrind_mysqltest )
4575
# Prefix the Valgrind options to the argument list.
4576
# We do this here, since we do not want to Valgrind the nested invocations
4577
# of mysqltest; that would mess up the stderr output causing test failure.
4578
my @args_saved = @$args;
4579
mtr_init_args(\$args);
4580
valgrind_arguments($args, \$exe);
4581
mtr_add_arg($args, "%s", $_) for @args_saved;
4584
mtr_add_arg($args, "--test-file=%s", $tinfo->{'path'});
4586
# Number of lines of resut to include in failure report
4587
mtr_add_arg($args, "--tail-lines=20");
4589
if ( defined $tinfo->{'result_file'} ) {
4590
mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'});
4595
mtr_add_arg($args, "--record");
4598
if ( $opt_client_gdb )
4600
gdb_arguments(\$args, \$exe, "client");
4602
elsif ( $opt_client_ddd )
4604
ddd_arguments(\$args, \$exe, "client");
4606
elsif ( $opt_client_debugger )
4608
debugger_arguments(\$args, \$exe, "client");
4611
if ( $opt_check_testcases )
4613
foreach my $mysqld (@{$master}, @{$slave})
4615
if ($mysqld->{'pid'})
4617
run_check_testcase("before", $mysqld);
4622
my $res = mtr_run_test($exe,$args,"","",$path_timefile,"");
4624
if ( $opt_check_testcases )
4626
foreach my $mysqld (@{$master}, @{$slave})
4628
if ($mysqld->{'pid'})
4630
if (run_check_testcase("after", $mysqld))
4632
# Check failed, mark the test case with that info
4633
$tinfo->{'check_testcase_failed'}= 1;
4645
# Modify the exe and args so that program is run in gdb in xterm
4652
# Write $args to gdb init file
4653
my $str= join(" ", @$$args);
4654
my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
4656
# Remove the old gdbinit file
4657
unlink($gdb_init_file);
4659
if ( $type eq "client" )
4661
# write init file for client
4662
mtr_tofile($gdb_init_file,
4668
# write init file for mysqld
4669
mtr_tofile($gdb_init_file,
4671
"break mysql_parse\n" .
4678
if ( $opt_manual_gdb )
4680
print "\nTo start gdb for $type, type in another window:\n";
4681
print "gdb -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
4683
# Indicate the exe should not be started
4689
mtr_add_arg($$args, "-title");
4690
mtr_add_arg($$args, "$type");
4691
mtr_add_arg($$args, "-e");
4695
mtr_add_arg($$args, $exe_libtool);
4696
mtr_add_arg($$args, "--mode=execute");
4699
mtr_add_arg($$args, "gdb");
4700
mtr_add_arg($$args, "-x");
4701
mtr_add_arg($$args, "$gdb_init_file");
4702
mtr_add_arg($$args, "$$exe");
4709
# Modify the exe and args so that program is run in ddd
4716
# Write $args to ddd init file
4717
my $str= join(" ", @$$args);
4718
my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
4720
# Remove the old gdbinit file
4721
unlink($gdb_init_file);
4723
if ( $type eq "client" )
4725
# write init file for client
4726
mtr_tofile($gdb_init_file,
4732
# write init file for mysqld
4733
mtr_tofile($gdb_init_file,
4736
"break mysql_parse\n" .
4742
if ( $opt_manual_ddd )
4744
print "\nTo start ddd for $type, type in another window:\n";
4745
print "ddd -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
4747
# Indicate the exe should not be started
4752
my $save_exe= $$exe;
4756
$$exe= $exe_libtool;
4757
mtr_add_arg($$args, "--mode=execute");
4758
mtr_add_arg($$args, "ddd");
4764
mtr_add_arg($$args, "--command=$gdb_init_file");
4765
mtr_add_arg($$args, "$save_exe");
4770
# Modify the exe and args so that program is run in the selected debugger
4772
sub debugger_arguments {
4775
my $debugger= $opt_debugger || $opt_client_debugger;
4777
if ( $debugger =~ /vcexpress|vc|devenv/ )
4779
# vc[express] /debugexe exe arg1 .. argn
4781
# Add /debugexe and name of the exe before args
4782
unshift(@$$args, "/debugexe");
4783
unshift(@$$args, "$$exe");
4785
# Set exe to debuggername
4789
elsif ( $debugger =~ /windbg/ )
4791
# windbg exe arg1 .. argn
4793
# Add name of the exe before args
4794
unshift(@$$args, "$$exe");
4796
# Set exe to debuggername
4800
elsif ( $debugger eq "dbx" )
4802
# xterm -e dbx -r exe arg1 .. argn
4804
unshift(@$$args, $$exe);
4805
unshift(@$$args, "-r");
4806
unshift(@$$args, $debugger);
4807
unshift(@$$args, "-e");
4814
mtr_error("Unknown argument \"$debugger\" passed to --debugger");
4820
# Modify the exe and args so that program is run in valgrind
4822
sub valgrind_arguments {
4826
if ( $opt_callgrind)
4828
mtr_add_arg($args, "--tool=callgrind");
4829
mtr_add_arg($args, "--base=$opt_vardir/log");
4833
mtr_add_arg($args, "--tool=memcheck"); # From >= 2.1.2 needs this option
4834
mtr_add_arg($args, "--alignment=8");
4835
mtr_add_arg($args, "--leak-check=yes");
4836
mtr_add_arg($args, "--num-callers=16");
4837
mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir)
4838
if -f "$glob_mysql_test_dir/valgrind.supp";
4841
# Add valgrind options, can be overriden by user
4842
mtr_add_arg($args, '%s', $_) for (@valgrind_args);
4844
mtr_add_arg($args, $$exe);
4846
$$exe= $opt_valgrind_path || "valgrind";
4850
# Add "libtool --mode-execute" before the test to execute
4851
# if running in valgrind(to avoid valgrinding bash)
4852
unshift(@$args, "--mode=execute", $$exe);
4853
$$exe= $exe_libtool;
4858
##############################################################################
4862
##############################################################################
4869
print STDERR "$message\n";
4874
$0 [ OPTIONS ] [ TESTCASE ]
4876
Options to control what engine/variation to run
4878
embedded-server Use the embedded server, i.e. no mysqld daemons
4879
ps-protocol Use the binary protocol between client and server
4880
cursor-protocol Use the cursor protocol between client and server
4881
(implies --ps-protocol)
4882
view-protocol Create a view to execute all non updating queries
4883
sp-protocol Create a stored procedure to execute all queries
4884
compress Use the compressed protocol between client and server
4885
ssl Use ssl protocol between client and server
4886
skip-ssl Dont start server with support for ssl connections
4887
bench Run the benchmark suite
4888
small-bench Run the benchmarks with --small-tests --small-tables
4889
ndb|with-ndbcluster Use cluster as default table type
4890
vs-config Visual Studio configuration used to create executables
4891
(default: MTR_VS_CONFIG environment variable)
4893
Options to control directories to use
4894
benchdir=DIR The directory where the benchmark suite is stored
4895
(default: ../../mysql-bench)
4896
tmpdir=DIR The directory where temporary files are stored
4897
(default: ./var/tmp).
4898
vardir=DIR The directory where files generated from the test run
4899
is stored (default: ./var). Specifying a ramdisk or
4900
tmpfs will speed up tests.
4901
mem Run testsuite in "memory" using tmpfs or ramdisk
4902
Attempts to find a suitable location
4903
using a builtin list of standard locations
4904
for tmpfs (/dev/shm)
4905
The option can also be set using environment
4906
variable MTR_MEM=[DIR]
4908
Options to control what test suites or cases to run
4910
force Continue to run the suite after failure
4911
with-ndbcluster-only Run only tests that include "ndb" in the filename
4912
skip-ndb[cluster] Skip all tests that need cluster
4913
skip-ndb[cluster]-slave Skip all tests that need a slave cluster
4914
ndb-extra Run extra tests from ndb directory
4915
do-test=PREFIX or REGEX
4916
Run test cases which name are prefixed with PREFIX
4918
skip-test=PREFIX or REGEX
4919
Skip test cases which name are prefixed with PREFIX
4921
start-from=PREFIX Run test cases starting from test prefixed with PREFIX
4922
suite[s]=NAME1,..,NAMEN Collect tests in suites from the comma separated
4923
list of suite names.
4924
The default is: "$opt_suites_default"
4925
skip-rpl Skip the replication test cases.
4926
big-test Set the environment variable BIG_TEST, which can be
4927
checked from test cases.
4928
combination="ARG1 .. ARG2" Specify a set of "mysqld" arguments for one
4930
skip-combination Skip any combination options and combinations files
4932
Options that specify ports
4934
master_port=PORT Specify the port number used by the first master
4935
slave_port=PORT Specify the port number used by the first slave
4936
ndbcluster-port=PORT Specify the port number used by cluster
4937
ndbcluster-port-slave=PORT Specify the port number used by slave cluster
4938
mtr-build-thread=# Specify unique collection of ports. Can also be set by
4939
setting the environment variable MTR_BUILD_THREAD.
4941
Options for test case authoring
4943
record TESTNAME (Re)genereate the result file for TESTNAME
4944
check-testcases Check testcases for sideeffects
4945
mark-progress Log line number and elapsed time to <testname>.progress
4947
Options that pass on options
4949
mysqld=ARGS Specify additional arguments to "mysqld"
4951
Options to run test on running server
4953
extern Use running server for tests
4954
ndb-connectstring=STR Use running cluster, and connect using STR
4955
ndb-connectstring-slave=STR Use running slave cluster, and connect using STR
4956
user=USER User for connection to extern server
4957
socket=PATH Socket for connection to extern server
4959
Options for debugging the product
4961
client-ddd Start mysqltest client in ddd
4962
client-debugger=NAME Start mysqltest in the selected debugger
4963
client-gdb Start mysqltest client in gdb
4964
ddd Start mysqld in ddd
4965
debug Dump trace output for all servers and client programs
4966
debugger=NAME Start mysqld in the selected debugger
4967
gdb Start the mysqld(s) in gdb
4968
manual-debug Let user manually start mysqld in debugger, before
4970
manual-gdb Let user manually start mysqld in gdb, before running
4972
manual-ddd Let user manually start mysqld in ddd, before running
4974
master-binary=PATH Specify the master "mysqld" to use
4975
slave-binary=PATH Specify the slave "mysqld" to use
4976
strace-client Create strace output for mysqltest client
4977
max-save-core Limit the number of core files saved (to avoid filling
4978
up disks for heavily crashing server). Defaults to
4979
$opt_max_save_core, set to 0 for no limit.
4981
Options for coverage, profiling etc
4985
valgrind Run the "mysqltest" and "mysqld" executables using
4986
valgrind with default options
4987
valgrind-all Synonym for --valgrind
4988
valgrind-mysqltest Run the "mysqltest" and "mysql_client_test" executable
4990
valgrind-mysqld Run the "mysqld" executable with valgrind
4991
valgrind-options=ARGS Deprecated, use --valgrind-option
4992
valgrind-option=ARGS Option to give valgrind, replaces default option(s),
4993
can be specified more then once
4994
valgrind-path=[EXE] Path to the valgrind executable
4995
callgrind Instruct valgrind to use callgrind
4999
comment=STR Write STR to the output
5000
notimer Don't show test case execution time
5001
script-debug Debug this script itself
5002
verbose More verbose output
5003
start-and-exit Only initialize and start the servers, using the
5004
startup settings for the specified test case (if any)
5005
start-dirty Only start the servers (without initialization) for
5006
the specified test case (if any)
5007
fast Don't try to clean up from earlier runs
5008
reorder Reorder tests to get fewer server restarts
5009
help Get this help text
5011
testcase-timeout=MINUTES Max test case run time (default $default_testcase_timeout)
5012
suite-timeout=MINUTES Max test suite run time (default $default_suite_timeout)
5013
warnings | log-warnings Pass --log-warnings to mysqld
5015
sleep=SECONDS Passed to mysqltest, will be used as fixed sleep time
5018
with-openssl Deprecated option for ssl