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