~mathiaz/ubuntu/lucid/mysql-dfsg-5.1/zap-bug-552053

« back to all changes in this revision

Viewing changes to mysql-test/mysql-test-run.pl

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-06-25 12:55:45 UTC
  • mfrom: (1.1.2 upstream) (0.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090625125545-m8ogs96zzsri74xe
Tags: 5.1.34-1ubuntu1
* Merge from debian experimental (and 5.0 from main), remaining changes:
  - debian/mysql-server-5.1.config:
    + ask for MySQL root password at priority high instead of medium so
      that the password prompt is seen on a default install. (LP: #319843)
    + don't ask for root password when upgrading from a 5.0 install.
  - debian/control:
    + Make libmysqlclient16-dev a transitional package depending on
      libmysqlclient-dev.
    + Make libmysqlclient-dev conflict with libmysqlclient15-dev.
    + Don't build mysql-server, mysql-client, mysql-common and
      libmysqlclient15-dev binary packages since they're still provided
      by mysql-dfsg-5.0.
    + Make mysql-{client,server}-5.1 packages conflict and
      replace mysql-{client,server}-5.0, but not provide
      mysql-{client,server}.
    + Depend on a specific version of mysql-common rather than the src
      version of mysql-dfsg-5.1 since mysql-common is currently part of
      mysql-dfsg-5.0.
    + Lower mailx from a Recommends to a Suggests to avoid pulling in
      a full MTA on all installs of mysql-server. (LP: #259477)
  - debian/rules:
    + added -fno-strict-aliasing to CFLAGS to get around mysql testsuite
      build failures.
    + install mysql-test and sql-bench to /usr/share/mysql/ rather than
      /usr/.
  - debian/additions/debian-start.inc.sh: support ANSI mode (LP: #310211)
  - Add AppArmor profile:
    - debian/apparmor-profile: apparmor profile.
    - debian/rules, debian/mysql-server-5.0.files: install apparmor profile.
    - debian/mysql-server-5.0.dirs: add etc/apparmor.d/force-complain
    - debian/mysql-server-5.0.postrm: remove symlink in force-complain/ on
      purge.
    - debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    - debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    - debian/mysql-server-5.1.postinst: reload apparmor profiles.
  - debian/additions/my.cnf: remove language option. Error message files are
    located in a different directory in MySQL 5.0. Setting the language
    option to use /usr/share/mysql/english breaks 5.0. Both 5.0 and 5.1
    use a default value that works. (LP: #316974)
  - debian/mysql-server-5.1.mysql.init:
    + Clearly indicate that we do not support running multiple instances
      of mysqld by duplicating the init script.
      (closes: #314785, #324834, #435165, #444216)
    + Properly parameterize all existing references to the mysql config
      file (/etc/mysql/my.cnf).
  - debian/mysql-server-5.0.postinst: Clear out the second password
    when setting up mysql. (LP: #344816)
  - mysql-server-core-5.1 package for files needed by Akonadi:
    + debian/control: create mysql-server-core-5.1 package.
    + debian/mysql-server-core-5.1.files, debian/mysql-server-5.1.files:
      move core mysqld files to mysql-server-core-5.1 package.
  - Don't package sql-bench and mysql-test file.
* Dropped changes:
  - debian/patches/92_ssl_test_cert.dpatch: certificate expiration in
    test suite (LP: #323755). Included upstream.
* Dropped from 5.0:
  - apparmor profile:
    - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6. All version
      of apparmor-profile (>hardy) are higher than this version.
    - debian/mysql-server-5.0.preinst: create symlink for force-complain/
      on pre-feisty upgrades, upgrades where apparmor-profiles profile is
      unchanged (ie non-enforcing) and upgrades where the profile
      doesn't exist. Support for pre-hardy upgrades is no longer needed.
* debian/mysql-server-5.1.postinst: fix debian-sys-maint user creation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#
7
7
#  mysql-test-run.pl
8
8
#
9
 
#  Tool used for executing a suite of .test file
 
9
#  Tool used for executing a suite of .test files
10
10
#
11
11
#  See the "MySQL Test framework manual" for more information
12
12
#  http://dev.mysql.com/doc/mysqltest/en/index.html
13
13
#
14
 
#  Please keep the test framework tools identical in all versions!
15
14
#
16
15
##############################################################################
17
 
#
18
 
# Coding style directions for this perl script
19
 
#
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.
23
 
#
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.
27
 
#
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.
33
 
#
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.
38
 
#
39
 
#   - The rule when it comes to the logic of this program is
40
 
#
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.
48
 
#
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"
53
 
#
54
 
 
55
 
 
56
 
use lib "lib/";
57
 
 
58
 
$Devel::Trace::TRACE= 0;       # Don't trace boring init stuff
59
 
 
60
 
#require 5.6.1;
61
 
use File::Path;
 
16
 
 
17
use strict;
 
18
use warnings;
 
19
 
 
20
BEGIN {
 
21
  # Check that mysql-test-run.pl is started from mysql-test/
 
22
  unless ( -f "mysql-test-run.pl" )
 
23
  {
 
24
    print "**** ERROR **** ",
 
25
      "You must start mysql-test-run from the mysql-test/ directory\n";
 
26
    exit(1);
 
27
  }
 
28
  # Check that lib exist
 
29
  unless ( -d "lib/" )
 
30
  {
 
31
    print "**** ERROR **** ",
 
32
      "Could not find the lib/ directory \n";
 
33
    exit(1);
 
34
  }
 
35
}
 
36
 
 
37
BEGIN {
 
38
  # Check backward compatibility support
 
39
  # By setting the environment variable MTR_VERSION
 
40
  # it's possible to use a previous version of
 
41
  # mysql-test-run.pl
 
42
  my $version= $ENV{MTR_VERSION} || 2;
 
43
  if ( $version == 1 )
 
44
  {
 
45
    print "=======================================================\n";
 
46
    print "  WARNING: Using mysql-test-run.pl version 1!  \n";
 
47
    print "=======================================================\n";
 
48
    # Should use exec() here on *nix but this appears not to work on Windows
 
49
    exit(system($^X, "lib/v1/mysql-test-run.pl", @ARGV) >> 8);
 
50
  }
 
51
  elsif ( $version == 2 )
 
52
  {
 
53
    # This is the current version, just continue
 
54
    ;
 
55
  }
 
56
  else
 
57
  {
 
58
    print "ERROR: Version $version of mysql-test-run does not exist!\n";
 
59
    exit(1);
 
60
  }
 
61
}
 
62
 
 
63
use lib "lib";
 
64
 
 
65
use Cwd;
 
66
use Getopt::Long;
 
67
use My::File::Path; # Patched version of File::Path
62
68
use File::Basename;
63
69
use File::Copy;
64
 
use File::Temp qw /tempdir/;
65
 
use File::Spec::Functions qw /splitdir/;
66
 
use Cwd;
67
 
use Getopt::Long;
68
 
use IO::Socket;
 
70
use File::Find;
 
71
use File::Temp qw / tempdir /;
 
72
use File::Spec::Functions qw / splitdir /;
 
73
use My::Platform;
 
74
use My::SafeProcess;
 
75
use My::ConfigFactory;
 
76
use My::Options;
 
77
use My::Find;
 
78
use My::SysInfo;
 
79
use My::CoreDump;
 
80
use mtr_cases;
 
81
use mtr_report;
 
82
use mtr_match;
 
83
use mtr_unique;
69
84
use IO::Socket::INET;
70
 
use strict;
71
 
use warnings;
72
 
 
73
 
select(STDOUT);
74
 
$| = 1; # Automatically flush STDOUT
75
 
 
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
80
 
 
81
 
require "lib/mtr_cases.pl";
82
 
require "lib/mtr_im.pl";
 
85
use IO::Select;
 
86
 
83
87
require "lib/mtr_process.pl";
84
 
require "lib/mtr_timer.pl";
85
88
require "lib/mtr_io.pl";
86
89
require "lib/mtr_gcov.pl";
87
 
require "lib/mtr_gprof.pl";
88
 
require "lib/mtr_report.pl";
89
 
require "lib/mtr_match.pl";
90
90
require "lib/mtr_misc.pl";
91
 
require "lib/mtr_stress.pl";
92
 
require "lib/mtr_unique.pl";
93
 
 
94
 
$Devel::Trace::TRACE= 1;
95
 
 
96
 
##############################################################################
97
 
#
98
 
#  Default settings
99
 
#
100
 
##############################################################################
101
 
 
102
 
# Misc global variables
 
91
 
 
92
$SIG{INT}= sub { mtr_error("Got ^C signal"); };
 
93
 
103
94
our $mysql_version_id;
104
 
our $glob_mysql_test_dir=         undef;
105
 
our $glob_mysql_bench_dir=        undef;
106
 
our $glob_scriptname=             undef;
107
 
our $glob_timers=                 undef;
108
 
our $glob_use_embedded_server=    0;
109
 
our @glob_test_mode;
110
 
 
111
 
our $glob_basedir;
 
95
our $glob_mysql_test_dir;
 
96
our $basedir;
112
97
 
113
98
our $path_charsetsdir;
114
99
our $path_client_bindir;
115
100
our $path_client_libdir;
116
 
our $path_share;
117
101
our $path_language;
118
 
our $path_timefile;
119
 
our $path_snapshot;
120
 
our $path_mysqltest_log;
121
 
our $path_current_test_log;
122
 
our $path_my_basedir;
123
 
 
124
 
our $opt_vardir;                 # A path but set directly on cmd line
125
 
our $path_vardir_trace;          # unix formatted opt_vardir for trace files
126
 
our $opt_tmpdir;                 # A path but set directly on cmd line
 
102
 
 
103
our $path_current_testlog;
 
104
our $path_testlog;
 
105
 
 
106
our $default_vardir;
 
107
our $opt_vardir;                # Path to use for var/ dir
 
108
my $path_vardir_trace;          # unix formatted opt_vardir for trace files
 
109
my $opt_tmpdir;                 # Path to use for tmp/ dir
 
110
my $opt_tmpdir_pid;
 
111
 
 
112
END {
 
113
  if ( defined $opt_tmpdir_pid and $opt_tmpdir_pid == $$ )
 
114
  {
 
115
    # Remove the tempdir this process has created
 
116
    mtr_verbose("Removing tmpdir '$opt_tmpdir");
 
117
    rmtree($opt_tmpdir);
 
118
  }
 
119
}
 
120
 
 
121
my $path_config_file;           # The generated config file, var/my.cnf
127
122
 
128
123
# Visual Studio produces executables in different sub-directories based on the
129
124
# configuration used to build them.  To make life easier, an environment
131
126
# executables will be used by the test suite.
132
127
our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
133
128
 
134
 
our $default_vardir;
 
129
my $DEFAULT_SUITES= "main,binlog,federated,rpl,rpl_ndb,ndb";
 
130
my $opt_suites;
135
131
 
136
 
our $opt_usage;
137
 
our $opt_suites;
138
 
our $opt_suites_default= "main,binlog,rpl,rpl_ndb,ndb"; # Default suites to run
139
 
our $opt_script_debug= 0;  # Script debugging, enable with --script-debug
140
132
our $opt_verbose= 0;  # Verbose output, enable with --verbose
141
 
 
142
 
our $exe_master_mysqld;
143
133
our $exe_mysql;
144
134
our $exe_mysqladmin;
145
 
our $exe_mysql_upgrade;
146
 
our $exe_mysqlbinlog;
147
 
our $exe_mysql_client_test;
148
 
our $exe_bug25714;
149
 
our $exe_mysqld;
150
 
our $exe_mysqlcheck;
151
 
our $exe_mysqldump;
152
 
our $exe_mysqlslap;
153
 
our $exe_mysqlimport;
154
 
our $exe_mysqlshow;
155
 
our $exe_mysql_fix_system_tables;
156
 
our $file_mysql_fix_privilege_tables;
157
135
our $exe_mysqltest;
158
 
our $exe_ndbd;
159
 
our $exe_ndb_mgmd;
160
 
our $exe_slave_mysqld;
161
 
our $exe_im;
162
 
our $exe_my_print_defaults;
163
 
our $exe_perror;
164
 
our $lib_udf_example;
165
 
our $lib_example_plugin;
166
 
our $lib_simple_parser;
167
136
our $exe_libtool;
168
137
 
169
 
our $opt_bench= 0;
170
 
our $opt_small_bench= 0;
171
138
our $opt_big_test= 0;
172
139
 
173
140
our @opt_combinations;
174
 
our $opt_skip_combination;
175
141
 
176
142
our @opt_extra_mysqld_opt;
177
143
 
178
 
our $opt_compress;
179
 
our $opt_ssl;
180
 
our $opt_skip_ssl;
181
 
our $opt_ssl_supported;
182
 
our $opt_ps_protocol;
183
 
our $opt_sp_protocol;
184
 
our $opt_cursor_protocol;
185
 
our $opt_view_protocol;
 
144
my $opt_compress;
 
145
my $opt_ssl;
 
146
my $opt_skip_ssl;
 
147
my $opt_ssl_supported;
 
148
my $opt_ps_protocol;
 
149
my $opt_sp_protocol;
 
150
my $opt_cursor_protocol;
 
151
my $opt_view_protocol;
186
152
 
187
153
our $opt_debug;
188
 
our $opt_do_test;
189
154
our @opt_cases;                  # The test cases names in argv
190
155
our $opt_embedded_server;
191
156
 
192
 
our $opt_extern= 0;
193
 
our $opt_socket;
 
157
# Options used when connecting to an already running server
 
158
my %opts_extern;
 
159
sub using_extern { return (keys %opts_extern > 0);};
194
160
 
195
 
our $opt_fast;
 
161
our $opt_fast= 0;
196
162
our $opt_force;
197
 
our $opt_reorder= 0;
198
 
our $opt_enable_disabled;
199
163
our $opt_mem= $ENV{'MTR_MEM'};
200
164
 
201
165
our $opt_gcov;
202
 
our $opt_gcov_err;
203
 
our $opt_gcov_msg;
 
166
our $opt_gcov_exe= "gcov";
 
167
our $opt_gcov_err= "mysql-test-gcov.msg";
 
168
our $opt_gcov_msg= "mysql-test-gcov.err";
204
169
 
205
170
our $glob_debugger= 0;
206
171
our $opt_gdb;
210
175
our $opt_manual_gdb;
211
176
our $opt_manual_ddd;
212
177
our $opt_manual_debug;
213
 
our $opt_mtr_build_thread=0;
214
178
our $opt_debugger;
215
179
our $opt_client_debugger;
216
180
 
217
 
our $opt_gprof;
218
 
our $opt_gprof_dir;
219
 
our $opt_gprof_master;
220
 
our $opt_gprof_slave;
221
 
 
222
 
our $master;
223
 
our $slave;
224
 
our $clusters;
225
 
 
226
 
our $instance_manager;
227
 
 
228
 
our $opt_master_myport;
229
 
our $opt_slave_myport;
230
 
our $im_port;
231
 
our $im_mysqld1_port;
232
 
our $im_mysqld2_port;
233
 
our $opt_ndbcluster_port;
234
 
our $opt_ndbconnectstring;
235
 
our $opt_ndbcluster_port_slave;
236
 
our $opt_ndbconnectstring_slave;
237
 
 
238
 
our $opt_record;
 
181
my $config; # The currently running config
 
182
my $current_config_name; # The currently running config file template
 
183
 
 
184
our $opt_experimental;
 
185
our $experimental_test_cases;
 
186
 
 
187
my $baseport;
 
188
my $opt_build_thread= $ENV{'MTR_BUILD_THREAD'} || "auto";
 
189
my $build_thread= 0;
 
190
 
 
191
my $opt_record;
239
192
my $opt_report_features;
240
 
our $opt_check_testcases;
241
 
our $opt_mark_progress;
242
 
 
243
 
our $opt_skip_rpl;
244
 
our $max_slave_num= 0;
245
 
our $max_master_num= 1;
246
 
our $use_innodb;
247
 
our $opt_skip_test;
248
 
our $opt_skip_im;
249
 
 
250
 
our $opt_sleep;
251
 
 
252
 
our $opt_testcase_timeout;
253
 
our $opt_suite_timeout;
254
 
my  $default_testcase_timeout=     15; # 15 min max
255
 
my  $default_suite_timeout=       300; # 5 hours max
256
 
 
257
 
our $opt_start_and_exit;
258
 
our $opt_start_dirty;
259
 
our $opt_start_from;
260
 
 
261
 
our $opt_strace_client;
262
 
 
263
 
our $opt_timer= 1;
264
 
 
265
 
our $opt_user;
 
193
 
 
194
my $opt_skip_core;
 
195
 
 
196
our $opt_check_testcases= 1;
 
197
my $opt_mark_progress;
 
198
 
 
199
my $opt_sleep;
 
200
 
 
201
my $opt_testcase_timeout=    15; # minutes
 
202
my $opt_suite_timeout   =   300; # minutes
 
203
my $opt_shutdown_timeout=    10; # seconds
 
204
my $opt_start_timeout   =   180; # seconds
 
205
 
 
206
sub testcase_timeout { return $opt_testcase_timeout * 60; };
 
207
sub suite_timeout { return $opt_suite_timeout * 60; };
 
208
sub check_timeout { return $opt_testcase_timeout * 6; };
 
209
 
 
210
my $opt_start;
 
211
my $opt_start_dirty;
 
212
my $opt_repeat= 1;
 
213
my $opt_retry= 3;
 
214
my $opt_retry_failure= 2;
 
215
 
 
216
my $opt_strace_client;
 
217
 
 
218
our $opt_user = "root";
266
219
 
267
220
my $opt_valgrind= 0;
268
221
my $opt_valgrind_mysqld= 0;
272
225
my $opt_valgrind_path;
273
226
my $opt_callgrind;
274
227
 
275
 
our $opt_stress=               "";
276
 
our $opt_stress_suite=     "main";
277
 
our $opt_stress_mode=    "random";
278
 
our $opt_stress_threads=        5;
279
 
our $opt_stress_test_count=     0;
280
 
our $opt_stress_loop_count=     0;
281
 
our $opt_stress_test_duration=  0;
282
 
our $opt_stress_init_file=     "";
283
 
our $opt_stress_test_file=     "";
284
 
 
285
 
our $opt_warnings;
 
228
our $opt_warnings= 1;
286
229
 
287
230
our $opt_skip_ndbcluster= 0;
288
 
our $opt_skip_ndbcluster_slave= 0;
289
 
our $opt_with_ndbcluster= 0;
290
 
our $opt_with_ndbcluster_only= 0;
291
 
our $glob_ndbcluster_supported= 0;
292
 
our $opt_ndb_extra_test= 0;
293
 
our $opt_skip_master_binlog= 0;
294
 
our $opt_skip_slave_binlog= 0;
295
 
 
296
 
our $exe_ndb_mgm;
297
 
our $exe_ndb_waiter;
298
 
our $path_ndb_tools_dir;
299
 
our $path_ndb_examples_dir;
300
 
our $exe_ndb_example;
301
 
our $path_ndb_testrun_log;
302
 
 
303
 
our $path_sql_dir;
304
 
 
305
 
our @data_dir_lst;
306
 
 
307
 
our $used_binlog_format;
308
 
our $used_default_engine;
 
231
 
 
232
my $exe_ndbd;
 
233
my $exe_ndb_mgmd;
 
234
my $exe_ndb_waiter;
 
235
 
309
236
our $debug_compiled_binaries;
310
237
 
311
238
our %mysqld_variables;
312
239
 
313
240
my $source_dist= 0;
314
241
 
315
 
our $opt_max_save_core= 5;
316
 
my $num_saved_cores= 0;  # Number of core files saved in vardir/log/ so far.
317
 
 
318
 
######################################################################
319
 
#
320
 
#  Function declarations
321
 
#
322
 
######################################################################
323
 
 
324
 
sub main ();
325
 
sub initial_setup ();
326
 
sub command_line_setup ();
327
 
sub set_mtr_build_thread_ports($);
328
 
sub datadir_list_setup ();
329
 
sub executable_setup ();
330
 
sub environment_setup ();
331
 
sub kill_running_servers ();
332
 
sub remove_stale_vardir ();
333
 
sub setup_vardir ();
334
 
sub check_ssl_support ($);
335
 
sub check_running_as_root();
336
 
sub check_ndbcluster_support ($);
337
 
sub rm_ndbcluster_tables ($);
338
 
sub ndbcluster_start_install ($);
339
 
sub ndbcluster_start ($$);
340
 
sub ndbcluster_wait_started ($$);
341
 
sub mysqld_wait_started($);
342
 
sub run_benchmarks ($);
343
 
sub initialize_servers ();
344
 
sub mysql_install_db ();
345
 
sub install_db ($$);
346
 
sub copy_install_db ($$);
347
 
sub run_testcase ($);
348
 
sub run_testcase_stop_servers ($$$);
349
 
sub run_testcase_start_servers ($);
350
 
sub run_testcase_check_skip_test($);
351
 
sub report_failure_and_restart ($);
352
 
sub do_before_start_master ($);
353
 
sub do_before_start_slave ($);
354
 
sub ndbd_start ($$$);
355
 
sub ndb_mgmd_start ($);
356
 
sub mysqld_start ($$$);
357
 
sub mysqld_arguments ($$$$);
358
 
sub stop_all_servers ();
359
 
sub run_mysqltest ($);
360
 
sub usage ($);
361
 
 
362
 
 
363
 
######################################################################
364
 
#
365
 
#  Main program
366
 
#
367
 
######################################################################
 
242
my $opt_max_save_core= $ENV{MTR_MAX_SAVE_CORE} || 5;
 
243
my $opt_max_save_datadir= $ENV{MTR_MAX_SAVE_DATADIR} || 20;
 
244
my $opt_max_test_fail= $ENV{MTR_MAX_TEST_FAIL} || 10;
 
245
 
 
246
my $opt_parallel= $ENV{MTR_PARALLEL} || 1;
 
247
 
 
248
select(STDOUT);
 
249
$| = 1; # Automatically flush STDOUT
368
250
 
369
251
main();
370
252
 
371
 
sub main () {
 
253
 
 
254
sub main {
 
255
  # Default, verbosity on
 
256
  report_option('verbose', 0);
 
257
 
 
258
  # This is needed for test log evaluation in "gen-build-status-page"
 
259
  # in all cases where the calling tool does not log the commands
 
260
  # directly before it executes them, like "make test-force-pl" in RPM builds.
 
261
  mtr_report("Logging: $0 ", join(" ", @ARGV));
372
262
 
373
263
  command_line_setup();
374
264
 
375
 
  check_ndbcluster_support(\%mysqld_variables);
376
 
  check_ssl_support(\%mysqld_variables);
377
 
  check_debug_support(\%mysqld_variables);
378
 
 
379
 
  executable_setup();
 
265
  if ( $opt_gcov ) {
 
266
    gcov_prepare($basedir);
 
267
  }
 
268
 
 
269
  if (!$opt_suites) {
 
270
    $opt_suites= $DEFAULT_SUITES;
 
271
 
 
272
    # Check for any extra suites to enable based on the path name
 
273
    my %extra_suites=
 
274
      (
 
275
       "mysql-5.1-new-ndb"              => "ndb_team",
 
276
       "mysql-5.1-new-ndb-merge"        => "ndb_team",
 
277
       "mysql-5.1-telco-6.2"            => "ndb_team",
 
278
       "mysql-5.1-telco-6.2-merge"      => "ndb_team",
 
279
       "mysql-5.1-telco-6.3"            => "ndb_team",
 
280
       "mysql-6.0-ndb"                  => "ndb_team",
 
281
      );
 
282
 
 
283
    foreach my $dir ( reverse splitdir($basedir) ) {
 
284
      my $extra_suite= $extra_suites{$dir};
 
285
      if (defined $extra_suite) {
 
286
        mtr_report("Found extra suite: $extra_suite");
 
287
        $opt_suites= "$extra_suite,$opt_suites";
 
288
        last;
 
289
      }
 
290
    }
 
291
  }
 
292
 
 
293
  mtr_report("Collecting tests...");
 
294
  my $tests= collect_test_cases($opt_suites, \@opt_cases);
 
295
 
 
296
  if ( $opt_report_features ) {
 
297
    # Put "report features" as the first test to run
 
298
    my $tinfo = My::Test->new
 
299
      (
 
300
       name           => 'report_features',
 
301
       # No result_file => Prints result
 
302
       path           => 'include/report-features.test',
 
303
       template_path  => "include/default_my.cnf",
 
304
       master_opt     => [],
 
305
       slave_opt      => [],
 
306
      );
 
307
    unshift(@$tests, $tinfo);
 
308
  }
 
309
 
 
310
  print "vardir: $opt_vardir\n";
 
311
  initialize_servers();
 
312
 
 
313
  #######################################################################
 
314
  my $num_tests= @$tests;
 
315
  if ( not defined $opt_parallel ) {
 
316
    # Try to find a suitable value for number of workers
 
317
    my $sys_info= My::SysInfo->new();
 
318
 
 
319
    $opt_parallel= $sys_info->num_cpus();
 
320
    for my $limit (2000, 1500, 1000, 500){
 
321
      $opt_parallel-- if ($sys_info->min_bogomips() < $limit);
 
322
    }
 
323
    $opt_parallel= 8 if ($opt_parallel > 8);
 
324
    $opt_parallel= $num_tests if ($opt_parallel > $num_tests);
 
325
    $opt_parallel= 1 if (IS_WINDOWS and $sys_info->isvm());
 
326
    $opt_parallel= 1 if ($opt_parallel < 1);
 
327
    mtr_report("Using parallel: $opt_parallel");
 
328
  }
 
329
 
 
330
  # Create server socket on any free port
 
331
  my $server = new IO::Socket::INET
 
332
    (
 
333
     LocalAddr => 'localhost',
 
334
     Proto => 'tcp',
 
335
     Listen => $opt_parallel,
 
336
    );
 
337
  mtr_error("Could not create testcase server port: $!") unless $server;
 
338
  my $server_port = $server->sockport();
 
339
  mtr_report("Using server port $server_port");
 
340
 
 
341
  # Create child processes
 
342
  my %children;
 
343
  for my $child_num (1..$opt_parallel){
 
344
    my $child_pid= My::SafeProcess::Base::_safe_fork();
 
345
    if ($child_pid == 0){
 
346
      $server= undef; # Close the server port in child
 
347
      $tests= {}; # Don't need the tests list in child
 
348
 
 
349
      # Use subdir of var and tmp unless only one worker
 
350
      if ($opt_parallel > 1) {
 
351
        set_vardir("$opt_vardir/$child_num");
 
352
        $opt_tmpdir= "$opt_tmpdir/$child_num";
 
353
      }
 
354
 
 
355
      run_worker($server_port, $child_num);
 
356
      exit(1);
 
357
    }
 
358
 
 
359
    $children{$child_pid}= 1;
 
360
  }
 
361
  #######################################################################
 
362
 
 
363
  mtr_report();
 
364
  mtr_print_thick_line();
 
365
  mtr_print_header();
 
366
 
 
367
  my $completed= run_test_server($server, $tests, $opt_parallel);
 
368
 
 
369
  # Send Ctrl-C to any children still running
 
370
  kill("INT", keys(%children));
 
371
 
 
372
  # Wait for childs to exit
 
373
  foreach my $pid (keys %children)
 
374
  {
 
375
    my $ret_pid= waitpid($pid, 0);
 
376
    if ($ret_pid != $pid){
 
377
      mtr_report("Unknown process $ret_pid exited");
 
378
    }
 
379
    else {
 
380
      delete $children{$ret_pid};
 
381
    }
 
382
  }
 
383
 
 
384
  if ( not defined @$completed ) {
 
385
    mtr_error("Test suite aborted");
 
386
  }
 
387
 
 
388
  if ( @$completed != $num_tests){
 
389
 
 
390
    if ($opt_force){
 
391
      # All test should have been run, print any that are still in $tests
 
392
      #foreach my $test ( @$tests ){
 
393
      #  $test->print_test();
 
394
      #}
 
395
    }
 
396
 
 
397
    # Not all tests completed, failure
 
398
    mtr_report();
 
399
    mtr_report("Only ", int(@$completed), " of $num_tests completed.");
 
400
    mtr_error("Not all tests completed");
 
401
  }
 
402
 
 
403
  mtr_print_line();
 
404
 
 
405
  if ( $opt_gcov ) {
 
406
    gcov_collect($basedir, $opt_gcov_exe,
 
407
                 $opt_gcov_msg, $opt_gcov_err);
 
408
  }
 
409
 
 
410
  mtr_report_stats($completed);
 
411
 
 
412
  exit(0);
 
413
}
 
414
 
 
415
 
 
416
sub run_test_server ($$$) {
 
417
  my ($server, $tests, $childs) = @_;
 
418
 
 
419
  my $num_saved_cores= 0;  # Number of core files saved in vardir/log/ so far.
 
420
  my $num_saved_datadir= 0;  # Number of datadirs saved in vardir/log/ so far.
 
421
  my $num_failed_test= 0; # Number of tests failed so far
 
422
 
 
423
  # Scheduler variables
 
424
  my $max_ndb= $childs / 2;
 
425
  $max_ndb = 4 if $max_ndb > 4;
 
426
  $max_ndb = 1 if $max_ndb < 1;
 
427
  my $num_ndb_tests= 0;
 
428
 
 
429
  my $completed= [];
 
430
  my %running;
 
431
  my $result;
 
432
 
 
433
  my $suite_timeout_proc= My::SafeProcess->timer(suite_timeout());
 
434
 
 
435
  my $s= IO::Select->new();
 
436
  $s->add($server);
 
437
  while (1) {
 
438
    my @ready = $s->can_read(1); # Wake up once every second
 
439
    foreach my $sock (@ready) {
 
440
      if ($sock == $server) {
 
441
        # New client connected
 
442
        my $child= $sock->accept();
 
443
        mtr_verbose("Client connected");
 
444
        $s->add($child);
 
445
        print $child "HELLO\n";
 
446
      }
 
447
      else {
 
448
        my $line= <$sock>;
 
449
        if (!defined $line) {
 
450
          # Client disconnected
 
451
          mtr_verbose("Child closed socket");
 
452
          $s->remove($sock);
 
453
          if (--$childs == 0){
 
454
            $suite_timeout_proc->kill();
 
455
            return $completed;
 
456
          }
 
457
          next;
 
458
        }
 
459
        chomp($line);
 
460
 
 
461
        if ($line eq 'TESTRESULT'){
 
462
          $result= My::Test::read_test($sock);
 
463
          # $result->print_test();
 
464
 
 
465
          # Report test status
 
466
          mtr_report_test($result);
 
467
 
 
468
          if ( $result->is_failed() ) {
 
469
 
 
470
            # Save the workers "savedir" in var/log
 
471
            my $worker_savedir= $result->{savedir};
 
472
            my $worker_savename= basename($worker_savedir);
 
473
            my $savedir= "$opt_vardir/log/$worker_savename";
 
474
 
 
475
            if ($opt_max_save_datadir > 0 &&
 
476
                $num_saved_datadir >= $opt_max_save_datadir)
 
477
            {
 
478
              mtr_report(" - skipping '$worker_savedir/'");
 
479
              rmtree($worker_savedir);
 
480
            }
 
481
            else {
 
482
              mtr_report(" - saving '$worker_savedir/' to '$savedir/'");
 
483
              rename($worker_savedir, $savedir);
 
484
              # Move any core files from e.g. mysqltest
 
485
              foreach my $coref (glob("core*"), glob("*.dmp"))
 
486
              {
 
487
                mtr_report(" - found '$coref', moving it to '$savedir'");
 
488
                move($coref, $savedir);
 
489
              }
 
490
              if ($opt_max_save_core > 0) {
 
491
                # Limit number of core files saved
 
492
                find({ no_chdir => 1,
 
493
                       wanted => sub {
 
494
                         my $core_file= $File::Find::name;
 
495
                         my $core_name= basename($core_file);
 
496
 
 
497
                         if ($core_name =~ /^core/ or  # Starting with core
 
498
                             (IS_WINDOWS and $core_name =~ /\.dmp$/)){
 
499
                                                       # Ending with .dmp
 
500
                           mtr_report(" - found '$core_name'",
 
501
                                      "($num_saved_cores/$opt_max_save_core)");
 
502
 
 
503
                           My::CoreDump->show($core_file);
 
504
 
 
505
                           if ($num_saved_cores >= $opt_max_save_core) {
 
506
                             mtr_report(" - deleting it, already saved",
 
507
                                        "$opt_max_save_core");
 
508
                             unlink("$core_file");
 
509
                           }
 
510
                           ++$num_saved_cores;
 
511
                         }
 
512
                       }
 
513
                     },
 
514
                     $savedir);
 
515
              }
 
516
            }
 
517
            $num_saved_datadir++;
 
518
 
 
519
            if ( !$opt_force ) {
 
520
              # Test has failed, force is off
 
521
              $suite_timeout_proc->kill();
 
522
              push(@$completed, $result);
 
523
              return $completed;
 
524
            }
 
525
            elsif ($opt_max_test_fail > 0 and
 
526
                   $num_failed_test >= $opt_max_test_fail) {
 
527
              $suite_timeout_proc->kill();
 
528
              mtr_report("Too many tests($num_failed_test) failed!",
 
529
                         "Terminating...");
 
530
              return undef;
 
531
            }
 
532
            $num_failed_test++;
 
533
          }
 
534
 
 
535
          # Retry test run after test failure
 
536
          my $retries= $result->{retries} || 2;
 
537
          my $test_has_failed= $result->{failures} || 0;
 
538
          if ($test_has_failed and $retries <= $opt_retry){
 
539
            # Test should be run one more time unless it has failed
 
540
            # too many times already
 
541
            my $failures= $result->{failures};
 
542
            if ($opt_retry > 1 and $failures >= $opt_retry_failure){
 
543
              mtr_report("\nTest has failed $failures times,",
 
544
                         "no more retries!\n");
 
545
            }
 
546
            else {
 
547
              mtr_report("\nRetrying test, attempt($retries/$opt_retry)...\n");
 
548
              delete($result->{result});
 
549
              $result->{retries}= $retries+1;
 
550
              $result->write_test($sock, 'TESTCASE');
 
551
              next;
 
552
            }
 
553
          }
 
554
 
 
555
          # Repeat test $opt_repeat number of times
 
556
          my $repeat= $result->{repeat} || 1;
 
557
          if ($repeat < $opt_repeat)
 
558
          {
 
559
            $result->{retries}= 0;
 
560
            $result->{failures}= 0;
 
561
            delete($result->{result});
 
562
            $result->{repeat}= $repeat+1;
 
563
            $result->write_test($sock, 'TESTCASE');
 
564
            next;
 
565
          }
 
566
 
 
567
          # Remove from list of running
 
568
          mtr_error("'", $result->{name},"' is not known to be running")
 
569
            unless delete $running{$result->key()};
 
570
 
 
571
          # Update scheduler variables
 
572
          $num_ndb_tests-- if ($result->{ndb_test});
 
573
 
 
574
          # Save result in completed list
 
575
          push(@$completed, $result);
 
576
 
 
577
        }
 
578
        elsif ($line eq 'START'){
 
579
          ; # Send first test
 
580
        }
 
581
        else {
 
582
          mtr_error("Unknown response: '$line' from client");
 
583
        }
 
584
 
 
585
        # Find next test to schedule
 
586
        # - Try to use same configuration as worker used last time
 
587
        # - Limit number of parallel ndb tests
 
588
 
 
589
        my $next;
 
590
        my $second_best;
 
591
        for(my $i= 0; $i <= @$tests; $i++)
 
592
        {
 
593
          my $t= $tests->[$i];
 
594
 
 
595
          last unless defined $t;
 
596
 
 
597
          if (run_testcase_check_skip_test($t)){
 
598
            # Move the test to completed list
 
599
            #mtr_report("skip - Moving test $i to completed");
 
600
            push(@$completed, splice(@$tests, $i, 1));
 
601
 
 
602
            # Since the test at pos $i was taken away, next
 
603
            # test will also be at $i -> redo
 
604
            redo;
 
605
          }
 
606
 
 
607
          # Limit number of parallell NDB tests
 
608
          if ($t->{ndb_test} and $num_ndb_tests >= $max_ndb){
 
609
            #mtr_report("Skipping, num ndb is already at max, $num_ndb_tests");
 
610
            next;
 
611
          }
 
612
 
 
613
          # Prefer same configuration
 
614
          if (defined $result and
 
615
              $result->{template_path} eq $t->{template_path})
 
616
          {
 
617
            #mtr_report("Test uses same config => good match");
 
618
            # Test uses same config => good match
 
619
            $next= splice(@$tests, $i, 1);
 
620
            last;
 
621
          }
 
622
 
 
623
          # Second best choice is the first that does not fulfill
 
624
          # any of the above conditions
 
625
          if (!defined $second_best){
 
626
            #mtr_report("Setting second_best to $i");
 
627
            $second_best= $i;
 
628
          }
 
629
        }
 
630
 
 
631
        # Use second best choice if no other test has been found
 
632
        if (!$next and defined $second_best){
 
633
          #mtr_report("Take second best choice $second_best");
 
634
          mtr_error("Internal error, second best too large($second_best)")
 
635
            if $second_best >  $#$tests;
 
636
          $next= splice(@$tests, $second_best, 1);
 
637
        }
 
638
 
 
639
        if ($next) {
 
640
          #$next->print_test();
 
641
          $next->write_test($sock, 'TESTCASE');
 
642
          $running{$next->key()}= $next;
 
643
          $num_ndb_tests++ if ($next->{ndb_test});
 
644
        }
 
645
        else {
 
646
          # No more test, tell child to exit
 
647
          #mtr_report("Saying BYE to child");
 
648
          print $sock "BYE\n";
 
649
        }
 
650
      }
 
651
    }
 
652
 
 
653
    # ----------------------------------------------------
 
654
    # Check if test suite timer expired
 
655
    # ----------------------------------------------------
 
656
    if ( ! $suite_timeout_proc->wait_one(0) )
 
657
    {
 
658
      mtr_report("Test suite timeout! Terminating...");
 
659
      return undef;
 
660
    }
 
661
  }
 
662
}
 
663
 
 
664
 
 
665
sub run_worker ($) {
 
666
  my ($server_port, $thread_num)= @_;
 
667
 
 
668
  $SIG{INT}= sub { exit(1); };
 
669
 
 
670
  # Connect to server
 
671
  my $server = new IO::Socket::INET
 
672
    (
 
673
     PeerAddr => 'localhost',
 
674
     PeerPort => $server_port,
 
675
     Proto    => 'tcp'
 
676
    );
 
677
  mtr_error("Could not connect to server at port $server_port: $!")
 
678
    unless $server;
 
679
 
 
680
  # --------------------------------------------------------------------------
 
681
  # Set worker name
 
682
  # --------------------------------------------------------------------------
 
683
  report_option('name',"worker[$thread_num]");
 
684
 
 
685
  # --------------------------------------------------------------------------
 
686
  # Set different ports per thread
 
687
  # --------------------------------------------------------------------------
 
688
  set_build_thread_ports($thread_num);
 
689
 
 
690
  # --------------------------------------------------------------------------
 
691
  # Turn off verbosity in workers, unless explicitly specified
 
692
  # --------------------------------------------------------------------------
 
693
  report_option('verbose', undef) if ($opt_verbose == 0);
380
694
 
381
695
  environment_setup();
382
 
  signal_setup();
383
 
 
384
 
  if ( $opt_gcov )
385
 
  {
386
 
    gcov_prepare();
387
 
  }
388
 
 
389
 
  if ( $opt_gprof )
390
 
  {
391
 
    gprof_prepare();
392
 
  }
393
 
 
394
 
  if ( $opt_bench )
395
 
  {
396
 
    initialize_servers();
397
 
    run_benchmarks(shift);      # Shift what? Extra arguments?!
398
 
  }
399
 
  elsif ( $opt_stress )
400
 
  {
401
 
    initialize_servers();
402
 
    run_stress_test()
403
 
  }
404
 
  else
405
 
  {
406
 
    # Figure out which tests we are going to run
407
 
    if (!$opt_suites)
408
 
    {
409
 
      $opt_suites= $opt_suites_default;
410
 
 
411
 
      # Check for any extra suites to enable based on the path name
412
 
      my %extra_suites=
413
 
        (
414
 
         "mysql-5.1-new-ndb"              => "ndb_team",
415
 
         "mysql-5.1-new-ndb-merge"        => "ndb_team",
416
 
         "mysql-5.1-telco-6.2"            => "ndb_team",
417
 
         "mysql-5.1-telco-6.2-merge"      => "ndb_team",
418
 
         "mysql-5.1-telco-6.3"            => "ndb_team",
419
 
         "mysql-6.0-ndb"                  => "ndb_team",
420
 
        );
421
 
 
422
 
      foreach my $dir ( reverse splitdir($glob_basedir) )
423
 
      {
424
 
        my $extra_suite= $extra_suites{$dir};
425
 
        if (defined $extra_suite){
426
 
          mtr_report("Found extra suite: $extra_suite");
427
 
          $opt_suites= "$extra_suite,$opt_suites";
428
 
          last;
429
 
        }
430
 
      }
431
 
    }
432
 
 
433
 
    my $tests= collect_test_cases($opt_suites);
434
 
 
435
 
    # Turn off NDB and other similar options if no tests use it
436
 
    my ($need_ndbcluster,$need_im);
437
 
    foreach my $test (@$tests)
438
 
    {
439
 
      next if $test->{skip};
440
 
 
441
 
      if (!$opt_extern)
442
 
      {
443
 
        $need_ndbcluster||= $test->{ndb_test};
444
 
        $need_im||= $test->{component_id} eq 'im';
445
 
 
446
 
        # Count max number of slaves used by a test case
447
 
        if ( $test->{slave_num} > $max_slave_num) {
448
 
          $max_slave_num= $test->{slave_num};
449
 
          mtr_error("Too many slaves") if $max_slave_num > 3;
450
 
        }
451
 
 
452
 
        # Count max number of masters used by a test case
453
 
        if ( $test->{master_num} > $max_master_num) {
454
 
          $max_master_num= $test->{master_num};
455
 
          mtr_error("Too many masters") if $max_master_num > 2;
456
 
          mtr_error("Too few masters") if $max_master_num < 1;
457
 
        }
458
 
      }
459
 
      $use_innodb||= $test->{'innodb_test'};
460
 
    }
461
 
 
462
 
    # Check if cluster can be skipped
463
 
    if ( !$need_ndbcluster )
464
 
    {
465
 
      $opt_skip_ndbcluster= 1;
466
 
      $opt_skip_ndbcluster_slave= 1;
467
 
    }
468
 
 
469
 
    # Check if slave cluster can be skipped
470
 
    if ($max_slave_num == 0)
471
 
    {
472
 
      $opt_skip_ndbcluster_slave= 1;
473
 
    }
474
 
 
475
 
    # Check if im can be skipped
476
 
    if ( ! $need_im )
477
 
    {
478
 
     $opt_skip_im= 1;
479
 
    }
480
 
 
481
 
    initialize_servers();
482
 
 
483
 
    if ( $opt_report_features ) {
484
 
      run_report_features();
485
 
    }
486
 
 
487
 
    run_tests($tests);
488
 
  }
489
 
 
490
 
  mtr_exit(0);
491
 
}
492
 
 
493
 
##############################################################################
494
 
#
495
 
#  Default settings
496
 
#
497
 
##############################################################################
498
 
 
499
 
#
500
 
# When an option is no longer used by this program, it must be explicitly
501
 
# ignored or else it will be passed through to mysqld.  GetOptions will call
502
 
# this subroutine once for each such option on the command line.  See
503
 
# Getopt::Long documentation.
504
 
#
505
 
 
506
 
sub warn_about_removed_option {
507
 
  my ($option, $value, $hash_value) = @_;
508
 
 
509
 
  warn "WARNING: This option is no longer used, and is ignored: --$option\n";
510
 
}
511
 
 
512
 
sub command_line_setup () {
513
 
 
514
 
  # These are defaults for things that are set on the command line
515
 
 
 
696
 
 
697
  # Read hello from server which it will send when shared
 
698
  # resources have been setup
 
699
  my $hello= <$server>;
 
700
 
 
701
  setup_vardir();
 
702
  check_running_as_root();
 
703
 
 
704
  if ( using_extern() ) {
 
705
    create_config_file_for_extern(%opts_extern);
 
706
  }
 
707
 
 
708
  # Ask server for first test
 
709
  print $server "START\n";
 
710
 
 
711
  while(my $line= <$server>){
 
712
    chomp($line);
 
713
    if ($line eq 'TESTCASE'){
 
714
      my $test= My::Test::read_test($server);
 
715
      #$test->print_test();
 
716
 
 
717
      # Clear comment and logfile, to avoid
 
718
      # reusing them from previous test
 
719
      delete($test->{'comment'});
 
720
      delete($test->{'logfile'});
 
721
 
 
722
      run_testcase($test);
 
723
      #$test->{result}= 'MTR_RES_PASSED';
 
724
      # Send it back, now with results set
 
725
      #$test->print_test();
 
726
      $test->write_test($server, 'TESTRESULT');
 
727
    }
 
728
    elsif ($line eq 'BYE'){
 
729
      mtr_report("Server said BYE");
 
730
      exit(0);
 
731
    }
 
732
    else {
 
733
      mtr_error("Could not understand server, '$line'");
 
734
    }
 
735
  }
 
736
 
 
737
  stop_all_servers();
 
738
 
 
739
  exit(1);
 
740
}
 
741
 
 
742
 
 
743
sub ignore_option {
 
744
  my ($opt, $value)= @_;
 
745
  mtr_report("Ignoring option '$opt'");
 
746
}
 
747
 
 
748
 
 
749
 
 
750
# Setup any paths that are $opt_vardir related
 
751
sub set_vardir {
 
752
  my ($vardir)= @_;
 
753
 
 
754
  $opt_vardir= $vardir;
 
755
 
 
756
  $path_vardir_trace= $opt_vardir;
 
757
  # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
 
758
  $path_vardir_trace=~ s/^\w://;
 
759
 
 
760
  # Location of my.cnf that all clients use
 
761
  $path_config_file= "$opt_vardir/my.cnf";
 
762
 
 
763
  $path_testlog=         "$opt_vardir/log/mysqltest.log";
 
764
  $path_current_testlog= "$opt_vardir/log/current_test";
 
765
 
 
766
}
 
767
 
 
768
 
 
769
sub command_line_setup {
516
770
  my $opt_comment;
517
 
 
518
 
  # Magic number -69.4 results in traditional test ports starting from 9306.
519
 
  set_mtr_build_thread_ports(-69.4);
520
 
 
521
 
  # If so requested, we try to avail ourselves of a unique build thread number.
522
 
  if ( $ENV{'MTR_BUILD_THREAD'} ) {
523
 
    if ( lc($ENV{'MTR_BUILD_THREAD'}) eq 'auto' ) {
524
 
      print "Requesting build thread... ";
525
 
      $ENV{'MTR_BUILD_THREAD'} = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
526
 
      print "got ".$ENV{'MTR_BUILD_THREAD'}."\n";
527
 
    }
528
 
  }
529
 
 
530
 
  if ( $ENV{'MTR_BUILD_THREAD'} )
531
 
  {
532
 
    set_mtr_build_thread_ports($ENV{'MTR_BUILD_THREAD'});
533
 
  }
534
 
 
535
 
  # This is needed for test log evaluation in "gen-build-status-page"
536
 
  # in all cases where the calling tool does not log the commands
537
 
  # directly before it executes them, like "make test-force-pl" in RPM builds.
538
 
  print "Logging: $0 ", join(" ", @ARGV), "\n";
539
 
 
540
 
  # Read the command line
 
771
  my $opt_usage;
 
772
 
 
773
  # Read the command line options
541
774
  # Note: Keep list, and the order, in sync with usage at end of this file
542
 
 
543
 
  # Options that are no longer used must still be processed, because all
544
 
  # unprocessed options are passed directly to mysqld.  The user will be
545
 
  # warned that the option is being ignored.
546
 
  #
547
 
  # Put the complete option string here.  For example, to remove the --suite
548
 
  # option, remove it from GetOptions() below and put 'suite|suites=s' here.
549
 
  my @removed_options = (
550
 
  );
551
 
 
552
775
  Getopt::Long::Configure("pass_through");
553
776
  GetOptions(
554
777
             # Control what engine/variation to run
560
783
             'ssl|with-openssl'         => \$opt_ssl,
561
784
             'skip-ssl'                 => \$opt_skip_ssl,
562
785
             'compress'                 => \$opt_compress,
563
 
             'bench'                    => \$opt_bench,
564
 
             'small-bench'              => \$opt_small_bench,
565
 
             'with-ndbcluster|ndb'      => \$opt_with_ndbcluster,
566
 
             'vs-config'            => \$opt_vs_config,
 
786
             'vs-config'                => \$opt_vs_config,
 
787
 
 
788
             # Max number of parallel threads to use
 
789
             'parallel=i'               => \$opt_parallel,
 
790
 
 
791
             # Config file to use as template for all tests
 
792
             'defaults-file=s'          => \&collect_option,
 
793
             # Extra config file to append to all generated configs
 
794
             'defaults-extra-file=s'    => \&collect_option,
567
795
 
568
796
             # Control what test suites or cases to run
569
797
             'force'                    => \$opt_force,
570
 
             'with-ndbcluster-only'     => \$opt_with_ndbcluster_only,
 
798
             'with-ndbcluster-only'     => \&collect_option,
571
799
             'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster,
572
 
             'skip-ndbcluster-slave|skip-ndb-slave'
573
 
                                        => \$opt_skip_ndbcluster_slave,
574
 
             'ndb-extra-test'           => \$opt_ndb_extra_test,
575
 
             'skip-master-binlog'       => \$opt_skip_master_binlog,
576
 
             'skip-slave-binlog'        => \$opt_skip_slave_binlog,
577
 
             'do-test=s'                => \$opt_do_test,
578
 
             'start-from=s'             => \$opt_start_from,
579
800
             'suite|suites=s'           => \$opt_suites,
580
 
             'skip-rpl'                 => \$opt_skip_rpl,
581
 
             'skip-im'                  => \$opt_skip_im,
582
 
             'skip-test=s'              => \$opt_skip_test,
 
801
             'skip-rpl'                 => \&collect_option,
 
802
             'skip-test=s'              => \&collect_option,
 
803
             'do-test=s'                => \&collect_option,
 
804
             'start-from=s'             => \&collect_option,
583
805
             'big-test'                 => \$opt_big_test,
584
 
             'combination=s'            => \@opt_combinations,
585
 
             'skip-combination'         => \$opt_skip_combination,
 
806
             'combination=s'            => \@opt_combinations,
 
807
             'skip-combinations'        => \&collect_option,
 
808
             'experimental=s'           => \$opt_experimental,
 
809
             'skip-im'                  => \&ignore_option,
586
810
 
587
811
             # Specify ports
588
 
             'master_port=i'            => \$opt_master_myport,
589
 
             'slave_port=i'             => \$opt_slave_myport,
590
 
             'ndbcluster-port|ndbcluster_port=i' => \$opt_ndbcluster_port,
591
 
             'ndbcluster-port-slave=i'  => \$opt_ndbcluster_port_slave,
592
 
             'im-port=i'                => \$im_port, # Instance Manager port.
593
 
             'im-mysqld1-port=i'        => \$im_mysqld1_port, # Port of mysqld, controlled by IM
594
 
             'im-mysqld2-port=i'        => \$im_mysqld2_port, # Port of mysqld, controlled by IM
595
 
             'mtr-build-thread=i'       => \$opt_mtr_build_thread,
 
812
             'build-thread|mtr-build-thread=i' => \$opt_build_thread,
596
813
 
597
814
             # Test case authoring
598
815
             'record'                   => \$opt_record,
599
 
             'check-testcases'          => \$opt_check_testcases,
 
816
             'check-testcases!'         => \$opt_check_testcases,
600
817
             'mark-progress'            => \$opt_mark_progress,
601
818
 
602
819
             # Extra options used when starting mysqld
603
820
             'mysqld=s'                 => \@opt_extra_mysqld_opt,
604
821
 
605
822
             # Run test on running server
606
 
             'extern'                   => \$opt_extern,
607
 
             'ndb-connectstring=s'       => \$opt_ndbconnectstring,
608
 
             'ndb-connectstring-slave=s' => \$opt_ndbconnectstring_slave,
 
823
             'extern=s'                  => \%opts_extern, # Append to hash
609
824
 
610
825
             # Debugging
 
826
             'debug'                    => \$opt_debug,
611
827
             'gdb'                      => \$opt_gdb,
612
828
             'client-gdb'               => \$opt_client_gdb,
613
829
             'manual-gdb'               => \$opt_manual_gdb,
617
833
             'manual-ddd'               => \$opt_manual_ddd,
618
834
             'debugger=s'               => \$opt_debugger,
619
835
             'client-debugger=s'        => \$opt_client_debugger,
620
 
             'strace-client'            => \$opt_strace_client,
621
 
             'master-binary=s'          => \$exe_master_mysqld,
622
 
             'slave-binary=s'           => \$exe_slave_mysqld,
 
836
             'strace-client:s'          => \$opt_strace_client,
623
837
             'max-save-core=i'          => \$opt_max_save_core,
 
838
             'max-save-datadir=i'       => \$opt_max_save_datadir,
 
839
             'max-test-fail=i'          => \$opt_max_test_fail,
624
840
 
625
841
             # Coverage, profiling etc
626
842
             'gcov'                     => \$opt_gcov,
627
 
             'gprof'                    => \$opt_gprof,
628
843
             'valgrind|valgrind-all'    => \$opt_valgrind,
629
844
             'valgrind-mysqltest'       => \$opt_valgrind_mysqltest,
630
845
             'valgrind-mysqld'          => \$opt_valgrind_mysqld,
643
858
             'valgrind-path=s'          => \$opt_valgrind_path,
644
859
             'callgrind'                => \$opt_callgrind,
645
860
 
646
 
             # Stress testing 
647
 
             'stress'                   => \$opt_stress,
648
 
             'stress-suite=s'           => \$opt_stress_suite,
649
 
             'stress-threads=i'         => \$opt_stress_threads,
650
 
             'stress-test-file=s'       => \$opt_stress_test_file,
651
 
             'stress-init-file=s'       => \$opt_stress_init_file,
652
 
             'stress-mode=s'            => \$opt_stress_mode,
653
 
             'stress-loop-count=i'      => \$opt_stress_loop_count,
654
 
             'stress-test-count=i'      => \$opt_stress_test_count,
655
 
             'stress-test-duration=i'   => \$opt_stress_test_duration,
656
 
 
657
861
             # Directories
658
862
             'tmpdir=s'                 => \$opt_tmpdir,
659
863
             'vardir=s'                 => \$opt_vardir,
660
 
             'benchdir=s'               => \$glob_mysql_bench_dir,
661
864
             'mem'                      => \$opt_mem,
662
865
             'client-bindir=s'          => \$path_client_bindir,
663
866
             'client-libdir=s'          => \$path_client_libdir,
665
868
             # Misc
666
869
             'report-features'          => \$opt_report_features,
667
870
             'comment=s'                => \$opt_comment,
668
 
             'debug'                    => \$opt_debug,
669
871
             'fast'                     => \$opt_fast,
670
 
             'reorder'                  => \$opt_reorder,
671
 
             'enable-disabled'          => \$opt_enable_disabled,
672
 
             'script-debug'             => \$opt_script_debug,
673
 
             'verbose'                  => \$opt_verbose,
 
872
             'reorder!'                 => \&collect_option,
 
873
             'enable-disabled'          => \&collect_option,
 
874
             'verbose+'                 => \$opt_verbose,
 
875
             'verbose-restart'          => \&report_option,
674
876
             'sleep=i'                  => \$opt_sleep,
675
 
             'socket=s'                 => \$opt_socket,
676
877
             'start-dirty'              => \$opt_start_dirty,
677
 
             'start-and-exit'           => \$opt_start_and_exit,
678
 
             'timer!'                   => \$opt_timer,
 
878
             'start'                    => \$opt_start,
 
879
             'print-testcases'          => \&collect_option,
 
880
             'repeat=i'                 => \$opt_repeat,
 
881
             'retry=i'                  => \$opt_retry,
 
882
             'retry-failure=i'          => \$opt_retry_failure,
 
883
             'timer!'                   => \&report_option,
679
884
             'user=s'                   => \$opt_user,
680
885
             'testcase-timeout=i'       => \$opt_testcase_timeout,
681
886
             'suite-timeout=i'          => \$opt_suite_timeout,
682
 
             'warnings|log-warnings'    => \$opt_warnings,
683
 
 
684
 
             # Options which are no longer used
685
 
             (map { $_ => \&warn_about_removed_option } @removed_options),
 
887
             'shutdown-timeout=i'       => \$opt_shutdown_timeout,
 
888
             'warnings!'                => \$opt_warnings,
 
889
             'timestamp'                => \&report_option,
 
890
             'timediff'                 => \&report_option,
686
891
 
687
892
             'help|h'                   => \$opt_usage,
688
893
            ) or usage("Can't read options");
689
894
 
690
895
  usage("") if $opt_usage;
691
896
 
692
 
  $glob_scriptname=  basename($0);
693
 
 
694
 
  if ($opt_mtr_build_thread != 0)
695
 
  {
696
 
    set_mtr_build_thread_ports($opt_mtr_build_thread)
697
 
  }
698
 
  elsif ($ENV{'MTR_BUILD_THREAD'})
699
 
  {
700
 
    $opt_mtr_build_thread= $ENV{'MTR_BUILD_THREAD'};
701
 
  }
702
 
 
703
 
  # We require that we are in the "mysql-test" directory
704
 
  # to run mysql-test-run
705
 
  if (! -f $glob_scriptname)
706
 
  {
707
 
    mtr_error("Can't find the location for the mysql-test-run script\n" .
708
 
              "Go to to the mysql-test directory and execute the script " .
709
 
              "as follows:\n./$glob_scriptname");
 
897
  # --------------------------------------------------------------------------
 
898
  # Setup verbosity
 
899
  # --------------------------------------------------------------------------
 
900
  if ($opt_verbose != 0){
 
901
    report_option('verbose', $opt_verbose);
710
902
  }
711
903
 
712
904
  if ( -d "../sql" )
715
907
  }
716
908
 
717
909
  # Find the absolute path to the test directory
718
 
  $glob_mysql_test_dir=  cwd();
719
 
  if ( $glob_cygwin_perl )
 
910
  $glob_mysql_test_dir= cwd();
 
911
  if (IS_CYGWIN)
720
912
  {
721
 
    # Windows programs like 'mysqld' needs Windows paths
722
 
    $glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`;
723
 
    chomp($glob_mysql_test_dir);
 
913
    # Use mixed path format i.e c:/path/to/
 
914
    $glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
724
915
  }
725
 
  $default_vardir= "$glob_mysql_test_dir/var";
726
916
 
727
917
  # In most cases, the base directory we find everything relative to,
728
918
  # is the parent directory of the "mysql-test" directory. For source
729
919
  # distributions, TAR binary distributions and some other packages.
730
 
  $glob_basedir= dirname($glob_mysql_test_dir);
 
920
  $basedir= dirname($glob_mysql_test_dir);
731
921
 
732
922
  # In the RPM case, binaries and libraries are installed in the
733
923
  # default system locations, instead of having our own private base
734
924
  # directory. And we install "/usr/share/mysql-test". Moving up one
735
925
  # more directory relative to "mysql-test" gives us a usable base
736
926
  # directory for RPM installs.
737
 
  if ( ! $source_dist and ! -d "$glob_basedir/bin" )
738
 
  {
739
 
    $glob_basedir= dirname($glob_basedir);
740
 
  }
741
 
 
742
 
  # Expect mysql-bench to be located adjacent to the source tree, by default
743
 
  $glob_mysql_bench_dir= "$glob_basedir/../mysql-bench"
744
 
    unless defined $glob_mysql_bench_dir;
745
 
  $glob_mysql_bench_dir= undef
746
 
    unless -d $glob_mysql_bench_dir;
747
 
 
748
 
  $path_my_basedir=
749
 
    $source_dist ? $glob_mysql_test_dir : $glob_basedir;
750
 
 
751
 
  $glob_timers= mtr_init_timers();
752
 
 
753
 
  # --------------------------------------------------------------------------
754
 
  # Embedded server flag
755
 
  # --------------------------------------------------------------------------
756
 
  if ( $opt_embedded_server )
757
 
  {
758
 
    $glob_use_embedded_server= 1;
759
 
    # Add the location for libmysqld.dll to the path.
760
 
    if ( $glob_win32 )
761
 
    {
762
 
      my $lib_mysqld=
763
 
        mtr_path_exists(vs_config_dirs('libmysqld',''));
764
 
          $lib_mysqld= $glob_cygwin_perl ? ":".`cygpath "$lib_mysqld"` 
765
 
                                     : ";".$lib_mysqld;
766
 
      chomp($lib_mysqld);
767
 
      $ENV{'PATH'}="$ENV{'PATH'}".$lib_mysqld;
768
 
    }
769
 
 
770
 
    push(@glob_test_mode, "embedded");
771
 
    $opt_skip_rpl= 1;              # We never run replication with embedded
772
 
    $opt_skip_ndbcluster= 1;       # Turn off use of NDB cluster
773
 
    $opt_skip_ssl= 1;              # Turn off use of SSL
774
 
 
775
 
    # Turn off use of bin log
776
 
    push(@opt_extra_mysqld_opt, "--skip-log-bin");
777
 
 
778
 
    if ( $opt_extern )
779
 
    {
780
 
      mtr_error("Can't use --extern with --embedded-server");
781
 
    }
782
 
  }
783
 
 
784
 
  #
785
 
  # Find the mysqld executable to be able to find the mysqld version
786
 
  # number as early as possible
787
 
  #
 
927
  if ( ! $source_dist and ! -d "$basedir/bin" )
 
928
  {
 
929
    $basedir= dirname($basedir);
 
930
  }
788
931
 
789
932
  # Look for the client binaries directory
790
933
  if ($path_client_bindir)
794
937
  }
795
938
  else
796
939
  {
797
 
    $path_client_bindir= mtr_path_exists("$glob_basedir/client_release",
798
 
                                         "$glob_basedir/client_debug",
 
940
    $path_client_bindir= mtr_path_exists("$basedir/client_release",
 
941
                                         "$basedir/client_debug",
799
942
                                         vs_config_dirs('client', ''),
800
 
                                         "$glob_basedir/client",
801
 
                                         "$glob_basedir/bin");
 
943
                                         "$basedir/client",
 
944
                                         "$basedir/bin");
802
945
  }
803
 
  
 
946
 
804
947
  # Look for language files and charsetsdir, use same share
805
 
  $path_share=      mtr_path_exists("$glob_basedir/share/mysql",
806
 
                                    "$glob_basedir/sql/share",
807
 
                                    "$glob_basedir/share");
808
 
 
809
 
  $path_language=      mtr_path_exists("$path_share/english");
 
948
  $path_language=   mtr_path_exists("$basedir/share/mysql/english",
 
949
                                    "$basedir/sql/share/english",
 
950
                                    "$basedir/share/english");
 
951
 
 
952
 
 
953
  my $path_share= dirname($path_language);
810
954
  $path_charsetsdir=   mtr_path_exists("$path_share/charsets");
811
955
 
812
 
 
813
 
  if (!$opt_extern)
814
 
  {
815
 
    $exe_mysqld=       mtr_exe_exists (vs_config_dirs('sql', 'mysqld'),
816
 
                                       vs_config_dirs('sql', 'mysqld-debug'),
817
 
                                       "$glob_basedir/sql/mysqld",
818
 
                                       "$path_client_bindir/mysqld-max-nt",
819
 
                                       "$path_client_bindir/mysqld-max",
820
 
                                       "$path_client_bindir/mysqld-nt",
821
 
                                       "$path_client_bindir/mysqld",
822
 
                                       "$path_client_bindir/mysqld-debug",
823
 
                                       "$path_client_bindir/mysqld-max",
824
 
                                       "$glob_basedir/libexec/mysqld",
825
 
                                       "$glob_basedir/bin/mysqld",
826
 
                                       "$glob_basedir/sbin/mysqld");
827
 
 
828
 
    # Use the mysqld found above to find out what features are available
 
956
  if (using_extern())
 
957
  {
 
958
    # Connect to the running mysqld and find out what it supports
 
959
    collect_mysqld_features_from_running_server();
 
960
  }
 
961
  else
 
962
  {
 
963
    # Run the mysqld to find out what features are available
829
964
    collect_mysqld_features();
830
965
  }
831
 
  else
832
 
  {
833
 
    $mysqld_variables{'port'}= 3306;
834
 
    $mysqld_variables{'master-port'}= 3306;
835
 
  }
836
966
 
837
967
  if ( $opt_comment )
838
968
  {
839
 
    print "\n";
840
 
    print '#' x 78, "\n";
841
 
    print "# $opt_comment\n";
842
 
    print '#' x 78, "\n\n";
 
969
    mtr_report();
 
970
    mtr_print_thick_line('#');
 
971
    mtr_report("# $opt_comment");
 
972
    mtr_print_thick_line('#');
 
973
  }
 
974
 
 
975
  if ( $opt_experimental )
 
976
  {
 
977
    # read the list of experimental test cases from the file specified on
 
978
    # the command line
 
979
    open(FILE, "<", $opt_experimental) or mtr_error("Can't read experimental file: $opt_experimental");
 
980
    mtr_report("Using experimental file: $opt_experimental");
 
981
    $experimental_test_cases = [];
 
982
    while(<FILE>) {
 
983
      chomp;
 
984
      # remove comments (# foo) at the beginning of the line, or after a 
 
985
      # blank at the end of the line
 
986
      s/( +|^)#.*$//;
 
987
      # remove whitespace
 
988
      s/^ +//;              
 
989
      s/ +$//;
 
990
      # if nothing left, don't need to remember this line
 
991
      if ( $_ eq "" ) {
 
992
        next;
 
993
      }
 
994
      # remember what is left as the name of another test case that should be
 
995
      # treated as experimental
 
996
      print " - $_\n";
 
997
      push @$experimental_test_cases, $_;
 
998
    }
 
999
    close FILE;
843
1000
  }
844
1001
 
845
1002
  foreach my $arg ( @ARGV )
867
1024
  # --------------------------------------------------------------------------
868
1025
  # Find out type of logging that are being used
869
1026
  # --------------------------------------------------------------------------
870
 
  if (!$opt_extern && $mysql_version_id >= 50100 )
 
1027
  foreach my $arg ( @opt_extra_mysqld_opt )
871
1028
  {
872
 
    foreach my $arg ( @opt_extra_mysqld_opt )
873
 
    {
874
 
      if ( $arg =~ /binlog[-_]format=(\S+)/ )
875
 
      {
876
 
        $used_binlog_format= $1;
877
 
      }
878
 
    }
879
 
    if (defined $used_binlog_format) 
880
 
    {
881
 
      mtr_report("Using binlog format '$used_binlog_format'");
882
 
    }
883
 
    else
884
 
    {
885
 
      mtr_report("Using dynamic switching of binlog format");
 
1029
    if ( $arg =~ /binlog[-_]format=(\S+)/ )
 
1030
    {
 
1031
      # Save this for collect phase
 
1032
      collect_option('binlog-format', $1);
 
1033
      mtr_report("Using binlog format '$1'");
886
1034
    }
887
1035
  }
888
1036
 
890
1038
  # --------------------------------------------------------------------------
891
1039
  # Find out default storage engine being used(if any)
892
1040
  # --------------------------------------------------------------------------
893
 
  if ( $opt_with_ndbcluster )
894
 
  {
895
 
    # --ndb or --with-ndbcluster turns on --default-storage-engine=ndbcluster
896
 
    push(@opt_extra_mysqld_opt, "--default-storage-engine=ndbcluster");
897
 
  }
898
 
 
899
1041
  foreach my $arg ( @opt_extra_mysqld_opt )
900
1042
  {
901
1043
    if ( $arg =~ /default-storage-engine=(\S+)/ )
902
1044
    {
903
 
      $used_default_engine= $1;
 
1045
      # Save this for collect phase
 
1046
      collect_option('default-storage-engine', $1);
 
1047
      mtr_report("Using default engine '$1'")
904
1048
    }
905
1049
  }
906
 
  mtr_report("Using default engine '$used_default_engine'")
907
 
    if defined $used_default_engine;
908
1050
 
909
1051
  # --------------------------------------------------------------------------
910
1052
  # Check if we should speed up tests by trying to run on tmpfs
911
1053
  # --------------------------------------------------------------------------
912
 
  if ( defined $opt_mem )
 
1054
  if ( defined $opt_mem)
913
1055
  {
914
1056
    mtr_error("Can't use --mem and --vardir at the same time ")
915
1057
      if $opt_vardir;
917
1059
      if $opt_tmpdir;
918
1060
 
919
1061
    # Search through list of locations that are known
920
 
    # to be "fast disks" to list to find a suitable location
 
1062
    # to be "fast disks" to find a suitable location
921
1063
    # Use --mem=<dir> as first location to look.
922
1064
    my @tmpfs_locations= ($opt_mem, "/dev/shm", "/tmp");
923
1065
 
925
1067
    {
926
1068
      if ( -d $fs )
927
1069
      {
928
 
        mtr_report("Using tmpfs in $fs");
929
 
        $opt_mem= "$fs/var";
930
 
        $opt_mem .= $opt_mtr_build_thread if $opt_mtr_build_thread;
 
1070
        my $template= "var_${opt_build_thread}_XXXX";
 
1071
        $opt_mem= tempdir( $template, DIR => $fs, CLEANUP => 0);
931
1072
        last;
932
1073
      }
933
1074
    }
934
1075
  }
935
1076
 
936
1077
  # --------------------------------------------------------------------------
937
 
  # Set the "var/" directory, as it is the base for everything else
 
1078
  # Set the "var/" directory, the base for everything else
938
1079
  # --------------------------------------------------------------------------
 
1080
  $default_vardir= "$glob_mysql_test_dir/var";
939
1081
  if ( ! $opt_vardir )
940
1082
  {
941
1083
    $opt_vardir= $default_vardir;
942
1084
  }
943
 
  elsif ( $mysql_version_id < 50000 and
944
 
          $opt_vardir ne $default_vardir)
945
 
  {
946
 
    # Version 4.1 and --vardir was specified
947
 
    # Only supported as a symlink from var/
948
 
    # by setting up $opt_mem that symlink will be created
949
 
    if ( ! $glob_win32 )
950
 
    {
951
 
      # Only platforms that have native symlinks can use the vardir trick
952
 
      $opt_mem= $opt_vardir;
953
 
      mtr_report("Using 4.1 vardir trick");
954
 
    }
955
 
 
956
 
    $opt_vardir= $default_vardir;
957
 
  }
958
 
 
959
 
  $path_vardir_trace= $opt_vardir;
960
 
  # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
961
 
  $path_vardir_trace=~ s/^\w://;
962
1085
 
963
1086
  # We make the path absolute, as the server will do a chdir() before usage
964
1087
  unless ( $opt_vardir =~ m,^/, or
965
 
           ($glob_win32 and $opt_vardir =~ m,^[a-z]:/,i) )
 
1088
           (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:/,i) )
966
1089
  {
967
1090
    # Make absolute path, relative test dir
968
1091
    $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
969
1092
  }
970
1093
 
971
 
  # --------------------------------------------------------------------------
972
 
  # Set tmpdir
973
 
  # --------------------------------------------------------------------------
974
 
  $opt_tmpdir=       "$opt_vardir/tmp" unless $opt_tmpdir;
 
1094
  set_vardir($opt_vardir);
 
1095
 
 
1096
  # --------------------------------------------------------------------------
 
1097
  # Set the "tmp" directory
 
1098
  # --------------------------------------------------------------------------
 
1099
  if ( ! $opt_tmpdir )
 
1100
  {
 
1101
    $opt_tmpdir=       "$opt_vardir/tmp" unless $opt_tmpdir;
 
1102
 
 
1103
    if (check_socket_path_length("$opt_tmpdir/mysql_testsocket.sock"))
 
1104
    {
 
1105
      mtr_report("Too long tmpdir path '$opt_tmpdir'",
 
1106
                 " creating a shorter one...");
 
1107
 
 
1108
      # Create temporary directory in standard location for temporary files
 
1109
      $opt_tmpdir= tempdir( TMPDIR => 1, CLEANUP => 0 );
 
1110
      mtr_report(" - using tmpdir: '$opt_tmpdir'\n");
 
1111
 
 
1112
      # Remember pid that created dir so it's removed by correct process
 
1113
      $opt_tmpdir_pid= $$;
 
1114
    }
 
1115
  }
975
1116
  $opt_tmpdir =~ s,/+$,,;       # Remove ending slash if any
976
1117
 
977
1118
  # --------------------------------------------------------------------------
978
 
  # Check im suport
979
 
  # --------------------------------------------------------------------------
980
 
  if ($opt_extern)
981
 
  {
982
 
    mtr_report("Disable instance manager when running with extern mysqld");
983
 
    $opt_skip_im= 1;
984
 
  }
985
 
  elsif ( $mysql_version_id < 50000 )
986
 
  {
987
 
    # Instance manager is not supported until 5.0
988
 
    $opt_skip_im= 1;
989
 
  }
990
 
  elsif ( $glob_win32 )
991
 
  {
992
 
    mtr_report("Disable Instance manager - testing not supported on Windows");
993
 
    $opt_skip_im= 1;
 
1119
  # fast option
 
1120
  # --------------------------------------------------------------------------
 
1121
  if ($opt_fast){
 
1122
    $opt_shutdown_timeout= 0; # Kill processes instead of nice shutdown
 
1123
  }
 
1124
 
 
1125
  # --------------------------------------------------------------------------
 
1126
  # Check parallel value
 
1127
  # --------------------------------------------------------------------------
 
1128
  if ($opt_parallel < 1)
 
1129
  {
 
1130
    mtr_error("0 or negative parallel value makes no sense, use positive number");
994
1131
  }
995
1132
 
996
1133
  # --------------------------------------------------------------------------
1001
1138
    mtr_error("Will not run in record mode without a specific test case");
1002
1139
  }
1003
1140
 
1004
 
  if ( $opt_record )
1005
 
  {
1006
 
    $opt_skip_combination = 1;
1007
 
  }
1008
 
 
1009
 
  # --------------------------------------------------------------------------
1010
 
  # ps protcol flag
1011
 
  # --------------------------------------------------------------------------
1012
 
  if ( $opt_ps_protocol )
1013
 
  {
1014
 
    push(@glob_test_mode, "ps-protocol");
1015
 
  }
1016
 
 
1017
 
  # --------------------------------------------------------------------------
1018
 
  # Bench flags
1019
 
  # --------------------------------------------------------------------------
1020
 
  if ( $opt_small_bench )
1021
 
  {
1022
 
    $opt_bench=  1;
 
1141
  if ( $opt_record ) {
 
1142
    # Use only one worker with --record
 
1143
    $opt_parallel= 1;
 
1144
  }
 
1145
 
 
1146
  # --------------------------------------------------------------------------
 
1147
  # Embedded server flag
 
1148
  # --------------------------------------------------------------------------
 
1149
  if ( $opt_embedded_server )
 
1150
  {
 
1151
    if ( IS_WINDOWS )
 
1152
    {
 
1153
      # Add the location for libmysqld.dll to the path.
 
1154
      my $separator= ";";
 
1155
      my $lib_mysqld=
 
1156
        mtr_path_exists(vs_config_dirs('libmysqld',''));
 
1157
      if ( IS_CYGWIN )
 
1158
      {
 
1159
        $lib_mysqld= posix_path($lib_mysqld);
 
1160
        $separator= ":";
 
1161
      }
 
1162
      $ENV{'PATH'}= "$ENV{'PATH'}".$separator.$lib_mysqld;
 
1163
    }
 
1164
    $opt_skip_ndbcluster= 1;       # Turn off use of NDB cluster
 
1165
    $opt_skip_ssl= 1;              # Turn off use of SSL
 
1166
 
 
1167
    # Turn off use of bin log
 
1168
    push(@opt_extra_mysqld_opt, "--skip-log-bin");
 
1169
 
 
1170
    if ( using_extern() )
 
1171
    {
 
1172
      mtr_error("Can't use --extern with --embedded-server");
 
1173
    }
 
1174
 
 
1175
 
 
1176
    if ($opt_gdb)
 
1177
    {
 
1178
      mtr_warning("Silently converting --gdb to --client-gdb in embedded mode");
 
1179
      $opt_client_gdb= $opt_gdb;
 
1180
      $opt_gdb= undef;
 
1181
    }
 
1182
 
 
1183
    if ($opt_ddd)
 
1184
    {
 
1185
      mtr_warning("Silently converting --ddd to --client-ddd in embedded mode");
 
1186
      $opt_client_ddd= $opt_ddd;
 
1187
      $opt_ddd= undef;
 
1188
    }
 
1189
 
 
1190
    if ($opt_debugger)
 
1191
    {
 
1192
      mtr_warning("Silently converting --debugger to --client-debugger in embedded mode");
 
1193
      $opt_client_debugger= $opt_debugger;
 
1194
      $opt_debugger= undef;
 
1195
    }
 
1196
 
 
1197
    if ( $opt_gdb || $opt_ddd || $opt_manual_gdb || $opt_manual_ddd ||
 
1198
         $opt_manual_debug || $opt_debugger )
 
1199
    {
 
1200
      mtr_error("You need to use the client debug options for the",
 
1201
                "embedded server. Ex: --client-gdb");
 
1202
    }
1023
1203
  }
1024
1204
 
1025
1205
  # --------------------------------------------------------------------------
1047
1227
  {
1048
1228
    # Indicate that we are using debugger
1049
1229
    $glob_debugger= 1;
1050
 
    if ( $opt_extern )
 
1230
    if ( using_extern() )
1051
1231
    {
1052
1232
      mtr_error("Can't use --extern when using debugger");
1053
1233
    }
1054
1234
  }
1055
1235
 
1056
1236
  # --------------------------------------------------------------------------
1057
 
  # Check if special exe was selected for master or slave
 
1237
  # Check timeout arguments
1058
1238
  # --------------------------------------------------------------------------
1059
 
  $exe_master_mysqld= $exe_master_mysqld || $exe_mysqld;
1060
 
  $exe_slave_mysqld=  $exe_slave_mysqld  || $exe_mysqld;
 
1239
 
 
1240
  mtr_error("Invalid value '$opt_testcase_timeout' supplied ".
 
1241
            "for option --testcase-timeout")
 
1242
    if ($opt_testcase_timeout <= 0);
 
1243
  mtr_error("Invalid value '$opt_suite_timeout' supplied ".
 
1244
            "for option --testsuite-timeout")
 
1245
    if ($opt_suite_timeout <= 0);
1061
1246
 
1062
1247
  # --------------------------------------------------------------------------
1063
1248
  # Check valgrind arguments
1068
1253
    $opt_valgrind= 1;
1069
1254
    $opt_valgrind_mysqld= 1;
1070
1255
    $opt_valgrind_mysqltest= 1;
 
1256
 
 
1257
    # Increase the timeouts when running with valgrind
 
1258
    $opt_testcase_timeout*= 10;
 
1259
    $opt_suite_timeout*= 6;
 
1260
    $opt_start_timeout*= 10;
 
1261
 
1071
1262
  }
1072
1263
  elsif ( $opt_valgrind_mysqld )
1073
1264
  {
1101
1292
               join(" ", @valgrind_args), "\"");
1102
1293
  }
1103
1294
 
1104
 
  if ( ! $opt_testcase_timeout )
1105
 
  {
1106
 
    $opt_testcase_timeout= $default_testcase_timeout;
1107
 
    $opt_testcase_timeout*= 10 if $opt_valgrind;
1108
 
    $opt_testcase_timeout*= 10 if ($opt_debug and $glob_win32);
1109
 
  }
1110
 
 
1111
 
  if ( ! $opt_suite_timeout )
1112
 
  {
1113
 
    $opt_suite_timeout= $default_suite_timeout;
1114
 
    $opt_suite_timeout*= 6 if $opt_valgrind;
1115
 
    $opt_suite_timeout*= 6 if ($opt_debug and $glob_win32);
1116
 
  }
1117
 
 
1118
 
  if ( ! $opt_user )
1119
 
  {
1120
 
    if ( $opt_extern )
1121
 
    {
1122
 
      $opt_user= "test";
1123
 
    }
1124
 
    else
1125
 
    {
1126
 
      $opt_user= "root"; # We want to do FLUSH xxx commands
1127
 
    }
1128
 
  }
1129
 
 
1130
 
  # On QNX, /tmp/dir/master.sock and /tmp/dir//master.sock seem to be
1131
 
  # considered different, so avoid the extra slash (/) in the socket
1132
 
  # paths.
1133
 
  my $sockdir = $opt_tmpdir;
1134
 
  $sockdir =~ s|/+$||;
1135
 
 
1136
 
  # On some operating systems, there is a limit to the length of a
1137
 
  # UNIX domain socket's path far below PATH_MAX, so try to avoid long
1138
 
  # socket path names.
1139
 
  $sockdir = tempdir(CLEANUP => 0) if ( length($sockdir) >= 70 );
1140
 
 
1141
 
  $master->[0]=
1142
 
  {
1143
 
   pid           => 0,
1144
 
   type          => "master",
1145
 
   idx           => 0,
1146
 
   path_myddir   => "$opt_vardir/master-data",
1147
 
   path_myerr    => "$opt_vardir/log/master.err",
1148
 
   path_pid    => "$opt_vardir/run/master.pid",
1149
 
   path_sock   => "$sockdir/master.sock",
1150
 
   port   =>  $opt_master_myport,
1151
 
   start_timeout =>  400, # enough time create innodb tables
1152
 
   cluster       =>  0, # index in clusters list
1153
 
   start_opts    => [],
1154
 
  };
1155
 
 
1156
 
  $master->[1]=
1157
 
  {
1158
 
   pid           => 0,
1159
 
   type          => "master",
1160
 
   idx           => 1,
1161
 
   path_myddir   => "$opt_vardir/master1-data",
1162
 
   path_myerr    => "$opt_vardir/log/master1.err",
1163
 
   path_pid    => "$opt_vardir/run/master1.pid",
1164
 
   path_sock   => "$sockdir/master1.sock",
1165
 
   port   => $opt_master_myport + 1,
1166
 
   start_timeout => 400, # enough time create innodb tables
1167
 
   cluster       =>  0, # index in clusters list
1168
 
   start_opts    => [],
1169
 
  };
1170
 
 
1171
 
  $slave->[0]=
1172
 
  {
1173
 
   pid           => 0,
1174
 
   type          => "slave",
1175
 
   idx           => 0,
1176
 
   path_myddir   => "$opt_vardir/slave-data",
1177
 
   path_myerr    => "$opt_vardir/log/slave.err",
1178
 
   path_pid    => "$opt_vardir/run/slave.pid",
1179
 
   path_sock   => "$sockdir/slave.sock",
1180
 
   port   => $opt_slave_myport,
1181
 
   start_timeout => 400,
1182
 
 
1183
 
   cluster       =>  1, # index in clusters list
1184
 
   start_opts    => [],
1185
 
  };
1186
 
 
1187
 
  $slave->[1]=
1188
 
  {
1189
 
   pid           => 0,
1190
 
   type          => "slave",
1191
 
   idx           => 1,
1192
 
   path_myddir   => "$opt_vardir/slave1-data",
1193
 
   path_myerr    => "$opt_vardir/log/slave1.err",
1194
 
   path_pid    => "$opt_vardir/run/slave1.pid",
1195
 
   path_sock   => "$sockdir/slave1.sock",
1196
 
   port   => $opt_slave_myport + 1,
1197
 
   start_timeout => 300,
1198
 
   cluster       =>  -1, # index in clusters list
1199
 
   start_opts    => [],
1200
 
  };
1201
 
 
1202
 
  $slave->[2]=
1203
 
  {
1204
 
   pid           => 0,
1205
 
   type          => "slave",
1206
 
   idx           => 2,
1207
 
   path_myddir   => "$opt_vardir/slave2-data",
1208
 
   path_myerr    => "$opt_vardir/log/slave2.err",
1209
 
   path_pid    => "$opt_vardir/run/slave2.pid",
1210
 
   path_sock   => "$sockdir/slave2.sock",
1211
 
   port   => $opt_slave_myport + 2,
1212
 
   start_timeout => 300,
1213
 
   cluster       =>  -1, # index in clusters list
1214
 
   start_opts    => [],
1215
 
  };
1216
 
 
1217
 
  $instance_manager=
1218
 
  {
1219
 
   path_err =>        "$opt_vardir/log/im.err",
1220
 
   path_log =>        "$opt_vardir/log/im.log",
1221
 
   path_pid =>        "$opt_vardir/run/im.pid",
1222
 
   path_angel_pid =>  "$opt_vardir/run/im.angel.pid",
1223
 
   path_sock =>       "$sockdir/im.sock",
1224
 
   port =>            $im_port,
1225
 
   start_timeout =>   $master->[0]->{'start_timeout'},
1226
 
   admin_login =>     'im_admin',
1227
 
   admin_password =>  'im_admin_secret',
1228
 
   admin_sha1 =>      '*598D51AD2DFF7792045D6DF3DDF9AA1AF737B295',
1229
 
   password_file =>   "$opt_vardir/im.passwd",
1230
 
   defaults_file =>   "$opt_vardir/im.cnf",
1231
 
  };
1232
 
 
1233
 
  $instance_manager->{'instances'}->[0]=
1234
 
  {
1235
 
   server_id    => 1,
1236
 
   port         => $im_mysqld1_port,
1237
 
   path_datadir => "$opt_vardir/im_mysqld_1.data",
1238
 
   path_sock    => "$sockdir/mysqld_1.sock",
1239
 
   path_pid     => "$opt_vardir/run/mysqld_1.pid",
1240
 
   start_timeout  => 400, # enough time create innodb tables
1241
 
   old_log_format => 1
1242
 
  };
1243
 
 
1244
 
  $instance_manager->{'instances'}->[1]=
1245
 
  {
1246
 
   server_id    => 2,
1247
 
   port         => $im_mysqld2_port,
1248
 
   path_datadir => "$opt_vardir/im_mysqld_2.data",
1249
 
   path_sock    => "$sockdir/mysqld_2.sock",
1250
 
   path_pid     => "$opt_vardir/run/mysqld_2.pid",
1251
 
   nonguarded   => 1,
1252
 
   start_timeout  => 400, # enough time create innodb tables
1253
 
   old_log_format => 1
1254
 
  };
1255
 
 
1256
 
  my $data_dir= "$opt_vardir/ndbcluster-$opt_ndbcluster_port";
1257
 
  $clusters->[0]=
1258
 
  {
1259
 
   name            => "Master",
1260
 
   nodes           => 2,
1261
 
   port            => "$opt_ndbcluster_port",
1262
 
   data_dir        => "$data_dir",
1263
 
   connect_string  => "host=localhost:$opt_ndbcluster_port",
1264
 
   path_pid        => "$data_dir/ndb_3.pid", # Nodes + 1
1265
 
   pid             => 0, # pid of ndb_mgmd
1266
 
   installed_ok    => 0,
1267
 
  };
1268
 
 
1269
 
  $data_dir= "$opt_vardir/ndbcluster-$opt_ndbcluster_port_slave";
1270
 
  $clusters->[1]=
1271
 
  {
1272
 
   name            => "Slave",
1273
 
   nodes           => 1,
1274
 
   port            => "$opt_ndbcluster_port_slave",
1275
 
   data_dir        => "$data_dir",
1276
 
   connect_string  => "host=localhost:$opt_ndbcluster_port_slave",
1277
 
   path_pid        => "$data_dir/ndb_2.pid", # Nodes + 1
1278
 
   pid             => 0, # pid of ndb_mgmd
1279
 
   installed_ok    => 0,
1280
 
  };
1281
 
 
1282
 
  # Init pids of ndbd's
1283
 
  foreach my $cluster ( @{$clusters} )
1284
 
  {
1285
 
    for ( my $idx= 0; $idx < $cluster->{'nodes'}; $idx++ )
1286
 
    {
1287
 
      my $nodeid= $idx+1;
1288
 
      $cluster->{'ndbds'}->[$idx]=
1289
 
        {
1290
 
         pid      => 0,
1291
 
         nodeid => $nodeid,
1292
 
         path_pid => "$cluster->{'data_dir'}/ndb_${nodeid}.pid",
1293
 
         path_fs => "$cluster->{'data_dir'}/ndb_${nodeid}_fs",
1294
 
        };
1295
 
    }
1296
 
  }
1297
 
 
1298
 
  # --------------------------------------------------------------------------
1299
 
  # extern
1300
 
  # --------------------------------------------------------------------------
1301
 
  if ( $opt_extern )
1302
 
  {
1303
 
    # Turn off features not supported when running with extern server
1304
 
    $opt_skip_rpl= 1;
1305
 
    $opt_skip_ndbcluster= 1;
1306
 
 
1307
 
    # Setup master->[0] with the settings for the extern server
1308
 
    $master->[0]->{'path_sock'}=  $opt_socket ? $opt_socket : "/tmp/mysql.sock";
1309
 
    mtr_report("Using extern server at '$master->[0]->{path_sock}'");
1310
 
  }
1311
 
  else
1312
 
  {
1313
 
    mtr_error("--socket can only be used in combination with --extern")
1314
 
      if $opt_socket;
1315
 
  }
1316
 
 
1317
 
 
1318
 
  # --------------------------------------------------------------------------
1319
 
  # ndbconnectstring and ndbconnectstring_slave
1320
 
  # --------------------------------------------------------------------------
1321
 
  if ( $opt_ndbconnectstring )
1322
 
  {
1323
 
    # ndbconnectstring was supplied by user, the tests shoudl be run
1324
 
    # against an already started cluster, change settings
1325
 
    my $cluster= $clusters->[0]; # Master cluster
1326
 
    $cluster->{'connect_string'}= $opt_ndbconnectstring;
1327
 
    $cluster->{'use_running'}= 1;
1328
 
 
1329
 
    mtr_error("Can't specify --ndb-connectstring and --skip-ndbcluster")
1330
 
      if $opt_skip_ndbcluster;
1331
 
  }
1332
 
  $ENV{'NDB_CONNECTSTRING'}= $clusters->[0]->{'connect_string'};
1333
 
 
1334
 
 
1335
 
  if ( $opt_ndbconnectstring_slave )
1336
 
  {
1337
 
    # ndbconnectstring-slave was supplied by user, the tests should be run
1338
 
    # agains an already started slave cluster, change settings
1339
 
    my $cluster= $clusters->[1]; # Slave cluster
1340
 
    $cluster->{'connect_string'}= $opt_ndbconnectstring_slave;
1341
 
    $cluster->{'use_running'}= 1;
1342
 
 
1343
 
    mtr_error("Can't specify ndb-connectstring_slave and " .
1344
 
              "--skip-ndbcluster-slave")
1345
 
      if $opt_skip_ndbcluster_slave;
1346
 
  }
1347
 
 
1348
 
 
1349
 
  $path_timefile=  "$opt_vardir/log/mysqltest-time";
1350
 
  $path_mysqltest_log=  "$opt_vardir/log/mysqltest.log";
1351
 
  $path_current_test_log= "$opt_vardir/log/current_test";
1352
 
  $path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log";
1353
 
 
1354
 
  $path_snapshot= "$opt_tmpdir/snapshot_$opt_master_myport/";
1355
 
 
1356
 
  if ( $opt_valgrind and $opt_debug )
1357
 
  {
1358
 
    # When both --valgrind and --debug is selected, send
1359
 
    # all output to the trace file, making it possible to
1360
 
    # see the exact location where valgrind complains
1361
 
    foreach my $mysqld (@{$master}, @{$slave})
1362
 
    {
1363
 
      my $sidx= $mysqld->{idx} ? "$mysqld->{idx}" : "";
1364
 
      $mysqld->{path_myerr}=
1365
 
        "$opt_vardir/log/" . $mysqld->{type} . "$sidx.trace";
1366
 
    }
1367
 
  }
 
1295
  mtr_report("Checking supported features...");
 
1296
 
 
1297
  check_ndbcluster_support(\%mysqld_variables);
 
1298
  check_ssl_support(\%mysqld_variables);
 
1299
  check_debug_support(\%mysqld_variables);
 
1300
 
 
1301
  executable_setup();
 
1302
 
1368
1303
}
1369
1304
 
 
1305
 
1370
1306
#
1371
1307
# To make it easier for different devs to work on the same host,
1372
1308
# an environment variable can be used to control all ports. A small
1382
1318
# http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
1383
1319
# But a fairly safe range seems to be 5001 - 32767
1384
1320
#
1385
 
 
1386
 
sub set_mtr_build_thread_ports($) {
1387
 
  my $mtr_build_thread= shift;
1388
 
 
1389
 
  if ( lc($mtr_build_thread) eq 'auto' ) {
1390
 
    print "Requesting build thread... ";
1391
 
    $ENV{'MTR_BUILD_THREAD'} = $mtr_build_thread = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
1392
 
    print "got ".$mtr_build_thread."\n";
1393
 
  }
1394
 
 
1395
 
  # Up to two masters, up to three slaves
1396
 
  # A magic value in command_line_setup depends on these equations.
1397
 
  $opt_master_myport=         $mtr_build_thread * 10 + 10000; # and 1
1398
 
  $opt_slave_myport=          $opt_master_myport + 2;  # and 3 4
1399
 
  $opt_ndbcluster_port=       $opt_master_myport + 5;
1400
 
  $opt_ndbcluster_port_slave= $opt_master_myport + 6;
1401
 
  $im_port=                   $opt_master_myport + 7;
1402
 
  $im_mysqld1_port=           $opt_master_myport + 8;
1403
 
  $im_mysqld2_port=           $opt_master_myport + 9;
1404
 
 
1405
 
  if ( $opt_master_myport < 5001 or $opt_master_myport + 10 >= 32767 )
 
1321
sub set_build_thread_ports($) {
 
1322
  my $thread= shift || 0;
 
1323
 
 
1324
  if ( lc($opt_build_thread) eq 'auto' ) {
 
1325
    my $found_free = 0;
 
1326
    $build_thread = 250;        # Start attempts from here
 
1327
    while (! $found_free)
 
1328
    {
 
1329
      $build_thread= mtr_get_unique_id($build_thread, 299);
 
1330
      if ( !defined $build_thread ) {
 
1331
        mtr_error("Could not get a unique build thread id");
 
1332
      }
 
1333
      $found_free= check_ports_free($build_thread);
 
1334
      # If not free, release and try from next number
 
1335
      mtr_release_unique_id($build_thread++) unless $found_free;
 
1336
    }
 
1337
  }
 
1338
  else
 
1339
  {
 
1340
    $build_thread = $opt_build_thread + $thread - 1;
 
1341
  }
 
1342
  $ENV{MTR_BUILD_THREAD}= $build_thread;
 
1343
 
 
1344
  if (! check_ports_free($build_thread)) {
 
1345
    # Some port was not free(which one has already been printed)
 
1346
    mtr_error("Some port(s) was not free")
 
1347
  }
 
1348
 
 
1349
  # Calculate baseport
 
1350
  $baseport= $build_thread * 10 + 10000;
 
1351
  if ( $baseport < 5001 or $baseport + 9 >= 32767 )
1406
1352
  {
1407
1353
    mtr_error("MTR_BUILD_THREAD number results in a port",
1408
1354
              "outside 5001 - 32767",
1409
 
              "($opt_master_myport - $opt_master_myport + 10)");
1410
 
  }
1411
 
}
1412
 
 
1413
 
 
1414
 
sub datadir_list_setup () {
1415
 
 
1416
 
  # Make a list of all data_dirs
1417
 
  for (my $idx= 0; $idx < $max_master_num; $idx++)
1418
 
  {
1419
 
    push(@data_dir_lst, $master->[$idx]->{'path_myddir'});
1420
 
  }
1421
 
 
1422
 
  for (my $idx= 0; $idx < $max_slave_num; $idx++)
1423
 
  {
1424
 
    push(@data_dir_lst, $slave->[$idx]->{'path_myddir'});
1425
 
  }
1426
 
 
1427
 
  unless ($opt_skip_im)
1428
 
  {
1429
 
    foreach my $instance (@{$instance_manager->{'instances'}})
1430
 
    {
1431
 
      push(@data_dir_lst, $instance->{'path_datadir'});
1432
 
    }
1433
 
  }
1434
 
}
1435
 
 
1436
 
 
1437
 
##############################################################################
1438
 
#
1439
 
#  Set paths to various executable programs
1440
 
#
1441
 
##############################################################################
1442
 
 
1443
 
 
1444
 
sub collect_mysqld_features () {
 
1355
              "($baseport - $baseport + 9)");
 
1356
  }
 
1357
 
 
1358
  mtr_report("Using MTR_BUILD_THREAD $build_thread,",
 
1359
             "with reserved ports $baseport..".($baseport+9));
 
1360
 
 
1361
}
 
1362
 
 
1363
 
 
1364
sub collect_mysqld_features {
1445
1365
  my $found_variable_list_start= 0;
1446
 
  my $tmpdir;
1447
 
  if ( $opt_tmpdir ) {
1448
 
    # Use the requested tmpdir
1449
 
    mkpath($opt_tmpdir) if (! -d $opt_tmpdir);
1450
 
    $tmpdir= $opt_tmpdir;
1451
 
  }
1452
 
  else {
1453
 
    $tmpdir= tempdir(CLEANUP => 0); # Directory removed by this function
1454
 
  }
 
1366
  my $use_tmpdir;
 
1367
  if ( defined $opt_tmpdir and -d $opt_tmpdir){
 
1368
    # Create the tempdir in $opt_tmpdir
 
1369
    $use_tmpdir= $opt_tmpdir;
 
1370
  }
 
1371
  my $tmpdir= tempdir(CLEANUP => 0, # Directory removed by this function
 
1372
                      DIR => $use_tmpdir);
1455
1373
 
1456
1374
  #
1457
 
  # Execute "mysqld --help --verbose" to get a list
 
1375
  # Execute "mysqld --no-defaults --help --verbose" to get a
1458
1376
  # list of all features and settings
1459
1377
  #
1460
1378
  # --no-defaults and --skip-grant-tables are to avoid loading
1462
1380
  #
1463
1381
  # --datadir must exist, mysqld will chdir into it
1464
1382
  #
1465
 
  my $list= `$exe_mysqld --no-defaults --datadir=$tmpdir --language=$path_language --skip-grant-tables --verbose --help`;
 
1383
  my $args;
 
1384
  mtr_init_args(\$args);
 
1385
  mtr_add_arg($args, "--no-defaults");
 
1386
  mtr_add_arg($args, "--datadir=%s", mixed_path($tmpdir));
 
1387
  mtr_add_arg($args, "--language=%s", $path_language);
 
1388
  mtr_add_arg($args, "--skip-grant-tables");
 
1389
  mtr_add_arg($args, "--verbose");
 
1390
  mtr_add_arg($args, "--help");
 
1391
 
 
1392
  my $exe_mysqld= find_mysqld($basedir);
 
1393
  my $cmd= join(" ", $exe_mysqld, @$args);
 
1394
  my $list= `$cmd`;
1466
1395
 
1467
1396
  foreach my $line (split('\n', $list))
1468
1397
  {
1517
1446
      }
1518
1447
    }
1519
1448
  }
1520
 
  rmtree($tmpdir) if (!$opt_tmpdir);
 
1449
  rmtree($tmpdir);
1521
1450
  mtr_error("Could not find version of MySQL") unless $mysql_version_id;
1522
1451
  mtr_error("Could not find variabes list") unless $found_variable_list_start;
1523
1452
 
1524
1453
}
1525
1454
 
1526
1455
 
1527
 
sub run_query($$) {
1528
 
  my ($mysqld, $query)= @_;
 
1456
 
 
1457
sub collect_mysqld_features_from_running_server ()
 
1458
{
 
1459
  my $mysql= mtr_exe_exists("$path_client_bindir/mysql");
1529
1460
 
1530
1461
  my $args;
1531
1462
  mtr_init_args(\$args);
1532
1463
 
1533
1464
  mtr_add_arg($args, "--no-defaults");
1534
1465
  mtr_add_arg($args, "--user=%s", $opt_user);
1535
 
  mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
1536
 
  mtr_add_arg($args, "--socket=%s", $mysqld->{'path_sock'});
 
1466
 
 
1467
  while (my ($option, $value)= each( %opts_extern )) {
 
1468
    mtr_add_arg($args, "--$option=$value");
 
1469
  }
 
1470
 
1537
1471
  mtr_add_arg($args, "--silent"); # Tab separated output
1538
 
  mtr_add_arg($args, "-e '%s'", $query);
1539
 
 
1540
 
  my $cmd= "$exe_mysql " . join(' ', @$args);
 
1472
  mtr_add_arg($args, "-e '%s'", "use mysql; SHOW VARIABLES");
 
1473
  my $cmd= "$mysql " . join(' ', @$args);
1541
1474
  mtr_verbose("cmd: $cmd");
1542
 
  return `$cmd`;
1543
 
}
1544
 
 
1545
 
 
1546
 
sub collect_mysqld_features_from_running_server ()
1547
 
{
1548
 
  my $list= run_query($master->[0], "use mysql; SHOW VARIABLES");
1549
 
 
1550
 
  foreach my $line (split('\n', $list))
 
1475
 
 
1476
  my $list = `$cmd` or
 
1477
    mtr_error("Could not connect to extern server using command: '$cmd'");
 
1478
  foreach my $line (split('\n', $list ))
1551
1479
  {
1552
1480
    # Put variables into hash
1553
1481
    if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
1554
1482
    {
1555
 
      print "$1=\"$2\"\n";
 
1483
      # print "$1=\"$2\"\n";
1556
1484
      $mysqld_variables{$1}= $2;
1557
1485
    }
1558
1486
  }
1559
 
}
1560
 
 
1561
 
sub executable_setup_im () {
1562
 
 
1563
 
  # Look for instance manager binary - mysqlmanager
1564
 
  $exe_im=
1565
 
    mtr_exe_maybe_exists(
1566
 
      "$glob_basedir/server-tools/instance-manager/mysqlmanager",
1567
 
      "$glob_basedir/libexec/mysqlmanager",
1568
 
      "$glob_basedir/bin/mysqlmanager",
1569
 
      "$glob_basedir/sbin/mysqlmanager");
1570
 
 
1571
 
  return ($exe_im eq "");
1572
 
}
1573
 
 
1574
 
sub executable_setup_ndb () {
1575
 
 
1576
 
  # Look for ndb tols and binaries
1577
 
  my $ndb_path= mtr_file_exists("$glob_basedir/ndb",
1578
 
                                "$glob_basedir/storage/ndb",
1579
 
                                "$glob_basedir/bin");
1580
 
 
1581
 
  # Some might be found in sbin, not bin.
1582
 
  my $daemon_path= mtr_file_exists("$glob_basedir/ndb",
1583
 
                                   "$glob_basedir/storage/ndb",
1584
 
                                   "$glob_basedir/sbin",
1585
 
                                   "$glob_basedir/bin");
1586
 
 
1587
 
  $exe_ndbd=
1588
 
    mtr_exe_maybe_exists("$ndb_path/src/kernel/ndbd",
1589
 
                         "$daemon_path/ndbd",
1590
 
                         "$glob_basedir/libexec/ndbd");
1591
 
  $exe_ndb_mgm=
1592
 
    mtr_exe_maybe_exists("$ndb_path/src/mgmclient/ndb_mgm",
1593
 
                         "$ndb_path/ndb_mgm");
1594
 
  $exe_ndb_mgmd=
1595
 
    mtr_exe_maybe_exists("$ndb_path/src/mgmsrv/ndb_mgmd",
1596
 
                         "$daemon_path/ndb_mgmd",
1597
 
                         "$glob_basedir/libexec/ndb_mgmd");
1598
 
  $exe_ndb_waiter=
1599
 
    mtr_exe_maybe_exists("$ndb_path/tools/ndb_waiter",
1600
 
                         "$ndb_path/ndb_waiter");
1601
 
 
1602
 
  # May not exist
1603
 
  $path_ndb_tools_dir= mtr_file_exists("$ndb_path/tools",
1604
 
                                       "$ndb_path");
1605
 
  # May not exist
1606
 
  $path_ndb_examples_dir=
1607
 
    mtr_file_exists("$ndb_path/ndbapi-examples",
1608
 
                    "$ndb_path/examples");
1609
 
  # May not exist
1610
 
  $exe_ndb_example=
1611
 
    mtr_file_exists("$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple");
1612
 
 
1613
 
  return ( $exe_ndbd eq "" or
1614
 
           $exe_ndb_mgm eq "" or
1615
 
           $exe_ndb_mgmd eq "" or
1616
 
           $exe_ndb_waiter eq "");
1617
 
}
 
1487
 
 
1488
  # Parse version
 
1489
  my $version_str= $mysqld_variables{'version'};
 
1490
  if ( $version_str =~ /^([0-9]*)\.([0-9]*)\.([0-9]*)/ )
 
1491
  {
 
1492
    #print "Major: $1 Minor: $2 Build: $3\n";
 
1493
    $mysql_version_id= $1*10000 + $2*100 + $3;
 
1494
    #print "mysql_version_id: $mysql_version_id\n";
 
1495
    mtr_report("MySQL Version $1.$2.$3");
 
1496
  }
 
1497
  mtr_error("Could not find version of MySQL") unless $mysql_version_id;
 
1498
}
 
1499
 
 
1500
sub find_mysqld {
 
1501
  my ($mysqld_basedir)= @_;
 
1502
 
 
1503
  my @mysqld_names= ("mysqld", "mysqld-max-nt", "mysqld-max",
 
1504
                     "mysqld-nt");
 
1505
 
 
1506
  if ( $opt_debug ){
 
1507
    # Put mysqld-debug first in the list of binaries to look for
 
1508
    mtr_verbose("Adding mysqld-debug first in list of binaries to look for");
 
1509
    unshift(@mysqld_names, "mysqld-debug");
 
1510
  }
 
1511
 
 
1512
  return my_find_bin($mysqld_basedir,
 
1513
                     ["sql", "libexec", "sbin", "bin"],
 
1514
                     [@mysqld_names]);
 
1515
}
 
1516
 
1618
1517
 
1619
1518
sub executable_setup () {
1620
1519
 
1633
1532
    }
1634
1533
  }
1635
1534
 
1636
 
  # Look for my_print_defaults
1637
 
  $exe_my_print_defaults=
1638
 
    mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
1639
 
                           "$path_client_bindir/my_print_defaults",
1640
 
                           "$glob_basedir/extra/my_print_defaults");
1641
 
 
1642
 
  # Look for perror
1643
 
  $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
1644
 
                                          "$glob_basedir/extra/perror",
1645
 
                                          "$path_client_bindir/perror");
1646
 
 
1647
1535
  # Look for the client binaries
1648
 
  $exe_mysqlcheck=     mtr_exe_exists("$path_client_bindir/mysqlcheck");
1649
 
  $exe_mysqldump=      mtr_exe_exists("$path_client_bindir/mysqldump");
1650
 
  $exe_mysqlimport=    mtr_exe_exists("$path_client_bindir/mysqlimport");
1651
 
  $exe_mysqlshow=      mtr_exe_exists("$path_client_bindir/mysqlshow");
1652
 
  $exe_mysqlbinlog=    mtr_exe_exists("$path_client_bindir/mysqlbinlog");
1653
1536
  $exe_mysqladmin=     mtr_exe_exists("$path_client_bindir/mysqladmin");
1654
1537
  $exe_mysql=          mtr_exe_exists("$path_client_bindir/mysql");
1655
1538
 
1656
 
  if (!$opt_extern)
 
1539
  if ( ! $opt_skip_ndbcluster )
1657
1540
  {
1658
 
    # Look for SQL scripts directory
1659
 
    if ( mtr_file_exists("$path_share/mysql_system_tables.sql") ne "")
1660
 
    {
1661
 
      # The SQL scripts are in path_share
1662
 
      $path_sql_dir= $path_share;
1663
 
    }
1664
 
    else
1665
 
    {
1666
 
      $path_sql_dir= mtr_path_exists("$glob_basedir/share",
1667
 
                                     "$glob_basedir/scripts");
1668
 
    }
1669
 
 
1670
 
    if ( $mysql_version_id >= 50100 )
1671
 
    {
1672
 
      $exe_mysqlslap=    mtr_exe_exists("$path_client_bindir/mysqlslap");
1673
 
    }
1674
 
    if ( $mysql_version_id >= 50000 and !$glob_use_embedded_server )
1675
 
    {
1676
 
      $exe_mysql_upgrade= mtr_exe_exists("$path_client_bindir/mysql_upgrade")
1677
 
    }
1678
 
    else
1679
 
    {
1680
 
      $exe_mysql_upgrade= "";
1681
 
    }
1682
 
 
1683
 
    if ( ! $glob_win32 )
1684
 
    {
1685
 
      # Look for mysql_fix_system_table script
1686
 
      $exe_mysql_fix_system_tables=
1687
 
        mtr_script_exists("$glob_basedir/scripts/mysql_fix_privilege_tables",
1688
 
                        "$path_client_bindir/mysql_fix_privilege_tables");
1689
 
    }
1690
 
 
1691
 
    # Look for mysql_fix_privilege_tables.sql script
1692
 
    $file_mysql_fix_privilege_tables=
1693
 
      mtr_file_exists("$glob_basedir/scripts/mysql_fix_privilege_tables.sql",
1694
 
                    "$glob_basedir/share/mysql_fix_privilege_tables.sql",
1695
 
                    "$glob_basedir/share/mysql/mysql_fix_privilege_tables.sql");
1696
 
 
1697
 
    if ( ! $opt_skip_ndbcluster and executable_setup_ndb())
1698
 
    {
1699
 
      mtr_warning("Could not find all required ndb binaries, " .
1700
 
                "all ndb tests will fail, use --skip-ndbcluster to " .
1701
 
                "skip testing it.");
1702
 
 
1703
 
      foreach my $cluster (@{$clusters})
1704
 
      {
1705
 
        $cluster->{"executable_setup_failed"}= 1;
1706
 
      }
1707
 
    }
1708
 
 
1709
 
    if ( ! $opt_skip_im and executable_setup_im())
1710
 
    {
1711
 
      mtr_warning("Could not find all required instance manager binaries, " .
1712
 
                "all im tests will fail, use --skip-im to " .
1713
 
                "continue without instance manager");
1714
 
      $instance_manager->{"executable_setup_failed"}= 1;
1715
 
    }
1716
 
 
1717
 
    # Look for the udf_example library
1718
 
    $lib_udf_example=
1719
 
      mtr_file_exists(vs_config_dirs('sql', 'udf_example.dll'),
1720
 
                      "$glob_basedir/sql/.libs/udf_example.so",);
1721
 
 
1722
 
    # Look for the ha_example library
1723
 
    $lib_example_plugin=
1724
 
      mtr_file_exists(vs_config_dirs('storage/example', 'ha_example.dll'),
1725
 
                      "$glob_basedir/storage/example/.libs/ha_example.so",);
1726
 
 
1727
 
    # Look for the simple_parser library
1728
 
    $lib_simple_parser=
1729
 
      mtr_file_exists(vs_config_dirs('plugin/fulltext', 'mypluglib.dll'),
1730
 
                      "$glob_basedir/plugin/fulltext/.libs/mypluglib.so",);
 
1541
    $exe_ndbd=
 
1542
      my_find_bin($basedir,
 
1543
                  ["storage/ndb/src/kernel", "libexec", "sbin", "bin"],
 
1544
                  "ndbd");
 
1545
 
 
1546
    $exe_ndb_mgmd=
 
1547
      my_find_bin($basedir,
 
1548
                  ["storage/ndb/src/mgmsrv", "libexec", "sbin", "bin"],
 
1549
                  "ndb_mgmd");
 
1550
 
 
1551
    $exe_ndb_waiter=
 
1552
      my_find_bin($basedir,
 
1553
                  ["storage/ndb/tools/", "bin"],
 
1554
                  "ndb_waiter");
 
1555
 
1731
1556
  }
1732
1557
 
1733
1558
  # Look for mysqltest executable
1734
 
  if ( $glob_use_embedded_server )
 
1559
  if ( $opt_embedded_server )
1735
1560
  {
1736
1561
    $exe_mysqltest=
1737
1562
      mtr_exe_exists(vs_config_dirs('libmysqld/examples','mysqltest_embedded'),
1738
 
                     "$glob_basedir/libmysqld/examples/mysqltest_embedded",
 
1563
                     "$basedir/libmysqld/examples/mysqltest_embedded",
1739
1564
                     "$path_client_bindir/mysqltest_embedded");
1740
1565
  }
1741
1566
  else
1743
1568
    $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest");
1744
1569
  }
1745
1570
 
1746
 
  # Look for mysql_client_test executable which may _not_ exist in
1747
 
  # some versions, test using it should be skipped
1748
 
  if ( $glob_use_embedded_server )
1749
 
  {
1750
 
    $exe_mysql_client_test=
1751
 
      mtr_exe_maybe_exists(
1752
 
        vs_config_dirs('libmysqld/examples', 'mysql_client_test_embedded'),
1753
 
        "$glob_basedir/libmysqld/examples/mysql_client_test_embedded");
1754
 
  }
1755
 
  else
1756
 
  {
1757
 
    $exe_mysql_client_test=
1758
 
      mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'),
1759
 
                           "$glob_basedir/tests/mysql_client_test",
1760
 
                           "$glob_basedir/bin/mysql_client_test");
1761
 
  }
1762
 
 
1763
 
  # Look for bug25714 executable which may _not_ exist in
1764
 
  # some versions, test using it should be skipped
1765
 
  $exe_bug25714=
1766
 
      mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'),
1767
 
                           "$glob_basedir/tests/bug25714");
1768
 
}
1769
 
 
1770
 
 
1771
 
sub generate_cmdline_mysqldump ($) {
1772
 
  my($mysqld) = @_;
1773
 
  return
1774
 
    mtr_native_path($exe_mysqldump) .
1775
 
      " --no-defaults -uroot --debug-check " .
1776
 
      "--port=$mysqld->{'port'} " .
1777
 
      "--socket=$mysqld->{'path_sock'} --password=";
1778
 
}
1779
 
 
1780
 
 
1781
 
##############################################################################
1782
 
#
1783
 
#  Set environment to be used by childs of this process for
1784
 
#  things that are constant duting the whole lifetime of mysql-test-run.pl
1785
 
#
1786
 
##############################################################################
1787
 
 
1788
 
sub mysql_client_test_arguments()
1789
 
{
1790
 
  my $exe= $exe_mysql_client_test;
1791
 
 
1792
 
  my $args;
1793
 
  mtr_init_args(\$args);
1794
 
  if ( $opt_valgrind_mysqltest )
1795
 
  {
 
1571
}
 
1572
 
 
1573
 
 
1574
sub client_debug_arg($$) {
 
1575
  my ($args, $client_name)= @_;
 
1576
 
 
1577
  if ( $opt_debug ) {
 
1578
    mtr_add_arg($args,
 
1579
                "--debug=d:t:A,%s/log/%s.trace",
 
1580
                $path_vardir_trace, $client_name)
 
1581
  }
 
1582
}
 
1583
 
 
1584
 
 
1585
sub mysql_fix_arguments () {
 
1586
 
 
1587
  return "" if ( IS_WINDOWS );
 
1588
 
 
1589
  my $exe=
 
1590
    mtr_script_exists("$basedir/scripts/mysql_fix_privilege_tables",
 
1591
                      "$path_client_bindir/mysql_fix_privilege_tables");
 
1592
  my $args;
 
1593
  mtr_init_args(\$args);
 
1594
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
1595
 
 
1596
  mtr_add_arg($args, "--basedir=%s", $basedir);
 
1597
  mtr_add_arg($args, "--bindir=%s", $path_client_bindir);
 
1598
  mtr_add_arg($args, "--verbose");
 
1599
  return mtr_args2str($exe, @$args);
 
1600
}
 
1601
 
 
1602
 
 
1603
sub client_arguments ($) {
 
1604
  my $client_name= shift;
 
1605
  my $client_exe= mtr_exe_exists("$path_client_bindir/$client_name");
 
1606
 
 
1607
  my $args;
 
1608
  mtr_init_args(\$args);
 
1609
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
1610
  client_debug_arg($args, $client_name);
 
1611
  return mtr_args2str($client_exe, @$args);
 
1612
}
 
1613
 
 
1614
 
 
1615
sub mysqlslap_arguments () {
 
1616
  my $exe= mtr_exe_maybe_exists("$path_client_bindir/mysqlslap");
 
1617
  if ( $exe eq "" ) {
 
1618
    # mysqlap was not found
 
1619
 
 
1620
    if (defined $mysql_version_id and $mysql_version_id >= 50100 ) {
 
1621
      mtr_error("Could not find the mysqlslap binary");
 
1622
    }
 
1623
    return ""; # Don't care about mysqlslap
 
1624
  }
 
1625
 
 
1626
  my $args;
 
1627
  mtr_init_args(\$args);
 
1628
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
1629
  client_debug_arg($args, "mysqlslap");
 
1630
  return mtr_args2str($exe, @$args);
 
1631
}
 
1632
 
 
1633
 
 
1634
sub mysqldump_arguments ($) {
 
1635
  my($group_suffix) = @_;
 
1636
  my $exe= mtr_exe_exists("$path_client_bindir/mysqldump");
 
1637
 
 
1638
  my $args;
 
1639
  mtr_init_args(\$args);
 
1640
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
1641
  mtr_add_arg($args, "--defaults-group-suffix=%s", $group_suffix);
 
1642
  client_debug_arg($args, "mysqldump-$group_suffix");
 
1643
  return mtr_args2str($exe, @$args);
 
1644
}
 
1645
 
 
1646
 
 
1647
sub mysql_client_test_arguments(){
 
1648
  my $exe;
 
1649
  # mysql_client_test executable may _not_ exist
 
1650
  if ( $opt_embedded_server ) {
 
1651
    $exe= mtr_exe_maybe_exists(
 
1652
            vs_config_dirs('libmysqld/examples','mysql_client_test_embedded'),
 
1653
              "$basedir/libmysqld/examples/mysql_client_test_embedded",
 
1654
                "$basedir/bin/mysql_client_test_embedded");
 
1655
  } else {
 
1656
    $exe= mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'),
 
1657
                               "$basedir/tests/mysql_client_test",
 
1658
                               "$basedir/bin/mysql_client_test");
 
1659
  }
 
1660
 
 
1661
  my $args;
 
1662
  mtr_init_args(\$args);
 
1663
  if ( $opt_valgrind_mysqltest ) {
1796
1664
    valgrind_arguments($args, \$exe);
1797
1665
  }
1798
 
 
1799
 
  mtr_add_arg($args, "--no-defaults");
 
1666
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
1800
1667
  mtr_add_arg($args, "--testcase");
1801
 
  mtr_add_arg($args, "--user=root");
1802
 
  mtr_add_arg($args, "--port=$master->[0]->{'port'}");
1803
 
  mtr_add_arg($args, "--socket=$master->[0]->{'path_sock'}");
1804
 
 
1805
 
  if ( $opt_extern || $mysql_version_id >= 50000 )
1806
 
  {
1807
 
    mtr_add_arg($args, "--vardir=$opt_vardir")
1808
 
  }
1809
 
 
1810
 
  if ( $opt_debug )
1811
 
  {
1812
 
    mtr_add_arg($args,
1813
 
      "--debug=d:t:A,$path_vardir_trace/log/mysql_client_test.trace");
1814
 
  }
1815
 
 
1816
 
  if ( $glob_use_embedded_server )
1817
 
  {
1818
 
    mtr_add_arg($args,
1819
 
      " -A --language=$path_language");
1820
 
    mtr_add_arg($args,
1821
 
      " -A --datadir=$slave->[0]->{'path_myddir'}");
1822
 
    mtr_add_arg($args,
1823
 
      " -A --character-sets-dir=$path_charsetsdir");
1824
 
  }
1825
 
 
1826
 
  return join(" ", $exe, @$args);
1827
 
}
1828
 
 
1829
 
sub mysql_upgrade_arguments()
1830
 
{
1831
 
  my $exe= $exe_mysql_upgrade;
1832
 
 
1833
 
  my $args;
1834
 
  mtr_init_args(\$args);
1835
 
#  if ( $opt_valgrind_mysql_ugrade )
1836
 
#  {
1837
 
#    valgrind_arguments($args, \$exe);
1838
 
#  }
1839
 
 
1840
 
  mtr_add_arg($args, "--no-defaults");
1841
 
  mtr_add_arg($args, "--user=root");
1842
 
  mtr_add_arg($args, "--port=$master->[0]->{'port'}");
1843
 
  mtr_add_arg($args, "--socket=$master->[0]->{'path_sock'}");
1844
 
  mtr_add_arg($args, "--datadir=$master->[0]->{'path_myddir'}");
1845
 
  mtr_add_arg($args, "--basedir=$glob_basedir");
1846
 
  mtr_add_arg($args, "--tmpdir=$opt_tmpdir");
1847
 
 
1848
 
  if ( $opt_debug )
1849
 
  {
1850
 
    mtr_add_arg($args,
1851
 
      "--debug=d:t:A,$path_vardir_trace/log/mysql_upgrade.trace");
1852
 
  }
1853
 
 
1854
 
  return join(" ", $exe, @$args);
1855
 
}
1856
 
 
1857
 
# Note that some env is setup in spawn/run, in "mtr_process.pl"
1858
 
 
1859
 
sub environment_setup () {
 
1668
  mtr_add_arg($args, "--vardir=$opt_vardir");
 
1669
  client_debug_arg($args,"mysql_client_test");
 
1670
 
 
1671
  return mtr_args2str($exe, @$args);
 
1672
}
 
1673
 
 
1674
 
 
1675
#
 
1676
# Set environment to be used by childs of this process for
 
1677
# things that are constant during the whole lifetime of mysql-test-run
 
1678
#
 
1679
sub environment_setup {
1860
1680
 
1861
1681
  umask(022);
1862
1682
 
1873
1693
    # are used in favor of the system installed ones
1874
1694
    if ( $source_dist )
1875
1695
    {
1876
 
      push(@ld_library_paths, "$glob_basedir/libmysql/.libs/",
1877
 
           "$glob_basedir/libmysql_r/.libs/",
1878
 
           "$glob_basedir/zlib.libs/");
 
1696
      push(@ld_library_paths, "$basedir/libmysql/.libs/",
 
1697
           "$basedir/libmysql_r/.libs/",
 
1698
           "$basedir/zlib.libs/");
1879
1699
    }
1880
1700
    else
1881
1701
    {
1882
 
      push(@ld_library_paths, "$glob_basedir/lib");
 
1702
      push(@ld_library_paths, "$basedir/lib");
1883
1703
    }
1884
1704
  }
1885
1705
 
1886
 
 # --------------------------------------------------------------------------
 
1706
  # --------------------------------------------------------------------------
1887
1707
  # Add the path where libndbclient can be found
1888
1708
  # --------------------------------------------------------------------------
1889
 
  if ( $glob_ndbcluster_supported )
1890
 
  {
1891
 
    push(@ld_library_paths,  "$glob_basedir/storage/ndb/src/.libs");
1892
 
  }
 
1709
  if ( !$opt_skip_ndbcluster )
 
1710
  {
 
1711
    push(@ld_library_paths,  "$basedir/storage/ndb/src/.libs");
 
1712
  }
 
1713
 
 
1714
  # --------------------------------------------------------------------------
 
1715
  # Add the path where mysqld will find udf_example.so
 
1716
  # --------------------------------------------------------------------------
 
1717
  my $lib_udf_example=
 
1718
    mtr_file_exists(vs_config_dirs('sql', 'udf_example.dll'),
 
1719
                    "$basedir/sql/.libs/udf_example.so",);
 
1720
 
 
1721
  if ( $lib_udf_example )
 
1722
  {
 
1723
    push(@ld_library_paths, dirname($lib_udf_example));
 
1724
  }
 
1725
 
 
1726
  $ENV{'UDF_EXAMPLE_LIB'}=
 
1727
    ($lib_udf_example ? basename($lib_udf_example) : "");
 
1728
  $ENV{'UDF_EXAMPLE_LIB_OPT'}= "--plugin-dir=".
 
1729
    ($lib_udf_example ? dirname($lib_udf_example) : "");
 
1730
 
 
1731
  # --------------------------------------------------------------------------
 
1732
  # Add the path where mysqld will find ha_example.so
 
1733
  # --------------------------------------------------------------------------
 
1734
  if ($mysql_version_id >= 50100) {
 
1735
    my $lib_example_plugin=
 
1736
      mtr_file_exists(vs_config_dirs('storage/example', 'ha_example.dll'),
 
1737
                      "$basedir/storage/example/.libs/ha_example.so",);
 
1738
    $ENV{'EXAMPLE_PLUGIN'}=
 
1739
      ($lib_example_plugin ? basename($lib_example_plugin) : "");
 
1740
    $ENV{'EXAMPLE_PLUGIN_OPT'}= "--plugin-dir=".
 
1741
      ($lib_example_plugin ? dirname($lib_example_plugin) : "");
 
1742
 
 
1743
  }
 
1744
 
 
1745
  # ----------------------------------------------------
 
1746
  # Add the path where mysqld will find mypluglib.so
 
1747
  # ----------------------------------------------------
 
1748
  my $lib_simple_parser=
 
1749
    mtr_file_exists(vs_config_dirs('plugin/fulltext', 'mypluglib.dll'),
 
1750
                    "$basedir/plugin/fulltext/.libs/mypluglib.so",);
 
1751
 
 
1752
  $ENV{'SIMPLE_PARSER'}=
 
1753
    ($lib_simple_parser ? basename($lib_simple_parser) : "");
 
1754
  $ENV{'SIMPLE_PARSER_OPT'}= "--plugin-dir=".
 
1755
    ($lib_simple_parser ? dirname($lib_simple_parser) : "");
1893
1756
 
1894
1757
  # --------------------------------------------------------------------------
1895
1758
  # Valgrind need to be run with debug libraries otherwise it's almost
1905
1768
  my $deb_version;
1906
1769
  if (  $opt_valgrind and -d $debug_libraries_path and
1907
1770
        (! -e '/etc/debian_version' or
1908
 
         ($deb_version= mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
 
1771
         ($deb_version=
 
1772
            mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
1909
1773
         $deb_version > 3.1 ) )
1910
1774
  {
1911
1775
    push(@ld_library_paths, $debug_libraries_path);
1933
1797
                        split(':', $ENV{'LIBPATH'}) : ());
1934
1798
  mtr_debug("LIBPATH: $ENV{'LIBPATH'}");
1935
1799
 
1936
 
  # --------------------------------------------------------------------------
1937
 
  # Also command lines in .opt files may contain env vars
1938
 
  # --------------------------------------------------------------------------
1939
 
 
1940
1800
  $ENV{'CHARSETSDIR'}=              $path_charsetsdir;
1941
1801
  $ENV{'UMASK'}=              "0660"; # The octal *string*
1942
1802
  $ENV{'UMASK_DIR'}=          "0770"; # The octal *string*
1943
 
  
 
1803
 
1944
1804
  #
1945
1805
  # MySQL tests can produce output in various character sets
1946
1806
  # (especially, ctype_xxx.test). To avoid confusing Perl
1951
1811
  #
1952
1812
  $ENV{'LC_ALL'}=             "C";
1953
1813
  $ENV{'LC_CTYPE'}=           "C";
1954
 
  
 
1814
 
1955
1815
  $ENV{'LC_COLLATE'}=         "C";
1956
 
  $ENV{'USE_RUNNING_SERVER'}= $opt_extern;
 
1816
  $ENV{'USE_RUNNING_SERVER'}= using_extern();
1957
1817
  $ENV{'MYSQL_TEST_DIR'}=     $glob_mysql_test_dir;
 
1818
  $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'master-port'} || 3306;
 
1819
  $ENV{'MYSQL_TMP_DIR'}=      $opt_tmpdir;
1958
1820
  $ENV{'MYSQLTEST_VARDIR'}=   $opt_vardir;
1959
 
  $ENV{'MYSQL_TMP_DIR'}=      $opt_tmpdir;
1960
 
  $ENV{'MASTER_MYSOCK'}=      $master->[0]->{'path_sock'};
1961
 
  $ENV{'MASTER_MYSOCK1'}=     $master->[1]->{'path_sock'};
1962
 
  $ENV{'MASTER_MYPORT'}=      $master->[0]->{'port'};
1963
 
  $ENV{'MASTER_MYPORT1'}=     $master->[1]->{'port'};
1964
 
  $ENV{'SLAVE_MYSOCK'}=       $slave->[0]->{'path_sock'};
1965
 
  $ENV{'SLAVE_MYPORT'}=       $slave->[0]->{'port'};
1966
 
  $ENV{'SLAVE_MYPORT1'}=      $slave->[1]->{'port'};
1967
 
  $ENV{'SLAVE_MYPORT2'}=      $slave->[2]->{'port'};
1968
 
  $ENV{'MYSQL_TCP_PORT'}=     $mysqld_variables{'port'};
1969
 
  $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'master-port'};
1970
 
 
1971
 
  $ENV{'IM_PATH_SOCK'}=       $instance_manager->{path_sock};
1972
 
  $ENV{'IM_USERNAME'}=        $instance_manager->{admin_login};
1973
 
  $ENV{'IM_PASSWORD'}=        $instance_manager->{admin_password};
1974
 
  $ENV{MTR_BUILD_THREAD}=      $opt_mtr_build_thread;
1975
 
 
1976
 
  $ENV{'EXE_MYSQL'}=          $exe_mysql;
1977
 
 
1978
1821
 
1979
1822
  # ----------------------------------------------------
1980
1823
  # Setup env for NDB
1981
1824
  # ----------------------------------------------------
1982
1825
  if ( ! $opt_skip_ndbcluster )
1983
1826
  {
1984
 
    $ENV{'NDB_MGM'}=                  $exe_ndb_mgm;
1985
 
 
1986
 
    $ENV{'NDBCLUSTER_PORT'}=          $opt_ndbcluster_port;
1987
 
    $ENV{'NDBCLUSTER_PORT_SLAVE'}=    $opt_ndbcluster_port_slave;
1988
 
 
1989
 
    $ENV{'NDB_EXTRA_TEST'}=           $opt_ndb_extra_test;
1990
 
 
1991
 
    $ENV{'NDB_BACKUP_DIR'}=           $clusters->[0]->{'data_dir'};
1992
 
    $ENV{'NDB_DATA_DIR'}=             $clusters->[0]->{'data_dir'};
1993
 
    $ENV{'NDB_TOOLS_DIR'}=            $path_ndb_tools_dir;
 
1827
    $ENV{'NDB_MGM'}=
 
1828
      my_find_bin($basedir,
 
1829
                  ["storage/ndb/src/mgmclient", "bin"],
 
1830
                  "ndb_mgm");
 
1831
 
 
1832
    $ENV{'NDB_TOOLS_DIR'}=
 
1833
      my_find_dir($basedir,
 
1834
                  ["storage/ndb/tools", "bin"]);
 
1835
 
 
1836
    $ENV{'NDB_EXAMPLES_DIR'}=
 
1837
      my_find_dir($basedir,
 
1838
                  ["storage/ndb/ndbapi-examples", "bin"]);
 
1839
 
 
1840
    $ENV{'NDB_EXAMPLES_BINARY'}=
 
1841
      my_find_bin($basedir,
 
1842
                  ["storage/ndb/ndbapi-examples/ndbapi_simple", "bin"],
 
1843
                  "ndbapi_simple", NOT_REQUIRED);
 
1844
 
 
1845
    my $path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log";
1994
1846
    $ENV{'NDB_TOOLS_OUTPUT'}=         $path_ndb_testrun_log;
1995
 
 
1996
 
    if ( $mysql_version_id >= 50000 )
1997
 
    {
1998
 
      $ENV{'NDB_EXAMPLES_DIR'}=         $path_ndb_examples_dir;
1999
 
      $ENV{'MY_NDB_EXAMPLES_BINARY'}=   $exe_ndb_example;
2000
 
    }
2001
1847
    $ENV{'NDB_EXAMPLES_OUTPUT'}=      $path_ndb_testrun_log;
2002
1848
  }
2003
1849
 
2004
1850
  # ----------------------------------------------------
2005
 
  # Setup env for IM
2006
 
  # ----------------------------------------------------
2007
 
  if ( ! $opt_skip_im )
2008
 
  {
2009
 
    $ENV{'IM_EXE'}=             $exe_im;
2010
 
    $ENV{'IM_PATH_PID'}=        $instance_manager->{path_pid};
2011
 
    $ENV{'IM_PATH_ANGEL_PID'}=  $instance_manager->{path_angel_pid};
2012
 
    $ENV{'IM_PORT'}=            $instance_manager->{port};
2013
 
    $ENV{'IM_DEFAULTS_PATH'}=   $instance_manager->{defaults_file};
2014
 
    $ENV{'IM_PASSWORD_PATH'}=   $instance_manager->{password_file};
2015
 
 
2016
 
    $ENV{'IM_MYSQLD1_SOCK'}=
2017
 
      $instance_manager->{instances}->[0]->{path_sock};
2018
 
    $ENV{'IM_MYSQLD1_PORT'}=
2019
 
      $instance_manager->{instances}->[0]->{port};
2020
 
    $ENV{'IM_MYSQLD1_PATH_PID'}=
2021
 
      $instance_manager->{instances}->[0]->{path_pid};
2022
 
    $ENV{'IM_MYSQLD2_SOCK'}=
2023
 
      $instance_manager->{instances}->[1]->{path_sock};
2024
 
    $ENV{'IM_MYSQLD2_PORT'}=
2025
 
      $instance_manager->{instances}->[1]->{port};
2026
 
    $ENV{'IM_MYSQLD2_PATH_PID'}=
2027
 
      $instance_manager->{instances}->[1]->{path_pid};
2028
 
  }
2029
 
 
2030
 
  # ----------------------------------------------------
2031
 
  # Setup env so childs can execute mysqlcheck
2032
 
  # ----------------------------------------------------
2033
 
  my $cmdline_mysqlcheck=
2034
 
    mtr_native_path($exe_mysqlcheck) .
2035
 
    " --no-defaults --debug-check -uroot " .
2036
 
    "--port=$master->[0]->{'port'} " .
2037
 
    "--socket=$master->[0]->{'path_sock'} --password=";
2038
 
 
2039
 
  if ( $opt_debug )
2040
 
  {
2041
 
    $cmdline_mysqlcheck .=
2042
 
      " --debug=d:t:A,$path_vardir_trace/log/mysqlcheck.trace";
2043
 
  }
2044
 
  $ENV{'MYSQL_CHECK'}=              $cmdline_mysqlcheck;
2045
 
 
2046
 
  # ----------------------------------------------------
2047
 
  # Setup env to childs can execute myqldump
2048
 
  # ----------------------------------------------------
2049
 
  my $cmdline_mysqldump= generate_cmdline_mysqldump($master->[0]);
2050
 
  my $cmdline_mysqldumpslave= generate_cmdline_mysqldump($slave->[0]);
2051
 
 
2052
 
  if ( $opt_debug )
2053
 
  {
2054
 
    $cmdline_mysqldump .=
2055
 
      " --debug=d:t:A,$path_vardir_trace/log/mysqldump-master.trace";
2056
 
    $cmdline_mysqldumpslave .=
2057
 
      " --debug=d:t:A,$path_vardir_trace/log/mysqldump-slave.trace";
2058
 
  }
2059
 
  $ENV{'MYSQL_DUMP'}= $cmdline_mysqldump;
2060
 
  $ENV{'MYSQL_DUMP_SLAVE'}= $cmdline_mysqldumpslave;
2061
 
 
2062
 
 
2063
 
  # ----------------------------------------------------
2064
 
  # Setup env so childs can execute mysqlslap
2065
 
  # ----------------------------------------------------
2066
 
  if ( $exe_mysqlslap )
2067
 
  {
2068
 
    my $cmdline_mysqlslap=
2069
 
      mtr_native_path($exe_mysqlslap) .
2070
 
      " -uroot " .
2071
 
      "--port=$master->[0]->{'port'} " .
2072
 
      "--socket=$master->[0]->{'path_sock'} --password= ";
2073
 
 
2074
 
    if ( $opt_debug )
2075
 
   {
2076
 
      $cmdline_mysqlslap .=
2077
 
        " --debug=d:t:A,$path_vardir_trace/log/mysqlslap.trace";
2078
 
    }
2079
 
    $ENV{'MYSQL_SLAP'}= $cmdline_mysqlslap;
2080
 
  }
2081
 
 
2082
 
  # ----------------------------------------------------
2083
 
  # Setup env so childs can execute mysqlimport
2084
 
  # ----------------------------------------------------
2085
 
  my $cmdline_mysqlimport=
2086
 
    mtr_native_path($exe_mysqlimport) .
2087
 
    " -uroot --debug-check " .
2088
 
    "--port=$master->[0]->{'port'} " .
2089
 
    "--socket=$master->[0]->{'path_sock'} --password=";
2090
 
 
2091
 
  if ( $opt_debug )
2092
 
  {
2093
 
    $cmdline_mysqlimport .=
2094
 
      " --debug=d:t:A,$path_vardir_trace/log/mysqlimport.trace";
2095
 
  }
2096
 
  $ENV{'MYSQL_IMPORT'}= $cmdline_mysqlimport;
2097
 
 
2098
 
 
2099
 
  # ----------------------------------------------------
2100
 
  # Setup env so childs can execute mysqlshow
2101
 
  # ----------------------------------------------------
2102
 
  my $cmdline_mysqlshow=
2103
 
    mtr_native_path($exe_mysqlshow) .
2104
 
    " -uroot --debug-check " .
2105
 
    "--port=$master->[0]->{'port'} " .
2106
 
    "--socket=$master->[0]->{'path_sock'} --password=";
2107
 
 
2108
 
  if ( $opt_debug )
2109
 
  {
2110
 
    $cmdline_mysqlshow .=
2111
 
      " --debug=d:t:A,$path_vardir_trace/log/mysqlshow.trace";
2112
 
  }
2113
 
  $ENV{'MYSQL_SHOW'}= $cmdline_mysqlshow;
2114
 
 
2115
 
  # ----------------------------------------------------
2116
 
  # Setup env so childs can execute mysqlbinlog
2117
 
  # ----------------------------------------------------
2118
 
  my $cmdline_mysqlbinlog=
2119
 
    mtr_native_path($exe_mysqlbinlog) .
2120
 
      " --no-defaults --disable-force-if-open --debug-check";
2121
 
  if ( !$opt_extern && $mysql_version_id >= 50000 )
2122
 
  {
2123
 
    $cmdline_mysqlbinlog .=" --character-sets-dir=$path_charsetsdir";
2124
 
  }
2125
 
  # Always use the given tmpdir for the LOAD files created
2126
 
  # by mysqlbinlog
2127
 
  $cmdline_mysqlbinlog .=" --local-load=$opt_tmpdir";
2128
 
 
2129
 
  if ( $opt_debug )
2130
 
  {
2131
 
    $cmdline_mysqlbinlog .=
2132
 
      " --debug=d:t:A,$path_vardir_trace/log/mysqlbinlog.trace";
2133
 
  }
2134
 
  $ENV{'MYSQL_BINLOG'}= $cmdline_mysqlbinlog;
2135
 
 
2136
 
  # ----------------------------------------------------
2137
 
  # Setup env so childs can execute mysql
2138
 
  # ----------------------------------------------------
2139
 
  my $cmdline_mysql=
2140
 
    mtr_native_path($exe_mysql) .
2141
 
    " --no-defaults --debug-check --host=localhost  --user=root --password= " .
2142
 
    "--port=$master->[0]->{'port'} " .
2143
 
    "--socket=$master->[0]->{'path_sock'} ".
2144
 
    "--character-sets-dir=$path_charsetsdir";
2145
 
 
2146
 
  $ENV{'MYSQL'}= $cmdline_mysql;
2147
 
 
2148
 
  # ----------------------------------------------------
2149
 
  # Setup env so childs can execute bug25714
2150
 
  # ----------------------------------------------------
2151
 
  $ENV{'MYSQL_BUG25714'}=  $exe_bug25714;
2152
 
 
2153
 
  # ----------------------------------------------------
2154
 
  # Setup env so childs can execute mysql_client_test
2155
 
  # ----------------------------------------------------
2156
 
  $ENV{'MYSQL_CLIENT_TEST'}=  mysql_client_test_arguments();
2157
 
 
2158
 
  # ----------------------------------------------------
2159
 
  # Setup env so childs can execute mysql_upgrade
2160
 
  # ----------------------------------------------------
2161
 
  if ( !$opt_extern && $mysql_version_id >= 50000 )
2162
 
  {
2163
 
    $ENV{'MYSQL_UPGRADE'}= mysql_upgrade_arguments();
2164
 
  }
2165
 
 
2166
 
  # ----------------------------------------------------
2167
 
  # Setup env so childs can execute mysql_fix_system_tables
2168
 
  # ----------------------------------------------------
2169
 
  if ( !$opt_extern && ! $glob_win32 )
2170
 
  {
2171
 
    my $cmdline_mysql_fix_system_tables=
2172
 
      "$exe_mysql_fix_system_tables --no-defaults --host=localhost " .
2173
 
      "--user=root --password= " .
2174
 
      "--basedir=$glob_basedir --bindir=$path_client_bindir --verbose " .
2175
 
      "--port=$master->[0]->{'port'} " .
2176
 
      "--socket=$master->[0]->{'path_sock'}";
2177
 
    $ENV{'MYSQL_FIX_SYSTEM_TABLES'}=  $cmdline_mysql_fix_system_tables;
2178
 
 
2179
 
  }
 
1851
  # mysql clients
 
1852
  # ----------------------------------------------------
 
1853
  $ENV{'MYSQL_CHECK'}=              client_arguments("mysqlcheck");
 
1854
  $ENV{'MYSQL_DUMP'}=               mysqldump_arguments(".1");
 
1855
  $ENV{'MYSQL_DUMP_SLAVE'}=         mysqldump_arguments(".2");
 
1856
  $ENV{'MYSQL_SLAP'}=               mysqlslap_arguments();
 
1857
  $ENV{'MYSQL_IMPORT'}=             client_arguments("mysqlimport");
 
1858
  $ENV{'MYSQL_SHOW'}=               client_arguments("mysqlshow");
 
1859
  $ENV{'MYSQL_BINLOG'}=             client_arguments("mysqlbinlog");
 
1860
  $ENV{'MYSQL'}=                    client_arguments("mysql");
 
1861
  $ENV{'MYSQL_UPGRADE'}=            client_arguments("mysql_upgrade");
 
1862
  $ENV{'MYSQLADMIN'}=               native_path($exe_mysqladmin);
 
1863
  $ENV{'MYSQL_CLIENT_TEST'}=        mysql_client_test_arguments();
 
1864
  $ENV{'MYSQL_FIX_SYSTEM_TABLES'}=  mysql_fix_arguments();
 
1865
  $ENV{'EXE_MYSQL'}=                $exe_mysql;
 
1866
 
 
1867
  # ----------------------------------------------------
 
1868
  # bug25714 executable may _not_ exist in
 
1869
  # some versions, test using it should be skipped
 
1870
  # ----------------------------------------------------
 
1871
  my $exe_bug25714=
 
1872
      mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'),
 
1873
                           "$basedir/tests/bug25714");
 
1874
  $ENV{'MYSQL_BUG25714'}=  native_path($exe_bug25714);
 
1875
 
 
1876
  # ----------------------------------------------------
 
1877
  # mysql_fix_privilege_tables.sql
 
1878
  # ----------------------------------------------------
 
1879
  my $file_mysql_fix_privilege_tables=
 
1880
    mtr_file_exists("$basedir/scripts/mysql_fix_privilege_tables.sql",
 
1881
                    "$basedir/share/mysql_fix_privilege_tables.sql",
 
1882
                    "$basedir/share/mysql/mysql_fix_privilege_tables.sql");
2180
1883
  $ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}=  $file_mysql_fix_privilege_tables;
2181
1884
 
2182
1885
  # ----------------------------------------------------
2183
 
  # Setup env so childs can execute my_print_defaults
2184
 
  # ----------------------------------------------------
2185
 
  $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= mtr_native_path($exe_my_print_defaults);
2186
 
 
2187
 
  # ----------------------------------------------------
2188
 
  # Setup env so childs can execute mysqladmin
2189
 
  # ----------------------------------------------------
2190
 
  $ENV{'MYSQLADMIN'}= mtr_native_path($exe_mysqladmin);
2191
 
 
2192
 
  # ----------------------------------------------------
2193
 
  # Setup env so childs can execute perror  
2194
 
  # ----------------------------------------------------
2195
 
  $ENV{'MY_PERROR'}= mtr_native_path($exe_perror);
2196
 
 
2197
 
  # ----------------------------------------------------
2198
 
  # Add the path where mysqld will find udf_example.so
2199
 
  # ----------------------------------------------------
2200
 
  $ENV{'UDF_EXAMPLE_LIB'}=
2201
 
    ($lib_udf_example ? basename($lib_udf_example) : "");
2202
 
  $ENV{'UDF_EXAMPLE_LIB_OPT'}=
2203
 
    ($lib_udf_example ? "--plugin_dir=" . dirname($lib_udf_example) : "");
2204
 
 
2205
 
  # ----------------------------------------------------
2206
 
  # Add the path where mysqld will find ha_example.so
2207
 
  # ----------------------------------------------------
2208
 
  $ENV{'EXAMPLE_PLUGIN'}=
2209
 
    ($lib_example_plugin ? basename($lib_example_plugin) : "");
2210
 
  $ENV{'EXAMPLE_PLUGIN_OPT'}=
2211
 
    ($lib_example_plugin ? "--plugin_dir=" . dirname($lib_example_plugin) : "");
2212
 
 
2213
 
  # ----------------------------------------------------
2214
 
  # Add the path where mysqld will find mypluglib.so
2215
 
  # ----------------------------------------------------
2216
 
  $ENV{'SIMPLE_PARSER'}=
2217
 
    ($lib_simple_parser ? basename($lib_simple_parser) : "");
2218
 
  $ENV{'SIMPLE_PARSER_OPT'}=
2219
 
    ($lib_simple_parser ? "--plugin_dir=" . dirname($lib_simple_parser) : "");
 
1886
  # my_print_defaults
 
1887
  # ----------------------------------------------------
 
1888
  my $exe_my_print_defaults=
 
1889
    mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
 
1890
                   "$path_client_bindir/my_print_defaults",
 
1891
                   "$basedir/extra/my_print_defaults");
 
1892
  $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= native_path($exe_my_print_defaults);
2220
1893
 
2221
1894
  # ----------------------------------------------------
2222
1895
  # Setup env so childs can execute myisampack and myisamchk
2223
1896
  # ----------------------------------------------------
2224
 
  $ENV{'MYISAMCHK'}= mtr_native_path(mtr_exe_exists(
 
1897
  $ENV{'MYISAMCHK'}= native_path(mtr_exe_exists(
2225
1898
                       vs_config_dirs('storage/myisam', 'myisamchk'),
2226
1899
                       vs_config_dirs('myisam', 'myisamchk'),
2227
1900
                       "$path_client_bindir/myisamchk",
2228
 
                       "$glob_basedir/storage/myisam/myisamchk",
2229
 
                       "$glob_basedir/myisam/myisamchk"));
2230
 
  $ENV{'MYISAMPACK'}= mtr_native_path(mtr_exe_exists(
 
1901
                       "$basedir/storage/myisam/myisamchk",
 
1902
                       "$basedir/myisam/myisamchk"));
 
1903
  $ENV{'MYISAMPACK'}= native_path(mtr_exe_exists(
2231
1904
                        vs_config_dirs('storage/myisam', 'myisampack'),
2232
1905
                        vs_config_dirs('myisam', 'myisampack'),
2233
1906
                        "$path_client_bindir/myisampack",
2234
 
                        "$glob_basedir/storage/myisam/myisampack",
2235
 
                        "$glob_basedir/myisam/myisampack"));
 
1907
                        "$basedir/storage/myisam/myisampack",
 
1908
                        "$basedir/myisam/myisampack"));
2236
1909
 
2237
1910
  # ----------------------------------------------------
2238
 
  # We are nice and report a bit about our settings
 
1911
  # perror
2239
1912
  # ----------------------------------------------------
2240
 
  if (!$opt_extern)
2241
 
  {
2242
 
    print "Using MTR_BUILD_THREAD      = $ENV{MTR_BUILD_THREAD}\n";
2243
 
    print "Using MASTER_MYPORT         = $ENV{MASTER_MYPORT}\n";
2244
 
    print "Using MASTER_MYPORT1        = $ENV{MASTER_MYPORT1}\n";
2245
 
    print "Using SLAVE_MYPORT          = $ENV{SLAVE_MYPORT}\n";
2246
 
    print "Using SLAVE_MYPORT1         = $ENV{SLAVE_MYPORT1}\n";
2247
 
    print "Using SLAVE_MYPORT2         = $ENV{SLAVE_MYPORT2}\n";
2248
 
    if ( ! $opt_skip_ndbcluster )
2249
 
    {
2250
 
      print "Using NDBCLUSTER_PORT       = $ENV{NDBCLUSTER_PORT}\n";
2251
 
      if ( ! $opt_skip_ndbcluster_slave )
2252
 
      {
2253
 
        print "Using NDBCLUSTER_PORT_SLAVE = $ENV{NDBCLUSTER_PORT_SLAVE}\n";
2254
 
      }
2255
 
    }
2256
 
    if ( ! $opt_skip_im )
2257
 
    {
2258
 
      print "Using IM_PORT               = $ENV{IM_PORT}\n";
2259
 
      print "Using IM_MYSQLD1_PORT       = $ENV{IM_MYSQLD1_PORT}\n";
2260
 
      print "Using IM_MYSQLD2_PORT       = $ENV{IM_MYSQLD2_PORT}\n";
2261
 
    }
2262
 
  }
 
1913
  my $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
 
1914
                                 "$basedir/extra/perror",
 
1915
                                 "$path_client_bindir/perror");
 
1916
  $ENV{'MY_PERROR'}= native_path($exe_perror);
2263
1917
 
2264
1918
  # Create an environment variable to make it possible
2265
1919
  # to detect that valgrind is being used from test cases
2268
1922
}
2269
1923
 
2270
1924
 
2271
 
##############################################################################
2272
 
#
2273
 
#  If we get a ^C, we try to clean up before termination
2274
 
#
2275
 
##############################################################################
2276
 
# FIXME check restrictions what to do in a signal handler
2277
 
 
2278
 
sub signal_setup () {
2279
 
  $SIG{INT}= \&handle_int_signal;
2280
 
}
2281
 
 
2282
 
 
2283
 
sub handle_int_signal () {
2284
 
  $SIG{INT}= 'DEFAULT';         # If we get a ^C again, we die...
2285
 
  mtr_warning("got INT signal, cleaning up.....");
2286
 
  stop_all_servers();
2287
 
  mtr_error("We die from ^C signal from user");
2288
 
}
2289
 
 
2290
 
 
2291
 
##############################################################################
2292
 
#
2293
 
#  Handle left overs from previous runs
2294
 
#
2295
 
##############################################################################
2296
 
 
2297
 
sub kill_running_servers () {
2298
 
 
2299
 
  if ( $opt_fast or $glob_use_embedded_server )
2300
 
  {
2301
 
    # FIXME is embedded server really using PID files?!
2302
 
    unlink($master->[0]->{'path_pid'});
2303
 
    unlink($master->[1]->{'path_pid'});
2304
 
    unlink($slave->[0]->{'path_pid'});
2305
 
    unlink($slave->[1]->{'path_pid'});
2306
 
    unlink($slave->[2]->{'path_pid'});
2307
 
  }
2308
 
  else
2309
 
  {
2310
 
    # Ensure that no old mysqld test servers are running
2311
 
    # This is different from terminating processes we have
2312
 
    # started from this run of the script, this is terminating
2313
 
    # leftovers from previous runs.
2314
 
    mtr_kill_leftovers();
2315
 
   }
2316
 
}
2317
1925
 
2318
1926
#
2319
1927
# Remove var and any directories in var/ created by previous
2321
1929
#
2322
1930
sub remove_stale_vardir () {
2323
1931
 
2324
 
  mtr_report("Removing Stale Files");
 
1932
  mtr_report("Removing old var directory...");
2325
1933
 
2326
1934
  # Safety!
2327
1935
  mtr_error("No, don't remove the vardir when running with --extern")
2328
 
    if $opt_extern;
 
1936
    if using_extern();
2329
1937
 
2330
1938
  mtr_verbose("opt_vardir: $opt_vardir");
2331
1939
  if ( $opt_vardir eq $default_vardir )
2337
1945
    {
2338
1946
      # var is a symlink
2339
1947
 
2340
 
      if ( $opt_mem and readlink($opt_vardir) eq $opt_mem )
 
1948
      if ( $opt_mem )
2341
1949
      {
2342
1950
        # Remove the directory which the link points at
2343
1951
        mtr_verbose("Removing " . readlink($opt_vardir));
2344
 
        mtr_rmtree(readlink($opt_vardir));
 
1952
        rmtree(readlink($opt_vardir));
2345
1953
 
2346
1954
        # Remove the "var" symlink
2347
1955
        mtr_verbose("unlink($opt_vardir)");
2348
1956
        unlink($opt_vardir);
2349
1957
      }
2350
 
      elsif ( $opt_mem )
2351
 
      {
2352
 
        # Just remove the "var" symlink
2353
 
        mtr_report("WARNING: Removing '$opt_vardir' symlink it's wrong");
2354
 
 
2355
 
        mtr_verbose("unlink($opt_vardir)");
2356
 
        unlink($opt_vardir);
2357
 
      }
2358
1958
      else
2359
1959
      {
2360
1960
        # Some users creates a soft link in mysql-test/var to another area
2361
1961
        # - allow it, but remove all files in it
2362
1962
 
2363
 
        mtr_report("WARNING: Using the 'mysql-test/var' symlink");
 
1963
        mtr_report(" - WARNING: Using the 'mysql-test/var' symlink");
2364
1964
 
2365
1965
        # Make sure the directory where it points exist
2366
1966
        mtr_error("The destination for symlink $opt_vardir does not exist")
2369
1969
        foreach my $bin ( glob("$opt_vardir/*") )
2370
1970
        {
2371
1971
          mtr_verbose("Removing bin $bin");
2372
 
          mtr_rmtree($bin);
 
1972
          rmtree($bin);
2373
1973
        }
2374
1974
      }
2375
1975
    }
2377
1977
    {
2378
1978
      # Remove the entire "var" dir
2379
1979
      mtr_verbose("Removing $opt_vardir/");
2380
 
      mtr_rmtree("$opt_vardir/");
 
1980
      rmtree("$opt_vardir/");
2381
1981
    }
2382
1982
 
2383
1983
    if ( $opt_mem )
2386
1986
      # remove the $opt_mem dir to assure the symlink
2387
1987
      # won't point at an old directory
2388
1988
      mtr_verbose("Removing $opt_mem");
2389
 
      mtr_rmtree($opt_mem);
 
1989
      rmtree($opt_mem);
2390
1990
    }
2391
1991
 
2392
1992
  }
2399
1999
    # Remove the var/ dir in mysql-test dir if any
2400
2000
    # this could be an old symlink that shouldn't be there
2401
2001
    mtr_verbose("Removing $default_vardir");
2402
 
    mtr_rmtree($default_vardir);
 
2002
    rmtree($default_vardir);
2403
2003
 
2404
2004
    # Remove the "var" dir
2405
2005
    mtr_verbose("Removing $opt_vardir/");
2406
 
    mtr_rmtree("$opt_vardir/");
 
2006
    rmtree("$opt_vardir/");
2407
2007
  }
2408
2008
  # Remove the "tmp" dir
2409
2009
  mtr_verbose("Removing $opt_tmpdir/");
2410
 
  mtr_rmtree("$opt_tmpdir/");
 
2010
  rmtree("$opt_tmpdir/");
2411
2011
}
2412
2012
 
 
2013
 
 
2014
 
2413
2015
#
2414
2016
# Create var and the directories needed in var
2415
2017
#
2416
2018
sub setup_vardir() {
2417
 
  mtr_report("Creating Directories");
 
2019
  mtr_report("Creating var directory '$opt_vardir'...");
2418
2020
 
2419
2021
  if ( $opt_vardir eq $default_vardir )
2420
2022
  {
2435
2037
      mtr_verbose("Creating $opt_mem");
2436
2038
      mkpath($opt_mem);
2437
2039
 
2438
 
      mtr_report("Symlinking 'var' to '$opt_mem'");
 
2040
      mtr_report(" - symlinking 'var' to '$opt_mem'");
2439
2041
      symlink($opt_mem, $opt_vardir);
2440
2042
    }
2441
2043
  }
2455
2057
 
2456
2058
  mkpath("$opt_vardir/log");
2457
2059
  mkpath("$opt_vardir/run");
 
2060
 
 
2061
  # Create var/tmp and tmp - they might be different
2458
2062
  mkpath("$opt_vardir/tmp");
2459
 
  mkpath($opt_tmpdir) if $opt_tmpdir ne "$opt_vardir/tmp";
2460
 
 
2461
 
  if ($master->[0]->{'path_sock'} !~ m/^$opt_tmpdir/)
2462
 
  {
2463
 
    mtr_report("Symlinking $master->[0]->{'path_sock'}");
2464
 
        symlink($master->[0]->{'path_sock'}, "$opt_tmpdir/master.sock");
2465
 
  }
2466
 
 
2467
 
  # Create new data dirs
2468
 
  foreach my $data_dir (@data_dir_lst)
2469
 
  {
2470
 
    mkpath("$data_dir/mysql");
2471
 
    mkpath("$data_dir/test");
2472
 
  }
2473
 
 
2474
 
  # Make a link std_data_ln in var/ that points to std_data
2475
 
  if ( ! $glob_win32 )
2476
 
  {
2477
 
    symlink("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data_ln");
2478
 
  }
2479
 
  else
2480
 
  {
2481
 
    # on windows, copy all files from std_data into var/std_data_ln
2482
 
    mkpath("$opt_vardir/std_data_ln");
2483
 
    mtr_copy_dir("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data_ln");
2484
 
  }
 
2063
  mkpath($opt_tmpdir) if ($opt_tmpdir ne "$opt_vardir/tmp");
 
2064
 
 
2065
  # On some operating systems, there is a limit to the length of a
 
2066
  # UNIX domain socket's path far below PATH_MAX.
 
2067
  # Don't allow that to happen
 
2068
  if (check_socket_path_length("$opt_tmpdir/testsocket.sock")){
 
2069
    mtr_error("Socket path '$opt_tmpdir' too long, it would be ",
 
2070
              "truncated and thus not possible to use for connection to ",
 
2071
              "MySQL Server. Set a shorter with --tmpdir=<path> option");
 
2072
  }
 
2073
 
 
2074
  # copy all files from std_data into var/std_data
 
2075
  # and make them world readable
 
2076
  copytree("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data", "0022");
2485
2077
 
2486
2078
  # Remove old log files
2487
2079
  foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
2491
2083
}
2492
2084
 
2493
2085
 
 
2086
#
 
2087
# Check if running as root
 
2088
# i.e a file can be read regardless what mode we set it to
 
2089
#
2494
2090
sub  check_running_as_root () {
2495
 
  # Check if running as root
2496
 
  # i.e a file can be read regardless what mode we set it to
2497
2091
  my $test_file= "$opt_vardir/test_running_as_root.txt";
2498
2092
  mtr_tofile($test_file, "MySQL");
2499
2093
  chmod(oct("0000"), $test_file);
2510
2104
  # the file will not return 0000
2511
2105
  my $file_mode= (stat($test_file))[2] & 07777;
2512
2106
 
2513
 
  $ENV{'MYSQL_TEST_ROOT'}= "NO";
2514
2107
  mtr_verbose("result: $result, file_mode: $file_mode");
2515
2108
  if ($result eq "MySQL" && $file_mode == 0)
2516
2109
  {
2521
2114
 
2522
2115
  chmod(oct("0755"), $test_file);
2523
2116
  unlink($test_file);
2524
 
 
2525
2117
}
2526
2118
 
2527
2119
 
2528
2120
sub check_ssl_support ($) {
2529
2121
  my $mysqld_variables= shift;
2530
2122
 
2531
 
  if ($opt_skip_ssl || $opt_extern)
 
2123
  if ($opt_skip_ssl)
2532
2124
  {
2533
 
    if (!$opt_extern)
2534
 
    {
2535
 
      mtr_report("Skipping SSL");
2536
 
    }
 
2125
    mtr_report(" - skipping SSL");
2537
2126
    $opt_ssl_supported= 0;
2538
2127
    $opt_ssl= 0;
2539
2128
    return;
2546
2135
      mtr_error("Couldn't find support for SSL");
2547
2136
      return;
2548
2137
    }
2549
 
    mtr_report("Skipping SSL, mysqld not compiled with SSL");
 
2138
    mtr_report(" - skipping SSL, mysqld not compiled with SSL");
2550
2139
    $opt_ssl_supported= 0;
2551
2140
    $opt_ssl= 0;
2552
2141
    return;
2553
2142
  }
2554
 
  mtr_report("Setting mysqld to support SSL connections");
 
2143
  mtr_report(" - SSL connections supported");
2555
2144
  $opt_ssl_supported= 1;
2556
2145
}
2557
2146
 
2561
2150
 
2562
2151
  if ( ! $mysqld_variables->{'debug'} )
2563
2152
  {
2564
 
    #mtr_report("Binaries are not debug compiled");
 
2153
    #mtr_report(" - binaries are not debug compiled");
2565
2154
    $debug_compiled_binaries= 0;
2566
2155
 
2567
2156
    if ( $opt_debug )
2570
2159
    }
2571
2160
    return;
2572
2161
  }
2573
 
  mtr_report("Binaries are debug compiled");
 
2162
  mtr_report(" - binaries are debug compiled");
2574
2163
  $debug_compiled_binaries= 1;
2575
2164
}
2576
2165
 
2577
 
##############################################################################
 
2166
 
2578
2167
#
2579
2168
# Helper function to handle configuration-based subdirectories which Visual
2580
2169
# Studio uses for storing binaries.  If opt_vs_config is set, this returns
2583
2172
#
2584
2173
# $exe can be undefined, if the directory itself will be used
2585
2174
#
2586
 
###############################################################################
2587
 
 
2588
2175
sub vs_config_dirs ($$) {
2589
2176
  my ($path_part, $exe) = @_;
2590
2177
 
2591
2178
  $exe = "" if not defined $exe;
2592
2179
 
 
2180
  # Don't look in these dirs when not on windows
 
2181
  return () unless IS_WINDOWS;
 
2182
 
2593
2183
  if ($opt_vs_config)
2594
2184
  {
2595
 
    return ("$glob_basedir/$path_part/$opt_vs_config/$exe");
 
2185
    return ("$basedir/$path_part/$opt_vs_config/$exe");
2596
2186
  }
2597
2187
 
2598
 
  return ("$glob_basedir/$path_part/release/$exe",
2599
 
          "$glob_basedir/$path_part/relwithdebinfo/$exe",
2600
 
          "$glob_basedir/$path_part/debug/$exe");
 
2188
  return ("$basedir/$path_part/release/$exe",
 
2189
          "$basedir/$path_part/relwithdebinfo/$exe",
 
2190
          "$basedir/$path_part/debug/$exe");
2601
2191
}
2602
2192
 
2603
 
##############################################################################
2604
 
#
2605
 
#  Start the ndb cluster
2606
 
#
2607
 
##############################################################################
2608
2193
 
2609
2194
sub check_ndbcluster_support ($) {
2610
2195
  my $mysqld_variables= shift;
2611
2196
 
2612
 
  if ($opt_skip_ndbcluster || $opt_extern)
2613
 
  {
2614
 
    if (!$opt_extern)
2615
 
    {
2616
 
      mtr_report("Skipping ndbcluster");
2617
 
    }
2618
 
    $opt_skip_ndbcluster_slave= 1;
2619
 
    return;
2620
 
  }
2621
 
 
2622
 
  if ( ! $mysqld_variables->{'ndb-connectstring'} )
2623
 
  {
2624
 
    mtr_report("Skipping ndbcluster, mysqld not compiled with ndbcluster");
2625
 
    $opt_skip_ndbcluster= 1;
2626
 
    $opt_skip_ndbcluster_slave= 1;
2627
 
    return;
2628
 
  }
2629
 
  $glob_ndbcluster_supported= 1;
2630
 
  mtr_report("Using ndbcluster when necessary, mysqld supports it");
2631
 
 
2632
 
  if ( $mysql_version_id < 50100 )
2633
 
  {
2634
 
    # Slave cluster is not supported until 5.1
2635
 
    $opt_skip_ndbcluster_slave= 1;
2636
 
 
2637
 
  }
 
2197
  if ($opt_skip_ndbcluster)
 
2198
  {
 
2199
    mtr_report(" - skipping ndbcluster");
 
2200
    return;
 
2201
  }
 
2202
 
 
2203
  if ( ! $mysqld_variables{'ndb-connectstring'} )
 
2204
  {
 
2205
    mtr_report(" - skipping ndbcluster, mysqld not compiled with ndbcluster");
 
2206
    $opt_skip_ndbcluster= 2;
 
2207
    return;
 
2208
  }
 
2209
 
 
2210
  mtr_report(" - using ndbcluster when necessary, mysqld supports it");
2638
2211
 
2639
2212
  return;
2640
2213
}
2641
2214
 
2642
2215
 
2643
 
sub ndbcluster_start_install ($) {
2644
 
  my $cluster= shift;
2645
 
 
2646
 
  mtr_report("Installing $cluster->{'name'} Cluster");
2647
 
 
2648
 
  mkdir($cluster->{'data_dir'});
2649
 
 
2650
 
  # Create a config file from template
2651
 
  my $ndb_no_ord=512;
2652
 
  my $ndb_no_attr=2048;
2653
 
  my $ndb_con_op=105000;
2654
 
  my $ndb_dmem="80M";
2655
 
  my $ndb_imem="24M";
2656
 
  my $ndb_pbmem="32M";
2657
 
  my $nodes= $cluster->{'nodes'};
2658
 
  my $ndb_host= "localhost";
2659
 
  my $ndb_diskless= 0;
2660
 
 
2661
 
  if (!$opt_bench)
2662
 
  {
2663
 
    # Use a smaller configuration
2664
 
    if (  $mysql_version_id < 50100 )
2665
 
    {
2666
 
      # 4.1 and 5.0 is using a "larger" --small configuration
2667
 
      $ndb_no_ord=128;
2668
 
      $ndb_con_op=10000;
2669
 
      $ndb_dmem="40M";
2670
 
      $ndb_imem="12M";
2671
 
    }
2672
 
    else
2673
 
    {
2674
 
      $ndb_no_ord=32;
2675
 
      $ndb_con_op=10000;
2676
 
      $ndb_dmem="20M";
2677
 
      $ndb_imem="1M";
2678
 
      $ndb_pbmem="4M";
2679
 
    }
2680
 
  }
2681
 
 
2682
 
  my $config_file_template=     "ndb/ndb_config_${nodes}_node.ini";
2683
 
  my $config_file= "$cluster->{'data_dir'}/config.ini";
2684
 
 
2685
 
  open(IN, $config_file_template)
2686
 
    or mtr_error("Can't open $config_file_template: $!");
2687
 
  open(OUT, ">", $config_file)
2688
 
    or mtr_error("Can't write to $config_file: $!");
2689
 
  while (<IN>)
2690
 
  {
2691
 
    chomp;
2692
 
 
2693
 
    s/CHOOSE_MaxNoOfAttributes/$ndb_no_attr/;
2694
 
    s/CHOOSE_MaxNoOfOrderedIndexes/$ndb_no_ord/;
2695
 
    s/CHOOSE_MaxNoOfConcurrentOperations/$ndb_con_op/;
2696
 
    s/CHOOSE_DataMemory/$ndb_dmem/;
2697
 
    s/CHOOSE_IndexMemory/$ndb_imem/;
2698
 
    s/CHOOSE_Diskless/$ndb_diskless/;
2699
 
    s/CHOOSE_HOSTNAME_.*/$ndb_host/;
2700
 
    s/CHOOSE_FILESYSTEM/$cluster->{'data_dir'}/;
2701
 
    s/CHOOSE_PORT_MGM/$cluster->{'port'}/;
2702
 
    if ( $mysql_version_id < 50000 )
2703
 
    {
2704
 
      my $base_port= $cluster->{'port'} + 1;
2705
 
      s/CHOOSE_PORT_TRANSPORTER/$base_port/;
2706
 
    }
2707
 
    s/CHOOSE_DiskPageBufferMemory/$ndb_pbmem/;
2708
 
 
2709
 
    print OUT "$_ \n";
2710
 
  }
2711
 
  close OUT;
2712
 
  close IN;
2713
 
 
2714
 
 
2715
 
  # Start cluster with "--initial"
2716
 
 
2717
 
  ndbcluster_start($cluster, "--initial");
2718
 
 
2719
 
  return 0;
2720
 
}
2721
 
 
2722
 
 
2723
2216
sub ndbcluster_wait_started($$){
2724
2217
  my $cluster= shift;
2725
2218
  my $ndb_waiter_extra_opt= shift;
2726
 
  my $path_waiter_log= "$cluster->{'data_dir'}/ndb_waiter.log";
 
2219
  my $path_waitlog= join('/', $opt_vardir, $cluster->name(), "ndb_waiter.log");
 
2220
 
2727
2221
  my $args;
2728
 
 
2729
2222
  mtr_init_args(\$args);
2730
 
 
2731
 
  mtr_add_arg($args, "--no-defaults");
2732
 
  mtr_add_arg($args, "--core");
2733
 
  mtr_add_arg($args, "--ndb-connectstring=%s", $cluster->{'connect_string'});
2734
 
  mtr_add_arg($args, "--timeout=60");
 
2223
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
2224
  mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
 
2225
  mtr_add_arg($args, "--timeout=%d", $opt_start_timeout);
2735
2226
 
2736
2227
  if ($ndb_waiter_extra_opt)
2737
2228
  {
2741
2232
  # Start the ndb_waiter which will connect to the ndb_mgmd
2742
2233
  # and poll it for state of the ndbd's, will return when
2743
2234
  # all nodes in the cluster is started
2744
 
  my $res= mtr_run($exe_ndb_waiter, $args,
2745
 
                   "", $path_waiter_log, $path_waiter_log, "");
2746
 
  mtr_verbose("ndbcluster_wait_started, returns: $res") if $res;
2747
 
  return $res;
2748
 
}
2749
 
 
2750
 
 
2751
 
 
2752
 
sub mysqld_wait_started($){
2753
 
  my $mysqld= shift;
2754
 
 
2755
 
  if (sleep_until_file_created($mysqld->{'path_pid'},
2756
 
                               $mysqld->{'start_timeout'},
2757
 
                               $mysqld->{'pid'}) == 0)
2758
 
  {
2759
 
    # Failed to wait for pid file
 
2235
 
 
2236
  my $res= My::SafeProcess->run
 
2237
    (
 
2238
     name          => "ndb_waiter ".$cluster->name(),
 
2239
     path          => $exe_ndb_waiter,
 
2240
     args          => \$args,
 
2241
     output        => $path_waitlog,
 
2242
     error         => $path_waitlog,
 
2243
     append        => 1,
 
2244
    );
 
2245
 
 
2246
  # Check that ndb_mgmd(s) are still alive
 
2247
  foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
 
2248
  {
 
2249
    my $proc= $ndb_mgmd->{proc};
 
2250
    if ( ! $proc->wait_one(0) )
 
2251
    {
 
2252
      mtr_warning("$proc died");
 
2253
      return 2;
 
2254
    }
 
2255
  }
 
2256
 
 
2257
  # Check that all started ndbd(s) are still alive
 
2258
  foreach my $ndbd ( in_cluster($cluster, ndbds()) )
 
2259
  {
 
2260
    my $proc= $ndbd->{proc};
 
2261
    next unless defined $proc;
 
2262
    if ( ! $proc->wait_one(0) )
 
2263
    {
 
2264
      mtr_warning("$proc died");
 
2265
      return 3;
 
2266
    }
 
2267
  }
 
2268
 
 
2269
  if ($res)
 
2270
  {
 
2271
    mtr_verbose("ndbcluster_wait_started failed");
2760
2272
    return 1;
2761
2273
  }
2762
 
 
2763
 
  # Get the "real pid" of the process, it will be used for killing
2764
 
  # the process in ActiveState's perl on windows
2765
 
  $mysqld->{'real_pid'}= mtr_get_pid_from_file($mysqld->{'path_pid'});
2766
 
 
2767
2274
  return 0;
2768
2275
}
2769
2276
 
2772
2279
  my ($cluster)= @_;
2773
2280
 
2774
2281
  my $retries= 100;
2775
 
  while (ndbcluster_wait_started($cluster, "--no-contact") and
2776
 
         $retries)
 
2282
  while ($retries)
2777
2283
  {
2778
 
    # Millisceond sleep emulated with select
2779
 
    select(undef, undef, undef, (0.1));
 
2284
    my $result= ndbcluster_wait_started($cluster, "--no-contact");
 
2285
    if ($result == 0)
 
2286
    {
 
2287
      # ndb_mgmd is started
 
2288
      mtr_verbose("ndb_mgmd is started");
 
2289
      return 0;
 
2290
    }
 
2291
    elsif ($result > 1)
 
2292
    {
 
2293
      mtr_warning("Cluster process failed while waiting for start");
 
2294
      return $result;
 
2295
    }
2780
2296
 
 
2297
    mtr_milli_sleep(100);
2781
2298
    $retries--;
2782
2299
  }
2783
2300
 
2784
 
  return $retries == 0;
2785
 
 
 
2301
  return 1;
2786
2302
}
2787
2303
 
2788
 
sub ndb_mgmd_start ($) {
2789
 
  my $cluster= shift;
2790
 
 
2791
 
  my $args;                             # Arg vector
2792
 
  my $pid= -1;
2793
 
 
 
2304
 
 
2305
sub ndb_mgmd_start ($$) {
 
2306
  my ($cluster, $ndb_mgmd)= @_;
 
2307
 
 
2308
  mtr_verbose("ndb_mgmd_start");
 
2309
 
 
2310
  my $dir= $ndb_mgmd->value("DataDir");
 
2311
  mkpath($dir) unless -d $dir;
 
2312
 
 
2313
  my $args;
2794
2314
  mtr_init_args(\$args);
2795
 
  mtr_add_arg($args, "--no-defaults");
2796
 
  mtr_add_arg($args, "--core");
 
2315
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
2316
  mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
 
2317
  mtr_add_arg($args, "--mycnf");
2797
2318
  mtr_add_arg($args, "--nodaemon");
2798
 
  mtr_add_arg($args, "--config-file=%s", "$cluster->{'data_dir'}/config.ini");
2799
 
 
2800
 
 
2801
 
  my $path_ndb_mgmd_log= "$cluster->{'data_dir'}/\l$cluster->{'name'}_ndb_mgmd.log";
2802
 
  $pid= mtr_spawn($exe_ndb_mgmd, $args, "",
2803
 
                  $path_ndb_mgmd_log,
2804
 
                  $path_ndb_mgmd_log,
2805
 
                  "",
2806
 
                  { append_log_file => 1 });
 
2319
 
 
2320
  my $path_ndb_mgmd_log= "$dir/ndb_mgmd.log";
 
2321
 
 
2322
  $ndb_mgmd->{'proc'}= My::SafeProcess->new
 
2323
    (
 
2324
     name          => $ndb_mgmd->after('cluster_config.'),
 
2325
     path          => $exe_ndb_mgmd,
 
2326
     args          => \$args,
 
2327
     output        => $path_ndb_mgmd_log,
 
2328
     error         => $path_ndb_mgmd_log,
 
2329
     append        => 1,
 
2330
     verbose       => $opt_verbose,
 
2331
    );
 
2332
  mtr_verbose("Started $ndb_mgmd->{proc}");
2807
2333
 
2808
2334
  # FIXME Should not be needed
2809
2335
  # Unfortunately the cluster nodes will fail to start
2810
2336
  # if ndb_mgmd has not started properly
2811
2337
  if (ndb_mgmd_wait_started($cluster))
2812
2338
  {
2813
 
    mtr_error("Failed to wait for start of ndb_mgmd");
 
2339
    mtr_warning("Failed to wait for start of ndb_mgmd");
 
2340
    return 1;
2814
2341
  }
2815
2342
 
2816
 
  # Remember pid of ndb_mgmd
2817
 
  $cluster->{'pid'}= $pid;
2818
 
 
2819
 
  mtr_verbose("ndb_mgmd_start, pid: $pid");
2820
 
 
2821
 
  return $pid;
 
2343
  return 0;
2822
2344
}
2823
2345
 
2824
2346
 
2825
 
sub ndbd_start ($$$) {
2826
 
  my $cluster= shift;
2827
 
  my $idx= shift;
2828
 
  my $extra_args= shift;
2829
 
 
2830
 
  my $args;                             # Arg vector
2831
 
  my $pid= -1;
2832
 
 
 
2347
sub ndbd_start {
 
2348
  my ($cluster, $ndbd)= @_;
 
2349
 
 
2350
  mtr_verbose("ndbd_start");
 
2351
 
 
2352
  my $dir= $ndbd->value("DataDir");
 
2353
  mkpath($dir) unless -d $dir;
 
2354
 
 
2355
  my $args;
2833
2356
  mtr_init_args(\$args);
2834
 
  mtr_add_arg($args, "--no-defaults");
2835
 
  mtr_add_arg($args, "--core");
2836
 
  mtr_add_arg($args, "--ndb-connectstring=%s", "$cluster->{'connect_string'}");
2837
 
  if ( $mysql_version_id >= 50000)
2838
 
  {
2839
 
    mtr_add_arg($args, "--character-sets-dir=%s", "$path_charsetsdir");
2840
 
  }
 
2357
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
2358
  mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
2841
2359
  mtr_add_arg($args, "--nodaemon");
2842
 
  mtr_add_arg($args, "$extra_args");
2843
 
 
2844
 
  my $nodeid= $cluster->{'ndbds'}->[$idx]->{'nodeid'};
2845
 
  my $path_ndbd_log= "$cluster->{'data_dir'}/ndb_${nodeid}.log";
2846
 
  $pid= mtr_spawn($exe_ndbd, $args, "",
2847
 
                  $path_ndbd_log,
2848
 
                  $path_ndbd_log,
2849
 
                  "",
2850
 
                  { append_log_file => 1 });
2851
 
 
2852
 
  # Add pid to list of pids for this cluster
2853
 
  $cluster->{'ndbds'}->[$idx]->{'pid'}= $pid;
2854
 
 
2855
 
  # Rememeber options used when starting
2856
 
  $cluster->{'ndbds'}->[$idx]->{'start_extra_args'}= $extra_args;
2857
 
  $cluster->{'ndbds'}->[$idx]->{'idx'}= $idx;
2858
 
 
2859
 
  mtr_verbose("ndbd_start, pid: $pid");
2860
 
 
2861
 
  return $pid;
 
2360
 
 
2361
# > 5.0 { 'character-sets-dir' => \&fix_charset_dir },
 
2362
 
 
2363
 
 
2364
  my $path_ndbd_log= "$dir/ndbd.log";
 
2365
  my $proc= My::SafeProcess->new
 
2366
    (
 
2367
     name          => $ndbd->after('cluster_config.'),
 
2368
     path          => $exe_ndbd,
 
2369
     args          => \$args,
 
2370
     output        => $path_ndbd_log,
 
2371
     error         => $path_ndbd_log,
 
2372
     append        => 1,
 
2373
     verbose       => $opt_verbose,
 
2374
    );
 
2375
  mtr_verbose("Started $proc");
 
2376
 
 
2377
  $ndbd->{proc}= $proc;
 
2378
 
 
2379
  return;
2862
2380
}
2863
2381
 
2864
2382
 
2865
 
sub ndbcluster_start ($$) {
 
2383
sub ndbcluster_start ($) {
2866
2384
  my $cluster= shift;
2867
 
  my $extra_args= shift;
2868
 
 
2869
 
  mtr_verbose("ndbcluster_start '$cluster->{'name'}'");
2870
 
 
2871
 
  if ( $cluster->{'use_running'} )
2872
 
  {
2873
 
    return 0;
2874
 
  }
2875
 
 
2876
 
  if ( $cluster->{'pid'} )
2877
 
  {
2878
 
    mtr_error("Cluster '$cluster->{'name'}' already started");
2879
 
  }
2880
 
 
2881
 
  ndb_mgmd_start($cluster);
2882
 
 
2883
 
  for ( my $idx= 0; $idx < $cluster->{'nodes'}; $idx++ )
2884
 
  {
2885
 
    ndbd_start($cluster, $idx, $extra_args);
 
2385
 
 
2386
  mtr_verbose("ndbcluster_start '".$cluster->name()."'");
 
2387
 
 
2388
  foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
 
2389
  {
 
2390
    next if started($ndb_mgmd);
 
2391
    ndb_mgmd_start($cluster, $ndb_mgmd);
 
2392
  }
 
2393
 
 
2394
  foreach my $ndbd ( in_cluster($cluster, ndbds()) )
 
2395
  {
 
2396
    next if started($ndbd);
 
2397
    ndbd_start($cluster, $ndbd);
2886
2398
  }
2887
2399
 
2888
2400
  return 0;
2889
2401
}
2890
2402
 
2891
2403
 
2892
 
sub rm_ndbcluster_tables ($) {
2893
 
  my $dir=       shift;
2894
 
  foreach my $bin ( glob("$dir/mysql/ndb_apply_status*"),
2895
 
                    glob("$dir/mysql/ndb_schema*"))
2896
 
  {
2897
 
    unlink($bin);
2898
 
  }
2899
 
}
2900
 
 
2901
 
 
2902
 
##############################################################################
2903
 
#
2904
 
#  Run the benchmark suite
2905
 
#
2906
 
##############################################################################
2907
 
 
2908
 
sub run_benchmarks ($) {
2909
 
  my $benchmark=  shift;
2910
 
 
2911
 
  my $args;
2912
 
 
2913
 
  if ( ! $glob_use_embedded_server )
2914
 
  {
2915
 
    mysqld_start($master->[0],[],[]);
2916
 
    if ( ! $master->[0]->{'pid'} )
2917
 
    {
2918
 
      mtr_error("Can't start the mysqld server");
2919
 
    }
2920
 
  }
2921
 
 
2922
 
  mtr_init_args(\$args);
2923
 
 
2924
 
  mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_sock'});
2925
 
  mtr_add_arg($args, "--user=%s", $opt_user);
2926
 
 
2927
 
  if ( $opt_small_bench )
2928
 
  {
2929
 
    mtr_add_arg($args, "--small-test");
2930
 
    mtr_add_arg($args, "--small-tables");
2931
 
  }
2932
 
 
2933
 
  if ( $opt_with_ndbcluster )
2934
 
  {
2935
 
    mtr_add_arg($args, "--create-options=TYPE=ndb");
2936
 
  }
2937
 
 
2938
 
  chdir($glob_mysql_bench_dir)
2939
 
    or mtr_error("Couldn't chdir to '$glob_mysql_bench_dir': $!");
2940
 
 
2941
 
  if ( ! $benchmark )
2942
 
  {
2943
 
    mtr_add_arg($args, "--log");
2944
 
    mtr_run("$glob_mysql_bench_dir/run-all-tests", $args, "", "", "", "");
2945
 
    # FIXME check result code?!
2946
 
  }
2947
 
  elsif ( -x $benchmark )
2948
 
  {
2949
 
    mtr_run("$glob_mysql_bench_dir/$benchmark", $args, "", "", "", "");
2950
 
    # FIXME check result code?!
2951
 
  }
2952
 
  else
2953
 
  {
2954
 
    mtr_error("Benchmark $benchmark not found");
2955
 
  }
2956
 
 
2957
 
  chdir($glob_mysql_test_dir);          # Go back
2958
 
 
2959
 
  if ( ! $glob_use_embedded_server )
2960
 
  {
2961
 
    stop_masters();
2962
 
  }
2963
 
}
2964
 
 
2965
 
 
2966
 
##############################################################################
2967
 
#
2968
 
#  Run the tests
2969
 
#
2970
 
##############################################################################
2971
 
 
2972
 
sub run_tests () {
2973
 
  my ($tests)= @_;
2974
 
 
2975
 
  mtr_print_thick_line();
2976
 
 
2977
 
  mtr_timer_start($glob_timers,"suite", 60 * $opt_suite_timeout);
2978
 
 
2979
 
  mtr_report_tests_not_skipped_though_disabled($tests);
2980
 
 
2981
 
  mtr_print_header();
2982
 
 
2983
 
  foreach my $tinfo ( @$tests )
2984
 
  {
2985
 
    if (run_testcase_check_skip_test($tinfo))
2986
 
    {
2987
 
      next;
2988
 
    }
2989
 
 
2990
 
    mtr_timer_start($glob_timers,"testcase", 60 * $opt_testcase_timeout);
2991
 
    run_testcase($tinfo);
2992
 
    mtr_timer_stop($glob_timers,"testcase");
2993
 
  }
2994
 
 
2995
 
  mtr_print_line();
2996
 
 
2997
 
  if ( ! $glob_debugger and
2998
 
       ! $opt_extern and
2999
 
       ! $glob_use_embedded_server )
3000
 
  {
3001
 
    stop_all_servers();
3002
 
  }
3003
 
 
3004
 
  if ( $opt_gcov )
3005
 
  {
3006
 
    gcov_collect(); # collect coverage information
3007
 
  }
3008
 
  if ( $opt_gprof )
3009
 
  {
3010
 
    gprof_collect(); # collect coverage information
3011
 
  }
3012
 
 
3013
 
  mtr_report_stats($tests);
3014
 
 
3015
 
  mtr_timer_stop($glob_timers,"suite");
3016
 
}
3017
 
 
3018
 
 
3019
 
##############################################################################
3020
 
#
3021
 
#  Initiate the test databases
3022
 
#
3023
 
##############################################################################
3024
 
 
3025
 
sub initialize_servers () {
3026
 
 
3027
 
  datadir_list_setup();
3028
 
 
3029
 
  if ( $opt_extern )
 
2404
sub create_config_file_for_extern {
 
2405
  my %opts=
 
2406
    (
 
2407
     socket     => '/tmp/mysqld.sock',
 
2408
     port       => 3306,
 
2409
     user       => $opt_user,
 
2410
     password   => '',
 
2411
     @_
 
2412
    );
 
2413
 
 
2414
  mtr_report("Creating my.cnf file for extern server...");
 
2415
  my $F= IO::File->new($path_config_file, "w")
 
2416
    or mtr_error("Can't write to $path_config_file: $!");
 
2417
 
 
2418
  print $F "[client]\n";
 
2419
  while (my ($option, $value)= each( %opts )) {
 
2420
    print $F "$option= $value\n";
 
2421
    mtr_report(" $option= $value");
 
2422
  }
 
2423
 
 
2424
  print $F <<EOF
 
2425
 
 
2426
# binlog reads from [client] and [mysqlbinlog]
 
2427
[mysqlbinlog]
 
2428
character-sets-dir= $path_charsetsdir
 
2429
 
 
2430
# mysql_fix_privilege_tables.sh don't read from [client]
 
2431
[mysql_fix_privilege_tables]
 
2432
socket            = $opts{'socket'}
 
2433
port              = $opts{'port'}
 
2434
user              = $opts{'user'}
 
2435
password          = $opts{'password'}
 
2436
 
 
2437
 
 
2438
EOF
 
2439
;
 
2440
 
 
2441
  $F= undef; # Close file
 
2442
}
 
2443
 
 
2444
 
 
2445
#
 
2446
# Kill processes left from previous runs, normally
 
2447
# there should be none so make sure to warn
 
2448
# if there is one
 
2449
#
 
2450
sub kill_leftovers ($) {
 
2451
  my $rundir= shift;
 
2452
  return unless ( -d $rundir );
 
2453
 
 
2454
  mtr_report("Checking leftover processes...");
 
2455
 
 
2456
  # Scan the "run" directory for process id's to kill
 
2457
  opendir(RUNDIR, $rundir)
 
2458
    or mtr_error("kill_leftovers, can't open dir \"$rundir\": $!");
 
2459
  while ( my $elem= readdir(RUNDIR) )
 
2460
  {
 
2461
    # Only read pid from files that end with .pid
 
2462
    if ( $elem =~ /.*[.]pid$/ )
 
2463
    {
 
2464
      my $pidfile= "$rundir/$elem";
 
2465
      next unless -f $pidfile;
 
2466
      my $pid= mtr_fromfile($pidfile);
 
2467
      unlink($pidfile);
 
2468
      unless ($pid=~ /^(\d+)/){
 
2469
        # The pid was not a valid number
 
2470
        mtr_warning("Got invalid pid '$pid' from '$elem'");
 
2471
        next;
 
2472
      }
 
2473
      mtr_report(" - found old pid $pid in '$elem', killing it...");
 
2474
 
 
2475
      my $ret= kill("KILL", $pid);
 
2476
      if ($ret == 0) {
 
2477
        mtr_report("   process did not exist!");
 
2478
        next;
 
2479
      }
 
2480
 
 
2481
      my $check_counter= 100;
 
2482
      while ($ret > 0 and $check_counter--) {
 
2483
        mtr_milli_sleep(100);
 
2484
        $ret= kill(0, $pid);
 
2485
      }
 
2486
      mtr_report($check_counter ? "   ok!" : "   failed!");
 
2487
    }
 
2488
    else
 
2489
    {
 
2490
      mtr_warning("Found non pid file '$elem' in '$rundir'")
 
2491
        if -f "$rundir/$elem";
 
2492
    }
 
2493
  }
 
2494
  closedir(RUNDIR);
 
2495
}
 
2496
 
 
2497
#
 
2498
# Check that all the ports that are going to
 
2499
# be used are free
 
2500
#
 
2501
sub check_ports_free ($)
 
2502
{
 
2503
  my $bthread= shift;
 
2504
  my $portbase = $bthread * 10 + 10000;
 
2505
  for ($portbase..$portbase+9){
 
2506
    if (mtr_ping_port($_)){
 
2507
      mtr_report(" - 'localhost:$_' was not free");
 
2508
      return 0; # One port was not free
 
2509
    }
 
2510
  }
 
2511
 
 
2512
  return 1; # All ports free
 
2513
}
 
2514
 
 
2515
 
 
2516
sub initialize_servers {
 
2517
 
 
2518
  if ( using_extern() )
3030
2519
  {
3031
2520
    # Running against an already started server, if the specified
3032
2521
    # vardir does not already exist it should be created
3033
2522
    if ( ! -d $opt_vardir )
3034
2523
    {
3035
 
      mtr_report("Creating '$opt_vardir'");
3036
2524
      setup_vardir();
3037
2525
    }
3038
2526
    else
3042
2530
  }
3043
2531
  else
3044
2532
  {
3045
 
    kill_running_servers();
 
2533
    # Kill leftovers from previous run
 
2534
    # using any pidfiles found in var/run
 
2535
    kill_leftovers("$opt_vardir/run");
3046
2536
 
3047
2537
    if ( ! $opt_start_dirty )
3048
2538
    {
3049
2539
      remove_stale_vardir();
3050
2540
      setup_vardir();
3051
2541
 
3052
 
      mysql_install_db();
3053
 
      if ( $opt_force )
3054
 
      {
3055
 
        # Save a snapshot of the freshly installed db
3056
 
        # to make it possible to restore to a known point in time
3057
 
        save_installed_db();
 
2542
      mysql_install_db(default_mysqld(), "$opt_vardir/install.db");
 
2543
    }
 
2544
  }
 
2545
}
 
2546
 
 
2547
 
 
2548
#
 
2549
# Remove all newline characters expect after semicolon
 
2550
#
 
2551
sub sql_to_bootstrap {
 
2552
  my ($sql) = @_;
 
2553
  my @lines= split(/\n/, $sql);
 
2554
  my $result= "\n";
 
2555
  my $delimiter= ';';
 
2556
 
 
2557
  foreach my $line (@lines) {
 
2558
 
 
2559
    # Change current delimiter if line starts with "delimiter"
 
2560
    if ( $line =~ /^delimiter (.*)/ ) {
 
2561
      my $new= $1;
 
2562
      # Remove old delimiter from end of new
 
2563
      $new=~ s/\Q$delimiter\E$//;
 
2564
      $delimiter = $new;
 
2565
      mtr_debug("changed delimiter to $delimiter");
 
2566
      # No need to add the delimiter to result
 
2567
      next;
 
2568
    }
 
2569
 
 
2570
    # Add newline if line ends with $delimiter
 
2571
    # and convert the current delimiter to semicolon
 
2572
    if ( $line =~ /\Q$delimiter\E$/ ){
 
2573
      $line =~ s/\Q$delimiter\E$/;/;
 
2574
      $result.= "$line\n";
 
2575
      mtr_debug("Added default delimiter");
 
2576
      next;
 
2577
    }
 
2578
 
 
2579
    # Remove comments starting with --
 
2580
    if ( $line =~ /^\s*--/ ) {
 
2581
      mtr_debug("Discarded $line");
 
2582
      next;
 
2583
    }
 
2584
 
 
2585
    # Replace @HOSTNAME with localhost
 
2586
    $line=~ s/\'\@HOSTNAME\@\'/localhost/;
 
2587
 
 
2588
    # Default, just add the line without newline
 
2589
    # but with a space as separator
 
2590
    $result.= "$line ";
 
2591
 
 
2592
  }
 
2593
  return $result;
 
2594
}
 
2595
 
 
2596
 
 
2597
sub default_mysqld {
 
2598
  # Generate new config file from template
 
2599
  my $config= My::ConfigFactory->new_config
 
2600
    ( {
 
2601
       basedir         => $basedir,
 
2602
       template_path   => "include/default_my.cnf",
 
2603
       vardir          => $opt_vardir,
 
2604
       tmpdir          => $opt_tmpdir,
 
2605
       baseport        => 0,
 
2606
       user            => $opt_user,
 
2607
       password        => '',
3058
2608
      }
3059
 
    }
3060
 
  }
3061
 
  check_running_as_root();
3062
 
 
3063
 
  mtr_log_init("$opt_vardir/log/mysql-test-run.log");
3064
 
 
3065
 
}
3066
 
 
3067
 
sub mysql_install_db () {
3068
 
 
3069
 
  install_db('master', $master->[0]->{'path_myddir'});
3070
 
 
3071
 
  if ($max_master_num > 1)
3072
 
  {
3073
 
    copy_install_db('master', $master->[1]->{'path_myddir'});
3074
 
  }
3075
 
 
3076
 
  # Install the number of slave databses needed
3077
 
  for (my $idx= 0; $idx < $max_slave_num; $idx++)
3078
 
  {
3079
 
    copy_install_db("slave".($idx+1), $slave->[$idx]->{'path_myddir'});
3080
 
  }
3081
 
 
3082
 
  if ( ! $opt_skip_im )
3083
 
  {
3084
 
    im_prepare_env($instance_manager);
3085
 
  }
3086
 
 
3087
 
  my $cluster_started_ok= 1; # Assume it can be started
3088
 
 
3089
 
  my $cluster= $clusters->[0]; # Master cluster
3090
 
  if ($opt_skip_ndbcluster ||
3091
 
      $cluster->{'use_running'} ||
3092
 
      $cluster->{executable_setup_failed})
3093
 
  {
3094
 
    # Don't install master cluster
3095
 
  }
3096
 
  elsif (ndbcluster_start_install($cluster))
3097
 
  {
3098
 
    mtr_warning("Failed to start install of $cluster->{name}");
3099
 
    $cluster_started_ok= 0;
3100
 
  }
3101
 
 
3102
 
  $cluster= $clusters->[1]; # Slave cluster
3103
 
  if ($max_slave_num == 0 ||
3104
 
      $opt_skip_ndbcluster_slave ||
3105
 
      $cluster->{'use_running'} ||
3106
 
      $cluster->{executable_setup_failed})
3107
 
  {
3108
 
    # Don't install slave cluster
3109
 
  }
3110
 
  elsif (ndbcluster_start_install($cluster))
3111
 
  {
3112
 
    mtr_warning("Failed to start install of $cluster->{name}");
3113
 
    $cluster_started_ok= 0;
3114
 
  }
3115
 
 
3116
 
  foreach $cluster (@{$clusters})
3117
 
  {
3118
 
 
3119
 
    next if !$cluster->{'pid'};
3120
 
 
3121
 
    $cluster->{'installed_ok'}= 1; # Assume install suceeds
3122
 
 
3123
 
    if (ndbcluster_wait_started($cluster, ""))
3124
 
    {
3125
 
      # failed to install, disable usage and flag that its no ok
3126
 
      mtr_report("ndbcluster_install of $cluster->{'name'} failed");
3127
 
      $cluster->{"installed_ok"}= 0;
3128
 
 
3129
 
      $cluster_started_ok= 0;
3130
 
    }
3131
 
  }
3132
 
 
3133
 
  if ( ! $cluster_started_ok )
3134
 
  {
3135
 
    if ( $opt_force)
3136
 
    {
3137
 
      # Continue without cluster
3138
 
    }
3139
 
    else
3140
 
    {
3141
 
      mtr_error("To continue, re-run with '--force'.");
3142
 
    }
3143
 
  }
3144
 
 
3145
 
  return 0;
3146
 
}
3147
 
 
3148
 
 
3149
 
sub copy_install_db ($$) {
3150
 
  my $type=      shift;
3151
 
  my $data_dir=  shift;
3152
 
 
3153
 
  mtr_report("Installing \u$type Database");
3154
 
 
3155
 
  # Just copy the installed db from first master
3156
 
  mtr_copy_dir($master->[0]->{'path_myddir'}, $data_dir);
3157
 
 
3158
 
}
3159
 
 
3160
 
 
3161
 
sub install_db ($$) {
3162
 
  my $type=      shift;
3163
 
  my $data_dir=  shift;
3164
 
 
3165
 
  mtr_report("Installing \u$type Database");
3166
 
 
 
2609
    );
 
2610
 
 
2611
  my $mysqld= $config->group('mysqld.1')
 
2612
    or mtr_error("Couldn't find mysqld.1 in default config");
 
2613
  return $mysqld;
 
2614
}
 
2615
 
 
2616
 
 
2617
sub mysql_install_db {
 
2618
  my ($mysqld, $datadir)= @_;
 
2619
 
 
2620
  my $install_datadir= $datadir || $mysqld->value('datadir');
 
2621
  my $install_basedir= $mysqld->value('basedir');
 
2622
  my $install_lang= $mysqld->value('language');
 
2623
  my $install_chsdir= $mysqld->value('character-sets-dir');
 
2624
 
 
2625
  mtr_report("Installing system database...");
3167
2626
 
3168
2627
  my $args;
3169
2628
  mtr_init_args(\$args);
3170
2629
  mtr_add_arg($args, "--no-defaults");
3171
2630
  mtr_add_arg($args, "--bootstrap");
3172
 
  mtr_add_arg($args, "--basedir=%s", $path_my_basedir);
3173
 
  mtr_add_arg($args, "--datadir=%s", $data_dir);
 
2631
  mtr_add_arg($args, "--basedir=%s", $install_basedir);
 
2632
  mtr_add_arg($args, "--datadir=%s", $install_datadir);
3174
2633
  mtr_add_arg($args, "--loose-skip-innodb");
 
2634
  mtr_add_arg($args, "--loose-skip-falcon");
3175
2635
  mtr_add_arg($args, "--loose-skip-ndbcluster");
3176
 
  mtr_add_arg($args, "--tmpdir=.");
 
2636
  mtr_add_arg($args, "--tmpdir=%s", "$opt_vardir/tmp/");
3177
2637
  mtr_add_arg($args, "--core-file");
3178
2638
 
3179
2639
  if ( $opt_debug )
3180
2640
  {
3181
 
    mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap_%s.trace",
3182
 
                $path_vardir_trace, $type);
 
2641
    mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap.trace",
 
2642
                $path_vardir_trace);
3183
2643
  }
3184
2644
 
3185
 
  if ( ! $glob_netware )
3186
 
  {
3187
 
    mtr_add_arg($args, "--language=%s", $path_language);
3188
 
    mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
3189
 
  }
 
2645
  mtr_add_arg($args, "--language=%s", $install_lang);
 
2646
  mtr_add_arg($args, "--character-sets-dir=%s", $install_chsdir);
3190
2647
 
3191
2648
  # If DISABLE_GRANT_OPTIONS is defined when the server is compiled (e.g.,
3192
2649
  # configure --disable-grant-options), mysqld will not recognize the
3193
2650
  # --bootstrap or --skip-grant-tables options.  The user can set
3194
2651
  # MYSQLD_BOOTSTRAP to the full path to a mysqld which does accept
3195
2652
  # --bootstrap, to accommodate this.
3196
 
  my $exe_mysqld_bootstrap = $ENV{'MYSQLD_BOOTSTRAP'} || $exe_mysqld;
 
2653
  my $exe_mysqld_bootstrap =
 
2654
    $ENV{'MYSQLD_BOOTSTRAP'} || find_mysqld($install_basedir);
3197
2655
 
3198
2656
  # ----------------------------------------------------------------------
3199
2657
  # export MYSQLD_BOOTSTRAP_CMD variable containing <path>/mysqld <args>
3200
2658
  # ----------------------------------------------------------------------
3201
2659
  $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args);
3202
2660
 
 
2661
 
 
2662
 
3203
2663
  # ----------------------------------------------------------------------
3204
2664
  # Create the bootstrap.sql file
3205
2665
  # ----------------------------------------------------------------------
3206
2666
  my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql";
3207
2667
 
3208
 
  # Use the mysql database for system tables
3209
 
  mtr_tofile($bootstrap_sql_file, "use mysql");
3210
 
 
3211
 
  # Add the offical mysql system tables
3212
 
  # for a production system
3213
 
  mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables.sql",
3214
 
                         $bootstrap_sql_file);
3215
 
 
3216
 
  # Add the mysql system tables initial data
3217
 
  # for a production system
3218
 
  mtr_appendfile_to_file("$path_sql_dir/mysql_system_tables_data.sql",
3219
 
                         $bootstrap_sql_file);
3220
 
 
3221
 
  # Add test data for timezone - this is just a subset, on a real
3222
 
  # system these tables will be populated either by mysql_tzinfo_to_sql
3223
 
  # or by downloading the timezone table package from our website
3224
 
  mtr_appendfile_to_file("$path_sql_dir/mysql_test_data_timezone.sql",
3225
 
                         $bootstrap_sql_file);
3226
 
 
3227
 
  # Fill help tables, just an empty file when running from bk repo
3228
 
  # but will be replaced by a real fill_help_tables.sql when
3229
 
  # building the source dist
3230
 
  mtr_appendfile_to_file("$path_sql_dir/fill_help_tables.sql",
3231
 
                         $bootstrap_sql_file);
 
2668
  my $path_sql= my_find_file($install_basedir,
 
2669
                             ["mysql", "sql/share", "share/mysql",
 
2670
                              "share", "scripts"],
 
2671
                             "mysql_system_tables.sql",
 
2672
                             NOT_REQUIRED);
 
2673
 
 
2674
  if (-f $path_sql )
 
2675
  {
 
2676
    my $sql_dir= dirname($path_sql);
 
2677
    # Use the mysql database for system tables
 
2678
    mtr_tofile($bootstrap_sql_file, "use mysql\n");
 
2679
 
 
2680
    # Add the offical mysql system tables
 
2681
    # for a production system
 
2682
    mtr_appendfile_to_file("$sql_dir/mysql_system_tables.sql",
 
2683
                           $bootstrap_sql_file);
 
2684
 
 
2685
    # Add the mysql system tables initial data
 
2686
    # for a production system
 
2687
    mtr_appendfile_to_file("$sql_dir/mysql_system_tables_data.sql",
 
2688
                           $bootstrap_sql_file);
 
2689
 
 
2690
    # Add test data for timezone - this is just a subset, on a real
 
2691
    # system these tables will be populated either by mysql_tzinfo_to_sql
 
2692
    # or by downloading the timezone table package from our website
 
2693
    mtr_appendfile_to_file("$sql_dir/mysql_test_data_timezone.sql",
 
2694
                           $bootstrap_sql_file);
 
2695
 
 
2696
    # Fill help tables, just an empty file when running from bk repo
 
2697
    # but will be replaced by a real fill_help_tables.sql when
 
2698
    # building the source dist
 
2699
    mtr_appendfile_to_file("$sql_dir/fill_help_tables.sql",
 
2700
                           $bootstrap_sql_file);
 
2701
 
 
2702
  }
 
2703
  else
 
2704
  {
 
2705
    # Install db from init_db.sql that exist in early 5.1 and 5.0
 
2706
    # versions of MySQL
 
2707
    my $init_file= "$install_basedir/mysql-test/lib/init_db.sql";
 
2708
    mtr_report(" - from '$init_file'");
 
2709
    my $text= mtr_grab_file($init_file) or
 
2710
      mtr_error("Can't open '$init_file': $!");
 
2711
 
 
2712
    mtr_tofile($bootstrap_sql_file,
 
2713
               sql_to_bootstrap($text));
 
2714
  }
3232
2715
 
3233
2716
  # Remove anonymous users
3234
2717
  mtr_tofile($bootstrap_sql_file,
3235
 
             "DELETE FROM mysql.user where user= '';");
 
2718
             "DELETE FROM mysql.user where user= '';\n");
 
2719
 
 
2720
  # Create mtr database
 
2721
  mtr_tofile($bootstrap_sql_file,
 
2722
             "CREATE DATABASE mtr;\n");
 
2723
 
 
2724
  # Add help tables and data for warning detection and supression
 
2725
  mtr_tofile($bootstrap_sql_file,
 
2726
             sql_to_bootstrap(mtr_grab_file("include/mtr_warnings.sql")));
 
2727
 
 
2728
  # Add procedures for checking server is restored after testcase
 
2729
  mtr_tofile($bootstrap_sql_file,
 
2730
             sql_to_bootstrap(mtr_grab_file("include/mtr_check.sql")));
3236
2731
 
3237
2732
  # Log bootstrap command
3238
2733
  my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
3239
2734
  mtr_tofile($path_bootstrap_log,
3240
2735
             "$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
3241
2736
 
3242
 
 
3243
 
  if ( mtr_run($exe_mysqld_bootstrap, $args, $bootstrap_sql_file,
3244
 
               $path_bootstrap_log, $path_bootstrap_log,
3245
 
               "", { append_log_file => 1 }) != 0 )
3246
 
 
 
2737
  # Create directories mysql and test
 
2738
  mkpath("$install_datadir/mysql");
 
2739
  mkpath("$install_datadir/test");
 
2740
 
 
2741
  if ( My::SafeProcess->run
 
2742
       (
 
2743
        name          => "bootstrap",
 
2744
        path          => $exe_mysqld_bootstrap,
 
2745
        args          => \$args,
 
2746
        input         => $bootstrap_sql_file,
 
2747
        output        => $path_bootstrap_log,
 
2748
        error         => $path_bootstrap_log,
 
2749
        append        => 1,
 
2750
        verbose       => $opt_verbose,
 
2751
       ) != 0)
3247
2752
  {
3248
2753
    mtr_error("Error executing mysqld --bootstrap\n" .
3249
2754
              "Could not install system database from $bootstrap_sql_file\n" .
3252
2757
}
3253
2758
 
3254
2759
 
3255
 
sub im_prepare_env($) {
3256
 
  my $instance_manager = shift;
3257
 
 
3258
 
  im_create_passwd_file($instance_manager);
3259
 
  im_prepare_data_dir($instance_manager);
3260
 
}
3261
 
 
3262
 
 
3263
 
sub im_create_passwd_file($) {
3264
 
  my $instance_manager = shift;
3265
 
 
3266
 
  my $pwd_file_path = $instance_manager->{'password_file'};
3267
 
 
3268
 
  mtr_report("Creating IM password file ($pwd_file_path)");
3269
 
 
3270
 
  open(OUT, ">", $pwd_file_path)
3271
 
    or mtr_error("Can't write to $pwd_file_path: $!");
3272
 
 
3273
 
  print OUT $instance_manager->{'admin_login'}, ":",
3274
 
        $instance_manager->{'admin_sha1'}, "\n";
3275
 
 
3276
 
  close(OUT);
3277
 
}
3278
 
 
3279
 
 
3280
 
sub im_create_defaults_file($) {
3281
 
  my $instance_manager = shift;
3282
 
 
3283
 
  my $defaults_file = $instance_manager->{'defaults_file'};
3284
 
 
3285
 
  open(OUT, ">", $defaults_file)
3286
 
    or mtr_error("Can't write to $defaults_file: $!");
3287
 
 
3288
 
  print OUT <<EOF
3289
 
[mysql]
3290
 
 
3291
 
[manager]
3292
 
pid-file            = $instance_manager->{path_pid}
3293
 
angel-pid-file      = $instance_manager->{path_angel_pid}
3294
 
socket              = $instance_manager->{path_sock}
3295
 
port                = $instance_manager->{port}
3296
 
password-file       = $instance_manager->{password_file}
3297
 
default-mysqld-path = $exe_mysqld
3298
 
 
3299
 
EOF
3300
 
;
3301
 
 
3302
 
  foreach my $instance (@{$instance_manager->{'instances'}})
3303
 
  {
3304
 
    my $server_id = $instance->{'server_id'};
3305
 
 
3306
 
    print OUT <<EOF
3307
 
[mysqld$server_id]
3308
 
socket              = $instance->{path_sock}
3309
 
pid-file            = $instance->{path_pid}
3310
 
port                = $instance->{port}
3311
 
datadir             = $instance->{path_datadir}
3312
 
log                 = $instance->{path_datadir}/mysqld$server_id.log
3313
 
log-error           = $instance->{path_datadir}/mysqld$server_id.err.log
3314
 
log-slow-queries    = $instance->{path_datadir}/mysqld$server_id.slow.log
3315
 
language            = $path_language
3316
 
character-sets-dir  = $path_charsetsdir
3317
 
basedir             = $path_my_basedir
3318
 
server_id           = $server_id
3319
 
shutdown-delay      = 10
3320
 
skip-stack-trace
3321
 
loose-skip-innodb
3322
 
loose-skip-ndbcluster
3323
 
EOF
3324
 
;
3325
 
    if ( $mysql_version_id < 50100 )
3326
 
    {
3327
 
      print OUT "skip-bdb\n";
3328
 
    }
3329
 
    print OUT "nonguarded\n" if $instance->{'nonguarded'};
3330
 
    if ( $mysql_version_id >= 50100 )
3331
 
    {
3332
 
      print OUT "log-output=FILE\n" if $instance->{'old_log_format'};
3333
 
    }
3334
 
    print OUT "\n";
3335
 
  }
3336
 
 
3337
 
  close(OUT);
3338
 
}
3339
 
 
3340
 
 
3341
 
sub im_prepare_data_dir($) {
3342
 
  my $instance_manager = shift;
3343
 
 
3344
 
  foreach my $instance (@{$instance_manager->{'instances'}})
3345
 
  {
3346
 
    copy_install_db(
3347
 
      'im_mysqld_' . $instance->{'server_id'},
3348
 
      $instance->{'path_datadir'});
3349
 
  }
3350
 
}
3351
 
 
3352
 
 
3353
 
 
3354
 
#
3355
 
# Restore snapshot of the installed slave databases
3356
 
# if the snapshot exists
3357
 
#
3358
 
sub restore_slave_databases ($) {
3359
 
  my ($num_slaves)= @_;
3360
 
 
3361
 
  if ( -d $path_snapshot)
3362
 
  {
3363
 
    for (my $idx= 0; $idx < $num_slaves; $idx++)
3364
 
    {
3365
 
      my $data_dir= $slave->[$idx]->{'path_myddir'};
3366
 
      my $name= basename($data_dir);
3367
 
      mtr_rmtree($data_dir);
3368
 
      mtr_copy_dir("$path_snapshot/$name", $data_dir);
3369
 
    }
3370
 
  }
3371
 
}
3372
 
 
3373
 
 
3374
2760
sub run_testcase_check_skip_test($)
3375
2761
{
3376
2762
  my ($tinfo)= @_;
3384
2770
 
3385
2771
  if ( $tinfo->{'skip'} )
3386
2772
  {
3387
 
    mtr_report_test_name($tinfo);
3388
2773
    mtr_report_test_skipped($tinfo);
3389
2774
    return 1;
3390
2775
  }
3391
2776
 
3392
 
  if ($tinfo->{'ndb_test'})
3393
 
  {
3394
 
    foreach my $cluster (@{$clusters})
3395
 
    {
3396
 
      # Slave cluster is skipped and thus not
3397
 
      # installed, no need to perform checks
3398
 
      last if ($opt_skip_ndbcluster_slave and
3399
 
               $cluster->{'name'} eq 'Slave');
3400
 
 
3401
 
      # Using running cluster - no need
3402
 
      # to check if test should be skipped
3403
 
      # will be done by test itself
3404
 
      last if ($cluster->{'use_running'});
3405
 
 
3406
 
      # If test needs this cluster, check binaries was found ok
3407
 
      if ( $cluster->{'executable_setup_failed'} )
3408
 
      {
3409
 
        mtr_report_test_name($tinfo);
3410
 
        $tinfo->{comment}=
3411
 
          "Failed to find cluster binaries";
3412
 
        mtr_report_test_failed($tinfo);
3413
 
        return 1;
3414
 
      }
3415
 
 
3416
 
      # If test needs this cluster, check it was installed ok
3417
 
      if ( !$cluster->{'installed_ok'} )
3418
 
      {
3419
 
        mtr_report_test_name($tinfo);
3420
 
        $tinfo->{comment}=
3421
 
          "Cluster $cluster->{'name'} was not installed ok";
3422
 
        mtr_report_test_failed($tinfo);
3423
 
        return 1;
3424
 
      }
3425
 
 
3426
 
    }
3427
 
  }
3428
 
 
3429
 
  if ( $tinfo->{'component_id'} eq 'im' )
3430
 
  {
3431
 
      # If test needs im, check binaries was found ok
3432
 
    if ( $instance_manager->{'executable_setup_failed'} )
3433
 
    {
3434
 
      mtr_report_test_name($tinfo);
3435
 
      $tinfo->{comment}=
3436
 
        "Failed to find MySQL manager binaries";
3437
 
      mtr_report_test_failed($tinfo);
3438
 
      return 1;
3439
 
    }
3440
 
  }
3441
 
 
3442
2777
  return 0;
3443
2778
}
3444
2779
 
3445
2780
 
 
2781
sub run_query {
 
2782
  my ($tinfo, $mysqld, $query)= @_;
 
2783
 
 
2784
  my $args;
 
2785
  mtr_init_args(\$args);
 
2786
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
2787
  mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
 
2788
 
 
2789
  mtr_add_arg($args, "-e %s", $query);
 
2790
 
 
2791
  my $res= My::SafeProcess->run
 
2792
    (
 
2793
     name          => "run_query -> ".$mysqld->name(),
 
2794
     path          => $exe_mysql,
 
2795
     args          => \$args,
 
2796
     output        => '/dev/null',
 
2797
     error         => '/dev/null'
 
2798
    );
 
2799
 
 
2800
  return $res
 
2801
}
 
2802
 
 
2803
 
3446
2804
sub do_before_run_mysqltest($)
3447
2805
{
3448
2806
  my $tinfo= shift;
3449
 
  my $args;
3450
2807
 
3451
2808
  # Remove old files produced by mysqltest
3452
 
  my $base_file= mtr_match_extension($tinfo->{'result_file'},
3453
 
                                    "result"); # Trim extension
3454
 
  unlink("$base_file.reject");
3455
 
  unlink("$base_file.progress");
3456
 
  unlink("$base_file.log");
3457
 
  unlink("$base_file.warnings");
3458
 
 
3459
 
  if (!$opt_extern)
 
2809
  my $base_file= mtr_match_extension($tinfo->{result_file},
 
2810
                                     "result"); # Trim extension
 
2811
  if (defined $base_file ){
 
2812
    unlink("$base_file.reject");
 
2813
    unlink("$base_file.progress");
 
2814
    unlink("$base_file.log");
 
2815
    unlink("$base_file.warnings");
 
2816
  }
 
2817
 
 
2818
  if ( $mysql_version_id < 50000 ) {
 
2819
    # Set environment variable NDB_STATUS_OK to 1
 
2820
    # if script decided to run mysqltest cluster _is_ installed ok
 
2821
    $ENV{'NDB_STATUS_OK'} = "1";
 
2822
  } elsif ( $mysql_version_id < 50100 ) {
 
2823
    # Set environment variable NDB_STATUS_OK to YES
 
2824
    # if script decided to run mysqltest cluster _is_ installed ok
 
2825
    $ENV{'NDB_STATUS_OK'} = "YES";
 
2826
  }
 
2827
}
 
2828
 
 
2829
 
 
2830
#
 
2831
# Check all server for sideffects
 
2832
#
 
2833
# RETURN VALUE
 
2834
#  0 ok
 
2835
#  1 Check failed
 
2836
#  >1 Fatal errro
 
2837
 
 
2838
sub check_testcase($$)
 
2839
{
 
2840
  my ($tinfo, $mode)= @_;
 
2841
  my $tname= $tinfo->{name};
 
2842
 
 
2843
  # Start the mysqltest processes in parallel to save time
 
2844
  # also makes it possible to wait for any process to exit during the check
 
2845
  my %started;
 
2846
  foreach my $mysqld ( mysqlds() )
3460
2847
  {
3461
 
    if ( $mysql_version_id < 50000 ) {
3462
 
      # Set environment variable NDB_STATUS_OK to 1
3463
 
      # if script decided to run mysqltest cluster _is_ installed ok
3464
 
      $ENV{'NDB_STATUS_OK'} = "1";
3465
 
    } elsif ( $mysql_version_id < 50100 ) {
3466
 
      # Set environment variable NDB_STATUS_OK to YES
3467
 
      # if script decided to run mysqltest cluster _is_ installed ok
3468
 
      $ENV{'NDB_STATUS_OK'} = "YES";
 
2848
    if ( defined $mysqld->{'proc'} )
 
2849
    {
 
2850
      my $proc= start_check_testcase($tinfo, $mode, $mysqld);
 
2851
      $started{$proc->pid()}= $proc;
3469
2852
    }
3470
 
    if (defined $tinfo->{binlog_format} and  $mysql_version_id > 50100 )
3471
 
    {
3472
 
      # Dynamically switch binlog format of
3473
 
      # master, slave is always restarted
3474
 
      foreach my $server ( @$master )
 
2853
  }
 
2854
 
 
2855
  # Return immediately if no check proceess was started
 
2856
  return 0 unless ( keys %started );
 
2857
 
 
2858
  my $timeout_proc= My::SafeProcess->timer(check_timeout());
 
2859
 
 
2860
  while (1){
 
2861
    my $result;
 
2862
    my $proc= My::SafeProcess->wait_any();
 
2863
    mtr_report("Got $proc");
 
2864
 
 
2865
    if ( delete $started{$proc->pid()} ) {
 
2866
 
 
2867
      my $err_file= $proc->user_data();
 
2868
      my $base_file= mtr_match_extension($err_file, "err"); # Trim extension
 
2869
 
 
2870
      # One check testcase process returned
 
2871
      my $res= $proc->exit_status();
 
2872
 
 
2873
      if ( $res == 0){
 
2874
        # Check completed without problem
 
2875
 
 
2876
        # Remove the .err file the check generated
 
2877
        unlink($err_file);
 
2878
 
 
2879
        # Remove the .result file the check generated
 
2880
        if ( $mode eq 'after' ){
 
2881
          unlink("$base_file.result");
 
2882
        }
 
2883
 
 
2884
        if ( keys(%started) == 0){
 
2885
          # All checks completed
 
2886
 
 
2887
          $timeout_proc->kill();
 
2888
 
 
2889
          return 0;
 
2890
        }
 
2891
        # Wait for next process to exit
 
2892
        next;
 
2893
      }
 
2894
      else
3475
2895
      {
3476
 
        next unless ($server->{'pid'});
3477
 
 
3478
 
        mtr_init_args(\$args);
3479
 
        mtr_add_arg($args, "--no-defaults");
3480
 
        mtr_add_arg($args, "--user=root");
3481
 
        mtr_add_arg($args, "--port=$server->{'port'}");
3482
 
        mtr_add_arg($args, "--socket=$server->{'path_sock'}");
3483
 
 
3484
 
        my $sql= "include/set_binlog_format_".$tinfo->{binlog_format}.".sql";
3485
 
        mtr_verbose("Setting binlog format:", $tinfo->{binlog_format});
3486
 
        if (mtr_run($exe_mysql, $args, $sql, "", "", "") != 0)
3487
 
        {
3488
 
          mtr_error("Failed to switch binlog format");
3489
 
        }
3490
 
      }
3491
 
    }
3492
 
  }
3493
 
}
3494
 
 
3495
 
sub do_after_run_mysqltest($)
3496
 
{
3497
 
  my $tinfo= shift;
3498
 
 
3499
 
  # Save info from this testcase run to mysqltest.log
3500
 
  mtr_appendfile_to_file($path_current_test_log, $path_mysqltest_log)
3501
 
    if -f $path_current_test_log;
3502
 
  mtr_appendfile_to_file($path_timefile, $path_mysqltest_log)
3503
 
    if -f $path_timefile;
3504
 
}
3505
 
 
3506
 
 
3507
 
sub run_testcase_mark_logs($$)
3508
 
{
3509
 
  my ($tinfo, $log_msg)= @_;
3510
 
 
3511
 
  # Write a marker to all log files
3512
 
 
3513
 
  # The file indicating current test name
3514
 
  mtr_tonewfile($path_current_test_log, $log_msg);
3515
 
 
3516
 
  # each mysqld's .err file
3517
 
  foreach my $mysqld (@{$master}, @{$slave})
3518
 
  {
3519
 
    mtr_tofile($mysqld->{path_myerr}, $log_msg);
3520
 
  }
3521
 
 
3522
 
  if ( $tinfo->{'component_id'} eq 'im')
3523
 
  {
3524
 
    mtr_tofile($instance_manager->{path_err}, $log_msg);
3525
 
    mtr_tofile($instance_manager->{path_log}, $log_msg);
3526
 
  }
3527
 
 
3528
 
  # ndbcluster log file
3529
 
  mtr_tofile($path_ndb_testrun_log, $log_msg);
3530
 
 
3531
 
}
 
2896
        if ( $mode eq "after" and $res == 1 )
 
2897
        {
 
2898
          # Test failed, grab the report mysqltest has created
 
2899
          my $report= mtr_grab_file($err_file);
 
2900
          $tinfo->{check}.=
 
2901
            "\nMTR's internal check of the test case '$tname' failed.
 
2902
This means that the test case does not preserve the state that existed
 
2903
before the test case was executed.  Most likely the test case did not
 
2904
do a proper clean-up.
 
2905
This is the diff of the states of the servers before and after the
 
2906
test case was executed:\n";
 
2907
          $tinfo->{check}.= $report;
 
2908
 
 
2909
          # Check failed, mark the test case with that info
 
2910
          $tinfo->{'check_testcase_failed'}= 1;
 
2911
          $result= 1;
 
2912
        }
 
2913
        elsif ( $res )
 
2914
        {
 
2915
          my $report= mtr_grab_file($err_file);
 
2916
          $tinfo->{comment}.=
 
2917
            "Could not execute 'check-testcase' $mode ".
 
2918
              "testcase '$tname' (res: $res):\n";
 
2919
          $tinfo->{comment}.= $report;
 
2920
 
 
2921
          $result= 2;
 
2922
        }
 
2923
 
 
2924
        # Remove the .result file the check generated
 
2925
        unlink("$base_file.result");
 
2926
 
 
2927
      }
 
2928
    }
 
2929
    elsif ( $proc eq $timeout_proc ) {
 
2930
      $tinfo->{comment}.= "Timeout $timeout_proc for ".
 
2931
        "'check-testcase' expired after ".check_timeout().
 
2932
          " seconds";
 
2933
      $result= 4;
 
2934
    }
 
2935
    else {
 
2936
      # Unknown process returned, most likley a crash, abort everything
 
2937
      $tinfo->{comment}=
 
2938
        "The server $proc crashed while running ".
 
2939
        "'check testcase $mode test'";
 
2940
      $result= 3;
 
2941
    }
 
2942
 
 
2943
    # Kill any check processes still running
 
2944
    map($_->kill(), values(%started));
 
2945
 
 
2946
    $timeout_proc->kill();
 
2947
 
 
2948
    return $result;
 
2949
  }
 
2950
 
 
2951
  mtr_error("INTERNAL_ERROR: check_testcase");
 
2952
}
 
2953
 
 
2954
 
 
2955
# Start run mysqltest on one server
 
2956
#
 
2957
# RETURN VALUE
 
2958
#  0 OK
 
2959
#  1 Check failed
 
2960
#
 
2961
sub start_run_one ($$) {
 
2962
  my ($mysqld, $run)= @_;
 
2963
 
 
2964
  my $name= "$run-".$mysqld->name();
 
2965
 
 
2966
  my $args;
 
2967
  mtr_init_args(\$args);
 
2968
 
 
2969
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
2970
  mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
 
2971
 
 
2972
  mtr_add_arg($args, "--silent");
 
2973
  mtr_add_arg($args, "--skip-safemalloc");
 
2974
  mtr_add_arg($args, "--test-file=%s", "include/$run.test");
 
2975
 
 
2976
  my $errfile= "$opt_vardir/tmp/$name.err";
 
2977
  my $proc= My::SafeProcess->new
 
2978
    (
 
2979
     name          => $name,
 
2980
     path          => $exe_mysqltest,
 
2981
     error         => $errfile,
 
2982
     output        => $errfile,
 
2983
     args          => \$args,
 
2984
     user_data     => $errfile,
 
2985
     verbose       => $opt_verbose,
 
2986
    );
 
2987
  mtr_verbose("Started $proc");
 
2988
  return $proc;
 
2989
}
 
2990
 
 
2991
 
 
2992
#
 
2993
# Run script on all servers, collect results
 
2994
#
 
2995
# RETURN VALUE
 
2996
#  0 ok
 
2997
#  1 Failure
 
2998
 
 
2999
sub run_on_all($$)
 
3000
{
 
3001
  my ($tinfo, $run)= @_;
 
3002
 
 
3003
  # Start the mysqltest processes in parallel to save time
 
3004
  # also makes it possible to wait for any process to exit during the check
 
3005
  # and to have a timeout process
 
3006
  my %started;
 
3007
  foreach my $mysqld ( mysqlds() )
 
3008
  {
 
3009
    if ( defined $mysqld->{'proc'} )
 
3010
    {
 
3011
      my $proc= start_run_one($mysqld, $run);
 
3012
      $started{$proc->pid()}= $proc;
 
3013
    }
 
3014
  }
 
3015
 
 
3016
  # Return immediately if no check proceess was started
 
3017
  return 0 unless ( keys %started );
 
3018
 
 
3019
  my $timeout_proc= My::SafeProcess->timer(check_timeout());
 
3020
 
 
3021
  while (1){
 
3022
    my $result;
 
3023
    my $proc= My::SafeProcess->wait_any();
 
3024
    mtr_report("Got $proc");
 
3025
 
 
3026
    if ( delete $started{$proc->pid()} ) {
 
3027
 
 
3028
      # One mysqltest process returned
 
3029
      my $err_file= $proc->user_data();
 
3030
      my $res= $proc->exit_status();
 
3031
 
 
3032
      # Append the report from .err file
 
3033
      $tinfo->{comment}.= " == $err_file ==\n";
 
3034
      $tinfo->{comment}.= mtr_grab_file($err_file);
 
3035
      $tinfo->{comment}.= "\n";
 
3036
 
 
3037
      # Remove the .err file
 
3038
      unlink($err_file);
 
3039
 
 
3040
      if ( keys(%started) == 0){
 
3041
        # All completed
 
3042
        $timeout_proc->kill();
 
3043
        return 0;
 
3044
      }
 
3045
 
 
3046
      # Wait for next process to exit
 
3047
      next;
 
3048
    }
 
3049
    elsif ( $proc eq $timeout_proc ) {
 
3050
      $tinfo->{comment}.= "Timeout $timeout_proc for '$run' ".
 
3051
        "expired after ". check_timeout().
 
3052
          " seconds";
 
3053
    }
 
3054
    else {
 
3055
      # Unknown process returned, most likley a crash, abort everything
 
3056
      $tinfo->{comment}.=
 
3057
        "The server $proc crashed while running '$run'";
 
3058
    }
 
3059
 
 
3060
    # Kill any check processes still running
 
3061
    map($_->kill(), values(%started));
 
3062
 
 
3063
    $timeout_proc->kill();
 
3064
 
 
3065
    return 1;
 
3066
  }
 
3067
  mtr_error("INTERNAL_ERROR: run_on_all");
 
3068
}
 
3069
 
 
3070
 
 
3071
sub mark_log {
 
3072
  my ($log, $tinfo)= @_;
 
3073
  my $log_msg= "CURRENT_TEST: $tinfo->{name}\n";
 
3074
  mtr_tofile($log, $log_msg);
 
3075
}
 
3076
 
3532
3077
 
3533
3078
sub find_testcase_skipped_reason($)
3534
3079
{
3537
3082
  # Set default message
3538
3083
  $tinfo->{'comment'}= "Detected by testcase(no log file)";
3539
3084
 
3540
 
  # Open mysqltest-time(the mysqltest log file)
3541
 
  my $F= IO::File->new($path_timefile)
 
3085
  # Open the test log file
 
3086
  my $F= IO::File->new($path_current_testlog)
3542
3087
    or return;
3543
3088
  my $reason;
3544
3089
 
3553
3098
 
3554
3099
  if ( ! $reason )
3555
3100
  {
3556
 
    mtr_warning("Could not find reason for skipping test in $path_timefile");
 
3101
    mtr_warning("Could not find reason for skipping test in $path_current_testlog");
3557
3102
    $reason= "Detected by testcase(reason unknown) ";
3558
3103
  }
3559
3104
  $tinfo->{'comment'}= $reason;
3560
3105
}
3561
3106
 
3562
3107
 
3563
 
##############################################################################
3564
 
#
3565
 
#  Run a single test case
3566
 
#
3567
 
##############################################################################
3568
 
 
3569
 
# When we get here, we have already filtered out test cases that doesn't
3570
 
# apply to the current setup, for example if we use a running server, test
3571
 
# cases that restart the server are dropped. So this function should mostly
3572
 
# be about doing things, not a lot of logic.
3573
 
 
3574
 
# We don't start and kill the servers for each testcase. But some
3575
 
# testcases needs a restart, because they specify options to start
3576
 
# mysqld with. After that testcase, we need to restart again, to set
3577
 
# back the normal options.
 
3108
sub find_analyze_request
 
3109
{
 
3110
  # Open the test log file
 
3111
  my $F= IO::File->new($path_current_testlog)
 
3112
    or return;
 
3113
  my $analyze;
 
3114
 
 
3115
  while ( my $line= <$F> )
 
3116
  {
 
3117
    # Look for "reason: <reason for skipping test>"
 
3118
    if ( $line =~ /analyze: (.*)/ )
 
3119
    {
 
3120
      $analyze= $1;
 
3121
    }
 
3122
  }
 
3123
 
 
3124
  return $analyze;
 
3125
}
 
3126
 
 
3127
 
 
3128
# Return timezone value of tinfo or default value
 
3129
sub timezone {
 
3130
  my ($tinfo)= @_;
 
3131
  return $tinfo->{timezone} || "GMT-3";
 
3132
}
 
3133
 
 
3134
 
 
3135
# Storage for changed environment variables
 
3136
my %old_env;
 
3137
 
 
3138
#
 
3139
# Run a single test case
 
3140
#
 
3141
# RETURN VALUE
 
3142
#  0 OK
 
3143
#  > 0 failure
 
3144
#
3578
3145
 
3579
3146
sub run_testcase ($) {
3580
3147
  my $tinfo=  shift;
3581
3148
 
 
3149
  mtr_verbose("Running test:", $tinfo->{name});
 
3150
 
3582
3151
  # -------------------------------------------------------
3583
3152
  # Init variables that can change between each test case
3584
3153
  # -------------------------------------------------------
3585
 
 
3586
 
  $ENV{'TZ'}= $tinfo->{'timezone'};
3587
 
  mtr_verbose("Setting timezone: $tinfo->{'timezone'}");
3588
 
 
3589
 
  my $master_restart= run_testcase_need_master_restart($tinfo);
3590
 
  my $slave_restart= run_testcase_need_slave_restart($tinfo);
3591
 
 
3592
 
  if ($master_restart or $slave_restart)
3593
 
  {
3594
 
    # Can't restart a running server that may be in use
3595
 
    if ( $opt_extern )
3596
 
    {
3597
 
      mtr_report_test_name($tinfo);
3598
 
      $tinfo->{comment}= "Can't restart a running server";
3599
 
      mtr_report_test_skipped($tinfo);
3600
 
      return;
3601
 
    }
3602
 
 
3603
 
    run_testcase_stop_servers($tinfo, $master_restart, $slave_restart);
3604
 
  }
3605
 
 
3606
 
  # Write to all log files to indicate start of testcase
3607
 
  run_testcase_mark_logs($tinfo, "CURRENT_TEST: $tinfo->{name}\n");
3608
 
 
3609
 
  my $died= mtr_record_dead_children();
3610
 
  if ($died or $master_restart or $slave_restart)
3611
 
  {
3612
 
    if (run_testcase_start_servers($tinfo))
3613
 
    {
3614
 
      mtr_report_test_name($tinfo);
 
3154
  my $timezone= timezone($tinfo);
 
3155
  $ENV{'TZ'}= $timezone;
 
3156
  mtr_verbose("Setting timezone: $timezone");
 
3157
 
 
3158
  if ( ! using_extern() )
 
3159
  {
 
3160
    my @restart= servers_need_restart($tinfo);
 
3161
    if ( @restart != 0) {
 
3162
      stop_servers($tinfo, @restart );
 
3163
    }
 
3164
 
 
3165
    if ( started(all_servers()) == 0 )
 
3166
    {
 
3167
 
 
3168
      # Remove old datadirs
 
3169
      clean_datadir();
 
3170
 
 
3171
      # Restore old ENV
 
3172
      while (my ($option, $value)= each( %old_env )) {
 
3173
        if (defined $value){
 
3174
          mtr_verbose("Restoring $option to $value");
 
3175
          $ENV{$option}= $value;
 
3176
 
 
3177
        } else {
 
3178
          mtr_verbose("Removing $option");
 
3179
          delete($ENV{$option});
 
3180
        }
 
3181
      }
 
3182
      %old_env= ();
 
3183
 
 
3184
      mtr_verbose("Generating my.cnf from '$tinfo->{template_path}'");
 
3185
 
 
3186
      # Generate new config file from template
 
3187
      $config= My::ConfigFactory->new_config
 
3188
        ( {
 
3189
           basedir         => $basedir,
 
3190
           template_path   => $tinfo->{template_path},
 
3191
           extra_template_path => $tinfo->{extra_template_path},
 
3192
           vardir          => $opt_vardir,
 
3193
           tmpdir          => $opt_tmpdir,
 
3194
           baseport        => $baseport,
 
3195
           #hosts          => [ 'host1', 'host2' ],
 
3196
           user            => $opt_user,
 
3197
           password        => '',
 
3198
           ssl             => $opt_ssl_supported,
 
3199
           embedded        => $opt_embedded_server,
 
3200
          }
 
3201
        );
 
3202
 
 
3203
      # Write the new my.cnf
 
3204
      $config->save($path_config_file);
 
3205
 
 
3206
      # Remember current config so a restart can occur when a test need
 
3207
      # to use a different one
 
3208
      $current_config_name= $tinfo->{template_path};
 
3209
 
 
3210
      #
 
3211
      # Set variables in the ENV section
 
3212
      #
 
3213
      foreach my $option ($config->options_in_group("ENV"))
 
3214
      {
 
3215
        # Save old value to restore it before next time
 
3216
        $old_env{$option->name()}= $ENV{$option->name()};
 
3217
 
 
3218
        mtr_verbose($option->name(), "=",$option->value());
 
3219
        $ENV{$option->name()}= $option->value();
 
3220
      }
 
3221
    }
 
3222
 
 
3223
    # Write start of testcase to log
 
3224
    mark_log($path_current_testlog, $tinfo);
 
3225
 
 
3226
    if (start_servers($tinfo))
 
3227
    {
3615
3228
      report_failure_and_restart($tinfo);
3616
3229
      return 1;
3617
3230
    }
3618
3231
  }
3619
 
  elsif ($glob_use_embedded_server)
3620
 
  {
3621
 
    run_master_init_script($tinfo);
3622
 
  }
3623
3232
 
3624
 
  # ----------------------------------------------------------------------
3625
 
  # If --start-and-exit or --start-dirty given, stop here to let user manually
 
3233
  # --------------------------------------------------------------------
 
3234
  # If --start or --start-dirty given, stop here to let user manually
3626
3235
  # run tests
3627
3236
  # ----------------------------------------------------------------------
3628
 
  if ( $opt_start_and_exit or $opt_start_dirty )
3629
 
  {
3630
 
    mtr_timer_stop_all($glob_timers);
3631
 
    mtr_report("\nServers started, exiting");
3632
 
    if ($glob_win32_perl)
3633
 
    {
3634
 
      #ActiveState perl hangs  when using normal exit, use  POSIX::_exit instead
3635
 
      use POSIX qw[ _exit ]; 
3636
 
      POSIX::_exit(0);
3637
 
    }
3638
 
    else
3639
 
    {
3640
 
      exit(0);
3641
 
    }
3642
 
  }
3643
 
 
3644
 
  {
3645
 
    do_before_run_mysqltest($tinfo);
3646
 
 
3647
 
    my $res= run_mysqltest($tinfo);
3648
 
    mtr_report_test_name($tinfo);
3649
 
 
3650
 
    do_after_run_mysqltest($tinfo);
3651
 
 
3652
 
    if ( $res == 0 )
3653
 
    {
3654
 
      mtr_report_test_passed($tinfo);
3655
 
    }
3656
 
    elsif ( $res == 62 )
3657
 
    {
3658
 
      # Testcase itself tell us to skip this one
3659
 
 
3660
 
      # Try to get reason from mysqltest.log
3661
 
      find_testcase_skipped_reason($tinfo);
3662
 
      mtr_report_test_skipped($tinfo);
3663
 
    }
3664
 
    elsif ( $res == 63 )
3665
 
    {
3666
 
      $tinfo->{'timeout'}= 1;           # Mark as timeout
3667
 
      report_failure_and_restart($tinfo);
3668
 
    }
3669
 
    elsif ( $res == 1 )
3670
 
    {
3671
 
      # Test case failure reported by mysqltest
3672
 
      report_failure_and_restart($tinfo);
3673
 
    }
3674
 
    else
3675
 
    {
3676
 
      # mysqltest failed, probably crashed
3677
 
      $tinfo->{comment}=
3678
 
        "mysqltest returned unexpected code $res, it has probably crashed";
3679
 
      report_failure_and_restart($tinfo);
3680
 
    }
3681
 
  }
3682
 
 
3683
 
  # Remove the file that mysqltest writes info to
3684
 
  unlink($path_timefile);
3685
 
 
3686
 
  # ----------------------------------------------------------------------
3687
 
  # Stop Instance Manager if we are processing an IM-test case.
3688
 
  # ----------------------------------------------------------------------
3689
 
  if ( $tinfo->{'component_id'} eq 'im' and
3690
 
       !mtr_im_stop($instance_manager, $tinfo->{'name'}))
3691
 
  {
3692
 
    mtr_error("Failed to stop Instance Manager.")
3693
 
  }
3694
 
}
3695
 
 
3696
 
 
3697
 
#
3698
 
# Save a snapshot of the installed test db(s)
3699
 
# I.e take a snapshot of the var/ dir
3700
 
#
3701
 
sub save_installed_db () {
3702
 
 
3703
 
  mtr_report("Saving snapshot of installed databases");
3704
 
  mtr_rmtree($path_snapshot);
3705
 
 
3706
 
  foreach my $data_dir (@data_dir_lst)
3707
 
  {
3708
 
    my $name= basename($data_dir);
3709
 
    mtr_copy_dir("$data_dir", "$path_snapshot/$name");
3710
 
  }
3711
 
}
3712
 
 
3713
 
 
3714
 
#
3715
 
# Save any interesting files in the data_dir
3716
 
# before the data dir is removed.
3717
 
#
3718
 
sub save_files_before_restore($$) {
3719
 
  my $test_name= shift;
3720
 
  my $data_dir= shift;
3721
 
  my $save_name= "$opt_vardir/log/$test_name";
3722
 
 
3723
 
  # Look for core files
3724
 
  foreach my $core_file ( glob("$data_dir/core*") )
3725
 
  {
3726
 
    last if $opt_max_save_core > 0 && $num_saved_cores >= $opt_max_save_core;
3727
 
    my $core_name= basename($core_file);
3728
 
    mtr_report("Saving $core_name");
3729
 
    mkdir($save_name) if ! -d $save_name;
3730
 
    rename("$core_file", "$save_name/$core_name");
3731
 
    ++$num_saved_cores;
3732
 
  }
3733
 
}
3734
 
 
3735
 
 
3736
 
#
3737
 
# Restore snapshot of the installed test db(s)
3738
 
# if the snapshot exists
3739
 
#
3740
 
sub restore_installed_db ($) {
3741
 
  my $test_name= shift;
3742
 
 
3743
 
  if ( -d $path_snapshot)
3744
 
  {
3745
 
    mtr_report("Restoring snapshot of databases");
3746
 
 
3747
 
    foreach my $data_dir (@data_dir_lst)
3748
 
    {
3749
 
      my $name= basename($data_dir);
3750
 
      save_files_before_restore($test_name, $data_dir);
3751
 
      mtr_rmtree("$data_dir");
3752
 
      mtr_copy_dir("$path_snapshot/$name", "$data_dir");
3753
 
    }
3754
 
 
3755
 
    # Remove the ndb_*_fs dirs for all ndbd nodes
3756
 
    # forcing a clean start of ndb
3757
 
    foreach my $cluster (@{$clusters})
3758
 
    {
3759
 
      foreach my $ndbd (@{$cluster->{'ndbds'}})
3760
 
      {
3761
 
        mtr_rmtree("$ndbd->{'path_fs'}" );
3762
 
      }
3763
 
    }
3764
 
  }
3765
 
  else
3766
 
  {
3767
 
    # No snapshot existed
3768
 
    mtr_error("No snapshot existed");
3769
 
  }
3770
 
}
 
3237
  if ( $opt_start or $opt_start_dirty )
 
3238
  {
 
3239
    mtr_print("\nStarted", started(all_servers()));
 
3240
    mtr_print("Waiting for server(s) to exit...");
 
3241
    my $proc= My::SafeProcess->wait_any();
 
3242
    if ( grep($proc eq $_, started(all_servers())) )
 
3243
    {
 
3244
      mtr_print("Server $proc died");
 
3245
      exit(1);
 
3246
    }
 
3247
    mtr_print("Unknown process $proc died");
 
3248
    exit(1);
 
3249
  }
 
3250
 
 
3251
  my $test_timeout_proc= My::SafeProcess->timer(testcase_timeout());
 
3252
 
 
3253
  do_before_run_mysqltest($tinfo);
 
3254
 
 
3255
  if ( $opt_check_testcases and check_testcase($tinfo, "before") ){
 
3256
    # Failed to record state of server or server crashed
 
3257
    report_failure_and_restart($tinfo);
 
3258
 
 
3259
    # Stop the test case timer
 
3260
    $test_timeout_proc->kill();
 
3261
 
 
3262
    return 1;
 
3263
  }
 
3264
 
 
3265
  my $test= start_mysqltest($tinfo);
 
3266
 
 
3267
  while (1)
 
3268
  {
 
3269
    my $proc= My::SafeProcess->wait_any();
 
3270
    unless ( defined $proc )
 
3271
    {
 
3272
      mtr_error("wait_any failed");
 
3273
    }
 
3274
    mtr_verbose("Got $proc");
 
3275
 
 
3276
    # ----------------------------------------------------
 
3277
    # Was it the test program that exited
 
3278
    # ----------------------------------------------------
 
3279
    if ($proc eq $test)
 
3280
    {
 
3281
      # Stop the test case timer
 
3282
      $test_timeout_proc->kill();
 
3283
 
 
3284
      my $res= $test->exit_status();
 
3285
 
 
3286
      if ($res == 0 and $opt_warnings and check_warnings($tinfo) )
 
3287
      {
 
3288
        # Test case suceeded, but it has produced unexpected
 
3289
        # warnings, continue in $res == 1
 
3290
        $res= 1;
 
3291
      }
 
3292
 
 
3293
      if ( $res == 0 )
 
3294
      {
 
3295
        my $check_res;
 
3296
        if ( $opt_check_testcases and
 
3297
             $check_res= check_testcase($tinfo, "after"))
 
3298
        {
 
3299
          if ($check_res == 1) {
 
3300
            # Test case had sideeffects, not fatal error, just continue
 
3301
            stop_all_servers();
 
3302
            mtr_report("Resuming tests...\n");
 
3303
          }
 
3304
          else {
 
3305
            # Test case check failed fatally, probably a server crashed
 
3306
            report_failure_and_restart($tinfo);
 
3307
            return 1;
 
3308
          }
 
3309
        }
 
3310
        mtr_report_test_passed($tinfo);
 
3311
      }
 
3312
      elsif ( $res == 62 )
 
3313
      {
 
3314
        # Testcase itself tell us to skip this one
 
3315
        $tinfo->{skip_detected_by_test}= 1;
 
3316
        # Try to get reason from test log file
 
3317
        find_testcase_skipped_reason($tinfo);
 
3318
        mtr_report_test_skipped($tinfo);
 
3319
      }
 
3320
      elsif ( $res == 65 )
 
3321
      {
 
3322
        # Testprogram killed by signal
 
3323
        $tinfo->{comment}=
 
3324
          "testprogram crashed(returned code $res)";
 
3325
        report_failure_and_restart($tinfo);
 
3326
      }
 
3327
      elsif ( $res == 1 )
 
3328
      {
 
3329
        # Check if the test tool requests that
 
3330
        # an analyze script should be run
 
3331
        my $analyze= find_analyze_request();
 
3332
        if ($analyze){
 
3333
          run_on_all($tinfo, "analyze-$analyze");
 
3334
        }
 
3335
 
 
3336
        # Test case failure reported by mysqltest
 
3337
        report_failure_and_restart($tinfo);
 
3338
      }
 
3339
      else
 
3340
      {
 
3341
        # mysqltest failed, probably crashed
 
3342
        $tinfo->{comment}=
 
3343
          "mysqltest failed with unexpected return code $res";
 
3344
        report_failure_and_restart($tinfo);
 
3345
      }
 
3346
 
 
3347
      # Save info from this testcase run to mysqltest.log
 
3348
      if( -f $path_current_testlog)
 
3349
      {
 
3350
        mtr_appendfile_to_file($path_current_testlog, $path_testlog);
 
3351
        unlink($path_current_testlog);
 
3352
      }
 
3353
 
 
3354
      return ($res == 62) ? 0 : $res;
 
3355
 
 
3356
    }
 
3357
 
 
3358
    # ----------------------------------------------------
 
3359
    # Check if it was an expected crash
 
3360
    # ----------------------------------------------------
 
3361
    if ( check_expected_crash_and_restart($proc) )
 
3362
    {
 
3363
      next;
 
3364
    }
 
3365
 
 
3366
    # ----------------------------------------------------
 
3367
    # Stop the test case timer
 
3368
    # ----------------------------------------------------
 
3369
    $test_timeout_proc->kill();
 
3370
 
 
3371
    # ----------------------------------------------------
 
3372
    # Check if it was a server that died
 
3373
    # ----------------------------------------------------
 
3374
    if ( grep($proc eq $_, started(all_servers())) )
 
3375
    {
 
3376
      # Server failed, probably crashed
 
3377
      $tinfo->{comment}=
 
3378
        "Server $proc failed during test run";
 
3379
 
 
3380
      # ----------------------------------------------------
 
3381
      # It's not mysqltest that has exited, kill it
 
3382
      # ----------------------------------------------------
 
3383
      $test->kill();
 
3384
 
 
3385
      report_failure_and_restart($tinfo);
 
3386
      return 1;
 
3387
    }
 
3388
 
 
3389
    # Try to dump core for mysqltest and all servers
 
3390
    foreach my $proc ($test, started(all_servers())) 
 
3391
    {
 
3392
      mtr_print("Trying to dump core for $proc");
 
3393
      if ($proc->dump_core())
 
3394
      {
 
3395
        $proc->wait_one(20);
 
3396
      }
 
3397
    }
 
3398
 
 
3399
    # ----------------------------------------------------
 
3400
    # It's not mysqltest that has exited, kill it
 
3401
    # ----------------------------------------------------
 
3402
    $test->kill();
 
3403
 
 
3404
    # ----------------------------------------------------
 
3405
    # Check if testcase timer expired
 
3406
    # ----------------------------------------------------
 
3407
    if ( $proc eq $test_timeout_proc )
 
3408
    {
 
3409
      my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log";
 
3410
      $tinfo->{comment}=
 
3411
        "Test case timeout after ".testcase_timeout().
 
3412
          " seconds\n\n";
 
3413
      # Add 20 last executed commands from test case log file
 
3414
      if  (-e $log_file_name)
 
3415
      {
 
3416
        $tinfo->{comment}.=
 
3417
           "== $log_file_name == \n".
 
3418
             mtr_lastlinesfromfile($log_file_name, 20)."\n";
 
3419
      }
 
3420
      $tinfo->{'timeout'}= testcase_timeout(); # Mark as timeout
 
3421
      run_on_all($tinfo, 'analyze-timeout');
 
3422
 
 
3423
      report_failure_and_restart($tinfo);
 
3424
      return 1;
 
3425
    }
 
3426
 
 
3427
    mtr_error("Unhandled process $proc exited");
 
3428
  }
 
3429
  mtr_error("Should never come here");
 
3430
}
 
3431
 
 
3432
 
 
3433
#
 
3434
# Perform a rough examination of the servers
 
3435
# error log and write all lines that look
 
3436
# suspicious into $error_log.warnings
 
3437
#
 
3438
sub extract_warning_lines ($) {
 
3439
  my ($error_log) = @_;
 
3440
 
 
3441
  # Open the servers .err log file and read all lines
 
3442
  # belonging to current tets into @lines
 
3443
  my $Ferr = IO::File->new($error_log)
 
3444
    or mtr_error("Could not open file '$error_log' for reading: $!");
 
3445
 
 
3446
  my @lines;
 
3447
  while ( my $line = <$Ferr> )
 
3448
  {
 
3449
    if ( $line =~ /^CURRENT_TEST:/ )
 
3450
    {
 
3451
      # Throw away lines from previous tests
 
3452
      @lines = ();
 
3453
    }
 
3454
    push(@lines, $line);
 
3455
  }
 
3456
  $Ferr = undef; # Close error log file
 
3457
 
 
3458
  # mysql_client_test.test sends a COM_DEBUG packet to the server
 
3459
  # to provoke a SAFEMALLOC leak report, ignore any warnings
 
3460
  # between "Begin/end safemalloc memory dump"
 
3461
  if ( grep(/Begin safemalloc memory dump:/, @lines) > 0)
 
3462
  {
 
3463
    my $discard_lines= 1;
 
3464
    foreach my $line ( @lines )
 
3465
    {
 
3466
      if ($line =~ /Begin safemalloc memory dump:/){
 
3467
        $discard_lines = 1;
 
3468
      } elsif ($line =~ /End safemalloc memory dump./){
 
3469
        $discard_lines = 0;
 
3470
      }
 
3471
 
 
3472
      if ($discard_lines){
 
3473
        $line = "ignored";
 
3474
      }
 
3475
    }
 
3476
  }
 
3477
 
 
3478
  # Write all suspicious lines to $error_log.warnings file
 
3479
  my $warning_log = "$error_log.warnings";
 
3480
  my $Fwarn = IO::File->new($warning_log, "w")
 
3481
    or die("Could not open file '$warning_log' for writing: $!");
 
3482
  print $Fwarn "Suspicious lines from $error_log\n";
 
3483
 
 
3484
  my @patterns =
 
3485
    (
 
3486
     # The patterns for detection of [Warning] and [ERROR]
 
3487
     # in the server log files have been faulty for a longer period
 
3488
     # and correcting them shows a few additional harmless warnings.
 
3489
     # Thus those patterns are temporarily removed from the list
 
3490
     # of patterns. For more info see BUG#42408
 
3491
     # qr/^Warning:|mysqld: Warning|\[Warning\]/,
 
3492
     # qr/^Error:|\[ERROR\]/,
 
3493
     qr/^Warning:|mysqld: Warning/,
 
3494
     qr/^Error:/,
 
3495
     qr/^==.* at 0x/,
 
3496
     qr/InnoDB: Warning|InnoDB: Error/,
 
3497
     qr/^safe_mutex:|allocated at line/,
 
3498
     qr/missing DBUG_RETURN/,
 
3499
     qr/Attempting backtrace/,
 
3500
     qr/Assertion .* failed/,
 
3501
    );
 
3502
 
 
3503
  foreach my $line ( @lines )
 
3504
  {
 
3505
    foreach my $pat ( @patterns )
 
3506
    {
 
3507
      if ( $line =~ /$pat/ )
 
3508
      {
 
3509
        print $Fwarn $line;
 
3510
        last;
 
3511
      }
 
3512
    }
 
3513
  }
 
3514
  $Fwarn = undef; # Close file
 
3515
 
 
3516
}
 
3517
 
 
3518
 
 
3519
# Run include/check-warnings.test
 
3520
#
 
3521
# RETURN VALUE
 
3522
#  0 OK
 
3523
#  1 Check failed
 
3524
#
 
3525
sub start_check_warnings ($$) {
 
3526
  my $tinfo=    shift;
 
3527
  my $mysqld=   shift;
 
3528
 
 
3529
  my $name= "warnings-".$mysqld->name();
 
3530
 
 
3531
  my $log_error= $mysqld->value('#log-error');
 
3532
  # To be communicated to the test
 
3533
  $ENV{MTR_LOG_ERROR}= $log_error;
 
3534
  extract_warning_lines($log_error);
 
3535
 
 
3536
  my $args;
 
3537
  mtr_init_args(\$args);
 
3538
 
 
3539
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
3540
  mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
 
3541
 
 
3542
  mtr_add_arg($args, "--skip-safemalloc");
 
3543
  mtr_add_arg($args, "--test-file=%s", "include/check-warnings.test");
 
3544
  mtr_add_arg($args, "--verbose");
 
3545
 
 
3546
  if ( $opt_embedded_server )
 
3547
  {
 
3548
 
 
3549
    # Get the args needed for the embedded server
 
3550
    # and append them to args prefixed
 
3551
    # with --sever-arg=
 
3552
 
 
3553
    my $mysqld=  $config->group('embedded')
 
3554
      or mtr_error("Could not get [embedded] section");
 
3555
 
 
3556
    my $mysqld_args;
 
3557
    mtr_init_args(\$mysqld_args);
 
3558
    my $extra_opts= get_extra_opts($mysqld, $tinfo);
 
3559
    mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
 
3560
    mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
 
3561
  }
 
3562
 
 
3563
  my $errfile= "$opt_vardir/tmp/$name.err";
 
3564
  my $proc= My::SafeProcess->new
 
3565
    (
 
3566
     name          => $name,
 
3567
     path          => $exe_mysqltest,
 
3568
     error         => $errfile,
 
3569
     output        => $errfile,
 
3570
     args          => \$args,
 
3571
     user_data     => $errfile,
 
3572
     verbose       => $opt_verbose,
 
3573
    );
 
3574
  mtr_verbose("Started $proc");
 
3575
  return $proc;
 
3576
}
 
3577
 
 
3578
 
 
3579
#
 
3580
# Loop through our list of processes and check the error log
 
3581
# for unexepcted errors and warnings
 
3582
#
 
3583
sub check_warnings ($) {
 
3584
  my ($tinfo)= @_;
 
3585
  my $res= 0;
 
3586
 
 
3587
  my $tname= $tinfo->{name};
 
3588
 
 
3589
  # Clear previous warnings
 
3590
  delete($tinfo->{warnings});
 
3591
 
 
3592
  # Start the mysqltest processes in parallel to save time
 
3593
  # also makes it possible to wait for any process to exit during the check
 
3594
  my %started;
 
3595
  foreach my $mysqld ( mysqlds() )
 
3596
  {
 
3597
    if ( defined $mysqld->{'proc'} )
 
3598
    {
 
3599
      my $proc= start_check_warnings($tinfo, $mysqld);
 
3600
      $started{$proc->pid()}= $proc;
 
3601
    }
 
3602
  }
 
3603
 
 
3604
  # Return immediately if no check proceess was started
 
3605
  return 0 unless ( keys %started );
 
3606
 
 
3607
  my $timeout_proc= My::SafeProcess->timer(check_timeout());
 
3608
 
 
3609
  while (1){
 
3610
    my $result= 0;
 
3611
    my $proc= My::SafeProcess->wait_any();
 
3612
    mtr_report("Got $proc");
 
3613
 
 
3614
    if ( delete $started{$proc->pid()} ) {
 
3615
      # One check warning process returned
 
3616
      my $res= $proc->exit_status();
 
3617
      my $err_file= $proc->user_data();
 
3618
 
 
3619
      if ( $res == 0 or $res == 62 ){
 
3620
 
 
3621
        if ( $res == 0 ) {
 
3622
          # Check completed with problem
 
3623
          my $report= mtr_grab_file($err_file);
 
3624
          # Log to var/log/warnings file
 
3625
          mtr_tofile("$opt_vardir/log/warnings",
 
3626
                     $tname."\n".$report);
 
3627
 
 
3628
          $tinfo->{'warnings'}.= $report;
 
3629
          $result= 1;
 
3630
        }
 
3631
 
 
3632
        if ( $res == 62 ) {
 
3633
          # Test case was ok and called "skip"
 
3634
          # Remove the .err file the check generated
 
3635
          unlink($err_file);
 
3636
        }
 
3637
 
 
3638
        if ( keys(%started) == 0){
 
3639
          # All checks completed
 
3640
 
 
3641
          $timeout_proc->kill();
 
3642
 
 
3643
          return $result;
 
3644
        }
 
3645
        # Wait for next process to exit
 
3646
        next;
 
3647
      }
 
3648
      else
 
3649
      {
 
3650
        my $report= mtr_grab_file($err_file);
 
3651
        $tinfo->{comment}.=
 
3652
          "Could not execute 'check-warnings' for ".
 
3653
            "testcase '$tname' (res: $res):\n";
 
3654
        $tinfo->{comment}.= $report;
 
3655
 
 
3656
        $result= 2;
 
3657
      }
 
3658
    }
 
3659
    elsif ( $proc eq $timeout_proc ) {
 
3660
      $tinfo->{comment}.= "Timeout $timeout_proc for ".
 
3661
        "'check warnings' expired after ".check_timeout().
 
3662
          " seconds";
 
3663
      $result= 4;
 
3664
    }
 
3665
    else {
 
3666
      # Unknown process returned, most likley a crash, abort everything
 
3667
      $tinfo->{comment}=
 
3668
        "The server $proc crashed while running 'check warnings'";
 
3669
      $result= 3;
 
3670
    }
 
3671
 
 
3672
    # Kill any check processes still running
 
3673
    map($_->kill(), values(%started));
 
3674
 
 
3675
    $timeout_proc->kill();
 
3676
 
 
3677
    return $result;
 
3678
  }
 
3679
 
 
3680
  mtr_error("INTERNAL_ERROR: check_warnings");
 
3681
}
 
3682
 
 
3683
 
 
3684
#
 
3685
# Loop through our list of processes and look for and entry
 
3686
# with the provided pid, if found check for the file indicating
 
3687
# expected crash and restart it.
 
3688
#
 
3689
sub check_expected_crash_and_restart {
 
3690
  my ($proc)= @_;
 
3691
 
 
3692
  foreach my $mysqld ( mysqlds() )
 
3693
  {
 
3694
    next unless ( $mysqld->{proc} eq $proc );
 
3695
 
 
3696
    # Check if crash expected by looking at the .expect file
 
3697
    # in var/tmp
 
3698
    my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect";
 
3699
    if ( -f $expect_file )
 
3700
    {
 
3701
      mtr_verbose("Crash was expected, file '$expect_file' exists");
 
3702
 
 
3703
      while (1){
 
3704
 
 
3705
        # If last line in expect file starts with "wait"
 
3706
        # sleep a little and try again, thus allowing the
 
3707
        # test script to control when the server should start
 
3708
        # up again
 
3709
        my $last_line= mtr_lastlinesfromfile($expect_file, 1);
 
3710
        if ($last_line =~ /^wait/ )
 
3711
        {
 
3712
          mtr_verbose("Test says wait before restart");
 
3713
          mtr_milli_sleep(100);
 
3714
          next;
 
3715
        }
 
3716
 
 
3717
        unlink($expect_file);
 
3718
 
 
3719
        # Start server with same settings as last time
 
3720
        mysqld_start($mysqld, $mysqld->{'started_opts'});
 
3721
 
 
3722
        last;
 
3723
      }
 
3724
    }
 
3725
 
 
3726
    return 1;
 
3727
  }
 
3728
 
 
3729
  # Not an expected crash
 
3730
  return 0;
 
3731
}
 
3732
 
 
3733
 
 
3734
# Remove all files and subdirectories of a directory
 
3735
sub clean_dir {
 
3736
  my ($dir)= @_;
 
3737
  mtr_verbose("clean_dir: $dir");
 
3738
  finddepth(
 
3739
          { no_chdir => 1,
 
3740
            wanted => sub {
 
3741
              if (-d $_){
 
3742
                # A dir
 
3743
                if ($_ eq $dir){
 
3744
                  # The dir to clean
 
3745
                  return;
 
3746
                } else {
 
3747
                  mtr_verbose("rmdir: '$_'");
 
3748
                  rmdir($_) or mtr_warning("rmdir($_) failed: $!");
 
3749
                }
 
3750
              } else {
 
3751
                # Hopefully a file
 
3752
                mtr_verbose("unlink: '$_'");
 
3753
                unlink($_) or mtr_warning("unlink($_) failed: $!");
 
3754
              }
 
3755
            }
 
3756
          },
 
3757
            $dir);
 
3758
}
 
3759
 
 
3760
 
 
3761
sub clean_datadir {
 
3762
 
 
3763
  mtr_verbose("Cleaning datadirs...");
 
3764
 
 
3765
  if (started(all_servers()) != 0){
 
3766
    mtr_error("Trying to clean datadir before all servers stopped");
 
3767
  }
 
3768
 
 
3769
  foreach my $cluster ( clusters() )
 
3770
  {
 
3771
    my $cluster_dir= "$opt_vardir/".$cluster->{name};
 
3772
    mtr_verbose(" - removing '$cluster_dir'");
 
3773
    rmtree($cluster_dir);
 
3774
 
 
3775
  }
 
3776
 
 
3777
  foreach my $mysqld ( mysqlds() )
 
3778
  {
 
3779
    my $mysqld_dir= dirname($mysqld->value('datadir'));
 
3780
    if (-d $mysqld_dir ) {
 
3781
      mtr_verbose(" - removing '$mysqld_dir'");
 
3782
      rmtree($mysqld_dir);
 
3783
    }
 
3784
  }
 
3785
 
 
3786
  # Remove all files in tmp and var/tmp
 
3787
  clean_dir("$opt_vardir/tmp");
 
3788
  if ($opt_tmpdir ne "$opt_vardir/tmp"){
 
3789
    clean_dir($opt_tmpdir);
 
3790
  }
 
3791
}
 
3792
 
 
3793
 
 
3794
#
 
3795
# Save datadir before it's removed
 
3796
#
 
3797
sub save_datadir_after_failure($$) {
 
3798
  my ($dir, $savedir)= @_;
 
3799
 
 
3800
  mtr_report(" - saving '$dir'");
 
3801
  my $dir_name= basename($dir);
 
3802
  rename("$dir", "$savedir/$dir_name");
 
3803
}
 
3804
 
 
3805
 
 
3806
sub remove_ndbfs_from_ndbd_datadir {
 
3807
  my ($ndbd_datadir)= @_;
 
3808
  # Remove the ndb_*_fs directory from ndbd.X/ dir
 
3809
  foreach my $ndbfs_dir ( glob("$ndbd_datadir/ndb_*_fs") )
 
3810
  {
 
3811
    next unless -d $ndbfs_dir; # Skip if not a directory
 
3812
    rmtree($ndbfs_dir);
 
3813
  }
 
3814
}
 
3815
 
 
3816
 
 
3817
sub after_failure ($) {
 
3818
  my ($tinfo)= @_;
 
3819
 
 
3820
  mtr_report("Saving datadirs...");
 
3821
 
 
3822
  my $save_dir= "$opt_vardir/log/";
 
3823
  $save_dir.= $tinfo->{name};
 
3824
  # Add combination name if any
 
3825
  $save_dir.= "-$tinfo->{combination}"
 
3826
    if defined $tinfo->{combination};
 
3827
 
 
3828
  # Save savedir  path for server
 
3829
  $tinfo->{savedir}= $save_dir;
 
3830
 
 
3831
  mkpath($save_dir) if ! -d $save_dir;
 
3832
 
 
3833
  # Save the used my.cnf file
 
3834
  copy($path_config_file, $save_dir);
 
3835
 
 
3836
  # Copy the tmp dir
 
3837
  copytree("$opt_vardir/tmp/", "$save_dir/tmp/");
 
3838
 
 
3839
  if ( clusters() ) {
 
3840
    foreach my $cluster ( clusters() ) {
 
3841
      my $cluster_dir= "$opt_vardir/".$cluster->{name};
 
3842
 
 
3843
      # Remove the fileystem of each ndbd
 
3844
      foreach my $ndbd ( in_cluster($cluster, ndbds()) )
 
3845
      {
 
3846
        my $ndbd_datadir= $ndbd->value("DataDir");
 
3847
        remove_ndbfs_from_ndbd_datadir($ndbd_datadir);
 
3848
      }
 
3849
 
 
3850
      save_datadir_after_failure($cluster_dir, $save_dir);
 
3851
    }
 
3852
  }
 
3853
  else {
 
3854
    foreach my $mysqld ( mysqlds() ) {
 
3855
      my $data_dir= $mysqld->value('datadir');
 
3856
      save_datadir_after_failure(dirname($data_dir), $save_dir);
 
3857
    }
 
3858
  }
 
3859
}
 
3860
 
3771
3861
 
3772
3862
sub report_failure_and_restart ($) {
3773
3863
  my $tinfo= shift;
3774
3864
 
3775
 
  mtr_report_test_failed($tinfo);
3776
 
  print "\n";
3777
 
  if ( $opt_force )
3778
 
  {
3779
 
    # Stop all servers that are known to be running
3780
 
    stop_all_servers();
3781
 
 
3782
 
    # Restore the snapshot of the installed test db
3783
 
    restore_installed_db($tinfo->{'name'});
3784
 
    mtr_report("Resuming Tests\n");
3785
 
    return;
3786
 
  }
3787
 
 
3788
 
  my $test_mode= join(" ", @::glob_test_mode) || "default";
3789
 
  mtr_report("Aborting: $tinfo->{'name'} failed in $test_mode mode. ");
3790
 
  mtr_report("To continue, re-run with '--force'.");
3791
 
  if ( ! $glob_debugger and
3792
 
       ! $opt_extern and
3793
 
       ! $glob_use_embedded_server )
3794
 
  {
3795
 
    stop_all_servers();
3796
 
  }
3797
 
  mtr_exit(1);
3798
 
 
3799
 
}
3800
 
 
3801
 
 
3802
 
sub run_master_init_script ($) {
3803
 
  my ($tinfo)= @_;
3804
 
  my $init_script= $tinfo->{'master_sh'};
3805
 
 
3806
 
  # Run master initialization shell script if one exists
3807
 
  if ( $init_script )
3808
 
  {
3809
 
    my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
3810
 
    if ( $ret != 0 )
3811
 
    {
3812
 
      # FIXME rewrite those scripts to return 0 if successful
3813
 
      # mtr_warning("$init_script exited with code $ret");
3814
 
    }
3815
 
  }
3816
 
}
3817
 
 
3818
 
 
3819
 
##############################################################################
3820
 
#
3821
 
#  Start and stop servers
3822
 
#
3823
 
##############################################################################
3824
 
 
3825
 
 
3826
 
sub do_before_start_master ($) {
3827
 
  my ($tinfo)= @_;
3828
 
 
3829
 
  my $tname= $tinfo->{'name'};
3830
 
 
3831
 
  # FIXME what about second master.....
3832
 
 
3833
 
  # Don't delete anything if starting dirty
3834
 
  return if ($opt_start_dirty);
3835
 
 
3836
 
  foreach my $bin ( glob("$opt_vardir/log/master*-bin*") )
3837
 
  {
3838
 
    unlink($bin);
3839
 
  }
3840
 
 
3841
 
  # FIXME only remove the ones that are tied to this master
3842
 
  # Remove old master.info and relay-log.info files
3843
 
  unlink("$master->[0]->{'path_myddir'}/master.info");
3844
 
  unlink("$master->[0]->{'path_myddir'}/relay-log.info");
3845
 
  unlink("$master->[1]->{'path_myddir'}/master.info");
3846
 
  unlink("$master->[1]->{'path_myddir'}/relay-log.info");
3847
 
 
3848
 
  run_master_init_script($tinfo);
3849
 
}
3850
 
 
3851
 
 
3852
 
sub do_before_start_slave ($) {
3853
 
  my ($tinfo)= @_;
3854
 
 
3855
 
  my $tname= $tinfo->{'name'};
3856
 
  my $init_script= $tinfo->{'master_sh'};
3857
 
 
3858
 
  # Don't delete anything if starting dirty
3859
 
  return if ($opt_start_dirty);
3860
 
 
3861
 
  foreach my $bin ( glob("$opt_vardir/log/slave*-bin*") )
3862
 
  {
3863
 
    unlink($bin);
3864
 
  }
3865
 
 
3866
 
  unlink("$slave->[0]->{'path_myddir'}/master.info");
3867
 
  unlink("$slave->[0]->{'path_myddir'}/relay-log.info");
3868
 
 
3869
 
  # Run slave initialization shell script if one exists
3870
 
  if ( $init_script )
3871
 
  {
3872
 
    my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
3873
 
    if ( $ret != 0 )
3874
 
    {
3875
 
      # FIXME rewrite those scripts to return 0 if successful
3876
 
      # mtr_warning("$init_script exited with code $ret");
3877
 
    }
3878
 
  }
3879
 
 
3880
 
  foreach my $bin ( glob("$slave->[0]->{'path_myddir'}/log.*") )
3881
 
  {
3882
 
    unlink($bin);
3883
 
  }
3884
 
}
3885
 
 
3886
 
 
3887
 
sub mysqld_arguments ($$$$) {
 
3865
  stop_all_servers();
 
3866
 
 
3867
  $tinfo->{'result'}= 'MTR_RES_FAILED';
 
3868
 
 
3869
  my $test_failures= $tinfo->{'failures'} || 0;
 
3870
  $tinfo->{'failures'}=  $test_failures + 1;
 
3871
 
 
3872
 
 
3873
  if ( $tinfo->{comment} )
 
3874
  {
 
3875
    # The test failure has been detected by mysql-test-run.pl
 
3876
    # when starting the servers or due to other error, the reason for
 
3877
    # failing the test is saved in "comment"
 
3878
    ;
 
3879
  }
 
3880
 
 
3881
  if ( !defined $tinfo->{logfile} )
 
3882
  {
 
3883
    my $logfile= $path_current_testlog;
 
3884
    if ( defined $logfile )
 
3885
    {
 
3886
      if ( -f $logfile )
 
3887
      {
 
3888
        # Test failure was detected by test tool and its report
 
3889
        # about what failed has been saved to file. Save the report
 
3890
        # in tinfo
 
3891
        $tinfo->{logfile}= mtr_fromfile($logfile);
 
3892
      }
 
3893
      else
 
3894
      {
 
3895
        # The test tool report didn't exist, display an
 
3896
        # error message
 
3897
        $tinfo->{logfile}= "Could not open test tool report '$logfile'";
 
3898
      }
 
3899
    }
 
3900
  }
 
3901
 
 
3902
  after_failure($tinfo);
 
3903
 
 
3904
  mtr_report_test($tinfo);
 
3905
 
 
3906
}
 
3907
 
 
3908
 
 
3909
sub run_sh_script {
 
3910
  my ($script)= @_;
 
3911
 
 
3912
  return 0 unless defined $script;
 
3913
 
 
3914
  mtr_verbose("Running '$script'");
 
3915
  my $ret= system("/bin/sh $script") >> 8;
 
3916
  return $ret;
 
3917
}
 
3918
 
 
3919
 
 
3920
sub mysqld_stop {
 
3921
  my $mysqld= shift or die "usage: mysqld_stop(<mysqld>)";
 
3922
 
 
3923
  my $args;
 
3924
  mtr_init_args(\$args);
 
3925
 
 
3926
  mtr_add_arg($args, "--no-defaults");
 
3927
  mtr_add_arg($args, "--user=%s", $opt_user);
 
3928
  mtr_add_arg($args, "--password=");
 
3929
  mtr_add_arg($args, "--port=%d", $mysqld->value('port'));
 
3930
  mtr_add_arg($args, "--host=%s", $mysqld->value('#host'));
 
3931
  mtr_add_arg($args, "--connect_timeout=20");
 
3932
  mtr_add_arg($args, "--protocol=tcp");
 
3933
 
 
3934
  mtr_add_arg($args, "shutdown");
 
3935
 
 
3936
  My::SafeProcess->run
 
3937
    (
 
3938
     name          => "mysqladmin shutdown ".$mysqld->name(),
 
3939
     path          => $exe_mysqladmin,
 
3940
     args          => \$args,
 
3941
     error         => "/dev/null",
 
3942
 
 
3943
    );
 
3944
}
 
3945
 
 
3946
 
 
3947
sub mysqld_arguments ($$$) {
3888
3948
  my $args=              shift;
3889
3949
  my $mysqld=            shift;
3890
 
  my $extra_opt=         shift;
3891
 
  my $slave_master_info= shift;
3892
 
 
3893
 
  my $idx= $mysqld->{'idx'};
3894
 
  my $sidx= "";                 # Index as string, 0 is empty string
3895
 
  if ( $idx> 0 )
3896
 
  {
3897
 
    $sidx= $idx;
3898
 
  }
3899
 
 
3900
 
  my $prefix= "";               # If mysqltest server arg
3901
 
  if ( $glob_use_embedded_server )
3902
 
  {
3903
 
    $prefix= "--server-arg=";
3904
 
  }
3905
 
 
3906
 
  mtr_add_arg($args, "%s--no-defaults", $prefix);
3907
 
 
3908
 
  mtr_add_arg($args, "%s--basedir=%s", $prefix, $path_my_basedir);
3909
 
  mtr_add_arg($args, "%s--character-sets-dir=%s", $prefix, $path_charsetsdir);
3910
 
 
3911
 
  if ( $mysql_version_id >= 50036)
3912
 
  {
3913
 
    # By default, prevent the started mysqld to access files outside of vardir
3914
 
    mtr_add_arg($args, "%s--secure-file-priv=%s", $prefix, $opt_vardir);
3915
 
  }
3916
 
 
3917
 
  if ( $mysql_version_id >= 50000 )
3918
 
  {
3919
 
    mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix);
3920
 
  }
3921
 
 
3922
 
  mtr_add_arg($args, "%s--default-character-set=latin1", $prefix);
3923
 
  mtr_add_arg($args, "%s--language=%s", $prefix, $path_language);
3924
 
  mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix);
3925
 
 
3926
 
  # Increase default connect_timeout to avoid intermittent
3927
 
  # disconnects when test servers are put under load
3928
 
  # see BUG#28359
3929
 
  mtr_add_arg($args, "%s--connect-timeout=60", $prefix);
3930
 
 
 
3950
  my $extra_opts=        shift;
 
3951
 
 
3952
  mtr_add_arg($args, "--defaults-file=%s",  $path_config_file);
3931
3953
 
3932
3954
  # When mysqld is run by a root user(euid is 0), it will fail
3933
3955
  # to start unless we specify what user to run as, see BUG#30630
3934
3956
  my $euid= $>;
3935
 
  if (!$glob_win32 and $euid == 0 and
3936
 
      grep(/^--user/, @$extra_opt, @opt_extra_mysqld_opt) == 0) {
3937
 
    mtr_add_arg($args, "%s--user=root", $prefix);
 
3957
  if (!IS_WINDOWS and $euid == 0 and
 
3958
      (grep(/^--user/, @$extra_opts)) == 0) {
 
3959
    mtr_add_arg($args, "--user=root");
3938
3960
  }
3939
3961
 
3940
3962
  if ( $opt_valgrind_mysqld )
3941
3963
  {
3942
 
    mtr_add_arg($args, "%s--skip-safemalloc", $prefix);
 
3964
    mtr_add_arg($args, "--skip-safemalloc");
3943
3965
 
3944
3966
    if ( $mysql_version_id < 50100 )
3945
3967
    {
3946
 
      mtr_add_arg($args, "%s--skip-bdb", $prefix);
 
3968
      mtr_add_arg($args, "--skip-bdb");
3947
3969
    }
3948
3970
  }
3949
3971
 
3950
 
  mtr_add_arg($args, "%s--pid-file=%s", $prefix,
3951
 
              $mysqld->{'path_pid'});
3952
 
 
3953
 
  mtr_add_arg($args, "%s--port=%d", $prefix,
3954
 
                $mysqld->{'port'});
3955
 
 
3956
 
  mtr_add_arg($args, "%s--socket=%s", $prefix,
3957
 
              $mysqld->{'path_sock'});
3958
 
 
3959
 
  mtr_add_arg($args, "%s--datadir=%s", $prefix,
3960
 
              $mysqld->{'path_myddir'});
3961
 
 
3962
 
 
3963
3972
  if ( $mysql_version_id >= 50106 )
3964
3973
  {
3965
 
    # Turn on logging to bothe tables and file
3966
 
    mtr_add_arg($args, "%s--log-output=table,file", $prefix);
3967
 
  }
3968
 
 
3969
 
  my $log_base_path= "$opt_vardir/log/$mysqld->{'type'}$sidx";
3970
 
  mtr_add_arg($args, "%s--log=%s.log", $prefix, $log_base_path);
3971
 
  mtr_add_arg($args,
3972
 
              "%s--log-slow-queries=%s-slow.log", $prefix, $log_base_path);
3973
 
 
3974
 
  # Check if "extra_opt" contains --skip-log-bin
3975
 
  my $skip_binlog= grep(/^--skip-log-bin/, @$extra_opt, @opt_extra_mysqld_opt);
3976
 
  if ( $mysqld->{'type'} eq 'master' )
3977
 
  {
3978
 
    if (! ($opt_skip_master_binlog || $skip_binlog) )
3979
 
    {
3980
 
      mtr_add_arg($args, "%s--log-bin=%s/log/master-bin%s", $prefix,
3981
 
                  $opt_vardir, $sidx);
3982
 
    }
3983
 
 
3984
 
    mtr_add_arg($args, "%s--server-id=%d", $prefix,
3985
 
               $idx > 0 ? $idx + 101 : 1);
3986
 
 
3987
 
    mtr_add_arg($args, "%s--loose-innodb_data_file_path=ibdata1:10M:autoextend",
3988
 
                $prefix);
3989
 
 
3990
 
    mtr_add_arg($args, "%s--local-infile", $prefix);
3991
 
 
3992
 
    if ( $idx > 0 or !$use_innodb)
3993
 
    {
3994
 
      mtr_add_arg($args, "%s--loose-skip-innodb", $prefix);
3995
 
    }
3996
 
 
3997
 
    my $cluster= $clusters->[$mysqld->{'cluster'}];
3998
 
    if ( $cluster->{'pid'} ||           # Cluster is started
3999
 
         $cluster->{'use_running'} )    # Using running cluster
4000
 
    {
4001
 
      mtr_add_arg($args, "%s--ndbcluster", $prefix);
4002
 
      mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
4003
 
                  $cluster->{'connect_string'});
4004
 
      if ( $mysql_version_id >= 50100 )
4005
 
      {
4006
 
        mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
4007
 
      }
4008
 
    }
4009
 
    else
4010
 
    {
4011
 
      mtr_add_arg($args, "%s--loose-skip-ndbcluster", $prefix);
4012
 
    }
4013
 
  }
4014
 
  else
4015
 
  {
4016
 
    mtr_error("unknown mysqld type")
4017
 
      unless $mysqld->{'type'} eq 'slave';
4018
 
 
4019
 
    mtr_add_arg($args, "%s--init-rpl-role=slave", $prefix);
4020
 
    if (! ( $opt_skip_slave_binlog || $skip_binlog ))
4021
 
    {
4022
 
      mtr_add_arg($args, "%s--log-bin=%s/log/slave%s-bin", $prefix,
4023
 
                  $opt_vardir, $sidx); # FIXME use own dir for binlogs
4024
 
      mtr_add_arg($args, "%s--log-slave-updates", $prefix);
4025
 
    }
4026
 
 
4027
 
    mtr_add_arg($args, "%s--master-retry-count=10", $prefix);
4028
 
 
4029
 
    mtr_add_arg($args, "%s--relay-log=%s/log/slave%s-relay-bin", $prefix,
4030
 
                $opt_vardir, $sidx);
4031
 
    mtr_add_arg($args, "%s--report-host=127.0.0.1", $prefix);
4032
 
    mtr_add_arg($args, "%s--report-port=%d", $prefix,
4033
 
                $mysqld->{'port'});
4034
 
    mtr_add_arg($args, "%s--report-user=root", $prefix);
4035
 
    mtr_add_arg($args, "%s--loose-skip-innodb", $prefix);
4036
 
    mtr_add_arg($args, "%s--skip-slave-start", $prefix);
4037
 
 
4038
 
    # Directory where slaves find the dumps generated by "load data"
4039
 
    # on the server. The path need to have constant length otherwise
4040
 
    # test results will vary, thus a relative path is used.
4041
 
    my $slave_load_path= "../tmp";
4042
 
    mtr_add_arg($args, "%s--slave-load-tmpdir=%s", $prefix,
4043
 
                $slave_load_path);
4044
 
    mtr_add_arg($args, "%s--set-variable=slave_net_timeout=120", $prefix);
4045
 
 
4046
 
    if ( @$slave_master_info )
4047
 
    {
4048
 
      foreach my $arg ( @$slave_master_info )
4049
 
      {
4050
 
        mtr_add_arg($args, "%s%s", $prefix, $arg);
4051
 
      }
4052
 
    }
4053
 
    else
4054
 
    {
4055
 
      if ($mysql_version_id < 50200)
4056
 
      {
4057
 
        mtr_add_arg($args, "%s--master-user=root", $prefix);
4058
 
        mtr_add_arg($args, "%s--master-connect-retry=1", $prefix);
4059
 
        mtr_add_arg($args, "%s--master-host=127.0.0.1", $prefix);
4060
 
        mtr_add_arg($args, "%s--master-password=", $prefix);
4061
 
        mtr_add_arg($args, "%s--master-port=%d", $prefix,
4062
 
                    $master->[0]->{'port'}); # First master
4063
 
      }
4064
 
      my $slave_server_id=  2 + $idx;
4065
 
      my $slave_rpl_rank= $slave_server_id;
4066
 
      mtr_add_arg($args, "%s--server-id=%d", $prefix, $slave_server_id);
4067
 
      mtr_add_arg($args, "%s--rpl-recovery-rank=%d", $prefix, $slave_rpl_rank);
4068
 
    }
4069
 
 
4070
 
    my $cluster= $clusters->[$mysqld->{'cluster'}];
4071
 
    if ( $cluster->{'pid'} ||         # Slave cluster is started
4072
 
         $cluster->{'use_running'} )  # Using running slave cluster
4073
 
    {
4074
 
      mtr_add_arg($args, "%s--ndbcluster", $prefix);
4075
 
      mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
4076
 
                  $cluster->{'connect_string'});
4077
 
 
4078
 
      if ( $mysql_version_id >= 50100 )
4079
 
      {
4080
 
        mtr_add_arg($args, "%s--ndb-extra-logging", $prefix);
4081
 
      }
4082
 
    }
4083
 
    else
4084
 
    {
4085
 
      mtr_add_arg($args, "%s--loose-skip-ndbcluster", $prefix);
4086
 
    }
4087
 
 
4088
 
  } # end slave
4089
 
 
4090
 
  if ( $opt_debug )
4091
 
  {
4092
 
    mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/%s%s.trace",
4093
 
                $prefix, $path_vardir_trace, $mysqld->{'type'}, $sidx);
4094
 
  }
4095
 
 
4096
 
  mtr_add_arg($args, "%s--key_buffer_size=1M", $prefix);
4097
 
  mtr_add_arg($args, "%s--sort_buffer=256K", $prefix);
4098
 
  mtr_add_arg($args, "%s--max_heap_table_size=1M", $prefix);
4099
 
 
4100
 
  if ( $opt_ssl_supported )
4101
 
  {
4102
 
    mtr_add_arg($args, "%s--ssl-ca=%s/std_data/cacert.pem", $prefix,
4103
 
                $glob_mysql_test_dir);
4104
 
    mtr_add_arg($args, "%s--ssl-cert=%s/std_data/server-cert.pem", $prefix,
4105
 
                $glob_mysql_test_dir);
4106
 
    mtr_add_arg($args, "%s--ssl-key=%s/std_data/server-key.pem", $prefix,
4107
 
                $glob_mysql_test_dir);
4108
 
  }
4109
 
 
4110
 
  if ( $opt_warnings )
4111
 
  {
4112
 
    mtr_add_arg($args, "%s--log-warnings", $prefix);
4113
 
  }
4114
 
 
4115
 
  # Indicate to "mysqld" it will be debugged in debugger
 
3974
    # Turn on logging to both tables and file
 
3975
    mtr_add_arg($args, "--log-output=table,file");
 
3976
  }
 
3977
 
 
3978
  # Check if "extra_opt" contains skip-log-bin
 
3979
  my $skip_binlog= grep(/^(--|--loose-)skip-log-bin/, @$extra_opts);
 
3980
 
 
3981
  # Indicate to mysqld it will be debugged in debugger
4116
3982
  if ( $glob_debugger )
4117
3983
  {
4118
 
    mtr_add_arg($args, "%s--gdb", $prefix);
 
3984
    mtr_add_arg($args, "--gdb");
4119
3985
  }
4120
3986
 
4121
3987
  my $found_skip_core= 0;
4122
 
  foreach my $arg ( @opt_extra_mysqld_opt, @$extra_opt )
 
3988
  foreach my $arg ( @$extra_opts )
4123
3989
  {
4124
3990
    # Allow --skip-core-file to be set in <testname>-[master|slave].opt file
4125
3991
    if ($arg eq "--skip-core-file")
4130
3996
    {
4131
3997
      ; # Dont add --binlog-format when running without binlog
4132
3998
    }
 
3999
    elsif ($arg eq "--loose-skip-log-bin" and
 
4000
           $mysqld->option("log-slave-updates"))
 
4001
    {
 
4002
      ; # Dont add --skip-log-bin when mysqld have --log-slave-updates in config
 
4003
    }
4133
4004
    else
4134
4005
    {
4135
 
      mtr_add_arg($args, "%s%s", $prefix, $arg);
 
4006
      mtr_add_arg($args, "%s", $arg);
4136
4007
    }
4137
4008
  }
 
4009
  $opt_skip_core = $found_skip_core;
4138
4010
  if ( !$found_skip_core )
4139
4011
  {
4140
 
    mtr_add_arg($args, "%s%s", $prefix, "--core-file");
4141
 
  }
4142
 
 
4143
 
  if ( $opt_bench )
4144
 
  {
4145
 
    mtr_add_arg($args, "%s--rpl-recovery-rank=1", $prefix);
4146
 
    mtr_add_arg($args, "%s--init-rpl-role=master", $prefix);
4147
 
  }
4148
 
  elsif ( $mysqld->{'type'} eq 'master' )
4149
 
  {
4150
 
    mtr_add_arg($args, "%s--open-files-limit=1024", $prefix);
 
4012
    mtr_add_arg($args, "%s", "--core-file");
4151
4013
  }
4152
4014
 
4153
4015
  return $args;
4154
4016
}
4155
4017
 
4156
4018
 
4157
 
##############################################################################
4158
 
#
4159
 
#  Start mysqld and return the PID
4160
 
#
4161
 
##############################################################################
4162
4019
 
4163
 
sub mysqld_start ($$$) {
 
4020
sub mysqld_start ($$) {
4164
4021
  my $mysqld=            shift;
4165
 
  my $extra_opt=         shift;
4166
 
  my $slave_master_info= shift;
4167
 
 
4168
 
  my $args;                             # Arg vector
4169
 
  my $exe;
4170
 
  my $pid= -1;
 
4022
  my $extra_opts=        shift;
 
4023
 
 
4024
  mtr_verbose(My::Options::toStr("mysqld_start", @$extra_opts));
 
4025
 
 
4026
  my $exe= find_mysqld($mysqld->value('basedir'));
4171
4027
  my $wait_for_pid_file= 1;
4172
4028
 
4173
 
  my $type= $mysqld->{'type'};
4174
 
  my $idx= $mysqld->{'idx'};
4175
 
 
4176
4029
  mtr_error("Internal error: mysqld should never be started for embedded")
4177
 
    if $glob_use_embedded_server;
4178
 
 
4179
 
  if ( $type eq 'master' )
4180
 
  {
4181
 
    $exe= $exe_master_mysqld;
4182
 
  }
4183
 
  elsif ( $type eq 'slave' )
4184
 
  {
4185
 
    $exe= $exe_slave_mysqld;
4186
 
  }
4187
 
  else
4188
 
  {
4189
 
    mtr_error("Unknown 'type' \"$type\" passed to mysqld_start");
4190
 
  }
4191
 
 
 
4030
    if $opt_embedded_server;
 
4031
 
 
4032
  my $args;
4192
4033
  mtr_init_args(\$args);
4193
4034
 
4194
4035
  if ( $opt_valgrind_mysqld )
4196
4037
    valgrind_arguments($args, \$exe);
4197
4038
  }
4198
4039
 
4199
 
  mysqld_arguments($args,$mysqld,$extra_opt,$slave_master_info);
4200
 
 
4201
 
  if ( $opt_gdb || $opt_manual_gdb)
4202
 
  {
4203
 
    gdb_arguments(\$args, \$exe, "$type"."_$idx");
 
4040
  mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
 
4041
  mysqld_arguments($args,$mysqld,$extra_opts);
 
4042
 
 
4043
  if ( $opt_debug )
 
4044
  {
 
4045
    mtr_add_arg($args, "--debug=d:t:i:A,%s/log/%s.trace",
 
4046
                $path_vardir_trace, $mysqld->name());
 
4047
  }
 
4048
 
 
4049
  if (IS_WINDOWS)
 
4050
  {
 
4051
    # Trick the server to send output to stderr, with --console
 
4052
    mtr_add_arg($args, "--console");
 
4053
  }
 
4054
 
 
4055
  if ( $opt_gdb || $opt_manual_gdb )
 
4056
  {
 
4057
    gdb_arguments(\$args, \$exe, $mysqld->name());
4204
4058
  }
4205
4059
  elsif ( $opt_ddd || $opt_manual_ddd )
4206
4060
  {
4207
 
    ddd_arguments(\$args, \$exe, "$type"."_$idx");
 
4061
    ddd_arguments(\$args, \$exe, $mysqld->name());
4208
4062
  }
4209
4063
  elsif ( $opt_debugger )
4210
4064
  {
4211
 
    debugger_arguments(\$args, \$exe, "$type"."_$idx");
 
4065
    debugger_arguments(\$args, \$exe, $mysqld->name());
4212
4066
  }
4213
4067
  elsif ( $opt_manual_debug )
4214
4068
  {
4215
 
     print "\nStart $type in your debugger\n" .
 
4069
     print "\nStart " .$mysqld->name()." in your debugger\n" .
4216
4070
           "dir: $glob_mysql_test_dir\n" .
4217
4071
           "exe: $exe\n" .
4218
4072
           "args:  " . join(" ", @$args)  . "\n\n" .
4227
4081
    $wait_for_pid_file= 0;
4228
4082
  }
4229
4083
 
4230
 
  # Remove the pidfile
4231
 
  unlink($mysqld->{'path_pid'});
 
4084
  # Remove the old pidfile if any
 
4085
  unlink($mysqld->value('pid-file'));
 
4086
 
 
4087
  my $output= $mysqld->value('#log-error');
 
4088
  if ( $opt_valgrind and $opt_debug )
 
4089
  {
 
4090
    # When both --valgrind and --debug is selected, send
 
4091
    # all output to the trace file, making it possible to
 
4092
    # see the exact location where valgrind complains
 
4093
    $output= "$opt_vardir/log/".$mysqld->name().".trace";
 
4094
  }
4232
4095
 
4233
4096
  if ( defined $exe )
4234
4097
  {
4235
 
    $pid= mtr_spawn($exe, $args, "",
4236
 
                    $mysqld->{'path_myerr'},
4237
 
                    $mysqld->{'path_myerr'},
4238
 
                    "",
4239
 
                    { append_log_file => 1 });
 
4098
    $mysqld->{'proc'}= My::SafeProcess->new
 
4099
      (
 
4100
       name          => $mysqld->name(),
 
4101
       path          => $exe,
 
4102
       args          => \$args,
 
4103
       output        => $output,
 
4104
       error         => $output,
 
4105
       append        => 1,
 
4106
       verbose       => $opt_verbose,
 
4107
       nocore        => $opt_skip_core,
 
4108
       host          => undef,
 
4109
       shutdown      => sub { mysqld_stop($mysqld) },
 
4110
      );
 
4111
    mtr_verbose("Started $mysqld->{proc}");
4240
4112
  }
4241
4113
 
4242
 
 
4243
 
  if ( $wait_for_pid_file && !sleep_until_file_created($mysqld->{'path_pid'},
4244
 
                                                       $mysqld->{'start_timeout'},
4245
 
                                                       $pid))
 
4114
  if ( $wait_for_pid_file &&
 
4115
       !sleep_until_file_created($mysqld->value('pid-file'),
 
4116
                                 $opt_start_timeout,
 
4117
                                 $mysqld->{'proc'}))
4246
4118
  {
4247
 
 
4248
 
    mtr_error("Failed to start mysqld $mysqld->{'type'}");
 
4119
    mtr_error("Failed to start mysqld $mysqld->name()");
4249
4120
  }
4250
4121
 
4251
 
 
4252
 
  # Remember pid of the started process
4253
 
  $mysqld->{'pid'}= $pid;
4254
 
 
4255
4122
  # Remember options used when starting
4256
 
  $mysqld->{'start_opts'}= $extra_opt;
4257
 
  $mysqld->{'start_slave_master_info'}= $slave_master_info;
 
4123
  $mysqld->{'started_opts'}= $extra_opts;
4258
4124
 
4259
 
  mtr_verbose("mysqld pid: $pid");
4260
 
  return $pid;
 
4125
  return;
4261
4126
}
4262
4127
 
4263
4128
 
4264
4129
sub stop_all_servers () {
4265
4130
 
4266
 
  mtr_report("Stopping All Servers");
4267
 
 
4268
 
  if ( ! $opt_skip_im )
4269
 
  {
4270
 
    mtr_report("Shutting-down Instance Manager");
4271
 
    unless (mtr_im_stop($instance_manager, "stop_all_servers"))
4272
 
    {
4273
 
      mtr_error("Failed to stop Instance Manager.")
4274
 
    }
4275
 
  }
4276
 
 
4277
 
  my %admin_pids; # hash of admin processes that requests shutdown
4278
 
  my @kill_pids;  # list of processes to shutdown/kill
4279
 
  my $pid;
4280
 
 
4281
 
  # Start shutdown of all started masters
4282
 
  foreach my $mysqld (@{$slave}, @{$master})
4283
 
  {
4284
 
    if ( $mysqld->{'pid'} )
4285
 
    {
4286
 
      $pid= mtr_mysqladmin_start($mysqld, "shutdown", 70);
4287
 
      $admin_pids{$pid}= 1;
4288
 
 
4289
 
      push(@kill_pids,{
4290
 
                       pid      => $mysqld->{'pid'},
4291
 
                       real_pid => $mysqld->{'real_pid'},
4292
 
                       pidfile  => $mysqld->{'path_pid'},
4293
 
                       sockfile => $mysqld->{'path_sock'},
4294
 
                       port     => $mysqld->{'port'},
4295
 
                       errfile  => $mysqld->{'path_myerr'},
4296
 
                      });
4297
 
 
4298
 
      $mysqld->{'pid'}= 0; # Assume we are done with it
4299
 
    }
4300
 
  }
4301
 
 
4302
 
  # Start shutdown of clusters
4303
 
  foreach my $cluster (@{$clusters})
4304
 
  {
4305
 
    if ( $cluster->{'pid'} )
4306
 
    {
4307
 
      $pid= mtr_ndbmgm_start($cluster, "shutdown");
4308
 
      $admin_pids{$pid}= 1;
4309
 
 
4310
 
      push(@kill_pids,{
4311
 
                       pid      => $cluster->{'pid'},
4312
 
                       pidfile  => $cluster->{'path_pid'}
4313
 
                      });
4314
 
 
4315
 
      $cluster->{'pid'}= 0; # Assume we are done with it
4316
 
 
4317
 
      foreach my $ndbd (@{$cluster->{'ndbds'}})
4318
 
      {
4319
 
        if ( $ndbd->{'pid'} )
4320
 
        {
4321
 
          push(@kill_pids,{
4322
 
                           pid      => $ndbd->{'pid'},
4323
 
                           pidfile  => $ndbd->{'path_pid'},
4324
 
                          });
4325
 
          $ndbd->{'pid'}= 0;
4326
 
        }
4327
 
      }
4328
 
    }
4329
 
  }
4330
 
 
4331
 
  # Wait blocking until all shutdown processes has completed
4332
 
  mtr_wait_blocking(\%admin_pids);
4333
 
 
4334
 
  # Make sure that process has shutdown else try to kill them
4335
 
  mtr_check_stop_servers(\@kill_pids);
4336
 
 
4337
 
  foreach my $mysqld (@{$master}, @{$slave})
4338
 
  {
4339
 
    rm_ndbcluster_tables($mysqld->{'path_myddir'});
4340
 
  }
4341
 
}
4342
 
 
4343
 
 
4344
 
sub run_testcase_need_master_restart($)
4345
 
{
4346
 
  my ($tinfo)= @_;
4347
 
 
4348
 
  # We try to find out if we are to restart the master(s)
4349
 
  my $do_restart= 0;          # Assumes we don't have to
4350
 
 
4351
 
  if ( $glob_use_embedded_server )
4352
 
  {
4353
 
    mtr_verbose("Never start or restart for embedded server");
4354
 
    return $do_restart;
4355
 
  }
4356
 
  elsif ( $tinfo->{'master_sh'} )
4357
 
  {
4358
 
    $do_restart= 1;           # Always restart if script to run
4359
 
    mtr_verbose("Restart master: Always restart if script to run");
4360
 
  }
4361
 
  if ( $tinfo->{'force_restart'} )
4362
 
  {
4363
 
    $do_restart= 1; # Always restart if --force-restart in -opt file
4364
 
    mtr_verbose("Restart master: Restart forced with --force-restart");
4365
 
  }
4366
 
  elsif ( ! $opt_skip_ndbcluster and
4367
 
          !$tinfo->{'ndb_test'} and
4368
 
          $clusters->[0]->{'pid'} != 0 )
4369
 
  {
4370
 
    $do_restart= 1;           # Restart without cluster
4371
 
    mtr_verbose("Restart master: Test does not need cluster");
4372
 
  }
4373
 
  elsif ( ! $opt_skip_ndbcluster and
4374
 
          $tinfo->{'ndb_test'} and
4375
 
          $clusters->[0]->{'pid'} == 0 )
4376
 
  {
4377
 
    $do_restart= 1;           # Restart with cluster
4378
 
    mtr_verbose("Restart master: Test need cluster");
4379
 
  }
4380
 
  elsif( $tinfo->{'component_id'} eq 'im' )
4381
 
  {
4382
 
    $do_restart= 1;
4383
 
    mtr_verbose("Restart master: Always restart for im tests");
4384
 
  }
4385
 
  elsif ( $master->[0]->{'running_master_options'} and
4386
 
          $master->[0]->{'running_master_options'}->{'timezone'} ne
4387
 
          $tinfo->{'timezone'})
4388
 
  {
4389
 
    $do_restart= 1;
4390
 
    mtr_verbose("Restart master: Different timezone");
4391
 
  }
4392
 
  # Check that running master was started with same options
4393
 
  # as the current test requires
4394
 
  elsif (! mtr_same_opts($master->[0]->{'start_opts'},
4395
 
                         $tinfo->{'master_opt'}) )
4396
 
  {
4397
 
    $do_restart= 1;
4398
 
    mtr_verbose("Restart master: running with different options '" .
4399
 
                join(" ", @{$tinfo->{'master_opt'}}) . "' != '" .
4400
 
                join(" ", @{$master->[0]->{'start_opts'}}) . "'" );
4401
 
  }
4402
 
  elsif( ! $master->[0]->{'pid'} )
4403
 
  {
4404
 
    if ( $opt_extern )
4405
 
    {
4406
 
      $do_restart= 0;
4407
 
      mtr_verbose("No restart: using extern master");
4408
 
    }
4409
 
    else
4410
 
    {
4411
 
      $do_restart= 1;
4412
 
      mtr_verbose("Restart master: master is not started");
4413
 
    }
4414
 
  }
4415
 
  return $do_restart;
4416
 
}
4417
 
 
4418
 
sub run_testcase_need_slave_restart($)
4419
 
{
4420
 
  my ($tinfo)= @_;
4421
 
 
4422
 
  # We try to find out if we are to restart the slaves
4423
 
  my $do_slave_restart= 0;     # Assumes we don't have to
4424
 
 
4425
 
  if ( $glob_use_embedded_server )
4426
 
  {
4427
 
    mtr_verbose("Never start or restart for embedded server");
4428
 
    return $do_slave_restart;
4429
 
  }
4430
 
  elsif ( $max_slave_num == 0)
4431
 
  {
4432
 
    mtr_verbose("Skip slave restart: No testcase use slaves");
4433
 
  }
4434
 
  else
4435
 
  {
4436
 
 
4437
 
    # Check if any slave is currently started
4438
 
    my $any_slave_started= 0;
4439
 
    foreach my $mysqld (@{$slave})
4440
 
    {
4441
 
      if ( $mysqld->{'pid'} )
4442
 
      {
4443
 
        $any_slave_started= 1;
4444
 
        last;
4445
 
      }
4446
 
    }
4447
 
 
4448
 
    if ($any_slave_started)
4449
 
    {
4450
 
      mtr_verbose("Restart slave: Slave is started, always restart");
4451
 
      $do_slave_restart= 1;
4452
 
    }
4453
 
    elsif ( $tinfo->{'slave_num'} )
4454
 
    {
4455
 
      mtr_verbose("Restart slave: Test need slave");
4456
 
      $do_slave_restart= 1;
4457
 
    }
4458
 
  }
4459
 
 
4460
 
  return $do_slave_restart;
4461
 
 
4462
 
}
4463
 
 
4464
 
# ----------------------------------------------------------------------
4465
 
# If not using a running servers we may need to stop and restart.
4466
 
# We restart in the case we have initiation scripts, server options
4467
 
# etc to run. But we also restart again after the test first restart
4468
 
# and test is run, to get back to normal server settings.
4469
 
#
4470
 
# To make the code a bit more clean, we actually only stop servers
4471
 
# here, and mark this to be done. Then a generic "start" part will
4472
 
# start up the needed servers again.
4473
 
# ----------------------------------------------------------------------
4474
 
 
4475
 
sub run_testcase_stop_servers($$$) {
4476
 
  my ($tinfo, $do_restart, $do_slave_restart)= @_;
4477
 
  my $pid;
4478
 
  my %admin_pids; # hash of admin processes that requests shutdown
4479
 
  my @kill_pids;  # list of processes to shutdown/kill
 
4131
  mtr_verbose("Stopping all servers...");
 
4132
 
 
4133
  # Kill all started servers
 
4134
  My::SafeProcess::shutdown(0, # shutdown timeout 0 => kill
 
4135
                            started(all_servers()));
 
4136
 
 
4137
  # Remove pidfiles
 
4138
  foreach my $server ( all_servers() )
 
4139
  {
 
4140
    my $pid_file= $server->if_exist('pid-file');
 
4141
    unlink($pid_file) if defined $pid_file;
 
4142
  }
 
4143
 
 
4144
  # Mark servers as stopped
 
4145
  map($_->{proc}= undef, all_servers());
 
4146
 
 
4147
}
 
4148
 
 
4149
 
 
4150
# Find out if server should be restarted for this test
 
4151
sub server_need_restart {
 
4152
  my ($tinfo, $server)= @_;
 
4153
 
 
4154
  if ( using_extern() )
 
4155
  {
 
4156
    mtr_verbose_restart($server, "no restart for --extern server");
 
4157
    return 0;
 
4158
  }
 
4159
 
 
4160
  if ( $tinfo->{'force_restart'} ) {
 
4161
    mtr_verbose_restart($server, "forced in .opt file");
 
4162
    return 1;
 
4163
  }
 
4164
 
 
4165
  if ( $tinfo->{template_path} ne $current_config_name)
 
4166
  {
 
4167
    mtr_verbose_restart($server, "using different config file");
 
4168
    return 1;
 
4169
  }
 
4170
 
 
4171
  if ( $tinfo->{'master_sh'}  || $tinfo->{'slave_sh'} )
 
4172
  {
 
4173
    mtr_verbose_restart($server, "sh script to run");
 
4174
    return 1;
 
4175
  }
 
4176
 
 
4177
  if ( ! started($server) )
 
4178
  {
 
4179
    mtr_verbose_restart($server, "not started");
 
4180
    return 1;
 
4181
  }
 
4182
 
 
4183
  my $started_tinfo= $server->{'started_tinfo'};
 
4184
  if ( defined $started_tinfo )
 
4185
  {
 
4186
 
 
4187
    # Check if timezone of  test that server was started
 
4188
    # with differs from timezone of next test
 
4189
    if ( timezone($started_tinfo) ne timezone($tinfo) )
 
4190
    {
 
4191
      mtr_verbose_restart($server, "different timezone");
 
4192
      return 1;
 
4193
    }
 
4194
  }
 
4195
 
 
4196
  # Temporary re-enable the "always restart slave" hack
 
4197
  # this should be removed asap, but will require that each rpl
 
4198
  # testcase cleanup better after itself - ie. stop and reset
 
4199
  # replication
 
4200
  # Use the "#!use-slave-opt" marker to detect that this is a "slave"
 
4201
  # server
 
4202
  if ( $server->option("#!use-slave-opt") ){
 
4203
    mtr_verbose_restart($server, "Always restart slave(s)");
 
4204
    return 1;
 
4205
  }
 
4206
 
 
4207
  my $is_mysqld= grep ($server eq $_, mysqlds());
 
4208
  if ($is_mysqld)
 
4209
  {
 
4210
 
 
4211
    # Check that running process was started with same options
 
4212
    # as the current test requires
 
4213
    my $extra_opts= get_extra_opts($server, $tinfo);
 
4214
    my $started_opts= $server->{'started_opts'};
 
4215
 
 
4216
    if (!My::Options::same($started_opts, $extra_opts) )
 
4217
    {
 
4218
      my $use_dynamic_option_switch= 0;
 
4219
      if (!$use_dynamic_option_switch)
 
4220
      {
 
4221
        mtr_verbose_restart($server, "running with different options '" .
 
4222
                            join(" ", @{$extra_opts}) . "' != '" .
 
4223
                            join(" ", @{$started_opts}) . "'" );
 
4224
        return 1;
 
4225
      }
 
4226
 
 
4227
      mtr_verbose(My::Options::toStr("started_opts", @$started_opts));
 
4228
      mtr_verbose(My::Options::toStr("extra_opts", @$extra_opts));
 
4229
 
 
4230
      # Get diff and check if dynamic switch is possible
 
4231
      my @diff_opts= My::Options::diff($started_opts, $extra_opts);
 
4232
      mtr_verbose(My::Options::toStr("diff_opts", @diff_opts));
 
4233
 
 
4234
      my $query= My::Options::toSQL(@diff_opts);
 
4235
      mtr_verbose("Attempting dynamic switch '$query'");
 
4236
      if (run_query($tinfo, $server, $query)){
 
4237
        mtr_verbose("Restart: running with different options '" .
 
4238
                    join(" ", @{$extra_opts}) . "' != '" .
 
4239
                    join(" ", @{$started_opts}) . "'" );
 
4240
        return 1;
 
4241
      }
 
4242
 
 
4243
      # Remember the dynamically set options
 
4244
      $server->{'started_opts'}= $extra_opts;
 
4245
    }
 
4246
  }
 
4247
 
 
4248
  # Default, no restart
 
4249
  return 0;
 
4250
}
 
4251
 
 
4252
 
 
4253
sub servers_need_restart($) {
 
4254
  my ($tinfo)= @_;
 
4255
  return grep { server_need_restart($tinfo, $_); } all_servers();
 
4256
}
 
4257
 
 
4258
 
 
4259
 
 
4260
#
 
4261
# Return list of specific servers
 
4262
#  - there is no servers in an empty config
 
4263
#
 
4264
sub _like   { return $config ? $config->like($_[0]) : (); }
 
4265
sub mysqlds { return _like('mysqld.'); }
 
4266
sub ndbds   { return _like('cluster_config.ndbd.');}
 
4267
sub ndb_mgmds { return _like('cluster_config.ndb_mgmd.'); }
 
4268
sub clusters  { return _like('mysql_cluster.'); }
 
4269
sub all_servers { return ( mysqlds(), ndb_mgmds(), ndbds() ); }
 
4270
 
 
4271
 
 
4272
#
 
4273
# Filter a list of servers and return only those that are part
 
4274
# of the specified cluster
 
4275
#
 
4276
sub in_cluster {
 
4277
  my ($cluster)= shift;
 
4278
  # Return only processes for a specific cluster
 
4279
  return grep { $_->suffix() eq $cluster->suffix() } @_;
 
4280
}
 
4281
 
 
4282
 
 
4283
 
 
4284
#
 
4285
# Filter a list of servers and return the SafeProcess
 
4286
# for only those that are started or stopped
 
4287
#
 
4288
sub started { return grep(defined $_, map($_->{proc}, @_));  }
 
4289
sub stopped { return grep(!defined $_, map($_->{proc}, @_)); }
 
4290
 
 
4291
 
 
4292
sub envsubst {
 
4293
  my $string= shift;
 
4294
 
 
4295
  if ( ! defined $ENV{$string} )
 
4296
  {
 
4297
    mtr_error(".opt file references '$string' which is not set");
 
4298
  }
 
4299
 
 
4300
  return $ENV{$string};
 
4301
}
 
4302
 
 
4303
 
 
4304
sub get_extra_opts {
 
4305
  my ($mysqld, $tinfo)= @_;
 
4306
 
 
4307
  my $opts=
 
4308
    $mysqld->option("#!use-slave-opt") ?
 
4309
      $tinfo->{slave_opt} : $tinfo->{master_opt};
 
4310
 
 
4311
  # Expand environment variables
 
4312
  foreach my $opt ( @$opts )
 
4313
  {
 
4314
    $opt =~ s/\$\{(\w+)\}/envsubst($1)/ge;
 
4315
    $opt =~ s/\$(\w+)/envsubst($1)/ge;
 
4316
  }
 
4317
  return $opts;
 
4318
}
 
4319
 
 
4320
 
 
4321
sub stop_servers($$) {
 
4322
  my ($tinfo, @servers)= @_;
4480
4323
 
4481
4324
  # Remember if we restarted for this test case (count restarts)
4482
 
  $tinfo->{'restarted'}= $do_restart;
4483
 
 
4484
 
  if ( $do_restart )
4485
 
  {
4486
 
    delete $master->[0]->{'running_master_options'}; # Forget history
4487
 
 
4488
 
    # Start shutdown of all started masters
4489
 
    foreach my $mysqld (@{$master})
4490
 
    {
4491
 
      if ( $mysqld->{'pid'} )
4492
 
      {
4493
 
        $pid= mtr_mysqladmin_start($mysqld, "shutdown", 20);
4494
 
 
4495
 
        $admin_pids{$pid}= 1;
4496
 
 
4497
 
        push(@kill_pids,{
4498
 
                         pid      => $mysqld->{'pid'},
4499
 
                         real_pid => $mysqld->{'real_pid'},
4500
 
                         pidfile  => $mysqld->{'path_pid'},
4501
 
                         sockfile => $mysqld->{'path_sock'},
4502
 
                         port     => $mysqld->{'port'},
4503
 
                         errfile   => $mysqld->{'path_myerr'},
4504
 
                        });
4505
 
 
4506
 
        $mysqld->{'pid'}= 0; # Assume we are done with it
4507
 
      }
4508
 
    }
4509
 
 
4510
 
    # Start shutdown of master cluster
4511
 
    my $cluster= $clusters->[0];
4512
 
    if ( $cluster->{'pid'} )
4513
 
    {
4514
 
      $pid= mtr_ndbmgm_start($cluster, "shutdown");
4515
 
      $admin_pids{$pid}= 1;
4516
 
 
4517
 
      push(@kill_pids,{
4518
 
                       pid      => $cluster->{'pid'},
4519
 
                       pidfile  => $cluster->{'path_pid'}
4520
 
                      });
4521
 
 
4522
 
      $cluster->{'pid'}= 0; # Assume we are done with it
4523
 
 
4524
 
      foreach my $ndbd (@{$cluster->{'ndbds'}})
4525
 
      {
4526
 
        push(@kill_pids,{
4527
 
                         pid      => $ndbd->{'pid'},
4528
 
                         pidfile  => $ndbd->{'path_pid'},
4529
 
                        });
4530
 
        $ndbd->{'pid'}= 0; # Assume we are done with it
4531
 
      }
4532
 
    }
4533
 
  }
4534
 
 
4535
 
  if ( $do_restart || $do_slave_restart )
4536
 
  {
4537
 
 
4538
 
    delete $slave->[0]->{'running_slave_options'}; # Forget history
4539
 
 
4540
 
    # Start shutdown of all started slaves
4541
 
    foreach my $mysqld (@{$slave})
4542
 
    {
4543
 
      if ( $mysqld->{'pid'} )
4544
 
      {
4545
 
        $pid= mtr_mysqladmin_start($mysqld, "shutdown", 20);
4546
 
 
4547
 
        $admin_pids{$pid}= 1;
4548
 
 
4549
 
        push(@kill_pids,{
4550
 
                         pid      => $mysqld->{'pid'},
4551
 
                         real_pid => $mysqld->{'real_pid'},
4552
 
                         pidfile  => $mysqld->{'path_pid'},
4553
 
                         sockfile => $mysqld->{'path_sock'},
4554
 
                         port     => $mysqld->{'port'},
4555
 
                         errfile   => $mysqld->{'path_myerr'},
4556
 
                        });
4557
 
 
4558
 
 
4559
 
        $mysqld->{'pid'}= 0; # Assume we are done with it
4560
 
      }
4561
 
    }
4562
 
 
4563
 
    # Start shutdown of slave cluster
4564
 
    my $cluster= $clusters->[1];
4565
 
    if ( $cluster->{'pid'} )
4566
 
    {
4567
 
      $pid= mtr_ndbmgm_start($cluster, "shutdown");
4568
 
 
4569
 
      $admin_pids{$pid}= 1;
4570
 
 
4571
 
      push(@kill_pids,{
4572
 
                       pid      => $cluster->{'pid'},
4573
 
                       pidfile  => $cluster->{'path_pid'}
4574
 
                      });
4575
 
 
4576
 
      $cluster->{'pid'}= 0; # Assume we are done with it
4577
 
 
4578
 
      foreach my $ndbd (@{$cluster->{'ndbds'}} )
4579
 
      {
4580
 
        push(@kill_pids,{
4581
 
                         pid      => $ndbd->{'pid'},
4582
 
                         pidfile  => $ndbd->{'path_pid'},
4583
 
                        });
4584
 
        $ndbd->{'pid'}= 0; # Assume we are done with it
4585
 
      }
4586
 
    }
4587
 
  }
4588
 
 
4589
 
  # ----------------------------------------------------------------------
4590
 
  # Shutdown has now been started and lists for the shutdown processes
4591
 
  # and the processes to be killed has been created
4592
 
  # ----------------------------------------------------------------------
4593
 
 
4594
 
  # Wait blocking until all shutdown processes has completed
4595
 
  mtr_wait_blocking(\%admin_pids);
4596
 
 
4597
 
 
4598
 
  # Make sure that process has shutdown else try to kill them
4599
 
  mtr_check_stop_servers(\@kill_pids);
4600
 
 
4601
 
  foreach my $mysqld (@{$master}, @{$slave})
4602
 
  {
4603
 
    if ( ! $mysqld->{'pid'} )
4604
 
    {
4605
 
      # Remove ndbcluster tables if server is stopped
4606
 
      rm_ndbcluster_tables($mysqld->{'path_myddir'});
4607
 
    }
 
4325
  $tinfo->{'restarted'}= 1;
 
4326
 
 
4327
  if ( join('|', @servers) eq join('|', all_servers()) )
 
4328
  {
 
4329
    # All servers are going down, use some kind of order to
 
4330
    # avoid too many warnings in the log files
 
4331
 
 
4332
   mtr_report("Restarting all servers");
 
4333
 
 
4334
    #  mysqld processes
 
4335
    My::SafeProcess::shutdown( $opt_shutdown_timeout, started(mysqlds()) );
 
4336
 
 
4337
    # cluster processes
 
4338
    My::SafeProcess::shutdown( $opt_shutdown_timeout,
 
4339
                               started(ndbds(), ndb_mgmds()) );
 
4340
  }
 
4341
  else
 
4342
  {
 
4343
    mtr_report("Restarting ", started(@servers));
 
4344
 
 
4345
     # Stop only some servers
 
4346
    My::SafeProcess::shutdown( $opt_shutdown_timeout,
 
4347
                               started(@servers) );
 
4348
  }
 
4349
 
 
4350
  foreach my $server (@servers)
 
4351
  {
 
4352
    # Mark server as stopped
 
4353
    $server->{proc}= undef;
 
4354
 
 
4355
    # Forget history
 
4356
    delete $server->{'started_tinfo'};
 
4357
    delete $server->{'started_opts'};
 
4358
    delete $server->{'started_cnf'};
4608
4359
  }
4609
4360
}
4610
4361
 
4611
4362
 
4612
4363
#
4613
 
# run_testcase_start_servers
 
4364
# start_servers
4614
4365
#
4615
 
# Start the servers needed by this test case
 
4366
# Start servers not already started
4616
4367
#
4617
4368
# RETURN
4618
4369
#  0 OK
4619
4370
#  1 Start failed
4620
4371
#
4621
 
 
4622
 
sub run_testcase_start_servers($) {
4623
 
  my $tinfo= shift;
4624
 
  my $tname= $tinfo->{'name'};
4625
 
 
4626
 
  if ( $tinfo->{'component_id'} eq 'mysqld' )
4627
 
  {
4628
 
    if ( ! $opt_skip_ndbcluster and
4629
 
         !$clusters->[0]->{'pid'} and
4630
 
         $tinfo->{'ndb_test'} )
4631
 
    {
4632
 
      # Test need cluster, cluster is not started, start it
4633
 
      ndbcluster_start($clusters->[0], "");
4634
 
    }
4635
 
 
4636
 
    if ( !$master->[0]->{'pid'} )
4637
 
    {
4638
 
      # Master mysqld is not started
4639
 
      do_before_start_master($tinfo);
4640
 
 
4641
 
      mysqld_start($master->[0],$tinfo->{'master_opt'},[]);
4642
 
 
4643
 
    }
4644
 
 
4645
 
    if ( $clusters->[0]->{'pid'} || $clusters->[0]->{'use_running'}
4646
 
         and ! $master->[1]->{'pid'} and
4647
 
         $tinfo->{'master_num'} > 1 )
4648
 
    {
4649
 
      # Test needs cluster, start an extra mysqld connected to cluster
4650
 
 
4651
 
      if ( $mysql_version_id >= 50100 )
4652
 
      {
4653
 
        # First wait for first mysql server to have created ndb system
4654
 
        # tables ok FIXME This is a workaround so that only one mysqld
4655
 
        # create the tables
4656
 
        if ( ! sleep_until_file_created(
4657
 
                  "$master->[0]->{'path_myddir'}/mysql/ndb_apply_status.ndb",
4658
 
                                        $master->[0]->{'start_timeout'},
4659
 
                                        $master->[0]->{'pid'}))
4660
 
        {
4661
 
 
4662
 
          $tinfo->{'comment'}= "Failed to create 'mysql/ndb_apply_status' table";
4663
 
          return 1;
4664
 
        }
4665
 
      }
4666
 
      mysqld_start($master->[1],$tinfo->{'master_opt'},[]);
4667
 
    }
4668
 
 
4669
 
    # Save this test case information, so next can examine it
4670
 
    $master->[0]->{'running_master_options'}= $tinfo;
4671
 
  }
4672
 
  elsif ( ! $opt_skip_im and $tinfo->{'component_id'} eq 'im' )
4673
 
  {
4674
 
    # We have to create defaults file every time, in order to ensure that it
4675
 
    # will be the same for each test. The problem is that test can change the
4676
 
    # file (by SET/UNSET commands), so w/o recreating the file, execution of
4677
 
    # one test can affect the other.
4678
 
 
4679
 
    im_create_defaults_file($instance_manager);
4680
 
 
4681
 
    if  ( ! mtr_im_start($instance_manager, $tinfo->{im_opts}) )
4682
 
    {
4683
 
      $tinfo->{'comment'}= "Failed to start Instance Manager. ";
4684
 
      return 1;
4685
 
    }
4686
 
  }
4687
 
 
4688
 
  # ----------------------------------------------------------------------
4689
 
  # Start slaves - if needed
4690
 
  # ----------------------------------------------------------------------
4691
 
  if ( $tinfo->{'slave_num'} )
4692
 
  {
4693
 
    restore_slave_databases($tinfo->{'slave_num'});
4694
 
 
4695
 
    do_before_start_slave($tinfo);
4696
 
 
4697
 
    if ( ! $opt_skip_ndbcluster_slave and
4698
 
         !$clusters->[1]->{'pid'} and
4699
 
         $tinfo->{'ndb_test'} )
4700
 
    {
4701
 
      # Test need slave cluster, cluster is not started, start it
4702
 
      ndbcluster_start($clusters->[1], "");
4703
 
    }
4704
 
 
4705
 
    for ( my $idx= 0; $idx <  $tinfo->{'slave_num'}; $idx++ )
4706
 
    {
4707
 
      if ( ! $slave->[$idx]->{'pid'} )
4708
 
      {
4709
 
        mysqld_start($slave->[$idx],$tinfo->{'slave_opt'},
4710
 
                     $tinfo->{'slave_mi'});
4711
 
 
4712
 
      }
4713
 
    }
4714
 
 
4715
 
    # Save this test case information, so next can examine it
4716
 
    $slave->[0]->{'running_slave_options'}= $tinfo;
 
4372
sub start_servers($) {
 
4373
  my ($tinfo)= @_;
 
4374
 
 
4375
  # Start clusters
 
4376
  foreach my $cluster ( clusters() )
 
4377
  {
 
4378
    ndbcluster_start($cluster);
 
4379
  }
 
4380
 
 
4381
  # Start mysqlds
 
4382
  foreach my $mysqld ( mysqlds() )
 
4383
  {
 
4384
    if ( $mysqld->{proc} )
 
4385
    {
 
4386
      # Already started
 
4387
 
 
4388
      # Write start of testcase to log file
 
4389
      mark_log($mysqld->value('#log-error'), $tinfo);
 
4390
 
 
4391
      next;
 
4392
    }
 
4393
 
 
4394
    my $datadir= $mysqld->value('datadir');
 
4395
    if ($opt_start_dirty)
 
4396
    {
 
4397
      # Don't delete anything if starting dirty
 
4398
      ;
 
4399
    }
 
4400
    else
 
4401
    {
 
4402
 
 
4403
      my @options= ('log-bin', 'relay-log');
 
4404
      foreach my $option_name ( @options )  {
 
4405
        next unless $mysqld->option($option_name);
 
4406
 
 
4407
        my $file_name= $mysqld->value($option_name);
 
4408
        next unless
 
4409
          defined $file_name and
 
4410
            -e $file_name;
 
4411
 
 
4412
        mtr_debug(" -removing '$file_name'");
 
4413
        unlink($file_name) or die ("unable to remove file '$file_name'");
 
4414
      }
 
4415
 
 
4416
      if (-d $datadir ) {
 
4417
        mtr_verbose(" - removing '$datadir'");
 
4418
        rmtree($datadir);
 
4419
      }
 
4420
    }
 
4421
 
 
4422
    my $mysqld_basedir= $mysqld->value('basedir');
 
4423
    if ( $basedir eq $mysqld_basedir )
 
4424
    {
 
4425
      # Copy datadir from installed system db
 
4426
      for my $path ( "$opt_vardir", "$opt_vardir/..") {
 
4427
        my $install_db= "$path/install.db";
 
4428
        copytree($install_db, $datadir)
 
4429
          if -d $install_db;
 
4430
      }
 
4431
      mtr_error("Failed to copy system db to '$datadir'")
 
4432
        unless -d $datadir;
 
4433
    }
 
4434
    else
 
4435
    {
 
4436
      mysql_install_db($mysqld); # For versional testing
 
4437
 
 
4438
      mtr_error("Failed to install system db to '$datadir'")
 
4439
        unless -d $datadir;
 
4440
 
 
4441
    }
 
4442
 
 
4443
    # Create the servers tmpdir
 
4444
    my $tmpdir= $mysqld->value('tmpdir');
 
4445
    mkpath($tmpdir) unless -d $tmpdir;
 
4446
 
 
4447
    # Write start of testcase to log file
 
4448
    mark_log($mysqld->value('#log-error'), $tinfo);
 
4449
 
 
4450
    # Run <tname>-master.sh
 
4451
    if ($mysqld->option('#!run-master-sh') and
 
4452
       run_sh_script($tinfo->{master_sh}) )
 
4453
    {
 
4454
      $tinfo->{'comment'}= "Failed to execute '$tinfo->{master_sh}'";
 
4455
      return 1;
 
4456
    }
 
4457
 
 
4458
    # Run <tname>-slave.sh
 
4459
    if ($mysqld->option('#!run-slave-sh') and
 
4460
        run_sh_script($tinfo->{slave_sh}))
 
4461
    {
 
4462
      $tinfo->{'comment'}= "Failed to execute '$tinfo->{slave_sh}'";
 
4463
      return 1;
 
4464
    }
 
4465
 
 
4466
    if (!$opt_embedded_server)
 
4467
    {
 
4468
      my $extra_opts= get_extra_opts($mysqld, $tinfo);
 
4469
      mysqld_start($mysqld,$extra_opts);
 
4470
 
 
4471
      # Save this test case information, so next can examine it
 
4472
      $mysqld->{'started_tinfo'}= $tinfo;
 
4473
    }
 
4474
 
4717
4475
  }
4718
4476
 
4719
4477
  # Wait for clusters to start
4720
 
  foreach my $cluster (@{$clusters})
 
4478
  foreach my $cluster ( clusters() )
4721
4479
  {
4722
 
 
4723
 
    next if !$cluster->{'pid'};
4724
 
 
4725
4480
    if (ndbcluster_wait_started($cluster, ""))
4726
4481
    {
4727
4482
      # failed to start
4728
 
      $tinfo->{'comment'}= "Start of $cluster->{'name'} cluster failed";
 
4483
      $tinfo->{'comment'}= "Start of '".$cluster->name()."' cluster failed";
4729
4484
      return 1;
4730
4485
    }
4731
4486
  }
4732
4487
 
4733
 
  # Wait for mysqld's to start
4734
 
  foreach my $mysqld (@{$master},@{$slave})
 
4488
  # Wait for mysqlds to start
 
4489
  foreach my $mysqld ( mysqlds() )
4735
4490
  {
4736
 
 
4737
 
    next if !$mysqld->{'pid'};
4738
 
 
4739
 
    if (mysqld_wait_started($mysqld))
4740
 
    {
4741
 
      # failed to start
4742
 
      $tinfo->{'comment'}=
4743
 
        "Failed to start $mysqld->{'type'} mysqld $mysqld->{'idx'}";
 
4491
    next if !started($mysqld);
 
4492
 
 
4493
    if (sleep_until_file_created($mysqld->value('pid-file'),
 
4494
                                 $opt_start_timeout,
 
4495
                                 $mysqld->{'proc'}) == 0) {
 
4496
      $tinfo->{comment}=
 
4497
        "Failed to start ".$mysqld->name();
 
4498
 
 
4499
      my $logfile= $mysqld->value('#log-error');
 
4500
      if ( defined $logfile and -f $logfile )
 
4501
      {
 
4502
        $tinfo->{logfile}= mtr_fromfile($logfile);
 
4503
      }
 
4504
      else
 
4505
      {
 
4506
        $tinfo->{logfile}= "Could not open server logfile: '$logfile'";
 
4507
      }
4744
4508
      return 1;
4745
4509
    }
4746
4510
  }
4747
4511
  return 0;
4748
4512
}
4749
4513
 
 
4514
 
4750
4515
#
4751
4516
# Run include/check-testcase.test
4752
 
# Before a testcase, run in record mode, save result file to var
 
4517
# Before a testcase, run in record mode and save result file to var/tmp
4753
4518
# After testcase, run and compare with the recorded file, they should be equal!
4754
4519
#
4755
4520
# RETURN VALUE
4756
 
#  0 OK
4757
 
#  1 Check failed
 
4521
#  The newly started process
4758
4522
#
4759
 
sub run_check_testcase ($$) {
4760
 
 
 
4523
sub start_check_testcase ($$$) {
 
4524
  my $tinfo=    shift;
4761
4525
  my $mode=     shift;
4762
4526
  my $mysqld=   shift;
4763
4527
 
4764
 
  my $name= "check-" . $mysqld->{'type'} . $mysqld->{'idx'};
 
4528
  my $name= "check-".$mysqld->name();
 
4529
  # Replace dots in name with underscore to avoid that mysqltest
 
4530
  # misinterpret's what the filename extension is :(
 
4531
  $name=~ s/\./_/g;
4765
4532
 
4766
4533
  my $args;
4767
4534
  mtr_init_args(\$args);
4768
4535
 
4769
 
  mtr_add_arg($args, "--no-defaults");
4770
 
  mtr_add_arg($args, "--silent");
 
4536
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
 
4537
  mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
 
4538
 
4771
4539
  mtr_add_arg($args, "--skip-safemalloc");
4772
 
  mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
4773
 
  mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
4774
 
 
4775
 
  mtr_add_arg($args, "--socket=%s", $mysqld->{'path_sock'});
4776
 
  mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
4777
 
  mtr_add_arg($args, "--database=test");
4778
 
  mtr_add_arg($args, "--user=%s", $opt_user);
4779
 
  mtr_add_arg($args, "--password=");
4780
 
 
4781
 
  mtr_add_arg($args, "-R");
4782
 
  mtr_add_arg($args, "$opt_vardir/tmp/$name.result");
 
4540
 
 
4541
  mtr_add_arg($args, "--result-file=%s", "$opt_vardir/tmp/$name.result");
 
4542
  mtr_add_arg($args, "--test-file=%s", "include/check-testcase.test");
 
4543
  mtr_add_arg($args, "--verbose");
4783
4544
 
4784
4545
  if ( $mode eq "before" )
4785
4546
  {
4786
4547
    mtr_add_arg($args, "--record");
4787
4548
  }
4788
 
 
4789
 
  my $res = mtr_run_test($exe_mysqltest,$args,
4790
 
                "include/check-testcase.test", "", "", "");
4791
 
 
4792
 
  if ( $res == 1  and $mode eq "after")
4793
 
  {
4794
 
    mtr_run("diff",["-u",
4795
 
                    "$opt_vardir/tmp/$name.result",
4796
 
                    "$opt_vardir/tmp/$name.reject"],
4797
 
            "", "", "", "");
4798
 
  }
4799
 
  elsif ( $res )
4800
 
  {
4801
 
    mtr_error("Could not execute 'check-testcase' $mode testcase");
4802
 
  }
4803
 
  return $res;
4804
 
}
4805
 
 
4806
 
##############################################################################
4807
 
#
4808
 
#  Report the features that were compiled in
4809
 
#
4810
 
##############################################################################
4811
 
 
4812
 
sub run_report_features () {
4813
 
  my $args;
4814
 
 
4815
 
  if ( ! $glob_use_embedded_server )
4816
 
  {
4817
 
    mysqld_start($master->[0],[],[]);
4818
 
    if ( ! $master->[0]->{'pid'} )
4819
 
    {
4820
 
      mtr_error("Can't start the mysqld server");
4821
 
    }
4822
 
    mysqld_wait_started($master->[0]);
4823
 
  }
4824
 
 
4825
 
  my $tinfo = {};
4826
 
  $tinfo->{'name'} = 'report features';
4827
 
  $tinfo->{'result_file'} = undef;
4828
 
  $tinfo->{'component_id'} = 'mysqld';
4829
 
  $tinfo->{'path'} = 'include/report-features.test';
4830
 
  $tinfo->{'timezone'}=  "GMT-3";
4831
 
  $tinfo->{'slave_num'} = 0;
4832
 
  $tinfo->{'master_opt'} = [];
4833
 
  $tinfo->{'slave_opt'} = [];
4834
 
  $tinfo->{'slave_mi'} = [];
4835
 
  $tinfo->{'comment'} = 'report server features';
4836
 
  run_mysqltest($tinfo);
4837
 
 
4838
 
  if ( ! $glob_use_embedded_server )
4839
 
  {
4840
 
    stop_all_servers();
4841
 
  }
 
4549
  my $errfile= "$opt_vardir/tmp/$name.err";
 
4550
  my $proc= My::SafeProcess->new
 
4551
    (
 
4552
     name          => $name,
 
4553
     path          => $exe_mysqltest,
 
4554
     error         => $errfile,
 
4555
     output        => $errfile,
 
4556
     args          => \$args,
 
4557
     user_data     => $errfile,
 
4558
     verbose       => $opt_verbose,
 
4559
    );
 
4560
 
 
4561
  mtr_report("Started $proc");
 
4562
  return $proc;
4842
4563
}
4843
4564
 
4844
4565
 
4845
4566
sub run_mysqltest ($) {
 
4567
  my $proc= start_mysqltest(@_);
 
4568
  $proc->wait();
 
4569
}
 
4570
 
 
4571
 
 
4572
sub start_mysqltest ($) {
4846
4573
  my ($tinfo)= @_;
4847
4574
  my $exe= $exe_mysqltest;
4848
4575
  my $args;
4849
4576
 
4850
4577
  mtr_init_args(\$args);
4851
4578
 
4852
 
  mtr_add_arg($args, "--no-defaults");
 
4579
  mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
4853
4580
  mtr_add_arg($args, "--silent");
4854
4581
  mtr_add_arg($args, "--skip-safemalloc");
4855
4582
  mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
4860
4587
  mtr_add_arg($args, "--mark-progress")
4861
4588
    if $opt_mark_progress;
4862
4589
 
4863
 
  if ($tinfo->{'component_id'} eq 'im')
4864
 
  {
4865
 
    mtr_add_arg($args, "--socket=%s", $instance_manager->{'path_sock'});
4866
 
    mtr_add_arg($args, "--port=%d", $instance_manager->{'port'});
4867
 
    mtr_add_arg($args, "--user=%s", $instance_manager->{'admin_login'});
4868
 
    mtr_add_arg($args, "--password=%s", $instance_manager->{'admin_password'});
4869
 
  }
4870
 
  else # component_id == mysqld
4871
 
  {
4872
 
    mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_sock'});
4873
 
    mtr_add_arg($args, "--port=%d", $master->[0]->{'port'});
4874
 
    mtr_add_arg($args, "--database=test");
4875
 
    mtr_add_arg($args, "--user=%s", $opt_user);
4876
 
    mtr_add_arg($args, "--password=");
4877
 
  }
 
4590
  mtr_add_arg($args, "--database=test");
4878
4591
 
4879
4592
  if ( $opt_ps_protocol )
4880
4593
  {
4898
4611
 
4899
4612
  if ( $opt_strace_client )
4900
4613
  {
4901
 
    $exe=  "strace";            # FIXME there are ktrace, ....
 
4614
    $exe=  $opt_strace_client || "strace";
4902
4615
    mtr_add_arg($args, "-o");
4903
4616
    mtr_add_arg($args, "%s/log/mysqltest.strace", $opt_vardir);
4904
4617
    mtr_add_arg($args, "$exe_mysqltest");
4905
4618
  }
4906
4619
 
4907
 
  if ( $opt_timer )
4908
 
  {
4909
 
    mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
4910
 
  }
 
4620
  mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
4911
4621
 
4912
4622
  if ( $opt_compress )
4913
4623
  {
4919
4629
    mtr_add_arg($args, "--sleep=%d", $opt_sleep);
4920
4630
  }
4921
4631
 
4922
 
  if ( $opt_debug )
4923
 
  {
4924
 
    mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace",
4925
 
                $path_vardir_trace);
4926
 
  }
4927
 
 
4928
 
  if ( $opt_ssl_supported )
4929
 
  {
4930
 
    mtr_add_arg($args, "--ssl-ca=%s/std_data/cacert.pem",
4931
 
                $glob_mysql_test_dir);
4932
 
    mtr_add_arg($args, "--ssl-cert=%s/std_data/client-cert.pem",
4933
 
                $glob_mysql_test_dir);
4934
 
    mtr_add_arg($args, "--ssl-key=%s/std_data/client-key.pem",
4935
 
                $glob_mysql_test_dir);
4936
 
  }
4937
 
 
4938
4632
  if ( $opt_ssl )
4939
4633
  {
4940
4634
    # Turn on SSL for _all_ test cases if option --ssl was used
4941
4635
    mtr_add_arg($args, "--ssl");
4942
4636
  }
4943
 
  elsif ( $opt_ssl_supported )
4944
 
  {
4945
 
    mtr_add_arg($args, "--skip-ssl");
4946
 
  }
4947
 
 
4948
 
  # ----------------------------------------------------------------------
4949
 
  # If embedded server, we create server args to give mysqltest to pass on
4950
 
  # ----------------------------------------------------------------------
4951
 
 
4952
 
  if ( $glob_use_embedded_server )
4953
 
  {
4954
 
    mysqld_arguments($args,$master->[0],$tinfo->{'master_opt'},[]);
 
4637
 
 
4638
  if ( $opt_embedded_server )
 
4639
  {
 
4640
 
 
4641
    # Get the args needed for the embedded server
 
4642
    # and append them to args prefixed
 
4643
    # with --sever-arg=
 
4644
 
 
4645
    my $mysqld=  $config->group('embedded')
 
4646
      or mtr_error("Could not get [embedded] section");
 
4647
 
 
4648
    my $mysqld_args;
 
4649
    mtr_init_args(\$mysqld_args);
 
4650
    my $extra_opts= get_extra_opts($mysqld, $tinfo);
 
4651
    mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
 
4652
    mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
 
4653
 
 
4654
    if (IS_WINDOWS)
 
4655
    {
 
4656
      # Trick the server to send output to stderr, with --console
 
4657
      mtr_add_arg($args, "--server-arg=--console");
 
4658
    }
4955
4659
  }
4956
4660
 
4957
4661
  # ----------------------------------------------------------------------
4958
4662
  # export MYSQL_TEST variable containing <path>/mysqltest <args>
4959
4663
  # ----------------------------------------------------------------------
4960
 
  $ENV{'MYSQL_TEST'}=
4961
 
    mtr_native_path($exe_mysqltest) . " " . join(" ", @$args);
 
4664
  $ENV{'MYSQL_TEST'}= mtr_args2str($exe_mysqltest, @$args);
4962
4665
 
4963
4666
  # ----------------------------------------------------------------------
4964
4667
  # Add arguments that should not go into the MYSQL_TEST env var
4965
4668
  # ----------------------------------------------------------------------
4966
 
 
4967
4669
  if ( $opt_valgrind_mysqltest )
4968
4670
  {
4969
4671
    # Prefix the Valgrind options to the argument list.
4984
4686
    mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'});
4985
4687
  }
4986
4688
 
 
4689
  client_debug_arg($args, "mysqltest");
 
4690
 
4987
4691
  if ( $opt_record )
4988
4692
  {
4989
4693
    mtr_add_arg($args, "--record");
 
4694
 
 
4695
    # When recording to a non existing result file
 
4696
    # the name of that file is in "record_file"
 
4697
    if ( defined $tinfo->{'record_file'} ) {
 
4698
      mtr_add_arg($args, "--result-file=%s", $tinfo->{record_file});
 
4699
    }
4990
4700
  }
4991
4701
 
4992
4702
  if ( $opt_client_gdb )
5002
4712
    debugger_arguments(\$args, \$exe, "client");
5003
4713
  }
5004
4714
 
5005
 
  if ( $opt_check_testcases )
5006
 
  {
5007
 
    foreach my $mysqld (@{$master}, @{$slave})
5008
 
    {
5009
 
      if ($mysqld->{'pid'})
5010
 
      {
5011
 
        run_check_testcase("before", $mysqld);
5012
 
      }
5013
 
    }
5014
 
  }
5015
 
 
5016
 
  my $res = mtr_run_test($exe,$args,"","",$path_timefile,"");
5017
 
 
5018
 
  if ( $opt_check_testcases )
5019
 
  {
5020
 
    foreach my $mysqld (@{$master}, @{$slave})
5021
 
    {
5022
 
      if ($mysqld->{'pid'})
5023
 
      {
5024
 
        if (run_check_testcase("after", $mysqld))
5025
 
        {
5026
 
          # Check failed, mark the test case with that info
5027
 
          $tinfo->{'check_testcase_failed'}= 1;
5028
 
        }
5029
 
      }
5030
 
    }
5031
 
  }
5032
 
 
5033
 
  return $res;
5034
 
 
 
4715
  my $proc= My::SafeProcess->new
 
4716
    (
 
4717
     name          => "mysqltest",
 
4718
     path          => $exe,
 
4719
     args          => \$args,
 
4720
     append        => 1,
 
4721
     error         => $path_current_testlog,
 
4722
     verbose       => $opt_verbose,
 
4723
    );
 
4724
  mtr_verbose("Started $proc");
 
4725
  return $proc;
5035
4726
}
5036
4727
 
5037
4728
 
5045
4736
 
5046
4737
  # Write $args to gdb init file
5047
4738
  my $str= join(" ", @$$args);
5048
 
  my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
 
4739
  my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
5049
4740
 
5050
4741
  # Remove the old gdbinit file
5051
4742
  unlink($gdb_init_file);
5109
4800
 
5110
4801
  # Write $args to ddd init file
5111
4802
  my $str= join(" ", @$$args);
5112
 
  my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
 
4803
  my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
5113
4804
 
5114
4805
  # Remove the old gdbinit file
5115
4806
  unlink($gdb_init_file);
5249
4940
}
5250
4941
 
5251
4942
 
5252
 
##############################################################################
5253
 
#
5254
 
#  Usage
5255
 
#
5256
 
##############################################################################
5257
 
 
 
4943
#
 
4944
# Usage
 
4945
#
5258
4946
sub usage ($) {
5259
 
  my $message= shift;
 
4947
  my ($message)= @_;
5260
4948
 
5261
4949
  if ( $message )
5262
4950
  {
5278
4966
  compress              Use the compressed protocol between client and server
5279
4967
  ssl                   Use ssl protocol between client and server
5280
4968
  skip-ssl              Dont start server with support for ssl connections
5281
 
  bench                 Run the benchmark suite
5282
 
  small-bench           Run the benchmarks with --small-tests --small-tables
5283
 
  ndb|with-ndbcluster   Use cluster as default table type
5284
4969
  vs-config             Visual Studio configuration used to create executables
5285
4970
                        (default: MTR_VS_CONFIG environment variable)
5286
4971
 
 
4972
  config|defaults-file=<config template> Use fixed config template for all
 
4973
                        tests
 
4974
  defaults_extra_file=<config template> Extra config template to add to
 
4975
                        all generated configs
 
4976
 
5287
4977
Options to control directories to use
5288
 
  benchdir=DIR          The directory where the benchmark suite is stored
5289
 
                        (default: ../../mysql-bench)
5290
4978
  tmpdir=DIR            The directory where temporary files are stored
5291
4979
                        (default: ./var/tmp).
5292
4980
  vardir=DIR            The directory where files generated from the test run
5298
4986
                        for tmpfs (/dev/shm)
5299
4987
                        The option can also be set using environment
5300
4988
                        variable MTR_MEM=[DIR]
 
4989
  client-bindir=PATH    Path to the directory where client binaries are located
 
4990
  client-libdir=PATH    Path to the directory where client libraries are located
 
4991
 
5301
4992
 
5302
4993
Options to control what test suites or cases to run
5303
4994
 
5305
4996
  with-ndbcluster-only  Run only tests that include "ndb" in the filename
5306
4997
  skip-ndb[cluster]     Skip all tests that need cluster
5307
4998
  skip-ndb[cluster]-slave Skip all tests that need a slave cluster
5308
 
  ndb-extra             Run extra tests from ndb directory
5309
4999
  do-test=PREFIX or REGEX
5310
5000
                        Run test cases which name are prefixed with PREFIX
5311
5001
                        or fulfills REGEX
5312
5002
  skip-test=PREFIX or REGEX
5313
5003
                        Skip test cases which name are prefixed with PREFIX
5314
5004
                        or fulfills REGEX
5315
 
  start-from=PREFIX     Run test cases starting from test prefixed with PREFIX
5316
 
  suite[s]=NAME1,..,NAMEN Collect tests in suites from the comma separated
 
5005
  start-from=PREFIX     Run test cases starting test prefixed with PREFIX where
 
5006
                        prefix may be suite.testname or just testname
 
5007
  suite[s]=NAME1,..,NAMEN
 
5008
                        Collect tests in suites from the comma separated
5317
5009
                        list of suite names.
5318
 
                        The default is: "$opt_suites_default"
 
5010
                        The default is: "$DEFAULT_SUITES"
5319
5011
  skip-rpl              Skip the replication test cases.
5320
 
  skip-im               Don't start IM, and skip the IM test cases
5321
 
  big-test              Set the environment variable BIG_TEST, which can be
5322
 
                        checked from test cases.
5323
 
  combination="ARG1 .. ARG2" Specify a set of "mysqld" arguments for one
5324
 
                        combination.
5325
 
  skip-combination      Skip any combination options and combinations files
 
5012
  big-test              Also run tests marked as "big"
5326
5013
 
5327
5014
Options that specify ports
5328
5015
 
5329
 
  master_port=PORT      Specify the port number used by the first master
5330
 
  slave_port=PORT       Specify the port number used by the first slave
5331
 
  ndbcluster-port=PORT  Specify the port number used by cluster
5332
 
  ndbcluster-port-slave=PORT  Specify the port number used by slave cluster
5333
 
  mtr-build-thread=#    Specify unique collection of ports. Can also be set by
5334
 
                        setting the environment variable MTR_BUILD_THREAD.
 
5016
  mtr-build-thread=#    Specify unique number to calculate port number(s) from.
 
5017
  build-thread=#        Can be set in environment variable MTR_BUILD_THREAD.
 
5018
                        Set  MTR_BUILD_THREAD="auto" to automatically aquire
 
5019
                        a build thread id that is unique to current host
5335
5020
 
5336
5021
Options for test case authoring
5337
5022
 
5345
5030
 
5346
5031
Options to run test on running server
5347
5032
 
5348
 
  extern                Use running server for tests
5349
 
  ndb-connectstring=STR Use running cluster, and connect using STR
5350
 
  ndb-connectstring-slave=STR Use running slave cluster, and connect using STR
5351
 
  user=USER             User for connection to extern server
5352
 
  socket=PATH           Socket for connection to extern server
 
5033
  extern option=value   Run only the tests against an already started server
 
5034
                        the options to use for connection to the extern server
 
5035
                        must be specified using name-value pair notation
 
5036
                        For example:
 
5037
                         ./$0 --extern socket=/tmp/mysqld.sock
5353
5038
 
5354
5039
Options for debugging the product
5355
5040
 
5366
5051
                        test(s)
5367
5052
  manual-ddd            Let user manually start mysqld in ddd, before running
5368
5053
                        test(s)
5369
 
  master-binary=PATH    Specify the master "mysqld" to use
5370
 
  slave-binary=PATH     Specify the slave "mysqld" to use
5371
 
  strace-client         Create strace output for mysqltest client
 
5054
  strace-client=[path]  Create strace output for mysqltest client, optionally
 
5055
                        specifying name and path to the trace program to use.
 
5056
                        Example: $0 --strace-client=ktrace
5372
5057
  max-save-core         Limit the number of core files saved (to avoid filling
5373
5058
                        up disks for heavily crashing server). Defaults to
5374
 
                        $opt_max_save_core, set to 0 for no limit.
5375
 
 
5376
 
Options for coverage, profiling etc
5377
 
 
5378
 
  gcov                  FIXME
5379
 
  gprof                 FIXME
 
5059
                        $opt_max_save_core, set to 0 for no limit. Set
 
5060
                        it's default with MTR_MAX_SAVE_CORE
 
5061
  max-save-datadir      Limit the number of datadir saved (to avoid filling
 
5062
                        up disks for heavily crashing server). Defaults to
 
5063
                        $opt_max_save_datadir, set to 0 for no limit. Set
 
5064
                        it's default with MTR_MAX_SAVE_DATDIR
 
5065
  max-test-fail         Limit the number of test failurs before aborting
 
5066
                        the current test run. Defaults to
 
5067
                        $opt_max_test_fail, set to 0 for no limit. Set
 
5068
                        it's default with MTR_MAX_TEST_FAIL
 
5069
 
 
5070
Options for valgrind
 
5071
 
5380
5072
  valgrind              Run the "mysqltest" and "mysqld" executables using
5381
5073
                        valgrind with default options
5382
5074
  valgrind-all          Synonym for --valgrind
5390
5082
  callgrind             Instruct valgrind to use callgrind
5391
5083
 
5392
5084
Misc options
5393
 
 
 
5085
  user=USER             User for connecting to mysqld(default: $opt_user)
5394
5086
  comment=STR           Write STR to the output
5395
5087
  notimer               Don't show test case execution time
5396
 
  script-debug          Debug this script itself
5397
 
  verbose               More verbose output
5398
 
  start-and-exit        Only initialize and start the servers, using the
5399
 
                        startup settings for the specified test case (if any)
 
5088
  verbose               More verbose output(use multiple times for even more)
 
5089
  start                 Only initialize and start the servers, using the
 
5090
                        startup settings for the first specified test case
 
5091
                        Example:
 
5092
                         $0 --start alias &
5400
5093
  start-dirty           Only start the servers (without initialization) for
5401
 
                        the specified test case (if any)
5402
 
  fast                  Don't try to clean up from earlier runs
 
5094
                        the first specified test case
 
5095
  fast                  Run as fast as possible, dont't wait for servers
 
5096
                        to shutdown etc.
 
5097
  repeat=N              Run each test N number of times
 
5098
  retry=N               Retry tests that fail N times, limit number of failures
 
5099
                        to $opt_retry_failure
 
5100
  retry-failure=N       Limit number of retries for a failed test
5403
5101
  reorder               Reorder tests to get fewer server restarts
5404
5102
  help                  Get this help text
5405
5103
 
5406
 
  testcase-timeout=MINUTES Max test case run time (default $default_testcase_timeout)
5407
 
  suite-timeout=MINUTES Max test suite run time (default $default_suite_timeout)
5408
 
  warnings | log-warnings Pass --log-warnings to mysqld
 
5104
  testcase-timeout=MINUTES Max test case run time (default $opt_testcase_timeout)
 
5105
  suite-timeout=MINUTES Max test suite run time (default $opt_suite_timeout)
 
5106
  shutdown-timeout=SECONDS Max number of seconds to wait for server shutdown
 
5107
                        before killing servers (default $opt_shutdown_timeout)
 
5108
  warnings              Scan the log files for warnings. Use --nowarnings
 
5109
                        to turn off.
5409
5110
 
5410
5111
  sleep=SECONDS         Passed to mysqltest, will be used as fixed sleep time
5411
 
  client-bindir=PATH    Path to the directory where client binaries are located
5412
 
  client-libdir=PATH    Path to the directory where client libraries are located
5413
 
 
5414
 
Deprecated options
5415
 
  with-openssl          Deprecated option for ssl
5416
 
 
 
5112
  gcov                  Collect coverage information after the test.
 
5113
                        The result is a gcov file per source and header file.
5417
5114
 
5418
5115
HERE
5419
 
  mtr_exit(1);
 
5116
  exit(1);
5420
5117
 
5421
5118
}
 
5119