~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

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