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