~drizzle-trunk/drizzle/development

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