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