~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#!/usr/bin/perl
2
# -*- cperl -*-
3
608 by Brian Aker
Adding snowman test (plus a dead variable removal).
4
use utf8;
5
1 by brian
clean slate
6
#
7
##############################################################################
8
#
77.1.40 by Monty Taylor
More naming changes.
9
#  drizzle-test-run.pl
1 by brian
clean slate
10
#
11
#  Tool used for executing a suite of .test file
12
#
370.1.1 by arjen at com
Initial mods for making all tests work again. Some tests adapted+added.
13
#  For now, see the "MySQL Test framework manual" for more information
14
#  http://dev.mysql.com/doc/mysqltest/en/index.html
15
#  (as the Drizzle test environment is currently still fairly similar)
1 by brian
clean slate
16
#
17
#  Please keep the test framework tools identical in all versions!
18
#
19
##############################################################################
20
#
21
# Coding style directions for this perl script
22
#
23
#   - To make this Perl script easy to alter even for those that not
24
#     code Perl that often, keeep the coding style as close as possible to
25
#     the C/C++ MySQL coding standard.
26
#
27
#   - All lists of arguments to send to commands are Perl lists/arrays,
28
#     not strings we append args to. Within reason, most string
29
#     concatenation for arguments should be avoided.
30
#
31
#   - Functions defined in the main program are not to be prefixed,
32
#     functions in "library files" are to be prefixed with "mtr_" (for
33
#     Mysql-Test-Run). There are some exceptions, code that fits best in
34
#     the main program, but are put into separate files to avoid
35
#     clutter, may be without prefix.
36
#
37
#   - All stat/opendir/-f/ is to be kept in collect_test_cases(). It
38
#     will create a struct that the rest of the program can use to get
39
#     the information. This separates the "find information" from the
40
#     "do the work" and makes the program more easy to maintain.
41
#
42
#   - The rule when it comes to the logic of this program is
43
#
44
#       command_line_setup() - is to handle the logic between flags
45
#       collect_test_cases() - is to do its best to select what tests
46
#                              to run, dig out options, if needs restart etc.
47
#       run_testcase()       - is to run a single testcase, and follow the
48
#                              logic set in both above. No, or rare file
49
#                              system operations. If a test seems complex,
50
#                              it should probably not be here.
51
#
52
# A nice way to trace the execution of this script while debugging
53
# is to use the Devel::Trace package found at
54
# "http://www.plover.com/~mjd/perl/Trace/" and run this script like
77.1.40 by Monty Taylor
More naming changes.
55
# "perl -d:Trace drizzle-test-run.pl"
1 by brian
clean slate
56
#
57
58
59
use lib "lib/";
60
61
$Devel::Trace::TRACE= 0;       # Don't trace boring init stuff
62
63
#require 5.6.1;
64
use File::Path;
65
use File::Basename;
66
use File::Copy;
67
use File::Temp qw /tempdir/;
685.1.25 by Monty Taylor
Fixed absolute path generation for real. Sigh.
68
use File::Spec::Functions qw /splitdir catpath catdir
69
                              updir curdir splitpath rel2abs/;
1 by brian
clean slate
70
use Cwd;
71
use Getopt::Long;
72
use IO::Socket;
73
use IO::Socket::INET;
74
use strict;
75
use warnings;
76
77
select(STDOUT);
78
$| = 1; # Automatically flush STDOUT
79
236.1.22 by Monty Taylor
A couple of changes to move the actual test code to the tests dir and attempt
80
require "mtr_cases.pl";
81
require "mtr_process.pl";
82
require "mtr_timer.pl";
83
require "mtr_io.pl";
84
require "mtr_gcov.pl";
85
require "mtr_gprof.pl";
86
require "mtr_report.pl";
87
require "mtr_match.pl";
88
require "mtr_misc.pl";
89
require "mtr_stress.pl";
90
require "mtr_unique.pl";
1 by brian
clean slate
91
92
$Devel::Trace::TRACE= 1;
93
94
##############################################################################
95
#
96
#  Default settings
97
#
98
##############################################################################
99
100
# Misc global variables
101
our $mysql_version_id;
102
our $glob_mysql_test_dir=         undef;
103
our $glob_mysql_bench_dir=        undef;
104
our $glob_scriptname=             undef;
105
our $glob_timers=                 undef;
106
our @glob_test_mode;
107
685.1.17 by Monty Taylor
Makde mtr work in VPATH.
108
our $glob_builddir;
109
1 by brian
clean slate
110
our $glob_basedir;
111
112
our $path_client_bindir;
113
our $path_timefile;
114
our $path_snapshot;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
115
our $path_drizzletest_log;
1 by brian
clean slate
116
our $path_current_test_log;
117
our $path_my_basedir;
118
119
our $opt_vardir;                 # A path but set directly on cmd line
120
our $path_vardir_trace;          # unix formatted opt_vardir for trace files
121
our $opt_tmpdir;                 # A path but set directly on cmd line
685.1.13 by Monty Taylor
Attempt at some VPATH support for test suite.
122
our $opt_testdir;
1 by brian
clean slate
123
124
125
our $default_vardir;
126
127
our $opt_usage;
128
our $opt_suites;
798.2.11 by Brian Aker
Factor test-run for binlog removal
129
our $opt_suites_default= "main"; # Default suites to run
1 by brian
clean slate
130
our $opt_script_debug= 0;  # Script debugging, enable with --script-debug
131
our $opt_verbose= 0;  # Verbose output, enable with --verbose
132
974.1.1 by Stewart Smith
add repeat-test=n option to test-run.pl to repeat a test n times
133
our $opt_repeat_test= 1;
134
1 by brian
clean slate
135
our $exe_master_mysqld;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
136
our $exe_drizzle;
137
our $exe_drizzle_client_test;
1 by brian
clean slate
138
our $exe_bug25714;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
139
our $exe_drizzled;
140
our $exe_drizzlecheck;
141
our $exe_drizzledump;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
142
our $exe_drizzleslap;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
143
our $exe_drizzleimport;
144
our $exe_drizzle_fix_system_tables;
145
our $exe_drizzletest;
1 by brian
clean slate
146
our $exe_slave_mysqld;
147
our $exe_my_print_defaults;
148
our $exe_perror;
149
our $lib_udf_example;
150
our $lib_example_plugin;
151
our $exe_libtool;
152
153
our $opt_bench= 0;
154
our $opt_small_bench= 0;
155
156
our @opt_combinations;
157
our $opt_skip_combination;
158
159
our @opt_extra_mysqld_opt;
160
161
our $opt_compress;
162
163
our $opt_debug;
164
our $opt_do_test;
165
our @opt_cases;                  # The test cases names in argv
496.1.1 by Paul McCullagh
Added --engine option to drizzle-test-run (default innodb)
166
our $opt_engine;
1 by brian
clean slate
167
168
our $opt_extern= 0;
169
our $opt_socket;
170
171
our $opt_fast;
172
our $opt_force;
173
our $opt_reorder= 0;
174
our $opt_enable_disabled;
175
our $opt_mem= $ENV{'MTR_MEM'};
176
177
our $opt_gcov;
178
our $opt_gcov_err;
179
our $opt_gcov_msg;
180
181
our $glob_debugger= 0;
182
our $opt_gdb;
183
our $opt_client_gdb;
184
our $opt_ddd;
185
our $opt_client_ddd;
186
our $opt_manual_gdb;
187
our $opt_manual_ddd;
188
our $opt_manual_debug;
713.1.10 by Monty Taylor
Fixed default port range in test-run.pl.
189
# Magic number -69.4 results in traditional test ports starting from 9306.
190
our $opt_mtr_build_thread=-69.4;
1 by brian
clean slate
191
our $opt_debugger;
192
our $opt_client_debugger;
193
194
our $opt_gprof;
195
our $opt_gprof_dir;
196
our $opt_gprof_master;
197
our $opt_gprof_slave;
198
199
our $master;
200
our $slave;
201
our $clusters;
202
203
our $opt_master_myport;
204
our $opt_slave_myport;
205
our $opt_record;
206
my $opt_report_features;
207
our $opt_check_testcases;
208
our $opt_mark_progress;
209
798.2.11 by Brian Aker
Factor test-run for binlog removal
210
our $opt_skip_rpl= 1;
1 by brian
clean slate
211
our $max_slave_num= 0;
212
our $max_master_num= 1;
213
our $use_innodb;
214
our $opt_skip_test;
215
216
our $opt_sleep;
217
218
our $opt_testcase_timeout;
219
our $opt_suite_timeout;
220
my  $default_testcase_timeout=     15; # 15 min max
221
my  $default_suite_timeout=       180; # 3 hours max
222
223
our $opt_start_and_exit;
224
our $opt_start_dirty;
225
our $opt_start_from;
226
227
our $opt_strace_client;
228
229
our $opt_timer= 1;
230
231
our $opt_user;
232
233
my $opt_valgrind= 0;
234
my $opt_valgrind_mysqld= 0;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
235
my $opt_valgrind_drizzletest= 0;
1 by brian
clean slate
236
my @default_valgrind_args= ("--show-reachable=yes");
237
my @valgrind_args;
238
my $opt_valgrind_path;
239
my $opt_callgrind;
240
241
our $opt_stress=               "";
242
our $opt_stress_suite=     "main";
243
our $opt_stress_mode=    "random";
244
our $opt_stress_threads=        5;
245
our $opt_stress_test_count=     0;
246
our $opt_stress_loop_count=     0;
247
our $opt_stress_test_duration=  0;
248
our $opt_stress_init_file=     "";
249
our $opt_stress_test_file=     "";
250
251
our $opt_warnings;
252
253
our $path_sql_dir;
254
255
our @data_dir_lst;
256
257
our $used_default_engine;
258
our $debug_compiled_binaries;
259
260
our %mysqld_variables;
261
262
my $source_dist= 0;
263
264
our $opt_max_save_core= 5;
265
my $num_saved_cores= 0;  # Number of core files saved in vardir/log/ so far.
266
267
######################################################################
268
#
269
#  Function declarations
270
#
271
######################################################################
272
273
sub main ();
274
sub initial_setup ();
275
sub command_line_setup ();
276
sub set_mtr_build_thread_ports($);
277
sub datadir_list_setup ();
278
sub executable_setup ();
279
sub environment_setup ();
280
sub kill_running_servers ();
281
sub remove_stale_vardir ();
282
sub setup_vardir ();
283
sub check_running_as_root();
284
sub mysqld_wait_started($);
285
sub run_benchmarks ($);
286
sub initialize_servers ();
287
sub mysql_install_db ();
288
sub copy_install_db ($$);
289
sub run_testcase ($);
290
sub run_testcase_stop_servers ($$$);
291
sub run_testcase_start_servers ($);
292
sub run_testcase_check_skip_test($);
293
sub report_failure_and_restart ($);
294
sub do_before_start_master ($);
295
sub do_before_start_slave ($);
296
sub mysqld_start ($$$);
297
sub mysqld_arguments ($$$$);
298
sub stop_all_servers ();
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
299
sub run_drizzletest ($);
685.1.25 by Monty Taylor
Fixed absolute path generation for real. Sigh.
300
sub collapse_path ($);
1 by brian
clean slate
301
sub usage ($);
302
303
304
######################################################################
305
#
306
#  Main program
307
#
308
######################################################################
309
310
main();
311
312
sub main () {
313
314
  command_line_setup();
315
316
  check_debug_support(\%mysqld_variables);
317
318
  executable_setup();
319
320
  environment_setup();
321
  signal_setup();
322
323
  if ( $opt_gcov )
324
  {
325
    gcov_prepare();
326
  }
327
328
  if ( $opt_gprof )
329
  {
330
    gprof_prepare();
331
  }
332
333
  if ( $opt_bench )
334
  {
335
    initialize_servers();
336
    run_benchmarks(shift);      # Shift what? Extra arguments?!
337
  }
338
  elsif ( $opt_stress )
339
  {
340
    initialize_servers();
341
    run_stress_test()
342
  }
343
  else
344
  {
345
    # Figure out which tests we are going to run
346
    if (!$opt_suites)
347
    {
348
      $opt_suites= $opt_suites_default;
349
350
      # Check for any extra suites to enable based on the path name
88 by Brian Aker
More cleanup in mysql-test-run
351
      my %extra_suites= ();
1 by brian
clean slate
352
353
      foreach my $dir ( reverse splitdir($glob_basedir) )
354
      {
355
	my $extra_suite= $extra_suites{$dir};
356
	if (defined $extra_suite){
357
	  mtr_report("Found extra suite: $extra_suite");
358
	  $opt_suites= "$extra_suite,$opt_suites";
359
	  last;
360
	}
361
      }
362
    }
363
364
    my $tests= collect_test_cases($opt_suites);
365
366
    # Turn off NDB and other similar options if no tests use it
367
    foreach my $test (@$tests)
368
    {
369
      next if $test->{skip};
370
371
      if (!$opt_extern)
372
      {
373
	# Count max number of slaves used by a test case
374
	if ( $test->{slave_num} > $max_slave_num) {
375
	  $max_slave_num= $test->{slave_num};
376
	  mtr_error("Too many slaves") if $max_slave_num > 3;
377
	}
378
379
	# Count max number of masters used by a test case
380
	if ( $test->{master_num} > $max_master_num) {
381
	  $max_master_num= $test->{master_num};
382
	  mtr_error("Too many masters") if $max_master_num > 2;
383
	  mtr_error("Too few masters") if $max_master_num < 1;
384
	}
385
      }
386
      $use_innodb||= $test->{'innodb_test'};
387
    }
388
389
    initialize_servers();
390
391
    if ( $opt_report_features ) {
392
      run_report_features();
393
    }
394
395
    run_tests($tests);
396
  }
397
398
  mtr_exit(0);
399
}
400
401
##############################################################################
402
#
403
#  Default settings
404
#
405
##############################################################################
406
407
#
408
# When an option is no longer used by this program, it must be explicitly
409
# ignored or else it will be passed through to mysqld.  GetOptions will call
410
# this subroutine once for each such option on the command line.  See
411
# Getopt::Long documentation.
412
#
413
414
sub warn_about_removed_option {
415
  my ($option, $value, $hash_value) = @_;
416
417
  warn "WARNING: This option is no longer used, and is ignored: --$option\n";
418
}
419
420
sub command_line_setup () {
421
422
  # These are defaults for things that are set on the command line
423
424
  my $opt_comment;
425
426
  # If so requested, we try to avail ourselves of a unique build thread number.
427
  if ( $ENV{'MTR_BUILD_THREAD'} ) {
428
    if ( lc($ENV{'MTR_BUILD_THREAD'}) eq 'auto' ) {
429
      print "Requesting build thread... ";
430
      $ENV{'MTR_BUILD_THREAD'} = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
431
      print "got ".$ENV{'MTR_BUILD_THREAD'}."\n";
432
    }
433
  }
434
435
  if ( $ENV{'MTR_BUILD_THREAD'} )
436
  {
437
    set_mtr_build_thread_ports($ENV{'MTR_BUILD_THREAD'});
438
  }
439
440
  # This is needed for test log evaluation in "gen-build-status-page"
441
  # in all cases where the calling tool does not log the commands
442
  # directly before it executes them, like "make test-force-pl" in RPM builds.
443
  print "Logging: $0 ", join(" ", @ARGV), "\n";
444
445
  # Read the command line
446
  # Note: Keep list, and the order, in sync with usage at end of this file
447
448
  # Options that are no longer used must still be processed, because all
449
  # unprocessed options are passed directly to mysqld.  The user will be
450
  # warned that the option is being ignored.
451
  #
452
  # Put the complete option string here.  For example, to remove the --suite
453
  # option, remove it from GetOptions() below and put 'suite|suites=s' here.
454
  my @removed_options = (
455
    'skip-im',  # WL#4085 "Discontinue the instance manager"
456
  );
457
458
  Getopt::Long::Configure("pass_through");
459
  GetOptions(
460
             # Control what engine/variation to run
461
             'compress'                 => \$opt_compress,
462
             'bench'                    => \$opt_bench,
463
             'small-bench'              => \$opt_small_bench,
464
465
             # Control what test suites or cases to run
466
             'force'                    => \$opt_force,
467
             'do-test=s'                => \$opt_do_test,
468
             'start-from=s'             => \$opt_start_from,
469
             'suite|suites=s'           => \$opt_suites,
470
             'skip-rpl'                 => \$opt_skip_rpl,
471
             'skip-test=s'              => \$opt_skip_test,
472
             'combination=s'            => \@opt_combinations,
473
             'skip-combination'         => \$opt_skip_combination,
474
475
             # Specify ports
476
             'master_port=i'            => \$opt_master_myport,
477
             'slave_port=i'             => \$opt_slave_myport,
478
	     'mtr-build-thread=i'       => \$opt_mtr_build_thread,
479
480
             # Test case authoring
481
             'record'                   => \$opt_record,
482
             'check-testcases'          => \$opt_check_testcases,
483
             'mark-progress'            => \$opt_mark_progress,
484
485
             # Extra options used when starting mysqld
486
             'mysqld=s'                 => \@opt_extra_mysqld_opt,
496.1.1 by Paul McCullagh
Added --engine option to drizzle-test-run (default innodb)
487
             'engine=s'                 => \$opt_engine,
1 by brian
clean slate
488
489
             # Run test on running server
490
             'extern'                   => \$opt_extern,
491
492
             # Debugging
493
             'gdb'                      => \$opt_gdb,
494
             'client-gdb'               => \$opt_client_gdb,
495
             'manual-gdb'               => \$opt_manual_gdb,
496
             'manual-debug'             => \$opt_manual_debug,
497
             'ddd'                      => \$opt_ddd,
498
             'client-ddd'               => \$opt_client_ddd,
499
             'manual-ddd'               => \$opt_manual_ddd,
500
	     'debugger=s'               => \$opt_debugger,
501
	     'client-debugger=s'        => \$opt_client_debugger,
502
             'strace-client'            => \$opt_strace_client,
503
             'master-binary=s'          => \$exe_master_mysqld,
504
             'slave-binary=s'           => \$exe_slave_mysqld,
505
             'max-save-core=i'          => \$opt_max_save_core,
506
507
             # Coverage, profiling etc
508
             'gcov'                     => \$opt_gcov,
509
             'gprof'                    => \$opt_gprof,
510
             'valgrind|valgrind-all'    => \$opt_valgrind,
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
511
             'valgrind-drizzletest'       => \$opt_valgrind_drizzletest,
1 by brian
clean slate
512
             'valgrind-mysqld'          => \$opt_valgrind_mysqld,
513
             'valgrind-options=s'       => sub {
514
	       my ($opt, $value)= @_;
515
	       # Deprecated option unless it's what we know pushbuild uses
516
	       if ($value eq "--gen-suppressions=all --show-reachable=yes") {
517
		 push(@valgrind_args, $_) for (split(' ', $value));
518
		 return;
519
	       }
520
	       die("--valgrind-options=s is deprecated. Use ",
521
		   "--valgrind-option=s, to be specified several",
522
		   " times if necessary");
523
	     },
524
             'valgrind-option=s'        => \@valgrind_args,
525
             'valgrind-path=s'          => \$opt_valgrind_path,
526
	     'callgrind'                => \$opt_callgrind,
527
528
             # Stress testing 
529
             'stress'                   => \$opt_stress,
530
             'stress-suite=s'           => \$opt_stress_suite,
531
             'stress-threads=i'         => \$opt_stress_threads,
532
             'stress-test-file=s'       => \$opt_stress_test_file,
533
             'stress-init-file=s'       => \$opt_stress_init_file,
534
             'stress-mode=s'            => \$opt_stress_mode,
535
             'stress-loop-count=i'      => \$opt_stress_loop_count,
536
             'stress-test-count=i'      => \$opt_stress_test_count,
537
             'stress-test-duration=i'   => \$opt_stress_test_duration,
538
539
	     # Directories
540
             'tmpdir=s'                 => \$opt_tmpdir,
541
             'vardir=s'                 => \$opt_vardir,
685.1.13 by Monty Taylor
Attempt at some VPATH support for test suite.
542
	     'testdir=s'		=> \$opt_testdir,
1 by brian
clean slate
543
             'benchdir=s'               => \$glob_mysql_bench_dir,
544
             'mem'                      => \$opt_mem,
545
546
             # Misc
547
             'report-features'          => \$opt_report_features,
548
             'comment=s'                => \$opt_comment,
549
             'debug'                    => \$opt_debug,
550
             'fast'                     => \$opt_fast,
551
             'reorder'                  => \$opt_reorder,
552
             'enable-disabled'          => \$opt_enable_disabled,
553
             'script-debug'             => \$opt_script_debug,
554
             'verbose'                  => \$opt_verbose,
555
             'sleep=i'                  => \$opt_sleep,
556
             'socket=s'                 => \$opt_socket,
557
             'start-dirty'              => \$opt_start_dirty,
558
             'start-and-exit'           => \$opt_start_and_exit,
559
             'timer!'                   => \$opt_timer,
560
             'user=s'                   => \$opt_user,
561
             'testcase-timeout=i'       => \$opt_testcase_timeout,
562
             'suite-timeout=i'          => \$opt_suite_timeout,
563
             'warnings|log-warnings'    => \$opt_warnings,
974.1.1 by Stewart Smith
add repeat-test=n option to test-run.pl to repeat a test n times
564
	     'repeat-test=i'            => \$opt_repeat_test,
1 by brian
clean slate
565
566
             # Options which are no longer used
567
             (map { $_ => \&warn_about_removed_option } @removed_options),
568
569
             'help|h'                   => \$opt_usage,
570
            ) or usage("Can't read options");
571
572
  usage("") if $opt_usage;
573
574
  $glob_scriptname=  basename($0);
575
576
  if ($opt_mtr_build_thread != 0)
577
  {
578
    set_mtr_build_thread_ports($opt_mtr_build_thread)
579
  }
580
  elsif ($ENV{'MTR_BUILD_THREAD'})
581
  {
582
    $opt_mtr_build_thread= $ENV{'MTR_BUILD_THREAD'};
583
  }
584
214 by Brian Aker
Rename of fields (fix issue with string and decimal .h clashing).
585
  if ( -d "../drizzled" )
1 by brian
clean slate
586
  {
587
    $source_dist=  1;
588
  }
589
590
  # Find the absolute path to the test directory
685.1.13 by Monty Taylor
Attempt at some VPATH support for test suite.
591
  if ( ! $opt_testdir )
592
  {
593
    $glob_mysql_test_dir=  cwd();
594
  } 
595
  else
596
  {
597
    $glob_mysql_test_dir= $opt_testdir;
598
  }
1 by brian
clean slate
599
  $default_vardir= "$glob_mysql_test_dir/var";
600
601
  # In most cases, the base directory we find everything relative to,
602
  # is the parent directory of the "mysql-test" directory. For source
603
  # distributions, TAR binary distributions and some other packages.
604
  $glob_basedir= dirname($glob_mysql_test_dir);
605
606
  # In the RPM case, binaries and libraries are installed in the
607
  # default system locations, instead of having our own private base
608
  # directory. And we install "/usr/share/mysql-test". Moving up one
609
  # more directory relative to "mysql-test" gives us a usable base
610
  # directory for RPM installs.
611
  if ( ! $source_dist and ! -d "$glob_basedir/bin" )
612
  {
613
    $glob_basedir= dirname($glob_basedir);
614
  }
615
713.1.10 by Monty Taylor
Fixed default port range in test-run.pl.
616
  if ( $opt_testdir and -d $opt_testdir and $opt_vardir and -d $opt_vardir
685.1.17 by Monty Taylor
Makde mtr work in VPATH.
617
         and -f "$opt_vardir/../../drizzled/drizzled")
618
  {
619
    # probably in a VPATH build
620
    $glob_builddir= "$opt_vardir/../..";
621
  }
685.1.21 by Monty Taylor
Removed some prints. Also fixed some bad.
622
  else
623
  {
624
    $glob_builddir="..";
625
  }
685.1.17 by Monty Taylor
Makde mtr work in VPATH.
626
1 by brian
clean slate
627
  # Expect mysql-bench to be located adjacent to the source tree, by default
628
  $glob_mysql_bench_dir= "$glob_basedir/../mysql-bench"
629
    unless defined $glob_mysql_bench_dir;
630
  $glob_mysql_bench_dir= undef
631
    unless -d $glob_mysql_bench_dir;
632
633
  $path_my_basedir=
634
    $source_dist ? $glob_mysql_test_dir : $glob_basedir;
635
636
  $glob_timers= mtr_init_timers();
637
638
  #
639
  # Find the mysqld executable to be able to find the mysqld version
640
  # number as early as possible
641
  #
642
643
  # Look for the client binaries directory
685.1.17 by Monty Taylor
Makde mtr work in VPATH.
644
  $path_client_bindir= mtr_path_exists("$glob_builddir/client",
645
                                       "$glob_basedir/client",
1 by brian
clean slate
646
				       "$glob_basedir/bin");
647
648
  if (!$opt_extern)
649
  {
214 by Brian Aker
Rename of fields (fix issue with string and decimal .h clashing).
650
    $exe_drizzled=       mtr_exe_exists ("$glob_basedir/drizzled/drizzled",
91 by Brian Aker
Main binary now named drizzled
651
				       "$path_client_bindir/drizzled",
652
				       "$glob_basedir/libexec/drizzled",
653
				       "$glob_basedir/bin/drizzled",
685.1.17 by Monty Taylor
Makde mtr work in VPATH.
654
				       "$glob_basedir/sbin/drizzled",
655
                                       "$glob_builddir/drizzled/drizzled");
1 by brian
clean slate
656
657
    # Use the mysqld found above to find out what features are available
658
    collect_mysqld_features();
659
  }
660
  else
661
  {
165.1.1 by Elliot Murphy
new port number from IANA
662
    $mysqld_variables{'port'}= 4427;
1 by brian
clean slate
663
  }
664
496.1.1 by Paul McCullagh
Added --engine option to drizzle-test-run (default innodb)
665
  if (!$opt_engine)
666
  {
496.1.3 by Paul McCullagh
Set default to InnoDB
667
    $opt_engine= "innodb";
496.1.1 by Paul McCullagh
Added --engine option to drizzle-test-run (default innodb)
668
  }
669
1 by brian
clean slate
670
  if ( $opt_comment )
671
  {
672
    print "\n";
673
    print '#' x 78, "\n";
674
    print "# $opt_comment\n";
675
    print '#' x 78, "\n\n";
676
  }
677
678
  foreach my $arg ( @ARGV )
679
  {
680
    if ( $arg =~ /^--skip-/ )
681
    {
682
      push(@opt_extra_mysqld_opt, $arg);
683
    }
684
    elsif ( $arg =~ /^--$/ )
685
    {
686
      # It is an effect of setting 'pass_through' in option processing
687
      # that the lone '--' separating options from arguments survives,
688
      # simply ignore it.
689
    }
690
    elsif ( $arg =~ /^-/ )
691
    {
692
      usage("Invalid option \"$arg\"");
693
    }
694
    else
695
    {
696
      push(@opt_cases, $arg);
697
    }
698
  }
699
700
  # --------------------------------------------------------------------------
701
  # Find out default storage engine being used(if any)
702
  # --------------------------------------------------------------------------
703
  foreach my $arg ( @opt_extra_mysqld_opt )
704
  {
705
    if ( $arg =~ /default-storage-engine=(\S+)/ )
706
    {
707
      $used_default_engine= $1;
708
    }
709
  }
710
  mtr_report("Using default engine '$used_default_engine'")
711
    if defined $used_default_engine;
712
713
  # --------------------------------------------------------------------------
714
  # Check if we should speed up tests by trying to run on tmpfs
715
  # --------------------------------------------------------------------------
716
  if ( defined $opt_mem )
717
  {
718
    mtr_error("Can't use --mem and --vardir at the same time ")
719
      if $opt_vardir;
720
    mtr_error("Can't use --mem and --tmpdir at the same time ")
721
      if $opt_tmpdir;
722
723
    # Search through list of locations that are known
724
    # to be "fast disks" to list to find a suitable location
725
    # Use --mem=<dir> as first location to look.
726
    my @tmpfs_locations= ($opt_mem, "/dev/shm", "/tmp");
727
728
    foreach my $fs (@tmpfs_locations)
729
    {
730
      if ( -d $fs )
731
      {
732
	mtr_report("Using tmpfs in $fs");
733
	$opt_mem= "$fs/var";
734
	$opt_mem .= $opt_mtr_build_thread if $opt_mtr_build_thread;
735
	last;
736
      }
737
    }
738
  }
739
740
  # --------------------------------------------------------------------------
741
  # Set the "var/" directory, as it is the base for everything else
742
  # --------------------------------------------------------------------------
685.1.29 by Monty Taylor
Some more cleanups to mtr.
743
  if ( ! $opt_vardir )
1 by brian
clean slate
744
  {
745
    $opt_vardir= $default_vardir;
746
  }
747
748
  $path_vardir_trace= $opt_vardir;
749
  # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
750
  $path_vardir_trace=~ s/^\w://;
751
685.1.29 by Monty Taylor
Some more cleanups to mtr.
752
  $opt_vardir= collapse_path($opt_vardir);
1 by brian
clean slate
753
754
  # --------------------------------------------------------------------------
755
  # Set tmpdir
756
  # --------------------------------------------------------------------------
757
  $opt_tmpdir=       "$opt_vardir/tmp" unless $opt_tmpdir;
758
  $opt_tmpdir =~ s,/+$,,;       # Remove ending slash if any
759
760
# --------------------------------------------------------------------------
761
# Record flag
762
# --------------------------------------------------------------------------
763
  if ( $opt_record and ! @opt_cases )
764
  {
765
    mtr_error("Will not run in record mode without a specific test case");
766
  }
767
768
  if ( $opt_record )
769
  {
770
    $opt_skip_combination = 1;
771
  }
772
773
  # --------------------------------------------------------------------------
774
  # Bench flags
775
  # --------------------------------------------------------------------------
776
  if ( $opt_small_bench )
777
  {
778
    $opt_bench=  1;
779
  }
780
781
  # --------------------------------------------------------------------------
782
  # Gcov flag
783
  # --------------------------------------------------------------------------
784
  if ( $opt_gcov and ! $source_dist )
785
  {
786
    mtr_error("Coverage test needs the source - please use source dist");
787
  }
788
789
  # --------------------------------------------------------------------------
790
  # Check debug related options
791
  # --------------------------------------------------------------------------
792
  if ( $opt_gdb || $opt_client_gdb || $opt_ddd || $opt_client_ddd ||
793
       $opt_manual_gdb || $opt_manual_ddd || $opt_manual_debug ||
794
       $opt_debugger || $opt_client_debugger )
795
  {
796
    # Indicate that we are using debugger
797
    $glob_debugger= 1;
798
    if ( $opt_extern )
799
    {
800
      mtr_error("Can't use --extern when using debugger");
801
    }
802
  }
803
804
  # --------------------------------------------------------------------------
805
  # Check if special exe was selected for master or slave
806
  # --------------------------------------------------------------------------
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
807
  $exe_master_mysqld= $exe_master_mysqld || $exe_drizzled;
808
  $exe_slave_mysqld=  $exe_slave_mysqld  || $exe_drizzled;
1 by brian
clean slate
809
810
  # --------------------------------------------------------------------------
811
  # Check valgrind arguments
812
  # --------------------------------------------------------------------------
813
  if ( $opt_valgrind or $opt_valgrind_path or @valgrind_args)
814
  {
815
    mtr_report("Turning on valgrind for all executables");
816
    $opt_valgrind= 1;
817
    $opt_valgrind_mysqld= 1;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
818
    $opt_valgrind_drizzletest= 1;
1 by brian
clean slate
819
  }
820
  elsif ( $opt_valgrind_mysqld )
821
  {
822
    mtr_report("Turning on valgrind for mysqld(s) only");
823
    $opt_valgrind= 1;
824
  }
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
825
  elsif ( $opt_valgrind_drizzletest )
1 by brian
clean slate
826
  {
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
827
    mtr_report("Turning on valgrind for drizzletest and drizzle_client_test only");
1 by brian
clean slate
828
    $opt_valgrind= 1;
829
  }
830
831
  if ( $opt_callgrind )
832
  {
833
    mtr_report("Turning on valgrind with callgrind for mysqld(s)");
834
    $opt_valgrind= 1;
835
    $opt_valgrind_mysqld= 1;
836
837
    # Set special valgrind options unless options passed on command line
838
    push(@valgrind_args, "--trace-children=yes")
839
      unless @valgrind_args;
840
  }
841
842
  if ( $opt_valgrind )
843
  {
844
    # Set valgrind_options to default unless already defined
845
    push(@valgrind_args, @default_valgrind_args)
846
      unless @valgrind_args;
847
848
    mtr_report("Running valgrind with options \"",
849
	       join(" ", @valgrind_args), "\"");
850
  }
851
852
  if ( ! $opt_testcase_timeout )
853
  {
854
    $opt_testcase_timeout= $default_testcase_timeout;
855
    $opt_testcase_timeout*= 10 if $opt_valgrind;
856
  }
857
858
  if ( ! $opt_suite_timeout )
859
  {
860
    $opt_suite_timeout= $default_suite_timeout;
861
    $opt_suite_timeout*= 6 if $opt_valgrind;
862
  }
863
864
  if ( ! $opt_user )
865
  {
866
    if ( $opt_extern )
867
    {
868
      $opt_user= "test";
869
    }
870
    else
871
    {
872
      $opt_user= "root"; # We want to do FLUSH xxx commands
873
    }
874
  }
875
876
  # On QNX, /tmp/dir/master.sock and /tmp/dir//master.sock seem to be
877
  # considered different, so avoid the extra slash (/) in the socket
878
  # paths.
879
  my $sockdir = $opt_tmpdir;
880
  $sockdir =~ s|/+$||;
881
882
  # On some operating systems, there is a limit to the length of a
883
  # UNIX domain socket's path far below PATH_MAX, so try to avoid long
884
  # socket path names.
885
  $sockdir = tempdir(CLEANUP => 0) if ( length($sockdir) >= 70 );
886
887
  $master->[0]=
888
  {
889
   pid           => 0,
890
   type          => "master",
891
   idx           => 0,
892
   path_myddir   => "$opt_vardir/master-data",
893
   path_myerr    => "$opt_vardir/log/master.err",
894
   path_pid      => "$opt_vardir/run/master.pid",
895
   path_sock     => "$sockdir/master.sock",
896
   port          =>  $opt_master_myport,
897
   start_timeout =>  400, # enough time create innodb tables
898
   cluster       =>  0, # index in clusters list
899
   start_opts    => [],
900
  };
901
902
  $master->[1]=
903
  {
904
   pid           => 0,
905
   type          => "master",
906
   idx           => 1,
907
   path_myddir   => "$opt_vardir/master1-data",
908
   path_myerr    => "$opt_vardir/log/master1.err",
909
   path_pid      => "$opt_vardir/run/master1.pid",
910
   path_sock     => "$sockdir/master1.sock",
911
   port          => $opt_master_myport + 1,
912
   start_timeout => 400, # enough time create innodb tables
913
   cluster       =>  0, # index in clusters list
914
   start_opts    => [],
915
  };
916
917
  $slave->[0]=
918
  {
919
   pid           => 0,
920
   type          => "slave",
921
   idx           => 0,
922
   path_myddir   => "$opt_vardir/slave-data",
923
   path_myerr    => "$opt_vardir/log/slave.err",
924
   path_pid    => "$opt_vardir/run/slave.pid",
925
   path_sock   => "$sockdir/slave.sock",
926
   port   => $opt_slave_myport,
927
   start_timeout => 400,
928
929
   cluster       =>  1, # index in clusters list
930
   start_opts    => [],
931
  };
932
933
  $slave->[1]=
934
  {
935
   pid           => 0,
936
   type          => "slave",
937
   idx           => 1,
938
   path_myddir   => "$opt_vardir/slave1-data",
939
   path_myerr    => "$opt_vardir/log/slave1.err",
940
   path_pid    => "$opt_vardir/run/slave1.pid",
941
   path_sock   => "$sockdir/slave1.sock",
942
   port   => $opt_slave_myport + 1,
943
   start_timeout => 300,
944
   cluster       =>  -1, # index in clusters list
945
   start_opts    => [],
946
  };
947
948
  $slave->[2]=
949
  {
950
   pid           => 0,
951
   type          => "slave",
952
   idx           => 2,
953
   path_myddir   => "$opt_vardir/slave2-data",
954
   path_myerr    => "$opt_vardir/log/slave2.err",
955
   path_pid    => "$opt_vardir/run/slave2.pid",
956
   path_sock   => "$sockdir/slave2.sock",
957
   port   => $opt_slave_myport + 2,
958
   start_timeout => 300,
959
   cluster       =>  -1, # index in clusters list
960
   start_opts    => [],
961
  };
962
963
964
  # --------------------------------------------------------------------------
965
  # extern
966
  # --------------------------------------------------------------------------
967
  if ( $opt_extern )
968
  {
969
    # Turn off features not supported when running with extern server
970
    $opt_skip_rpl= 1;
971
    warn("Currenty broken --extern");
972
973
    # Setup master->[0] with the settings for the extern server
974
    $master->[0]->{'path_sock'}=  $opt_socket ? $opt_socket : "/tmp/mysql.sock";
975
    mtr_report("Using extern server at '$master->[0]->{path_sock}'");
976
  }
977
  else
978
  {
979
    mtr_error("--socket can only be used in combination with --extern")
980
      if $opt_socket;
981
  }
982
983
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
984
  $path_timefile=  "$opt_vardir/log/drizzletest-time";
985
  $path_drizzletest_log=  "$opt_vardir/log/drizzletest.log";
1 by brian
clean slate
986
  $path_current_test_log= "$opt_vardir/log/current_test";
987
988
  $path_snapshot= "$opt_tmpdir/snapshot_$opt_master_myport/";
989
990
  if ( $opt_valgrind and $opt_debug )
991
  {
992
    # When both --valgrind and --debug is selected, send
993
    # all output to the trace file, making it possible to
994
    # see the exact location where valgrind complains
995
    foreach my $mysqld (@{$master}, @{$slave})
996
    {
997
      my $sidx= $mysqld->{idx} ? "$mysqld->{idx}" : "";
998
      $mysqld->{path_myerr}=
999
	"$opt_vardir/log/" . $mysqld->{type} . "$sidx.trace";
1000
    }
1001
  }
1002
}
1003
1004
#
1005
# To make it easier for different devs to work on the same host,
1006
# an environment variable can be used to control all ports. A small
1007
# number is to be used, 0 - 16 or similar.
1008
#
1009
# Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
1010
# versions of this script, else a 4.0 test run might conflict with a
1011
# 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
1012
# all port numbers might not be used in this version of the script.
1013
#
1014
# Also note the limitation of ports we are allowed to hand out. This
1015
# differs between operating systems and configuration, see
1016
# http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
1017
# But a fairly safe range seems to be 5001 - 32767
1018
#
1019
1020
sub set_mtr_build_thread_ports($) {
1021
  my $mtr_build_thread= shift;
1022
1023
  if ( lc($mtr_build_thread) eq 'auto' ) {
1024
    print "Requesting build thread... ";
1025
    $ENV{'MTR_BUILD_THREAD'} = $mtr_build_thread = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
1026
    print "got ".$mtr_build_thread."\n";
1027
  }
1028
713.1.10 by Monty Taylor
Fixed default port range in test-run.pl.
1029
  $mtr_build_thread= (($mtr_build_thread * 10) % 2000) - 1000;
1030
1 by brian
clean slate
1031
  # Up to two masters, up to three slaves
1032
  # A magic value in command_line_setup depends on these equations.
713.1.10 by Monty Taylor
Fixed default port range in test-run.pl.
1033
  $opt_master_myport=         $mtr_build_thread + 9000; # and 1
1 by brian
clean slate
1034
  $opt_slave_myport=          $opt_master_myport + 2;  # and 3 4
1035
1036
  if ( $opt_master_myport < 5001 or $opt_master_myport + 10 >= 32767 )
1037
  {
1038
    mtr_error("MTR_BUILD_THREAD number results in a port",
1039
              "outside 5001 - 32767",
1040
              "($opt_master_myport - $opt_master_myport + 10)");
1041
  }
1042
}
1043
1044
1045
sub datadir_list_setup () {
1046
1047
  # Make a list of all data_dirs
1048
  for (my $idx= 0; $idx < $max_master_num; $idx++)
1049
  {
1050
    push(@data_dir_lst, $master->[$idx]->{'path_myddir'});
1051
  }
1052
1053
  for (my $idx= 0; $idx < $max_slave_num; $idx++)
1054
  {
1055
    push(@data_dir_lst, $slave->[$idx]->{'path_myddir'});
1056
  }
1057
}
1058
1059
1060
##############################################################################
1061
#
1062
#  Set paths to various executable programs
1063
#
1064
##############################################################################
1065
1066
1067
sub collect_mysqld_features () {
1068
  my $found_variable_list_start= 0;
1069
  my $tmpdir= tempdir(CLEANUP => 0); # Directory removed by this function
1070
1071
  #
1072
  # Execute "mysqld --help --verbose" to get a list
1073
  # list of all features and settings
1074
  #
1075
  # --no-defaults and --skip-grant-tables are to avoid loading
1076
  # system-wide configs and plugins
1077
  #
1078
  # --datadir must exist, mysqld will chdir into it
1079
  #
236.1.61 by Monty Taylor
Remove test references to charset dir.
1080
  my $list= `$exe_drizzled --no-defaults --datadir=$tmpdir --skip-grant-tables --verbose --help`;
1 by brian
clean slate
1081
1082
  foreach my $line (split('\n', $list))
1083
  {
1084
    # First look for version
1085
    if ( !$mysql_version_id )
1086
    {
1087
      # Look for version
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1088
      my $exe_name= basename($exe_drizzled);
1 by brian
clean slate
1089
      mtr_verbose("exe_name: $exe_name");
1090
      if ( $line =~ /^\S*$exe_name\s\sVer\s([0-9]*)\.([0-9]*)\.([0-9]*)/ )
1091
      {
1092
	#print "Major: $1 Minor: $2 Build: $3\n";
1093
	$mysql_version_id= $1*10000 + $2*100 + $3;
1094
	#print "mysql_version_id: $mysql_version_id\n";
1095
	mtr_report("MySQL Version $1.$2.$3");
1096
      }
1097
    }
1098
    else
1099
    {
1100
      if (!$found_variable_list_start)
1101
      {
1102
	# Look for start of variables list
1103
	if ( $line =~ /[\-]+\s[\-]+/ )
1104
	{
1105
	  $found_variable_list_start= 1;
1106
	}
1107
      }
1108
      else
1109
      {
1110
	# Put variables into hash
1111
	if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
1112
	{
1113
	  # print "$1=\"$2\"\n";
1114
	  $mysqld_variables{$1}= $2;
1115
	}
1116
	else
1117
	{
1118
	  # The variable list is ended with a blank line
1119
	  if ( $line =~ /^[\s]*$/ )
1120
	  {
1121
	    last;
1122
	  }
1123
	  else
1124
	  {
1125
	    # Send out a warning, we should fix the variables that has no
1126
	    # space between variable name and it's value
1127
	    # or should it be fixed width column parsing? It does not
1128
	    # look like that in function my_print_variables in my_getopt.c
1129
	    mtr_warning("Could not parse variable list line : $line");
1130
	  }
1131
	}
1132
      }
1133
    }
1134
  }
1135
  rmtree($tmpdir);
1136
  mtr_error("Could not find version of MySQL") unless $mysql_version_id;
1137
  mtr_error("Could not find variabes list") unless $found_variable_list_start;
1138
1139
}
1140
1141
1142
sub run_query($$) {
1143
  my ($mysqld, $query)= @_;
1144
1145
  my $args;
1146
  mtr_init_args(\$args);
1147
1148
  mtr_add_arg($args, "--no-defaults");
779.7.8 by Monty Taylor
Turn of the "friendly" stack trace in test-run to get a proper core file.
1149
  mtr_add_arg($args, "--skip-stack-trace");
1 by brian
clean slate
1150
  mtr_add_arg($args, "--user=%s", $opt_user);
1151
  mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
1152
  mtr_add_arg($args, "--silent"); # Tab separated output
1153
  mtr_add_arg($args, "-e '%s'", $query);
1154
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1155
  my $cmd= "$exe_drizzle " . join(' ', @$args);
1 by brian
clean slate
1156
  mtr_verbose("cmd: $cmd");
1157
  return `$cmd`;
1158
}
1159
1160
1161
sub collect_mysqld_features_from_running_server ()
1162
{
1163
  my $list= run_query($master->[0], "use mysql; SHOW VARIABLES");
1164
1165
  foreach my $line (split('\n', $list))
1166
  {
1167
    # Put variables into hash
1168
    if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
1169
    {
1170
      print "$1=\"$2\"\n";
1171
      $mysqld_variables{$1}= $2;
1172
    }
1173
  }
1174
}
1175
1176
sub executable_setup () {
1177
89 by Brian Aker
Saving changes/removals to test run
1178
#
1179
# Check if libtool is available in this distribution/clone
1180
# we need it when valgrinding or debugging non installed binary
1181
# Otherwise valgrind will valgrind the libtool wrapper or bash
1182
# and gdb will not find the real executable to debug
1183
#
1 by brian
clean slate
1184
  if ( -x "../libtool")
1185
  {
1186
    $exe_libtool= "../libtool";
1187
    if ($opt_valgrind or $glob_debugger)
1188
    {
1189
      mtr_report("Using \"$exe_libtool\" when running valgrind or debugger");
1190
    }
1191
  }
1192
89 by Brian Aker
Saving changes/removals to test run
1193
# Look for my_print_defaults
1 by brian
clean slate
1194
  $exe_my_print_defaults=
54.1.7 by Stewart Smith
fix drizzle-test-run.pl for sql/ => server/ rename and remove some vs_config_dir references
1195
    mtr_exe_exists(
89 by Brian Aker
Saving changes/removals to test run
1196
        "$path_client_bindir/my_print_defaults",
685.1.17 by Monty Taylor
Makde mtr work in VPATH.
1197
        "$glob_basedir/extra/my_print_defaults",
1198
        "$glob_builddir/extra/my_print_defaults");
1 by brian
clean slate
1199
89 by Brian Aker
Saving changes/removals to test run
1200
# Look for perror
3 by Brian Aker
Fix test push for version.
1201
  $exe_perror= "perror";
1 by brian
clean slate
1202
89 by Brian Aker
Saving changes/removals to test run
1203
# Look for the client binaries
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1204
  $exe_drizzlecheck= mtr_exe_exists("$path_client_bindir/drizzlecheck");
1205
  $exe_drizzledump= mtr_exe_exists("$path_client_bindir/drizzledump");
1206
  $exe_drizzleimport= mtr_exe_exists("$path_client_bindir/drizzleimport");
1207
  $exe_drizzle=          mtr_exe_exists("$path_client_bindir/drizzle");
1 by brian
clean slate
1208
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1209
  if (!$opt_extern)
1210
  {
1211
# Look for SQL scripts directory
1212
     if ( $mysql_version_id >= 50100 )
1213
     {
1214
         $exe_drizzleslap= mtr_exe_exists("$path_client_bindir/drizzleslap");
1215
     }
1216
  }
1217
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1218
# Look for drizzletest executable
1 by brian
clean slate
1219
  {
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1220
    $exe_drizzletest= mtr_exe_exists("$path_client_bindir/drizzletest");
1 by brian
clean slate
1221
  }
1222
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1223
# Look for drizzle_client_test executable which may _not_ exist in
89 by Brian Aker
Saving changes/removals to test run
1224
# some versions, test using it should be skipped
1 by brian
clean slate
1225
  {
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1226
    $exe_drizzle_client_test=
54.1.7 by Stewart Smith
fix drizzle-test-run.pl for sql/ => server/ rename and remove some vs_config_dir references
1227
      mtr_exe_maybe_exists(
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1228
          "$glob_basedir/tests/drizzle_client_test",
1229
          "$glob_basedir/bin/drizzle_client_test");
1 by brian
clean slate
1230
  }
1231
89 by Brian Aker
Saving changes/removals to test run
1232
# Look for bug25714 executable which may _not_ exist in
1233
# some versions, test using it should be skipped
1 by brian
clean slate
1234
  $exe_bug25714=
54.1.7 by Stewart Smith
fix drizzle-test-run.pl for sql/ => server/ rename and remove some vs_config_dir references
1235
    mtr_exe_maybe_exists(
89 by Brian Aker
Saving changes/removals to test run
1236
        "$glob_basedir/tests/bug25714");
1 by brian
clean slate
1237
}
1238
1239
89 by Brian Aker
Saving changes/removals to test run
1240
1 by brian
clean slate
1241
sub generate_cmdline_mysqldump ($) {
1242
  my($mysqld) = @_;
1243
  return
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1244
    mtr_native_path($exe_drizzledump) .
1 by brian
clean slate
1245
      " --no-defaults -uroot --debug-check " .
1246
      "--port=$mysqld->{'port'} ";
1247
}
1248
1249
1250
##############################################################################
1251
#
1252
#  Set environment to be used by childs of this process for
77.1.40 by Monty Taylor
More naming changes.
1253
#  things that are constant duting the whole lifetime of drizzle-test-run.pl
1 by brian
clean slate
1254
#
1255
##############################################################################
1256
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1257
sub drizzle_client_test_arguments()
1 by brian
clean slate
1258
{
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1259
  my $exe= $exe_drizzle_client_test;
1 by brian
clean slate
1260
1261
  my $args;
1262
  mtr_init_args(\$args);
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1263
  if ( $opt_valgrind_drizzletest )
1 by brian
clean slate
1264
  {
1265
    valgrind_arguments($args, \$exe);
1266
  }
1267
1268
  mtr_add_arg($args, "--no-defaults");
1269
  mtr_add_arg($args, "--testcase");
1270
  mtr_add_arg($args, "--user=root");
1271
  mtr_add_arg($args, "--port=$master->[0]->{'port'}");
1272
1273
  if ( $opt_extern || $mysql_version_id >= 50000 )
1274
  {
1275
    mtr_add_arg($args, "--vardir=$opt_vardir")
1276
  }
1277
1278
  if ( $opt_debug )
1279
  {
1280
    mtr_add_arg($args,
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1281
      "--debug=d:t:A,$path_vardir_trace/log/drizzle_client_test.trace");
1 by brian
clean slate
1282
  }
1283
1284
  return join(" ", $exe, @$args);
1285
}
1286
1287
1288
# Note that some env is setup in spawn/run, in "mtr_process.pl"
1289
1290
sub environment_setup () {
1291
1292
  umask(022);
1293
1294
  my @ld_library_paths;
1295
1296
  # --------------------------------------------------------------------------
1297
  # Setup LD_LIBRARY_PATH so the libraries from this distro/clone
1298
  # are used in favor of the system installed ones
1299
  # --------------------------------------------------------------------------
1300
  if ( $source_dist )
1301
  {
779.3.43 by Monty Taylor
Fixed a couple of distcheck related things.
1302
    push(@ld_library_paths, "$glob_basedir/libdrizzleclient/.libs/",
1303
                            "$glob_basedir/mysys/.libs/",
1304
                            "$glob_basedir/mystrings/.libs/",
779.3.44 by Monty Taylor
Added /usr/local to LD_LIBRARY_PATH in test run - it's the one most likely to not be set with an explicit rpath in the linking stage leading to pain during distcheck.
1305
                            "$glob_basedir/drizzled/.libs/",
1306
			    "/usr/local/lib");
1 by brian
clean slate
1307
  }
1308
  else
1309
  {
1310
    push(@ld_library_paths, "$glob_basedir/lib");
1311
  }
1312
1313
  # --------------------------------------------------------------------------
1314
  # Valgrind need to be run with debug libraries otherwise it's almost
1315
  # impossible to add correct supressions, that means if "/usr/lib/debug"
1316
  # is available, it should be added to
1317
  # LD_LIBRARY_PATH
1318
  #
1319
  # But pthread is broken in libc6-dbg on Debian <= 3.1 (see Debian
1320
  # bug 399035, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=399035),
1321
  # so don't change LD_LIBRARY_PATH on that platform.
1322
  # --------------------------------------------------------------------------
1323
  my $debug_libraries_path= "/usr/lib/debug";
1324
  my $deb_version;
1325
  if (  $opt_valgrind and -d $debug_libraries_path and
1326
        (! -e '/etc/debian_version' or
1327
	 ($deb_version= mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
1328
         $deb_version > 3.1 ) )
1329
  {
1330
    push(@ld_library_paths, $debug_libraries_path);
1331
  }
1332
992.1.2 by Monty Taylor
Append local @ld_library_paths, rather than the other way around.
1333
  $ENV{'LD_LIBRARY_PATH'}= join(":", 
1 by brian
clean slate
1334
				$ENV{'LD_LIBRARY_PATH'} ?
992.1.2 by Monty Taylor
Append local @ld_library_paths, rather than the other way around.
1335
				split(':', $ENV{'LD_LIBRARY_PATH'}) : (),
1336
                                @ld_library_paths);
1 by brian
clean slate
1337
  mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
1338
1339
  $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
1340
				  $ENV{'DYLD_LIBRARY_PATH'} ?
1341
				  split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ());
1342
  mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
1343
1344
  # The environment variable used for shared libs on AIX
1345
  $ENV{'SHLIB_PATH'}= join(":", @ld_library_paths,
1346
                           $ENV{'SHLIB_PATH'} ?
1347
                           split(':', $ENV{'SHLIB_PATH'}) : ());
1348
  mtr_debug("SHLIB_PATH: $ENV{'SHLIB_PATH'}");
1349
1350
  # The environment variable used for shared libs on hp-ux
1351
  $ENV{'LIBPATH'}= join(":", @ld_library_paths,
1352
                        $ENV{'LIBPATH'} ?
1353
                        split(':', $ENV{'LIBPATH'}) : ());
1354
  mtr_debug("LIBPATH: $ENV{'LIBPATH'}");
1355
1356
  # --------------------------------------------------------------------------
1357
  # Also command lines in .opt files may contain env vars
1358
  # --------------------------------------------------------------------------
1359
383.1.6 by Brian Aker
Removed more of the charset support.
1360
  $ENV{'CHARSETSDIR'}=              "";
1 by brian
clean slate
1361
  $ENV{'UMASK'}=              "0660"; # The octal *string*
1362
  $ENV{'UMASK_DIR'}=          "0770"; # The octal *string*
1363
  
1364
  #
1365
  # MySQL tests can produce output in various character sets
1366
  # (especially, ctype_xxx.test). To avoid confusing Perl
1367
  # with output which is incompatible with the current locale
1368
  # settings, we reset the current values of LC_ALL and LC_CTYPE to "C".
1369
  # For details, please see
1370
  # Bug#27636 tests fails if LC_* variables set to *_*.UTF-8
1371
  #
1372
  $ENV{'LC_ALL'}=             "C";
1373
  $ENV{'LC_CTYPE'}=           "C";
1374
  
1375
  $ENV{'LC_COLLATE'}=         "C";
1376
  $ENV{'USE_RUNNING_SERVER'}= $opt_extern;
685.1.29 by Monty Taylor
Some more cleanups to mtr.
1377
  $ENV{'DRIZZLE_TEST_DIR'}=     collapse_path($glob_mysql_test_dir);
1 by brian
clean slate
1378
  $ENV{'MYSQLTEST_VARDIR'}=   $opt_vardir;
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1379
  $ENV{'DRIZZLE_TMP_DIR'}=      $opt_tmpdir;
1 by brian
clean slate
1380
  $ENV{'MASTER_MYSOCK'}=      $master->[0]->{'path_sock'};
1381
  $ENV{'MASTER_MYSOCK1'}=     $master->[1]->{'path_sock'};
1382
  $ENV{'MASTER_MYPORT'}=      $master->[0]->{'port'};
1383
  $ENV{'MASTER_MYPORT1'}=     $master->[1]->{'port'};
1384
  $ENV{'SLAVE_MYSOCK'}=       $slave->[0]->{'path_sock'};
1385
  $ENV{'SLAVE_MYPORT'}=       $slave->[0]->{'port'};
1386
  $ENV{'SLAVE_MYPORT1'}=      $slave->[1]->{'port'};
1387
  $ENV{'SLAVE_MYPORT2'}=      $slave->[2]->{'port'};
301 by Brian Aker
Clean up port startup
1388
  $ENV{'DRIZZLE_TCP_PORT'}=     $mysqld_variables{'port'};
1 by brian
clean slate
1389
685.1.36 by Monty Taylor
Made make test rotate ports.
1390
  $ENV{'MTR_BUILD_THREAD'}=      $opt_mtr_build_thread;
1 by brian
clean slate
1391
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1392
  $ENV{'EXE_MYSQL'}=          $exe_drizzle;
1 by brian
clean slate
1393
1394
  # ----------------------------------------------------
1395
  # Setup env so childs can execute mysqlcheck
1396
  # ----------------------------------------------------
1397
  my $cmdline_mysqlcheck=
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1398
    mtr_native_path($exe_drizzlecheck) .
1 by brian
clean slate
1399
    " --no-defaults --debug-check -uroot " .
1400
    "--port=$master->[0]->{'port'} ";
1401
1402
  if ( $opt_debug )
1403
  {
1404
    $cmdline_mysqlcheck .=
1405
      " --debug=d:t:A,$path_vardir_trace/log/mysqlcheck.trace";
1406
  }
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1407
  $ENV{'DRIZZLE_CHECK'}=              $cmdline_mysqlcheck;
1 by brian
clean slate
1408
1409
  # ----------------------------------------------------
1410
  # Setup env to childs can execute myqldump
1411
  # ----------------------------------------------------
1412
  my $cmdline_mysqldump= generate_cmdline_mysqldump($master->[0]);
1413
  my $cmdline_mysqldumpslave= generate_cmdline_mysqldump($slave->[0]);
1414
1415
  if ( $opt_debug )
1416
  {
1417
    $cmdline_mysqldump .=
1418
      " --debug=d:t:A,$path_vardir_trace/log/mysqldump-master.trace";
1419
    $cmdline_mysqldumpslave .=
1420
      " --debug=d:t:A,$path_vardir_trace/log/mysqldump-slave.trace";
1421
  }
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1422
  $ENV{'DRIZZLE_DUMP'}= $cmdline_mysqldump;
1423
  $ENV{'DRIZZLE_DUMP_SLAVE'}= $cmdline_mysqldumpslave;
1 by brian
clean slate
1424
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1425
  # ----------------------------------------------------
1426
  # Setup env so childs can execute mysqlslap
1427
  # ----------------------------------------------------
1428
  if ( $exe_drizzleslap )
1429
  {
1430
    my $cmdline_drizzleslap=
1431
      mtr_native_path($exe_drizzleslap) .
1432
      " -uroot " .
1433
      "--port=$master->[0]->{'port'} ";
1434
1435
    if ( $opt_debug )
1436
   {
1437
      $cmdline_drizzleslap .=
1438
        " --debug=d:t:A,$path_vardir_trace/log/drizzleslap.trace";
1439
    }
1440
    $ENV{'DRIZZLE_SLAP'}= $cmdline_drizzleslap;
1441
  }
1442
1443
1 by brian
clean slate
1444
1445
  # ----------------------------------------------------
1446
  # Setup env so childs can execute mysqlimport
1447
  # ----------------------------------------------------
1448
  my $cmdline_mysqlimport=
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1449
    mtr_native_path($exe_drizzleimport) .
1 by brian
clean slate
1450
    " -uroot --debug-check " .
1451
    "--port=$master->[0]->{'port'} ";
1452
1453
  if ( $opt_debug )
1454
  {
1455
    $cmdline_mysqlimport .=
1456
      " --debug=d:t:A,$path_vardir_trace/log/mysqlimport.trace";
1457
  }
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1458
  $ENV{'DRIZZLE_IMPORT'}= $cmdline_mysqlimport;
1 by brian
clean slate
1459
1460
1461
  # ----------------------------------------------------
1462
  # Setup env so childs can execute mysql
1463
  # ----------------------------------------------------
1464
  my $cmdline_mysql=
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1465
    mtr_native_path($exe_drizzle) .
1 by brian
clean slate
1466
    " --no-defaults --debug-check --host=localhost  --user=root --password= " .
383.1.6 by Brian Aker
Removed more of the charset support.
1467
    "--port=$master->[0]->{'port'} ";
1 by brian
clean slate
1468
1469
  $ENV{'MYSQL'}= $cmdline_mysql;
1470
1471
  # ----------------------------------------------------
1472
  # Setup env so childs can execute bug25714
1473
  # ----------------------------------------------------
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1474
  $ENV{'DRIZZLE_BUG25714'}=  $exe_bug25714;
1 by brian
clean slate
1475
1476
  # ----------------------------------------------------
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1477
  # Setup env so childs can execute drizzle_client_test
1 by brian
clean slate
1478
  # ----------------------------------------------------
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1479
  $ENV{'DRIZZLE_CLIENT_TEST'}=  drizzle_client_test_arguments();
1 by brian
clean slate
1480
1481
1482
  # ----------------------------------------------------
1483
  # Setup env so childs can execute mysql_fix_system_tables
1484
  # ----------------------------------------------------
87 by Brian Aker
First pass on cleaning out mysql-test-run
1485
  #if ( !$opt_extern)
54 by brian
Disabling myisam tools until incomming link patch from Monty
1486
  if ( 0 )
1 by brian
clean slate
1487
  {
1488
    my $cmdline_mysql_fix_system_tables=
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
1489
      "$exe_drizzle_fix_system_tables --no-defaults --host=localhost " .
1 by brian
clean slate
1490
      "--user=root --password= " .
1491
      "--basedir=$glob_basedir --bindir=$path_client_bindir --verbose " .
1492
      "--port=$master->[0]->{'port'} ";
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1493
    $ENV{'DRIZZLE_FIX_SYSTEM_TABLES'}=  $cmdline_mysql_fix_system_tables;
1 by brian
clean slate
1494
1495
  }
1496
1497
  # ----------------------------------------------------
1498
  # Setup env so childs can execute my_print_defaults
1499
  # ----------------------------------------------------
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1500
  $ENV{'DRIZZLE_MY_PRINT_DEFAULTS'}= mtr_native_path($exe_my_print_defaults);
1 by brian
clean slate
1501
1502
  # ----------------------------------------------------
973.1.3 by Toru Maesaka
Remove drizzleadmin from the repository and fix the test suite for it.
1503
  # Setup env so childs can shutdown the server
1 by brian
clean slate
1504
  # ----------------------------------------------------
973.1.3 by Toru Maesaka
Remove drizzleadmin from the repository and fix the test suite for it.
1505
  $ENV{'DRIZZLED_SHUTDOWN'}= mtr_native_path($exe_drizzle);
1 by brian
clean slate
1506
1507
  # ----------------------------------------------------
1508
  # Setup env so childs can execute perror  
1509
  # ----------------------------------------------------
1510
  $ENV{'MY_PERROR'}= mtr_native_path($exe_perror);
1511
1512
  # ----------------------------------------------------
1513
  # Add the path where mysqld will find ha_example.so
1514
  # ----------------------------------------------------
1515
  $ENV{'EXAMPLE_PLUGIN'}=
1516
    ($lib_example_plugin ? basename($lib_example_plugin) : "");
1517
  $ENV{'EXAMPLE_PLUGIN_OPT'}=
1518
    ($lib_example_plugin ? "--plugin_dir=" . dirname($lib_example_plugin) : "");
1519
1520
  # ----------------------------------------------------
1521
  # Setup env so childs can execute myisampack and myisamchk
1522
  # ----------------------------------------------------
54 by brian
Disabling myisam tools until incomming link patch from Monty
1523
#  $ENV{'MYISAMCHK'}= mtr_native_path(mtr_exe_exists(
1524
#                       "$path_client_bindir/myisamchk",
1525
#                       "$glob_basedir/storage/myisam/myisamchk",
1526
#                       "$glob_basedir/myisam/myisamchk"));
1527
#  $ENV{'MYISAMPACK'}= mtr_native_path(mtr_exe_exists(
1528
#                        "$path_client_bindir/myisampack",
1529
#                        "$glob_basedir/storage/myisam/myisampack",
1530
#                        "$glob_basedir/myisam/myisampack"));
1 by brian
clean slate
1531
1532
  # ----------------------------------------------------
1533
  # We are nice and report a bit about our settings
1534
  # ----------------------------------------------------
1535
  if (!$opt_extern)
1536
  {
1537
    print "Using MTR_BUILD_THREAD      = $ENV{MTR_BUILD_THREAD}\n";
1538
    print "Using MASTER_MYPORT         = $ENV{MASTER_MYPORT}\n";
1539
    print "Using MASTER_MYPORT1        = $ENV{MASTER_MYPORT1}\n";
1540
    print "Using SLAVE_MYPORT          = $ENV{SLAVE_MYPORT}\n";
1541
    print "Using SLAVE_MYPORT1         = $ENV{SLAVE_MYPORT1}\n";
1542
    print "Using SLAVE_MYPORT2         = $ENV{SLAVE_MYPORT2}\n";
1543
  }
1544
1545
  # Create an environment variable to make it possible
1546
  # to detect that valgrind is being used from test cases
1547
  $ENV{'VALGRIND_TEST'}= $opt_valgrind;
1548
1549
}
1550
1551
1552
##############################################################################
1553
#
1554
#  If we get a ^C, we try to clean up before termination
1555
#
1556
##############################################################################
1557
# FIXME check restrictions what to do in a signal handler
1558
1559
sub signal_setup () {
1560
  $SIG{INT}= \&handle_int_signal;
1561
}
1562
1563
1564
sub handle_int_signal () {
1565
  $SIG{INT}= 'DEFAULT';         # If we get a ^C again, we die...
1566
  mtr_warning("got INT signal, cleaning up.....");
1567
  stop_all_servers();
1568
  mtr_error("We die from ^C signal from user");
1569
}
1570
1571
1572
##############################################################################
1573
#
1574
#  Handle left overs from previous runs
1575
#
1576
##############################################################################
1577
1578
sub kill_running_servers () {
1579
  {
1580
    # Ensure that no old mysqld test servers are running
1581
    # This is different from terminating processes we have
1582
    # started from this run of the script, this is terminating
1583
    # leftovers from previous runs.
1584
    mtr_kill_leftovers();
1585
   }
1586
}
1587
1588
#
1589
# Remove var and any directories in var/ created by previous
1590
# tests
1591
#
1592
sub remove_stale_vardir () {
1593
1594
  mtr_report("Removing Stale Files");
1595
1596
  # Safety!
1597
  mtr_error("No, don't remove the vardir when running with --extern")
1598
    if $opt_extern;
1599
1600
  mtr_verbose("opt_vardir: $opt_vardir");
1601
  if ( $opt_vardir eq $default_vardir )
1602
  {
1603
    #
1604
    # Running with "var" in mysql-test dir
1605
    #
1606
    if ( -l $opt_vardir)
1607
    {
1608
      # var is a symlink
1609
1610
      if ( $opt_mem and readlink($opt_vardir) eq $opt_mem )
1611
      {
1612
	# Remove the directory which the link points at
1613
	mtr_verbose("Removing " . readlink($opt_vardir));
1614
	mtr_rmtree(readlink($opt_vardir));
1615
1616
	# Remove the "var" symlink
1617
	mtr_verbose("unlink($opt_vardir)");
1618
	unlink($opt_vardir);
1619
      }
1620
      elsif ( $opt_mem )
1621
      {
1622
	# Just remove the "var" symlink
1623
	mtr_report("WARNING: Removing '$opt_vardir' symlink it's wrong");
1624
1625
	mtr_verbose("unlink($opt_vardir)");
1626
	unlink($opt_vardir);
1627
      }
1628
      else
1629
      {
1630
	# Some users creates a soft link in mysql-test/var to another area
1631
	# - allow it, but remove all files in it
1632
1633
	mtr_report("WARNING: Using the 'mysql-test/var' symlink");
1634
1635
	# Make sure the directory where it points exist
1636
	mtr_error("The destination for symlink $opt_vardir does not exist")
1637
	  if ! -d readlink($opt_vardir);
1638
1639
	foreach my $bin ( glob("$opt_vardir/*") )
1640
	{
1641
	  mtr_verbose("Removing bin $bin");
1642
	  mtr_rmtree($bin);
1643
	}
1644
      }
1645
    }
1646
    else
1647
    {
1648
      # Remove the entire "var" dir
1649
      mtr_verbose("Removing $opt_vardir/");
1650
      mtr_rmtree("$opt_vardir/");
1651
    }
1652
1653
    if ( $opt_mem )
1654
    {
1655
      # A symlink from var/ to $opt_mem will be set up
1656
      # remove the $opt_mem dir to assure the symlink
1657
      # won't point at an old directory
1658
      mtr_verbose("Removing $opt_mem");
1659
      mtr_rmtree($opt_mem);
1660
    }
1661
1662
  }
1663
  else
1664
  {
1665
    #
1666
    # Running with "var" in some other place
1667
    #
1668
1669
    # Remove the var/ dir in mysql-test dir if any
1670
    # this could be an old symlink that shouldn't be there
1671
    mtr_verbose("Removing $default_vardir");
1672
    mtr_rmtree($default_vardir);
1673
1674
    # Remove the "var" dir
1675
    mtr_verbose("Removing $opt_vardir/");
1676
    mtr_rmtree("$opt_vardir/");
1677
  }
1678
}
1679
1680
#
1681
# Create var and the directories needed in var
1682
#
1683
sub setup_vardir() {
1684
  mtr_report("Creating Directories");
1685
1686
  if ( $opt_vardir eq $default_vardir )
1687
  {
1688
    #
1689
    # Running with "var" in mysql-test dir
1690
    #
1691
    if ( -l $opt_vardir )
1692
    {
1693
      #  it's a symlink
1694
1695
      # Make sure the directory where it points exist
1696
      mtr_error("The destination for symlink $opt_vardir does not exist")
1697
	if ! -d readlink($opt_vardir);
1698
    }
1699
    elsif ( $opt_mem )
1700
    {
1701
      # Runinng with "var" as a link to some "memory" location, normally tmpfs
1702
      mtr_verbose("Creating $opt_mem");
1703
      mkpath($opt_mem);
1704
1705
      mtr_report("Symlinking 'var' to '$opt_mem'");
1706
      symlink($opt_mem, $opt_vardir);
1707
    }
1708
  }
1709
1710
  if ( ! -d $opt_vardir )
1711
  {
1712
    mtr_verbose("Creating $opt_vardir");
1713
    mkpath($opt_vardir);
1714
  }
1715
1716
  # Ensure a proper error message if vardir couldn't be created
1717
  unless ( -d $opt_vardir and -w $opt_vardir )
1718
  {
1719
    mtr_error("Writable 'var' directory is needed, use the " .
1720
	      "'--vardir=<path>' option");
1721
  }
1722
1723
  mkpath("$opt_vardir/log");
1724
  mkpath("$opt_vardir/run");
1725
  mkpath("$opt_vardir/tmp");
1726
  mkpath($opt_tmpdir) if $opt_tmpdir ne "$opt_vardir/tmp";
1727
1728
  # Create new data dirs
1729
  foreach my $data_dir (@data_dir_lst)
1730
  {
1731
    mkpath("$data_dir/mysql");
1732
    mkpath("$data_dir/test");
1733
  }
1734
1735
  # Make a link std_data_ln in var/ that points to std_data
685.1.29 by Monty Taylor
Some more cleanups to mtr.
1736
  symlink(collapse_path("$glob_mysql_test_dir/std_data"),
685.1.28 by Monty Taylor
Fixed a coupla more relative-path bugs.
1737
          "$opt_vardir/std_data_ln");
1 by brian
clean slate
1738
1739
  # Remove old log files
1740
  foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
1741
  {
1742
    unlink($name);
1743
  }
971.1.2 by Monty Taylor
Moved recursive chmod to test-run rather than Makefile - since the dir isn't there to chmod by Makefile time.
1744
  system("chmod -R ugo+r $opt_vardir");
988.3.1 by lbieber
fix test suite permission problem - https://bugs.launchpad.net/drizzle/+bug/324689
1745
  system("chmod -R ugo+r $opt_vardir/std_data_ln/*");
1 by brian
clean slate
1746
}
1747
1748
1749
sub  check_running_as_root () {
1750
  # Check if running as root
1751
  # i.e a file can be read regardless what mode we set it to
1752
  my $test_file= "$opt_vardir/test_running_as_root.txt";
1753
  mtr_tofile($test_file, "MySQL");
1754
  chmod(oct("0000"), $test_file);
1755
1756
  my $result="";
1757
  if (open(FILE,"<",$test_file))
1758
  {
1759
    $result= join('', <FILE>);
1760
    close FILE;
1761
  }
1762
1763
  # Some filesystems( for example CIFS) allows reading a file
1764
  # although mode was set to 0000, but in that case a stat on
1765
  # the file will not return 0000
1766
  my $file_mode= (stat($test_file))[2] & 07777;
1767
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1768
  $ENV{'DRIZZLE_TEST_ROOT'}= "NO";
1 by brian
clean slate
1769
  mtr_verbose("result: $result, file_mode: $file_mode");
1770
  if ($result eq "MySQL" && $file_mode == 0)
1771
  {
1772
    mtr_warning("running this script as _root_ will cause some " .
1773
                "tests to be skipped");
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1774
    $ENV{'DRIZZLE_TEST_ROOT'}= "YES";
1 by brian
clean slate
1775
  }
1776
1777
  chmod(oct("0755"), $test_file);
1778
  unlink($test_file);
1779
1780
}
1781
1782
1783
sub check_debug_support ($) {
1784
  my $mysqld_variables= shift;
1785
1786
  if ( ! $mysqld_variables->{'debug'} )
1787
  {
1788
    #mtr_report("Binaries are not debug compiled");
1789
    $debug_compiled_binaries= 0;
1790
1791
    if ( $opt_debug )
1792
    {
1793
      mtr_error("Can't use --debug, binaries does not support it");
1794
    }
1795
    return;
1796
  }
1797
  mtr_report("Binaries are debug compiled");
1798
  $debug_compiled_binaries= 1;
1799
}
1800
1801
1802
##############################################################################
1803
#
1804
#  Run the benchmark suite
1805
#
1806
##############################################################################
1807
1808
sub run_benchmarks ($) {
1809
  my $benchmark=  shift;
1810
1811
  my $args;
1812
1813
  {
1814
    mysqld_start($master->[0],[],[]);
1815
    if ( ! $master->[0]->{'pid'} )
1816
    {
1817
      mtr_error("Can't start the mysqld server");
1818
    }
1819
  }
1820
1821
  mtr_init_args(\$args);
1822
1823
  mtr_add_arg($args, "--user=%s", $opt_user);
1824
1825
  if ( $opt_small_bench )
1826
  {
1827
    mtr_add_arg($args, "--small-test");
1828
    mtr_add_arg($args, "--small-tables");
1829
  }
1830
1831
  chdir($glob_mysql_bench_dir)
1832
    or mtr_error("Couldn't chdir to '$glob_mysql_bench_dir': $!");
1833
1834
  if ( ! $benchmark )
1835
  {
1836
    mtr_add_arg($args, "--log");
1837
    mtr_run("$glob_mysql_bench_dir/run-all-tests", $args, "", "", "", "");
1838
    # FIXME check result code?!
1839
  }
1840
  elsif ( -x $benchmark )
1841
  {
1842
    mtr_run("$glob_mysql_bench_dir/$benchmark", $args, "", "", "", "");
1843
    # FIXME check result code?!
1844
  }
1845
  else
1846
  {
1847
    mtr_error("Benchmark $benchmark not found");
1848
  }
1849
1850
  chdir($glob_mysql_test_dir);          # Go back
1851
1852
  {
1853
    stop_masters();
1854
  }
1855
}
1856
1857
1858
##############################################################################
1859
#
1860
#  Run the tests
1861
#
1862
##############################################################################
1863
1864
sub run_tests () {
1865
  my ($tests)= @_;
1866
1867
  mtr_print_thick_line();
1868
1869
  mtr_timer_start($glob_timers,"suite", 60 * $opt_suite_timeout);
1870
1871
  mtr_report_tests_not_skipped_though_disabled($tests);
1872
1873
  mtr_print_header();
1874
1875
  foreach my $tinfo ( @$tests )
1876
  {
974.1.1 by Stewart Smith
add repeat-test=n option to test-run.pl to repeat a test n times
1877
    foreach(1..$opt_repeat_test)
1 by brian
clean slate
1878
    {
974.1.1 by Stewart Smith
add repeat-test=n option to test-run.pl to repeat a test n times
1879
      if (run_testcase_check_skip_test($tinfo))
1880
	{
1881
	  next;
1882
	}
1883
1884
      mtr_timer_start($glob_timers,"testcase", 60 * $opt_testcase_timeout);
1885
      run_testcase($tinfo);
1886
      mtr_timer_stop($glob_timers,"testcase");
1 by brian
clean slate
1887
    }
1888
  }
1889
1890
  mtr_print_line();
1891
1892
  if ( ! $glob_debugger and
89 by Brian Aker
Saving changes/removals to test run
1893
       ! $opt_extern )
1 by brian
clean slate
1894
  {
1895
    stop_all_servers();
1896
  }
1897
1898
  if ( $opt_gcov )
1899
  {
1900
    gcov_collect(); # collect coverage information
1901
  }
1902
  if ( $opt_gprof )
1903
  {
1904
    gprof_collect(); # collect coverage information
1905
  }
1906
1907
  mtr_report_stats($tests);
1908
1909
  mtr_timer_stop($glob_timers,"suite");
1910
}
1911
1912
1913
##############################################################################
1914
#
1915
#  Initiate the test databases
1916
#
1917
##############################################################################
1918
1919
sub initialize_servers () {
1920
1921
  datadir_list_setup();
1922
1923
  if ( $opt_extern )
1924
  {
1925
    # Running against an already started server, if the specified
1926
    # vardir does not already exist it should be created
1927
    if ( ! -d $opt_vardir )
1928
    {
1929
      mtr_report("Creating '$opt_vardir'");
1930
      setup_vardir();
1931
    }
1932
    else
1933
    {
1934
      mtr_verbose("No need to create '$opt_vardir' it already exists");
1935
    }
1936
  }
1937
  else
1938
  {
1939
    kill_running_servers();
1940
1941
    if ( ! $opt_start_dirty )
1942
    {
1943
      remove_stale_vardir();
1944
      setup_vardir();
1945
1946
      mysql_install_db();
1947
      if ( $opt_force )
1948
      {
1949
	# Save a snapshot of the freshly installed db
1950
	# to make it possible to restore to a known point in time
1951
	save_installed_db();
1952
      }
1953
    }
1954
  }
1955
  check_running_as_root();
1956
77.1.40 by Monty Taylor
More naming changes.
1957
  mtr_log_init("$opt_vardir/log/drizzle-test-run.log");
1 by brian
clean slate
1958
1959
}
1960
1961
sub mysql_install_db () {
1962
1963
  if ($max_master_num > 1)
1964
  {
1965
    copy_install_db('master', $master->[1]->{'path_myddir'});
1966
  }
1967
1968
  # Install the number of slave databses needed
1969
  for (my $idx= 0; $idx < $max_slave_num; $idx++)
1970
  {
1971
    copy_install_db("slave".($idx+1), $slave->[$idx]->{'path_myddir'});
1972
  }
1973
1974
  return 0;
1975
}
1976
1977
1978
sub copy_install_db ($$) {
1979
  my $type=      shift;
1980
  my $data_dir=  shift;
1981
1982
  mtr_report("Installing \u$type Database");
1983
1984
  # Just copy the installed db from first master
1985
  mtr_copy_dir($master->[0]->{'path_myddir'}, $data_dir);
1986
1987
}
1988
1989
1990
#
1991
# Restore snapshot of the installed slave databases
1992
# if the snapshot exists
1993
#
1994
sub restore_slave_databases ($) {
1995
  my ($num_slaves)= @_;
1996
1997
  if ( -d $path_snapshot)
1998
  {
1999
    for (my $idx= 0; $idx < $num_slaves; $idx++)
2000
    {
2001
      my $data_dir= $slave->[$idx]->{'path_myddir'};
2002
      my $name= basename($data_dir);
2003
      mtr_rmtree($data_dir);
2004
      mtr_copy_dir("$path_snapshot/$name", $data_dir);
2005
    }
2006
  }
2007
}
2008
2009
2010
sub run_testcase_check_skip_test($)
2011
{
2012
  my ($tinfo)= @_;
2013
2014
  # ----------------------------------------------------------------------
2015
  # If marked to skip, just print out and return.
2016
  # Note that a test case not marked as 'skip' can still be
2017
  # skipped later, because of the test case itself in cooperation
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2018
  # with the drizzletest program tells us so.
1 by brian
clean slate
2019
  # ----------------------------------------------------------------------
2020
2021
  if ( $tinfo->{'skip'} )
2022
  {
2023
    mtr_report_test_name($tinfo);
2024
    mtr_report_test_skipped($tinfo);
2025
    return 1;
2026
  }
2027
2028
  return 0;
2029
}
2030
2031
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2032
sub do_before_run_drizzletest($)
1 by brian
clean slate
2033
{
2034
  my $tinfo= shift;
2035
  my $args;
2036
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2037
  # Remove old files produced by drizzletest
1 by brian
clean slate
2038
  my $base_file= mtr_match_extension($tinfo->{'result_file'},
2039
				    "result"); # Trim extension
2040
  unlink("$base_file.reject");
2041
  unlink("$base_file.progress");
2042
  unlink("$base_file.log");
2043
  unlink("$base_file.warnings");
2044
2045
}
2046
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2047
sub do_after_run_drizzletest($)
1 by brian
clean slate
2048
{
2049
  my $tinfo= shift;
2050
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2051
  # Save info from this testcase run to drizzletest.log
2052
  mtr_appendfile_to_file($path_current_test_log, $path_drizzletest_log)
1 by brian
clean slate
2053
    if -f $path_current_test_log;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2054
  mtr_appendfile_to_file($path_timefile, $path_drizzletest_log)
1 by brian
clean slate
2055
    if -f $path_timefile;
2056
}
2057
2058
2059
sub run_testcase_mark_logs($$)
2060
{
2061
  my ($tinfo, $log_msg)= @_;
2062
2063
  # Write a marker to all log files
2064
2065
  # The file indicating current test name
2066
  mtr_tonewfile($path_current_test_log, $log_msg);
2067
2068
  # each mysqld's .err file
2069
  foreach my $mysqld (@{$master}, @{$slave})
2070
  {
2071
    mtr_tofile($mysqld->{path_myerr}, $log_msg);
2072
  }
2073
2074
}
2075
2076
sub find_testcase_skipped_reason($)
2077
{
2078
  my ($tinfo)= @_;
2079
2080
  # Set default message
2081
  $tinfo->{'comment'}= "Detected by testcase(no log file)";
2082
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2083
  # Open drizzletest-time(the drizzletest log file)
1 by brian
clean slate
2084
  my $F= IO::File->new($path_timefile)
2085
    or return;
2086
  my $reason;
2087
2088
  while ( my $line= <$F> )
2089
  {
2090
    # Look for "reason: <reason for skipping test>"
2091
    if ( $line =~ /reason: (.*)/ )
2092
    {
2093
      $reason= $1;
2094
    }
2095
  }
2096
2097
  if ( ! $reason )
2098
  {
2099
    mtr_warning("Could not find reason for skipping test in $path_timefile");
2100
    $reason= "Detected by testcase(reason unknown) ";
2101
  }
2102
  $tinfo->{'comment'}= $reason;
2103
}
2104
2105
2106
##############################################################################
2107
#
2108
#  Run a single test case
2109
#
2110
##############################################################################
2111
2112
# When we get here, we have already filtered out test cases that doesn't
2113
# apply to the current setup, for example if we use a running server, test
2114
# cases that restart the server are dropped. So this function should mostly
2115
# be about doing things, not a lot of logic.
2116
2117
# We don't start and kill the servers for each testcase. But some
2118
# testcases needs a restart, because they specify options to start
2119
# mysqld with. After that testcase, we need to restart again, to set
2120
# back the normal options.
2121
2122
sub run_testcase ($) {
2123
  my $tinfo=  shift;
2124
2125
  # -------------------------------------------------------
2126
  # Init variables that can change between each test case
2127
  # -------------------------------------------------------
2128
2129
  $ENV{'TZ'}= $tinfo->{'timezone'};
2130
  mtr_verbose("Setting timezone: $tinfo->{'timezone'}");
2131
2132
  my $master_restart= run_testcase_need_master_restart($tinfo);
2133
  my $slave_restart= run_testcase_need_slave_restart($tinfo);
2134
2135
  if ($master_restart or $slave_restart)
2136
  {
2137
    # Can't restart a running server that may be in use
2138
    if ( $opt_extern )
2139
    {
2140
      mtr_report_test_name($tinfo);
2141
      $tinfo->{comment}= "Can't restart a running server";
2142
      mtr_report_test_skipped($tinfo);
2143
      return;
2144
    }
2145
2146
    run_testcase_stop_servers($tinfo, $master_restart, $slave_restart);
2147
  }
2148
2149
  # Write to all log files to indicate start of testcase
2150
  run_testcase_mark_logs($tinfo, "CURRENT_TEST: $tinfo->{name}\n");
2151
2152
  my $died= mtr_record_dead_children();
2153
  if ($died or $master_restart or $slave_restart)
2154
  {
2155
    if (run_testcase_start_servers($tinfo))
2156
    {
2157
      mtr_report_test_name($tinfo);
2158
      report_failure_and_restart($tinfo);
2159
      return 1;
2160
    }
2161
  }
2162
  # ----------------------------------------------------------------------
2163
  # If --start-and-exit or --start-dirty given, stop here to let user manually
2164
  # run tests
2165
  # ----------------------------------------------------------------------
2166
  if ( $opt_start_and_exit or $opt_start_dirty )
2167
  {
2168
    mtr_timer_stop_all($glob_timers);
2169
    mtr_report("\nServers started, exiting");
2170
    exit(0);
2171
  }
2172
2173
  {
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2174
    do_before_run_drizzletest($tinfo);
1 by brian
clean slate
2175
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2176
    my $res= run_drizzletest($tinfo);
1 by brian
clean slate
2177
    mtr_report_test_name($tinfo);
2178
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2179
    do_after_run_drizzletest($tinfo);
1 by brian
clean slate
2180
2181
    if ( $res == 0 )
2182
    {
2183
      mtr_report_test_passed($tinfo);
2184
    }
2185
    elsif ( $res == 62 )
2186
    {
2187
      # Testcase itself tell us to skip this one
2188
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2189
      # Try to get reason from drizzletest.log
1 by brian
clean slate
2190
      find_testcase_skipped_reason($tinfo);
2191
      mtr_report_test_skipped($tinfo);
2192
    }
2193
    elsif ( $res == 63 )
2194
    {
2195
      $tinfo->{'timeout'}= 1;           # Mark as timeout
2196
      report_failure_and_restart($tinfo);
2197
    }
2198
    elsif ( $res == 1 )
2199
    {
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2200
      # Test case failure reported by drizzletest
1 by brian
clean slate
2201
      report_failure_and_restart($tinfo);
2202
    }
2203
    else
2204
    {
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2205
      # drizzletest failed, probably crashed
1 by brian
clean slate
2206
      $tinfo->{comment}=
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2207
	"drizzletest returned unexpected code $res, it has probably crashed";
1 by brian
clean slate
2208
      report_failure_and_restart($tinfo);
2209
    }
2210
  }
2211
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2212
  # Remove the file that drizzletest writes info to
1 by brian
clean slate
2213
  unlink($path_timefile);
2214
2215
  # ----------------------------------------------------------------------
2216
  # Stop Instance Manager if we are processing an IM-test case.
2217
  # ----------------------------------------------------------------------
2218
}
2219
2220
2221
#
2222
# Save a snapshot of the installed test db(s)
2223
# I.e take a snapshot of the var/ dir
2224
#
2225
sub save_installed_db () {
2226
2227
  mtr_report("Saving snapshot of installed databases");
2228
  mtr_rmtree($path_snapshot);
2229
2230
  foreach my $data_dir (@data_dir_lst)
2231
  {
2232
    my $name= basename($data_dir);
2233
    mtr_copy_dir("$data_dir", "$path_snapshot/$name");
2234
  }
2235
}
2236
2237
2238
#
2239
# Save any interesting files in the data_dir
2240
# before the data dir is removed.
2241
#
2242
sub save_files_before_restore($$) {
2243
  my $test_name= shift;
2244
  my $data_dir= shift;
2245
  my $save_name= "$opt_vardir/log/$test_name";
2246
2247
  # Look for core files
2248
  foreach my $core_file ( glob("$data_dir/core*") )
2249
  {
2250
    last if $opt_max_save_core > 0 && $num_saved_cores >= $opt_max_save_core;
2251
    my $core_name= basename($core_file);
2252
    mtr_report("Saving $core_name");
2253
    mkdir($save_name) if ! -d $save_name;
2254
    rename("$core_file", "$save_name/$core_name");
2255
    ++$num_saved_cores;
2256
  }
2257
}
2258
2259
2260
#
2261
# Restore snapshot of the installed test db(s)
2262
# if the snapshot exists
2263
#
2264
sub restore_installed_db ($) {
2265
  my $test_name= shift;
2266
2267
  if ( -d $path_snapshot)
2268
  {
2269
    mtr_report("Restoring snapshot of databases");
2270
2271
    foreach my $data_dir (@data_dir_lst)
2272
    {
2273
      my $name= basename($data_dir);
2274
      save_files_before_restore($test_name, $data_dir);
2275
      mtr_rmtree("$data_dir");
2276
      mtr_copy_dir("$path_snapshot/$name", "$data_dir");
2277
    }
2278
  }
2279
  else
2280
  {
2281
    # No snapshot existed
2282
    mtr_error("No snapshot existed");
2283
  }
2284
}
2285
2286
sub report_failure_and_restart ($) {
2287
  my $tinfo= shift;
2288
2289
  mtr_report_test_failed($tinfo);
2290
  print "\n";
2291
  if ( $opt_force )
2292
  {
2293
    # Stop all servers that are known to be running
2294
    stop_all_servers();
2295
2296
    # Restore the snapshot of the installed test db
2297
    restore_installed_db($tinfo->{'name'});
2298
    mtr_report("Resuming Tests\n");
2299
    return;
2300
  }
2301
2302
  my $test_mode= join(" ", @::glob_test_mode) || "default";
2303
  mtr_report("Aborting: $tinfo->{'name'} failed in $test_mode mode. ");
2304
  mtr_report("To continue, re-run with '--force'.");
2305
  if ( ! $glob_debugger and
89 by Brian Aker
Saving changes/removals to test run
2306
       ! $opt_extern )
1 by brian
clean slate
2307
  {
2308
    stop_all_servers();
2309
  }
2310
  mtr_exit(1);
2311
2312
}
2313
2314
2315
sub run_master_init_script ($) {
2316
  my ($tinfo)= @_;
2317
  my $init_script= $tinfo->{'master_sh'};
2318
2319
  # Run master initialization shell script if one exists
2320
  if ( $init_script )
2321
  {
2322
    my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
2323
    if ( $ret != 0 )
2324
    {
2325
      # FIXME rewrite those scripts to return 0 if successful
2326
      # mtr_warning("$init_script exited with code $ret");
2327
    }
2328
  }
2329
}
2330
2331
2332
##############################################################################
2333
#
2334
#  Start and stop servers
2335
#
2336
##############################################################################
2337
2338
2339
sub do_before_start_master ($) {
2340
  my ($tinfo)= @_;
2341
2342
  my $tname= $tinfo->{'name'};
2343
2344
  # FIXME what about second master.....
2345
2346
  # Don't delete anything if starting dirty
2347
  return if ($opt_start_dirty);
2348
2349
  foreach my $bin ( glob("$opt_vardir/log/master*-bin*") )
2350
  {
2351
    unlink($bin);
2352
  }
2353
2354
  # FIXME only remove the ones that are tied to this master
2355
  # Remove old master.info and relay-log.info files
2356
  unlink("$master->[0]->{'path_myddir'}/master.info");
2357
  unlink("$master->[0]->{'path_myddir'}/relay-log.info");
2358
  unlink("$master->[1]->{'path_myddir'}/master.info");
2359
  unlink("$master->[1]->{'path_myddir'}/relay-log.info");
2360
2361
  run_master_init_script($tinfo);
2362
}
2363
2364
2365
sub do_before_start_slave ($) {
2366
  my ($tinfo)= @_;
2367
2368
  my $tname= $tinfo->{'name'};
2369
  my $init_script= $tinfo->{'master_sh'};
2370
2371
  # Don't delete anything if starting dirty
2372
  return if ($opt_start_dirty);
2373
2374
  foreach my $bin ( glob("$opt_vardir/log/slave*-bin*") )
2375
  {
2376
    unlink($bin);
2377
  }
2378
2379
  unlink("$slave->[0]->{'path_myddir'}/master.info");
2380
  unlink("$slave->[0]->{'path_myddir'}/relay-log.info");
2381
2382
  # Run slave initialization shell script if one exists
2383
  if ( $init_script )
2384
  {
2385
    my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");
2386
    if ( $ret != 0 )
2387
    {
2388
      # FIXME rewrite those scripts to return 0 if successful
2389
      # mtr_warning("$init_script exited with code $ret");
2390
    }
2391
  }
2392
2393
  foreach my $bin ( glob("$slave->[0]->{'path_myddir'}/log.*") )
2394
  {
2395
    unlink($bin);
2396
  }
2397
}
2398
2399
2400
sub mysqld_arguments ($$$$) {
2401
  my $args=              shift;
2402
  my $mysqld=            shift;
2403
  my $extra_opt=         shift;
2404
  my $slave_master_info= shift;
2405
2406
  my $idx= $mysqld->{'idx'};
2407
  my $sidx= "";                 # Index as string, 0 is empty string
2408
  if ( $idx> 0 )
2409
  {
2410
    $sidx= $idx;
2411
  }
2412
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2413
  my $prefix= "";               # If drizzletest server arg
1 by brian
clean slate
2414
2415
  mtr_add_arg($args, "%s--no-defaults", $prefix);
2416
685.1.29 by Monty Taylor
Some more cleanups to mtr.
2417
  $path_my_basedir= collapse_path($path_my_basedir);
1 by brian
clean slate
2418
  mtr_add_arg($args, "%s--basedir=%s", $prefix, $path_my_basedir);
2419
496.1.1 by Paul McCullagh
Added --engine option to drizzle-test-run (default innodb)
2420
  if ($opt_engine)
2421
  {
2422
    mtr_add_arg($args, "%s--default-storage-engine=%s", $prefix, $opt_engine);
2423
  }
2424
1 by brian
clean slate
2425
  if ( $mysql_version_id >= 50036)
2426
  {
2427
    # By default, prevent the started mysqld to access files outside of vardir
2428
    mtr_add_arg($args, "%s--secure-file-priv=%s", $prefix, $opt_vardir);
2429
  }
2430
2431
  mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix);
2432
2433
  # Increase default connect_timeout to avoid intermittent
2434
  # disconnects when test servers are put under load
2435
  # see BUG#28359
2436
  mtr_add_arg($args, "%s--connect-timeout=60", $prefix);
2437
2438
2439
  # When mysqld is run by a root user(euid is 0), it will fail
2440
  # to start unless we specify what user to run as, see BUG#30630
2441
  my $euid= $>;
87 by Brian Aker
First pass on cleaning out mysql-test-run
2442
  if (grep(/^--user/, @$extra_opt, @opt_extra_mysqld_opt) == 0) {
1 by brian
clean slate
2443
    mtr_add_arg($args, "%s--user=root", $prefix);
2444
  }
2445
2446
  mtr_add_arg($args, "%s--pid-file=%s", $prefix,
2447
	      $mysqld->{'path_pid'});
2448
2449
  mtr_add_arg($args, "%s--port=%d", $prefix,
2450
                $mysqld->{'port'});
2451
2452
  mtr_add_arg($args, "%s--datadir=%s", $prefix,
2453
	      $mysqld->{'path_myddir'});
2454
2455
  my $log_base_path= "$opt_vardir/log/$mysqld->{'type'}$sidx";
2456
  mtr_add_arg($args, "%s--log=%s.log", $prefix, $log_base_path);
2457
2458
  # Check if "extra_opt" contains --skip-log-bin
2459
  if ( $mysqld->{'type'} eq 'master' )
2460
  {
2461
    mtr_add_arg($args, "%s--server-id=%d", $prefix,
2462
	       $idx > 0 ? $idx + 101 : 1);
2463
2464
    mtr_add_arg($args, "%s--loose-innodb_data_file_path=ibdata1:10M:autoextend",
2465
		$prefix);
2466
656.1.43 by Monty Taylor
Quick fix to lower the innodb_lock_wait_timeout so that the stinking lock_wait_timeout tests don't take a year and a day.
2467
    mtr_add_arg($args, "%s--loose-innodb-lock-wait-timeout=5", $prefix);
2468
1 by brian
clean slate
2469
    if ( $idx > 0 or !$use_innodb)
2470
    {
2471
      mtr_add_arg($args, "%s--loose-skip-innodb", $prefix);
2472
    }
2473
  }
2474
  else
2475
  {
2476
    mtr_error("unknown mysqld type")
2477
      unless $mysqld->{'type'} eq 'slave';
2478
2479
    # Directory where slaves find the dumps generated by "load data"
2480
    # on the server. The path need to have constant length otherwise
2481
    # test results will vary, thus a relative path is used.
2482
    my $slave_load_path= "../tmp";
2483
2484
    if ( @$slave_master_info )
2485
    {
2486
      foreach my $arg ( @$slave_master_info )
2487
      {
2488
        mtr_add_arg($args, "%s%s", $prefix, $arg);
2489
      }
2490
    }
2491
    else
2492
    {
2493
      my $slave_server_id=  2 + $idx;
2494
      my $slave_rpl_rank= $slave_server_id;
2495
      mtr_add_arg($args, "%s--server-id=%d", $prefix, $slave_server_id);
2496
    }
2497
  } # end slave
2498
2499
  if ( $opt_debug )
2500
  {
2501
    mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/%s%s.trace",
2502
                $prefix, $path_vardir_trace, $mysqld->{'type'}, $sidx);
2503
  }
2504
2505
  mtr_add_arg($args, "%s--key_buffer_size=1M", $prefix);
2506
  mtr_add_arg($args, "%s--sort_buffer=256K", $prefix);
2507
  mtr_add_arg($args, "%s--max_heap_table_size=1M", $prefix);
2508
2509
  if ( $opt_warnings )
2510
  {
2511
    mtr_add_arg($args, "%s--log-warnings", $prefix);
2512
  }
2513
2514
  # Indicate to "mysqld" it will be debugged in debugger
2515
  if ( $glob_debugger )
2516
  {
2517
    mtr_add_arg($args, "%s--gdb", $prefix);
2518
  }
2519
2520
  my $found_skip_core= 0;
2521
  foreach my $arg ( @opt_extra_mysqld_opt, @$extra_opt )
2522
  {
2523
    # Allow --skip-core-file to be set in <testname>-[master|slave].opt file
2524
    if ($arg eq "--skip-core-file")
2525
    {
2526
      $found_skip_core= 1;
2527
    }
2528
    else
2529
    {
2530
      mtr_add_arg($args, "%s%s", $prefix, $arg);
2531
    }
2532
  }
2533
  if ( !$found_skip_core )
2534
  {
2535
    mtr_add_arg($args, "%s%s", $prefix, "--core-file");
2536
  }
2537
2538
  return $args;
2539
}
2540
2541
2542
##############################################################################
2543
#
2544
#  Start mysqld and return the PID
2545
#
2546
##############################################################################
2547
2548
sub mysqld_start ($$$) {
2549
  my $mysqld=            shift;
2550
  my $extra_opt=         shift;
2551
  my $slave_master_info= shift;
2552
2553
  my $args;                             # Arg vector
2554
  my $exe;
2555
  my $pid= -1;
2556
  my $wait_for_pid_file= 1;
2557
2558
  my $type= $mysqld->{'type'};
2559
  my $idx= $mysqld->{'idx'};
2560
2561
  if ( $type eq 'master' )
2562
  {
2563
    $exe= $exe_master_mysqld;
2564
  }
2565
  elsif ( $type eq 'slave' )
2566
  {
2567
    $exe= $exe_slave_mysqld;
2568
  }
2569
  else
2570
  {
2571
    mtr_error("Unknown 'type' \"$type\" passed to mysqld_start");
2572
  }
2573
2574
  mtr_init_args(\$args);
2575
2576
  if ( $opt_valgrind_mysqld )
2577
  {
2578
    valgrind_arguments($args, \$exe);
2579
  }
2580
2581
  mysqld_arguments($args,$mysqld,$extra_opt,$slave_master_info);
2582
2583
  if ( $opt_gdb || $opt_manual_gdb)
2584
  {
2585
    gdb_arguments(\$args, \$exe, "$type"."_$idx");
2586
  }
2587
  elsif ( $opt_ddd || $opt_manual_ddd )
2588
  {
2589
    ddd_arguments(\$args, \$exe, "$type"."_$idx");
2590
  }
2591
  elsif ( $opt_debugger )
2592
  {
2593
    debugger_arguments(\$args, \$exe, "$type"."_$idx");
2594
  }
2595
  elsif ( $opt_manual_debug )
2596
  {
2597
     print "\nStart $type in your debugger\n" .
2598
           "dir: $glob_mysql_test_dir\n" .
2599
           "exe: $exe\n" .
2600
	   "args:  " . join(" ", @$args)  . "\n\n" .
2601
	   "Waiting ....\n";
2602
2603
     # Indicate the exe should not be started
2604
    $exe= undef;
2605
  }
2606
  else
2607
  {
2608
    # Default to not wait until pid file has been created
2609
    $wait_for_pid_file= 0;
2610
  }
2611
2612
  # Remove the pidfile
2613
  unlink($mysqld->{'path_pid'});
2614
2615
  if ( defined $exe )
2616
  {
2617
    $pid= mtr_spawn($exe, $args, "",
2618
		    $mysqld->{'path_myerr'},
2619
		    $mysqld->{'path_myerr'},
2620
		    "",
2621
		    { append_log_file => 1 });
2622
  }
2623
2624
2625
  if ( $wait_for_pid_file && !sleep_until_file_created($mysqld->{'path_pid'},
2626
						       $mysqld->{'start_timeout'},
2627
						       $pid))
2628
  {
2629
2630
    mtr_error("Failed to start mysqld $mysqld->{'type'}");
2631
  }
2632
2633
2634
  # Remember pid of the started process
2635
  $mysqld->{'pid'}= $pid;
2636
2637
  # Remember options used when starting
2638
  $mysqld->{'start_opts'}= $extra_opt;
2639
  $mysqld->{'start_slave_master_info'}= $slave_master_info;
2640
2641
  mtr_verbose("mysqld pid: $pid");
2642
  return $pid;
2643
}
2644
2645
2646
sub stop_all_servers () {
2647
2648
  mtr_report("Stopping All Servers");
2649
2650
  my %admin_pids; # hash of admin processes that requests shutdown
2651
  my @kill_pids;  # list of processes to shutdown/kill
2652
  my $pid;
2653
2654
  # Start shutdown of all started masters
2655
  foreach my $mysqld (@{$slave}, @{$master})
2656
  {
2657
    if ( $mysqld->{'pid'} )
2658
    {
973.1.3 by Toru Maesaka
Remove drizzleadmin from the repository and fix the test suite for it.
2659
      $pid= mtr_server_shutdown($mysqld);
1 by brian
clean slate
2660
      $admin_pids{$pid}= 1;
2661
2662
      push(@kill_pids,{
2663
		       pid      => $mysqld->{'pid'},
2664
                       real_pid => $mysqld->{'real_pid'},
2665
		       pidfile  => $mysqld->{'path_pid'},
2666
		       sockfile => $mysqld->{'path_sock'},
2667
		       port     => $mysqld->{'port'},
2668
                       errfile  => $mysqld->{'path_myerr'},
2669
		      });
2670
2671
      $mysqld->{'pid'}= 0; # Assume we are done with it
2672
    }
2673
  }
2674
2675
  # Wait blocking until all shutdown processes has completed
2676
  mtr_wait_blocking(\%admin_pids);
2677
2678
  # Make sure that process has shutdown else try to kill them
2679
  mtr_check_stop_servers(\@kill_pids);
2680
}
2681
2682
2683
sub run_testcase_need_master_restart($)
2684
{
2685
  my ($tinfo)= @_;
2686
2687
  # We try to find out if we are to restart the master(s)
2688
  my $do_restart= 0;          # Assumes we don't have to
2689
89 by Brian Aker
Saving changes/removals to test run
2690
  if ( $tinfo->{'master_sh'} )
1 by brian
clean slate
2691
  {
2692
    $do_restart= 1;           # Always restart if script to run
2693
    mtr_verbose("Restart master: Always restart if script to run");
2694
  }
2695
  if ( $tinfo->{'force_restart'} )
2696
  {
2697
    $do_restart= 1; # Always restart if --force-restart in -opt file
2698
    mtr_verbose("Restart master: Restart forced with --force-restart");
2699
  }
2700
  elsif( $tinfo->{'component_id'} eq 'im' )
2701
  {
2702
    $do_restart= 1;
2703
    mtr_verbose("Restart master: Always restart for im tests");
2704
  }
2705
  elsif ( $master->[0]->{'running_master_options'} and
2706
	  $master->[0]->{'running_master_options'}->{'timezone'} ne
2707
	  $tinfo->{'timezone'})
2708
  {
2709
    $do_restart= 1;
2710
    mtr_verbose("Restart master: Different timezone");
2711
  }
2712
  # Check that running master was started with same options
2713
  # as the current test requires
2714
  elsif (! mtr_same_opts($master->[0]->{'start_opts'},
2715
                         $tinfo->{'master_opt'}) )
2716
  {
2717
    # Chech that diff is binlog format only
2718
    my $diff_opts= mtr_diff_opts($master->[0]->{'start_opts'},$tinfo->{'master_opt'});
2719
    if (scalar(@$diff_opts) eq 2) 
2720
    {
798.2.11 by Brian Aker
Factor test-run for binlog removal
2721
      $do_restart= 1;
1 by brian
clean slate
2722
    }
2723
    else
2724
    {
2725
      $do_restart= 1;
2726
      mtr_verbose("Restart master: running with different options '" .
2727
	         join(" ", @{$tinfo->{'master_opt'}}) . "' != '" .
2728
	  	join(" ", @{$master->[0]->{'start_opts'}}) . "'" );
2729
    }
2730
  }
2731
  elsif( ! $master->[0]->{'pid'} )
2732
  {
2733
    if ( $opt_extern )
2734
    {
2735
      $do_restart= 0;
2736
      mtr_verbose("No restart: using extern master");
2737
    }
2738
    else
2739
    {
2740
      $do_restart= 1;
2741
      mtr_verbose("Restart master: master is not started");
2742
    }
2743
  }
2744
  return $do_restart;
2745
}
2746
2747
sub run_testcase_need_slave_restart($)
2748
{
2749
  my ($tinfo)= @_;
2750
2751
  # We try to find out if we are to restart the slaves
2752
  my $do_slave_restart= 0;     # Assumes we don't have to
2753
89 by Brian Aker
Saving changes/removals to test run
2754
  if ( $max_slave_num == 0)
1 by brian
clean slate
2755
  {
2756
    mtr_verbose("Skip slave restart: No testcase use slaves");
2757
  }
2758
  else
2759
  {
2760
2761
    # Check if any slave is currently started
2762
    my $any_slave_started= 0;
2763
    foreach my $mysqld (@{$slave})
2764
    {
2765
      if ( $mysqld->{'pid'} )
2766
      {
2767
	$any_slave_started= 1;
2768
	last;
2769
      }
2770
    }
2771
2772
    if ($any_slave_started)
2773
    {
2774
      mtr_verbose("Restart slave: Slave is started, always restart");
2775
      $do_slave_restart= 1;
2776
    }
2777
    elsif ( $tinfo->{'slave_num'} )
2778
    {
2779
      mtr_verbose("Restart slave: Test need slave");
2780
      $do_slave_restart= 1;
2781
    }
2782
  }
2783
2784
  return $do_slave_restart;
2785
2786
}
2787
2788
# ----------------------------------------------------------------------
2789
# If not using a running servers we may need to stop and restart.
2790
# We restart in the case we have initiation scripts, server options
2791
# etc to run. But we also restart again after the test first restart
2792
# and test is run, to get back to normal server settings.
2793
#
2794
# To make the code a bit more clean, we actually only stop servers
2795
# here, and mark this to be done. Then a generic "start" part will
2796
# start up the needed servers again.
2797
# ----------------------------------------------------------------------
2798
2799
sub run_testcase_stop_servers($$$) {
2800
  my ($tinfo, $do_restart, $do_slave_restart)= @_;
2801
  my $pid;
2802
  my %admin_pids; # hash of admin processes that requests shutdown
2803
  my @kill_pids;  # list of processes to shutdown/kill
2804
2805
  # Remember if we restarted for this test case (count restarts)
2806
  $tinfo->{'restarted'}= $do_restart;
2807
2808
  if ( $do_restart )
2809
  {
2810
    delete $master->[0]->{'running_master_options'}; # Forget history
2811
2812
    # Start shutdown of all started masters
2813
    foreach my $mysqld (@{$master})
2814
    {
2815
      if ( $mysqld->{'pid'} )
2816
      {
973.1.3 by Toru Maesaka
Remove drizzleadmin from the repository and fix the test suite for it.
2817
        $pid= mtr_server_shutdown($mysqld);
2818
2819
        $admin_pids{$pid}= 1;
2820
2821
        push(@kill_pids,{
2822
              pid      => $mysqld->{'pid'},
2823
              real_pid => $mysqld->{'real_pid'},
2824
              pidfile  => $mysqld->{'path_pid'},
2825
              sockfile => $mysqld->{'path_sock'},
2826
              port     => $mysqld->{'port'},
2827
              errfile   => $mysqld->{'path_myerr'},
2828
        });
2829
2830
        $mysqld->{'pid'}= 0; # Assume we are done with it
1 by brian
clean slate
2831
      }
2832
    }
2833
  }
2834
2835
  if ( $do_restart || $do_slave_restart )
2836
  {
2837
2838
    delete $slave->[0]->{'running_slave_options'}; # Forget history
2839
2840
    # Start shutdown of all started slaves
2841
    foreach my $mysqld (@{$slave})
2842
    {
2843
      if ( $mysqld->{'pid'} )
2844
      {
973.1.3 by Toru Maesaka
Remove drizzleadmin from the repository and fix the test suite for it.
2845
        $pid= mtr_server_shutdown($mysqld);
2846
2847
        $admin_pids{$pid}= 1;
2848
2849
        push(@kill_pids,{
2850
              pid      => $mysqld->{'pid'},
2851
              real_pid => $mysqld->{'real_pid'},
2852
              pidfile  => $mysqld->{'path_pid'},
2853
              sockfile => $mysqld->{'path_sock'},
2854
              port     => $mysqld->{'port'},
2855
              errfile  => $mysqld->{'path_myerr'},
2856
        });
2857
2858
        $mysqld->{'pid'}= 0; # Assume we are done with it
1 by brian
clean slate
2859
      }
2860
    }
2861
  }
2862
2863
  # ----------------------------------------------------------------------
2864
  # Shutdown has now been started and lists for the shutdown processes
2865
  # and the processes to be killed has been created
2866
  # ----------------------------------------------------------------------
2867
2868
  # Wait blocking until all shutdown processes has completed
2869
  mtr_wait_blocking(\%admin_pids);
2870
2871
2872
  # Make sure that process has shutdown else try to kill them
2873
  mtr_check_stop_servers(\@kill_pids);
2874
}
2875
2876
2877
#
2878
# run_testcase_start_servers
2879
#
2880
# Start the servers needed by this test case
2881
#
2882
# RETURN
2883
#  0 OK
2884
#  1 Start failed
2885
#
2886
2887
sub run_testcase_start_servers($) {
2888
  my $tinfo= shift;
2889
  my $tname= $tinfo->{'name'};
2890
2891
  if ( $tinfo->{'component_id'} eq 'mysqld' )
2892
  {
2893
    if ( !$master->[0]->{'pid'} )
2894
    {
2895
      # Master mysqld is not started
2896
      do_before_start_master($tinfo);
2897
2898
      mysqld_start($master->[0],$tinfo->{'master_opt'},[]);
2899
2900
    }
2901
2902
    # Save this test case information, so next can examine it
2903
    $master->[0]->{'running_master_options'}= $tinfo;
2904
  }
2905
2906
  # ----------------------------------------------------------------------
2907
  # Start slaves - if needed
2908
  # ----------------------------------------------------------------------
2909
  if ( $tinfo->{'slave_num'} )
2910
  {
2911
    restore_slave_databases($tinfo->{'slave_num'});
2912
2913
    do_before_start_slave($tinfo);
2914
2915
    for ( my $idx= 0; $idx <  $tinfo->{'slave_num'}; $idx++ )
2916
    {
2917
      if ( ! $slave->[$idx]->{'pid'} )
2918
      {
2919
	mysqld_start($slave->[$idx],$tinfo->{'slave_opt'},
2920
		     $tinfo->{'slave_mi'});
2921
2922
      }
2923
    }
2924
2925
    # Save this test case information, so next can examine it
2926
    $slave->[0]->{'running_slave_options'}= $tinfo;
2927
  }
2928
2929
  # Wait for mysqld's to start
2930
  foreach my $mysqld (@{$master},@{$slave})
2931
  {
2932
2933
    next if !$mysqld->{'pid'};
2934
2935
    if (mysqld_wait_started($mysqld))
2936
    {
2937
      # failed to start
2938
      $tinfo->{'comment'}=
2939
	"Failed to start $mysqld->{'type'} mysqld $mysqld->{'idx'}";
2940
      return 1;
2941
    }
2942
  }
2943
  return 0;
2944
}
2945
2946
#
2947
# Run include/check-testcase.test
2948
# Before a testcase, run in record mode, save result file to var
2949
# After testcase, run and compare with the recorded file, they should be equal!
2950
#
2951
# RETURN VALUE
2952
#  0 OK
2953
#  1 Check failed
2954
#
2955
sub run_check_testcase ($$) {
2956
2957
  my $mode=     shift;
2958
  my $mysqld=   shift;
2959
2960
  my $name= "check-" . $mysqld->{'type'} . $mysqld->{'idx'};
2961
2962
  my $args;
2963
  mtr_init_args(\$args);
2964
2965
  mtr_add_arg($args, "--no-defaults");
2966
  mtr_add_arg($args, "--silent");
2967
  mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
2968
2969
  mtr_add_arg($args, "--port=%d", $mysqld->{'port'});
2970
  mtr_add_arg($args, "--database=test");
2971
  mtr_add_arg($args, "--user=%s", $opt_user);
2972
  mtr_add_arg($args, "--password=");
2973
2974
  mtr_add_arg($args, "-R");
2975
  mtr_add_arg($args, "$opt_vardir/tmp/$name.result");
2976
2977
  if ( $mode eq "before" )
2978
  {
2979
    mtr_add_arg($args, "--record");
2980
  }
2981
685.1.22 by Monty Taylor
Added testdir setting support to drizzletest.
2982
  if ( $opt_testdir )
2983
  {
2984
    mtr_add_arg($args, "--testdir=%s", $opt_testdir);
2985
  }
2986
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
2987
  my $res = mtr_run_test($exe_drizzletest,$args,
1 by brian
clean slate
2988
	        "include/check-testcase.test", "", "", "");
2989
2990
  if ( $res == 1  and $mode eq "after")
2991
  {
2992
    mtr_run("diff",["-u",
2993
		    "$opt_vardir/tmp/$name.result",
2994
		    "$opt_vardir/tmp/$name.reject"],
2995
	    "", "", "", "");
2996
  }
2997
  elsif ( $res )
2998
  {
2999
    mtr_error("Could not execute 'check-testcase' $mode testcase");
3000
  }
3001
  return $res;
3002
}
3003
3004
##############################################################################
3005
#
3006
#  Report the features that were compiled in
3007
#
3008
##############################################################################
3009
3010
sub run_report_features () {
3011
  my $args;
3012
3013
  {
3014
    mysqld_start($master->[0],[],[]);
3015
    if ( ! $master->[0]->{'pid'} )
3016
    {
3017
      mtr_error("Can't start the mysqld server");
3018
    }
3019
    mysqld_wait_started($master->[0]);
3020
  }
3021
3022
  my $tinfo = {};
3023
  $tinfo->{'name'} = 'report features';
3024
  $tinfo->{'result_file'} = undef;
3025
  $tinfo->{'component_id'} = 'mysqld';
3026
  $tinfo->{'path'} = 'include/report-features.test';
3027
  $tinfo->{'timezone'}=  "GMT-3";
3028
  $tinfo->{'slave_num'} = 0;
3029
  $tinfo->{'master_opt'} = [];
3030
  $tinfo->{'slave_opt'} = [];
3031
  $tinfo->{'slave_mi'} = [];
3032
  $tinfo->{'comment'} = 'report server features';
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3033
  run_drizzletest($tinfo);
1 by brian
clean slate
3034
3035
  {
3036
    stop_all_servers();
3037
  }
3038
}
3039
3040
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3041
sub run_drizzletest ($) {
1 by brian
clean slate
3042
  my ($tinfo)= @_;
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3043
  my $exe= $exe_drizzletest;
1 by brian
clean slate
3044
  my $args;
3045
3046
  mtr_init_args(\$args);
3047
3048
  mtr_add_arg($args, "--no-defaults");
3049
  mtr_add_arg($args, "--silent");
3050
  mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
3051
  mtr_add_arg($args, "--logdir=%s/log", $opt_vardir);
3052
3053
  # Log line number and time  for each line in .test file
3054
  mtr_add_arg($args, "--mark-progress")
3055
    if $opt_mark_progress;
3056
3057
  {
3058
    mtr_add_arg($args, "--port=%d", $master->[0]->{'port'});
3059
    mtr_add_arg($args, "--database=test");
3060
    mtr_add_arg($args, "--user=%s", $opt_user);
3061
    mtr_add_arg($args, "--password=");
3062
  }
3063
3064
  if ( $opt_strace_client )
3065
  {
3066
    $exe=  "strace";            # FIXME there are ktrace, ....
3067
    mtr_add_arg($args, "-o");
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3068
    mtr_add_arg($args, "%s/log/drizzletest.strace", $opt_vardir);
3069
    mtr_add_arg($args, "$exe_drizzletest");
1 by brian
clean slate
3070
  }
3071
3072
  if ( $opt_timer )
3073
  {
3074
    mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
3075
  }
3076
3077
  if ( $opt_compress )
3078
  {
3079
    mtr_add_arg($args, "--compress");
3080
  }
3081
3082
  if ( $opt_sleep )
3083
  {
3084
    mtr_add_arg($args, "--sleep=%d", $opt_sleep);
3085
  }
3086
3087
  if ( $opt_debug )
3088
  {
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3089
    mtr_add_arg($args, "--debug=d:t:A,%s/log/drizzletest.trace",
1 by brian
clean slate
3090
		$path_vardir_trace);
3091
  }
3092
685.1.22 by Monty Taylor
Added testdir setting support to drizzletest.
3093
  if ( $opt_testdir )
3094
  {
3095
    mtr_add_arg($args, "--testdir=%s", $opt_testdir);
3096
  }
3097
3098
1 by brian
clean slate
3099
  # ----------------------------------------------------------------------
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3100
  # export DRIZZLE_TEST variable containing <path>/drizzletest <args>
1 by brian
clean slate
3101
  # ----------------------------------------------------------------------
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3102
  $ENV{'DRIZZLE_TEST'}=
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3103
    mtr_native_path($exe_drizzletest) . " " . join(" ", @$args);
1 by brian
clean slate
3104
3105
  # ----------------------------------------------------------------------
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3106
  # Add arguments that should not go into the DRIZZLE_TEST env var
1 by brian
clean slate
3107
  # ----------------------------------------------------------------------
3108
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3109
  if ( $opt_valgrind_drizzletest )
1 by brian
clean slate
3110
  {
3111
    # Prefix the Valgrind options to the argument list.
3112
    # We do this here, since we do not want to Valgrind the nested invocations
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3113
    # of drizzletest; that would mess up the stderr output causing test failure.
1 by brian
clean slate
3114
    my @args_saved = @$args;
3115
    mtr_init_args(\$args);
3116
    valgrind_arguments($args, \$exe);
3117
    mtr_add_arg($args, "%s", $_) for @args_saved;
3118
  }
3119
3120
  mtr_add_arg($args, "--test-file=%s", $tinfo->{'path'});
3121
3122
  # Number of lines of resut to include in failure report
3123
  mtr_add_arg($args, "--tail-lines=20");
3124
3125
  if ( defined $tinfo->{'result_file'} ) {
3126
    mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'});
3127
  }
3128
3129
  if ( $opt_record )
3130
  {
3131
    mtr_add_arg($args, "--record");
3132
  }
3133
3134
  if ( $opt_client_gdb )
3135
  {
3136
    gdb_arguments(\$args, \$exe, "client");
3137
  }
3138
  elsif ( $opt_client_ddd )
3139
  {
3140
    ddd_arguments(\$args, \$exe, "client");
3141
  }
3142
  elsif ( $opt_client_debugger )
3143
  {
3144
    debugger_arguments(\$args, \$exe, "client");
3145
  }
3146
3147
  if ( $opt_check_testcases )
3148
  {
3149
    foreach my $mysqld (@{$master}, @{$slave})
3150
    {
3151
      if ($mysqld->{'pid'})
3152
      {
3153
	run_check_testcase("before", $mysqld);
3154
      }
3155
    }
3156
  }
3157
3158
  my $res = mtr_run_test($exe,$args,"","",$path_timefile,"");
3159
3160
  if ( $opt_check_testcases )
3161
  {
3162
    foreach my $mysqld (@{$master}, @{$slave})
3163
    {
3164
      if ($mysqld->{'pid'})
3165
      {
3166
	if (run_check_testcase("after", $mysqld))
3167
	{
3168
	  # Check failed, mark the test case with that info
3169
	  $tinfo->{'check_testcase_failed'}= 1;
3170
	}
3171
      }
3172
    }
3173
  }
3174
3175
  return $res;
3176
3177
}
3178
3179
3180
#
3181
# Modify the exe and args so that program is run in gdb in xterm
3182
#
3183
sub gdb_arguments {
3184
  my $args= shift;
3185
  my $exe=  shift;
3186
  my $type= shift;
3187
3188
  # Write $args to gdb init file
3189
  my $str= join(" ", @$$args);
3190
  my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
3191
3192
  # Remove the old gdbinit file
3193
  unlink($gdb_init_file);
3194
3195
  if ( $type eq "client" )
3196
  {
3197
    # write init file for client
3198
    mtr_tofile($gdb_init_file,
3199
	       "set args $str\n" .
3200
	       "break main\n");
3201
  }
3202
  else
3203
  {
3204
    # write init file for mysqld
3205
    mtr_tofile($gdb_init_file,
3206
	       "set args $str\n" .
3207
	       "break mysql_parse\n" .
3208
	       "commands 1\n" .
3209
	       "disable 1\n" .
3210
	       "end\n" .
3211
	       "run");
3212
  }
3213
3214
  if ( $opt_manual_gdb )
3215
  {
3216
     print "\nTo start gdb for $type, type in another window:\n";
3217
     print "gdb -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
3218
3219
     # Indicate the exe should not be started
3220
     $$exe= undef;
3221
     return;
3222
  }
3223
3224
  $$args= [];
3225
  mtr_add_arg($$args, "-title");
3226
  mtr_add_arg($$args, "$type");
3227
  mtr_add_arg($$args, "-e");
3228
3229
  if ( $exe_libtool )
3230
  {
3231
    mtr_add_arg($$args, $exe_libtool);
3232
    mtr_add_arg($$args, "--mode=execute");
3233
  }
3234
3235
  mtr_add_arg($$args, "gdb");
3236
  mtr_add_arg($$args, "-x");
3237
  mtr_add_arg($$args, "$gdb_init_file");
3238
  mtr_add_arg($$args, "$$exe");
3239
3240
  $$exe= "xterm";
3241
}
3242
3243
3244
#
3245
# Modify the exe and args so that program is run in ddd
3246
#
3247
sub ddd_arguments {
3248
  my $args= shift;
3249
  my $exe=  shift;
3250
  my $type= shift;
3251
3252
  # Write $args to ddd init file
3253
  my $str= join(" ", @$$args);
3254
  my $gdb_init_file= "$opt_tmpdir/gdbinit.$type";
3255
3256
  # Remove the old gdbinit file
3257
  unlink($gdb_init_file);
3258
3259
  if ( $type eq "client" )
3260
  {
3261
    # write init file for client
3262
    mtr_tofile($gdb_init_file,
3263
	       "set args $str\n" .
3264
	       "break main\n");
3265
  }
3266
  else
3267
  {
3268
    # write init file for mysqld
3269
    mtr_tofile($gdb_init_file,
3270
	       "file $$exe\n" .
3271
	       "set args $str\n" .
3272
	       "break mysql_parse\n" .
3273
	       "commands 1\n" .
3274
	       "disable 1\n" .
3275
	       "end");
3276
  }
3277
3278
  if ( $opt_manual_ddd )
3279
  {
3280
     print "\nTo start ddd for $type, type in another window:\n";
3281
     print "ddd -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
3282
3283
     # Indicate the exe should not be started
3284
     $$exe= undef;
3285
     return;
3286
  }
3287
3288
  my $save_exe= $$exe;
3289
  $$args= [];
3290
  if ( $exe_libtool )
3291
  {
3292
    $$exe= $exe_libtool;
3293
    mtr_add_arg($$args, "--mode=execute");
3294
    mtr_add_arg($$args, "ddd");
3295
  }
3296
  else
3297
  {
3298
    $$exe= "ddd";
3299
  }
3300
  mtr_add_arg($$args, "--command=$gdb_init_file");
3301
  mtr_add_arg($$args, "$save_exe");
3302
}
3303
3304
3305
#
3306
# Modify the exe and args so that program is run in the selected debugger
3307
#
3308
sub debugger_arguments {
3309
  my $args= shift;
3310
  my $exe=  shift;
3311
  my $debugger= $opt_debugger || $opt_client_debugger;
3312
3313
  if ( $debugger =~ /vcexpress|vc|devenv/ )
3314
  {
3315
    # vc[express] /debugexe exe arg1 .. argn
3316
3317
    # Add /debugexe and name of the exe before args
3318
    unshift(@$$args, "/debugexe");
3319
    unshift(@$$args, "$$exe");
3320
3321
    # Set exe to debuggername
3322
    $$exe= $debugger;
3323
3324
  }
3325
  elsif ( $debugger eq "dbx" )
3326
  {
3327
    # xterm -e dbx -r exe arg1 .. argn
3328
3329
    unshift(@$$args, $$exe);
3330
    unshift(@$$args, "-r");
3331
    unshift(@$$args, $debugger);
3332
    unshift(@$$args, "-e");
3333
3334
    $$exe= "xterm";
3335
3336
  }
3337
  else
3338
  {
3339
    mtr_error("Unknown argument \"$debugger\" passed to --debugger");
3340
  }
3341
}
3342
3343
3344
#
3345
# Modify the exe and args so that program is run in valgrind
3346
#
3347
sub valgrind_arguments {
3348
  my $args= shift;
3349
  my $exe=  shift;
3350
3351
  if ( $opt_callgrind)
3352
  {
3353
    mtr_add_arg($args, "--tool=callgrind");
3354
    mtr_add_arg($args, "--base=$opt_vardir/log");
3355
  }
3356
  else
3357
  {
3358
    mtr_add_arg($args, "--tool=memcheck"); # From >= 2.1.2 needs this option
3359
    mtr_add_arg($args, "--alignment=8");
3360
    mtr_add_arg($args, "--leak-check=yes");
3361
    mtr_add_arg($args, "--num-callers=16");
3362
    mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir)
3363
      if -f "$glob_mysql_test_dir/valgrind.supp";
3364
  }
3365
3366
  # Add valgrind options, can be overriden by user
3367
  mtr_add_arg($args, '%s', $_) for (@valgrind_args);
3368
3369
  mtr_add_arg($args, $$exe);
3370
3371
  $$exe= $opt_valgrind_path || "valgrind";
3372
3373
  if ($exe_libtool)
3374
  {
3375
    # Add "libtool --mode-execute" before the test to execute
3376
    # if running in valgrind(to avoid valgrinding bash)
3377
    unshift(@$args, "--mode=execute", $$exe);
3378
    $$exe= $exe_libtool;
3379
  }
3380
}
3381
3382
87 by Brian Aker
First pass on cleaning out mysql-test-run
3383
sub mysqld_wait_started($){
3384
  my $mysqld= shift;
3385
3386
  if (sleep_until_file_created($mysqld->{'path_pid'},
3387
            $mysqld->{'start_timeout'},
3388
            $mysqld->{'pid'}) == 0)
3389
  {
3390
    # Failed to wait for pid file
3391
    return 1;
3392
  }
3393
3394
  # Get the "real pid" of the process, it will be used for killing
3395
  # the process in ActiveState's perl on windows
3396
  $mysqld->{'real_pid'}= mtr_get_pid_from_file($mysqld->{'path_pid'});
3397
3398
  return 0;
3399
}
3400
685.1.25 by Monty Taylor
Fixed absolute path generation for real. Sigh.
3401
sub collapse_path ($) {
3402
685.1.29 by Monty Taylor
Some more cleanups to mtr.
3403
    my $c_path= rel2abs(shift);
685.1.25 by Monty Taylor
Fixed absolute path generation for real. Sigh.
3404
    my $updir  = updir($c_path);
3405
    my $curdir = curdir($c_path);
3406
3407
    my($vol, $dirs, $file) = splitpath($c_path);
3408
    my @dirs = splitdir($dirs);
3409
3410
    my @collapsed;
3411
    foreach my $dir (@dirs) {
3412
        if( $dir eq $updir              and   # if we have an updir
3413
            @collapsed                  and   # and something to collapse
3414
            length $collapsed[-1]       and   # and its not the rootdir
3415
            $collapsed[-1] ne $updir    and   # nor another updir
3416
            $collapsed[-1] ne $curdir         # nor the curdir
3417
          )
3418
        {                                     # then
3419
            pop @collapsed;                   # collapse
3420
        }
3421
        else {                                # else
3422
            push @collapsed, $dir;            # just hang onto it
3423
        }
3424
    }
3425
3426
    return catpath($vol, catdir(@collapsed), $file);
3427
}
87 by Brian Aker
First pass on cleaning out mysql-test-run
3428
1 by brian
clean slate
3429
##############################################################################
3430
#
3431
#  Usage
3432
#
3433
##############################################################################
3434
3435
sub usage ($) {
3436
  my $message= shift;
3437
3438
  if ( $message )
3439
  {
3440
    print STDERR "$message\n";
3441
  }
3442
3443
  print <<HERE;
3444
3445
$0 [ OPTIONS ] [ TESTCASE ]
3446
3447
Options to control what engine/variation to run
3448
3449
  compress              Use the compressed protocol between client and server
3450
  bench                 Run the benchmark suite
3451
  small-bench           Run the benchmarks with --small-tests --small-tables
3452
3453
Options to control directories to use
3454
  benchdir=DIR          The directory where the benchmark suite is stored
3455
                        (default: ../../mysql-bench)
3456
  tmpdir=DIR            The directory where temporary files are stored
3457
                        (default: ./var/tmp).
3458
  vardir=DIR            The directory where files generated from the test run
3459
                        is stored (default: ./var). Specifying a ramdisk or
3460
                        tmpfs will speed up tests.
3461
  mem                   Run testsuite in "memory" using tmpfs or ramdisk
3462
                        Attempts to find a suitable location
3463
                        using a builtin list of standard locations
3464
                        for tmpfs (/dev/shm)
3465
                        The option can also be set using environment
3466
                        variable MTR_MEM=[DIR]
3467
3468
Options to control what test suites or cases to run
3469
3470
  force                 Continue to run the suite after failure
3471
  do-test=PREFIX or REGEX
3472
                        Run test cases which name are prefixed with PREFIX
3473
                        or fulfills REGEX
3474
  skip-test=PREFIX or REGEX
3475
                        Skip test cases which name are prefixed with PREFIX
3476
                        or fulfills REGEX
3477
  start-from=PREFIX     Run test cases starting from test prefixed with PREFIX
3478
  suite[s]=NAME1,..,NAMEN Collect tests in suites from the comma separated
3479
                        list of suite names.
3480
                        The default is: "$opt_suites_default"
3481
  skip-rpl              Skip the replication test cases.
3482
  combination="ARG1 .. ARG2" Specify a set of "mysqld" arguments for one
3483
                        combination.
3484
  skip-combination      Skip any combination options and combinations files
974.1.1 by Stewart Smith
add repeat-test=n option to test-run.pl to repeat a test n times
3485
  repeat-test=n         How many times to repeat each test (default: 1)
1 by brian
clean slate
3486
3487
Options that specify ports
3488
3489
  master_port=PORT      Specify the port number used by the first master
3490
  slave_port=PORT       Specify the port number used by the first slave
3491
  mtr-build-thread=#    Specify unique collection of ports. Can also be set by
3492
                        setting the environment variable MTR_BUILD_THREAD.
3493
3494
Options for test case authoring
3495
3496
  record TESTNAME       (Re)genereate the result file for TESTNAME
3497
  check-testcases       Check testcases for sideeffects
3498
  mark-progress         Log line number and elapsed time to <testname>.progress
3499
3500
Options that pass on options
3501
3502
  mysqld=ARGS           Specify additional arguments to "mysqld"
3503
3504
Options to run test on running server
3505
3506
  extern                Use running server for tests
3507
  user=USER             User for connection to extern server
3508
3509
Options for debugging the product
3510
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3511
  client-ddd            Start drizzletest client in ddd
3512
  client-debugger=NAME  Start drizzletest in the selected debugger
3513
  client-gdb            Start drizzletest client in gdb
1 by brian
clean slate
3514
  ddd                   Start mysqld in ddd
3515
  debug                 Dump trace output for all servers and client programs
3516
  debugger=NAME         Start mysqld in the selected debugger
3517
  gdb                   Start the mysqld(s) in gdb
3518
  manual-debug          Let user manually start mysqld in debugger, before
3519
                        running test(s)
3520
  manual-gdb            Let user manually start mysqld in gdb, before running
3521
                        test(s)
3522
  manual-ddd            Let user manually start mysqld in ddd, before running
3523
                        test(s)
3524
  master-binary=PATH    Specify the master "mysqld" to use
3525
  slave-binary=PATH     Specify the slave "mysqld" to use
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3526
  strace-client         Create strace output for drizzletest client
1 by brian
clean slate
3527
  max-save-core         Limit the number of core files saved (to avoid filling
3528
                        up disks for heavily crashing server). Defaults to
3529
                        $opt_max_save_core, set to 0 for no limit.
3530
3531
Options for coverage, profiling etc
3532
3533
  gcov                  FIXME
191 by Brian Aker
Merge from mark
3534
  gprof                 See online documentation on how to use it.
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3535
  valgrind              Run the "drizzletest" and "mysqld" executables using
1 by brian
clean slate
3536
                        valgrind with default options
3537
  valgrind-all          Synonym for --valgrind
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3538
  valgrind-drizzletest    Run the "drizzletest" and "drizzle_client_test" executable
1 by brian
clean slate
3539
                        with valgrind
3540
  valgrind-mysqld       Run the "mysqld" executable with valgrind
3541
  valgrind-options=ARGS Deprecated, use --valgrind-option
3542
  valgrind-option=ARGS  Option to give valgrind, replaces default option(s),
3543
                        can be specified more then once
3544
  valgrind-path=[EXE]   Path to the valgrind executable
3545
  callgrind             Instruct valgrind to use callgrind
3546
3547
Misc options
3548
3549
  comment=STR           Write STR to the output
3550
  notimer               Don't show test case execution time
3551
  script-debug          Debug this script itself
3552
  verbose               More verbose output
3553
  start-and-exit        Only initialize and start the servers, using the
3554
                        startup settings for the specified test case (if any)
3555
  start-dirty           Only start the servers (without initialization) for
3556
                        the specified test case (if any)
3557
  fast                  Don't try to clean up from earlier runs
3558
  reorder               Reorder tests to get fewer server restarts
3559
  help                  Get this help text
3560
3561
  testcase-timeout=MINUTES Max test case run time (default $default_testcase_timeout)
3562
  suite-timeout=MINUTES Max test suite run time (default $default_suite_timeout)
3563
  warnings | log-warnings Pass --log-warnings to mysqld
3564
77.3.9 by Monty Taylor
Renamed client programs to drizzle.
3565
  sleep=SECONDS         Passed to drizzletest, will be used as fixed sleep time
1 by brian
clean slate
3566
3567
HERE
3568
  mtr_exit(1);
3569
3570
}