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