~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/mtr_cases.pl

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- cperl -*-
 
2
# Copyright (C) 2005-2006 MySQL AB
 
3
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
16
 
 
17
# This is a library file used by the Perl version of mysql-test-run,
 
18
# and is part of the translation of the Bourne shell script with the
 
19
# same name.
 
20
 
 
21
use File::Basename;
 
22
use IO::File();
 
23
use strict;
 
24
 
 
25
use My::Config;
 
26
 
 
27
sub collect_test_cases ($);
 
28
sub collect_one_suite ($);
 
29
sub collect_one_test_case ($$$$$$$$$);
 
30
 
 
31
sub mtr_options_from_test_file($$);
 
32
 
 
33
my $do_test;
 
34
my $skip_test;
 
35
 
 
36
sub init_pattern {
 
37
  my ($from, $what)= @_;
 
38
  if ( $from =~ /^[a-z0-9]$/ ) {
 
39
    # Does not contain any regex, make the pattern match
 
40
    # beginning of string
 
41
    $from= "^$from";
 
42
  }
 
43
  # Check that pattern is a valid regex
 
44
  eval { "" =~/$from/; 1 } or
 
45
    mtr_error("Invalid regex '$from' passed to $what\nPerl says: $@");
 
46
  return $from;
 
47
}
 
48
 
 
49
 
 
50
 
 
51
##############################################################################
 
52
#
 
53
#  Collect information about test cases we are to run
 
54
#
 
55
##############################################################################
 
56
 
 
57
sub collect_test_cases ($) {
 
58
  $do_test= init_pattern($::opt_do_test, "--do-test");
 
59
  $skip_test= init_pattern($::opt_skip_test, "--skip-test");
 
60
 
 
61
  my $suites= shift; # Semicolon separated list of test suites
 
62
  my $cases = [];    # Array of hash
 
63
 
 
64
  foreach my $suite (split(",", $suites))
 
65
  {
 
66
    push(@$cases, collect_one_suite($suite));
 
67
  }
 
68
 
 
69
 
 
70
  if ( @::opt_cases )
 
71
  {
 
72
    # Check that the tests specified was found
 
73
    # in at least one suite
 
74
    foreach my $test_name_spec ( @::opt_cases )
 
75
    {
 
76
      my $found= 0;
 
77
      my ($sname, $tname, $extension)= split_testname($test_name_spec);
 
78
      foreach my $test ( @$cases )
 
79
      {
 
80
        # test->{name} is always in suite.name format
 
81
        if ( $test->{name} =~ /.*\.$tname/ )
 
82
        {
 
83
          $found= 1;
 
84
        }
 
85
      }
 
86
      if ( not $found )
 
87
      {
 
88
        mtr_error("Could not find $tname in any suite");
 
89
      }
 
90
    }
 
91
  }
 
92
 
 
93
  if ( $::opt_reorder )
 
94
  {
 
95
    # Reorder the test cases in an order that will make them faster to run
 
96
    my %sort_criteria;
 
97
 
 
98
    # Make a mapping of test name to a string that represents how that test
 
99
    # should be sorted among the other tests.  Put the most important criterion
 
100
    # first, then a sub-criterion, then sub-sub-criterion, et c.
 
101
    foreach my $tinfo (@$cases)
 
102
    {
 
103
      my @criteria = ();
 
104
 
 
105
      # Look for tests that muct be in run in a defined order
 
106
      # that is defined by test having the same name except for
 
107
      # the ending digit
 
108
 
 
109
      # Put variables into hash
 
110
      my $test_name= $tinfo->{'name'};
 
111
      my $depend_on_test_name;
 
112
      if ( $test_name =~ /^([\D]+)([0-9]{1})$/ )
 
113
      {
 
114
        my $base_name= $1;
 
115
        my $idx= $2;
 
116
        mtr_verbose("$test_name =>  $base_name idx=$idx");
 
117
        if ( $idx > 1 )
 
118
        {
 
119
          $idx-= 1;
 
120
          $base_name= "$base_name$idx";
 
121
          mtr_verbose("New basename $base_name");
 
122
        }
 
123
 
 
124
        foreach my $tinfo2 (@$cases)
 
125
        {
 
126
          if ( $tinfo2->{'name'} eq $base_name )
 
127
          {
 
128
            mtr_verbose("found dependent test $tinfo2->{'name'}");
 
129
            $depend_on_test_name=$base_name;
 
130
          }
 
131
        }
 
132
      }
 
133
 
 
134
      if ( defined $depend_on_test_name )
 
135
      {
 
136
        mtr_verbose("Giving $test_name same critera as $depend_on_test_name");
 
137
        $sort_criteria{$test_name} = $sort_criteria{$depend_on_test_name};
 
138
      }
 
139
      else
 
140
      {
 
141
        #
 
142
        # Append the criteria for sorting, in order of importance.
 
143
        #
 
144
        push(@criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "1" : "0"));
 
145
        # Group test with equal options together.
 
146
        # Ending with "~" makes empty sort later than filled
 
147
        push(@criteria, join("!", sort @{$tinfo->{'master_opt'}}) . "~");
 
148
 
 
149
        $sort_criteria{$test_name} = join(" ", @criteria);
 
150
      }
 
151
    }
 
152
 
 
153
    @$cases = sort {
 
154
      $sort_criteria{$a->{'name'}} . $a->{'name'} cmp
 
155
        $sort_criteria{$b->{'name'}} . $b->{'name'}; } @$cases;
 
156
 
 
157
    if ( $::opt_script_debug )
 
158
    {
 
159
      # For debugging the sort-order
 
160
      foreach my $tinfo (@$cases)
 
161
      {
 
162
        print("$sort_criteria{$tinfo->{'name'}} -> \t$tinfo->{'name'}\n");
 
163
      }
 
164
    }
 
165
  }
 
166
 
 
167
  return $cases;
 
168
 
 
169
}
 
170
 
 
171
# Valid extensions and their corresonding component id
 
172
my %exts = ( 'test' => 'mysqld',
 
173
             'imtest' => 'im'
 
174
           );
 
175
 
 
176
 
 
177
# Returns (suitename, testname, extension)
 
178
sub split_testname {
 
179
  my ($test_name)= @_;
 
180
 
 
181
  # Get rid of directory part and split name on .'s
 
182
  my @parts= split(/\./, basename($test_name));
 
183
 
 
184
  if (@parts == 1){
 
185
    # Only testname given, ex: alias
 
186
    return (undef , $parts[0], undef);
 
187
  } elsif (@parts == 2) {
 
188
    # Either testname.test or suite.testname given
 
189
    # Ex. main.alias or alias.test
 
190
 
 
191
    if (defined $exts{$parts[1]})
 
192
    {
 
193
      return (undef , $parts[0], $parts[1]);
 
194
    }
 
195
    else
 
196
    {
 
197
      return ($parts[0], $parts[1], undef);
 
198
    }
 
199
 
 
200
  } elsif (@parts == 3) {
 
201
    # Fully specified suitename.testname.test
 
202
    # ex main.alias.test
 
203
    return ( $parts[0], $parts[1], $parts[2]);
 
204
  }
 
205
 
 
206
  mtr_error("Illegal format of test name: $test_name");
 
207
}
 
208
 
 
209
 
 
210
sub collect_one_suite($)
 
211
{
 
212
  my $suite= shift;  # Test suite name
 
213
  my @cases;  # Array of hash
 
214
 
 
215
  mtr_verbose("Collecting: $suite");
 
216
 
 
217
  my $suitedir= "$::glob_mysql_test_dir"; # Default
 
218
  if ( $suite ne "main" )
 
219
  {
 
220
    $suitedir= mtr_path_exists("$suitedir/suite/$suite",
 
221
                               "$suitedir/$suite");
 
222
    mtr_verbose("suitedir: $suitedir");
 
223
  }
 
224
 
 
225
  my $testdir= "$suitedir/t";
 
226
  my $resdir=  "$suitedir/r";
 
227
 
 
228
  # ----------------------------------------------------------------------
 
229
  # Build a hash of disabled testcases for this suite
 
230
  # ----------------------------------------------------------------------
 
231
  my %disabled;
 
232
  if ( open(DISABLED, "$testdir/disabled.def" ) )
 
233
  {
 
234
    while ( <DISABLED> )
 
235
      {
 
236
        chomp;
 
237
        if ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )
 
238
          {
 
239
            $disabled{$1}= $2;
 
240
          }
 
241
      }
 
242
    close DISABLED;
 
243
  }
 
244
 
 
245
  # Read suite.opt file
 
246
  my $suite_opt_file=  "$testdir/suite.opt";
 
247
  my $suite_opts= [];
 
248
  if ( -f $suite_opt_file )
 
249
  {
 
250
    $suite_opts= mtr_get_opts_from_file($suite_opt_file);
 
251
  }
 
252
 
 
253
  if ( @::opt_cases )
 
254
  {
 
255
    # Collect in specified order
 
256
    foreach my $test_name_spec ( @::opt_cases )
 
257
    {
 
258
      my ($sname, $tname, $extension)= split_testname($test_name_spec);
 
259
 
 
260
      # The test name parts have now been defined
 
261
      #print "  suite_name: $sname\n";
 
262
      #print "  tname:      $tname\n";
 
263
      #print "  extension:  $extension\n";
 
264
 
 
265
      # Check cirrect suite if suitename is defined
 
266
      next if (defined $sname and $suite ne $sname);
 
267
 
 
268
      my $component_id;
 
269
      if ( defined $extension )
 
270
      {
 
271
        my $full_name= "$testdir/$tname.$extension";
 
272
        # Extension was specified, check if the test exists
 
273
        if ( ! -f $full_name)
 
274
        {
 
275
          # This is only an error if suite was specified, otherwise it
 
276
          # could exist in another suite
 
277
          mtr_error("Test '$full_name' was not found in suite '$sname'")
 
278
            if $sname;
 
279
 
 
280
          next;
 
281
        }
 
282
        $component_id= $exts{$extension};
 
283
      }
 
284
      else
 
285
      {
 
286
        # No extension was specified
 
287
        my ($ext, $component);
 
288
        while (($ext, $component)= each %exts) {
 
289
          my $full_name= "$testdir/$tname.$ext";
 
290
 
 
291
          if ( ! -f $full_name ) {
 
292
            next;
 
293
          }
 
294
          $component_id= $component;
 
295
          $extension= $ext;
 
296
        }
 
297
        # Test not found here, could exist in other suite
 
298
        next unless $component_id;
 
299
      }
 
300
 
 
301
      collect_one_test_case($testdir,$resdir,$suite,$tname,
 
302
                            "$tname.$extension",\@cases,\%disabled,
 
303
                            $component_id,$suite_opts);
 
304
    }
 
305
  }
 
306
  else
 
307
  {
 
308
    opendir(TESTDIR, $testdir) or mtr_error("Can't open dir \"$testdir\": $!");
 
309
 
 
310
    foreach my $elem ( sort readdir(TESTDIR) )
 
311
    {
 
312
      my $component_id= undef;
 
313
      my $tname= undef;
 
314
 
 
315
      if ($tname= mtr_match_extension($elem, 'test'))
 
316
      {
 
317
        $component_id = 'mysqld';
 
318
      }
 
319
      elsif ($tname= mtr_match_extension($elem, 'imtest'))
 
320
      {
 
321
        $component_id = 'im';
 
322
      }
 
323
      else
 
324
      {
 
325
        next;
 
326
      }
 
327
 
 
328
      # Skip tests that does not match the --do-test= filter
 
329
      next if ($do_test and not $tname =~ /$do_test/o);
 
330
 
 
331
      collect_one_test_case($testdir,$resdir,$suite,$tname,
 
332
                            $elem,\@cases,\%disabled,$component_id,
 
333
                            $suite_opts);
 
334
    }
 
335
    closedir TESTDIR;
 
336
  }
 
337
 
 
338
 
 
339
  #  Return empty list if no testcases found
 
340
  return if (@cases == 0);
 
341
 
 
342
  # ----------------------------------------------------------------------
 
343
  # Read combinations for this suite and build testcases x combinations
 
344
  # if any combinations exists
 
345
  # ----------------------------------------------------------------------
 
346
  if ( ! $::opt_skip_combination )
 
347
  {
 
348
    my @combinations;
 
349
    my $combination_file= "$suitedir/combinations";
 
350
    #print "combination_file: $combination_file\n";
 
351
    if (@::opt_combinations)
 
352
    {
 
353
      # take the combination from command-line
 
354
      mtr_verbose("Take the combination from command line");
 
355
      foreach my $combination (@::opt_combinations) {
 
356
        my $comb= {};
 
357
        $comb->{name}= $combination;
 
358
        push(@{$comb->{comb_opt}}, $combination);
 
359
        push(@combinations, $comb);
 
360
      }
 
361
    }
 
362
    elsif (-f $combination_file )
 
363
    {
 
364
      # Read combinations file in my.cnf format
 
365
      mtr_verbose("Read combinations file");
 
366
      my $config= My::Config->new($combination_file);
 
367
 
 
368
      foreach my $group ($config->groups()) {
 
369
        my $comb= {};
 
370
        $comb->{name}= $group->name();
 
371
        foreach my $option ( $group->options() ) {
 
372
          push(@{$comb->{comb_opt}}, $option->name()."=".$option->value());
 
373
        }
 
374
        push(@combinations, $comb);
 
375
      }
 
376
    }
 
377
 
 
378
    if (@combinations)
 
379
    {
 
380
      print " - adding combinations\n";
 
381
      #print_testcases(@cases);
 
382
 
 
383
      my @new_cases;
 
384
      foreach my $comb (@combinations)
 
385
      {
 
386
        foreach my $test (@cases)
 
387
        {
 
388
          #print $test->{name}, " ", $comb, "\n";
 
389
          my $new_test= {};
 
390
 
 
391
          while (my ($key, $value) = each(%$test)) {
 
392
            if (ref $value eq "ARRAY") {
 
393
              push(@{$new_test->{$key}}, @$value);
 
394
            } else {
 
395
              $new_test->{$key}= $value;
 
396
            }
 
397
          }
 
398
 
 
399
          # Append the combination options to master_opt and slave_opt
 
400
          push(@{$new_test->{master_opt}}, @{$comb->{comb_opt}});
 
401
          push(@{$new_test->{slave_opt}}, @{$comb->{comb_opt}});
 
402
 
 
403
          # Add combination name shrt name
 
404
          $new_test->{combination}= $comb->{name};
 
405
 
 
406
          # Add the new test to new test cases list
 
407
          push(@new_cases, $new_test);
 
408
        }
 
409
      }
 
410
      #print_testcases(@new_cases);
 
411
      @cases= @new_cases;
 
412
      #print_testcases(@cases);
 
413
    }
 
414
  }
 
415
 
 
416
  optimize_cases(\@cases);
 
417
  #print_testcases(@cases);
 
418
 
 
419
  return @cases;
 
420
}
 
421
 
 
422
 
 
423
#
 
424
# Loop through all test cases
 
425
# - optimize which test to run by skipping unnecessary ones
 
426
# - update settings if necessary
 
427
#
 
428
sub optimize_cases {
 
429
  my ($cases)= @_;
 
430
 
 
431
  foreach my $tinfo ( @$cases )
 
432
  {
 
433
    # Skip processing if already marked as skipped
 
434
    next if $tinfo->{skip};
 
435
 
 
436
    # Replication test needs an adjustment of binlog format
 
437
    if (mtr_match_prefix($tinfo->{'name'}, "rpl"))
 
438
    {
 
439
 
 
440
      # =======================================================
 
441
      # Get binlog-format used by this test from master_opt
 
442
      # =======================================================
 
443
      my $test_binlog_format;
 
444
      foreach my $opt ( @{$tinfo->{master_opt}} ) {
 
445
        $test_binlog_format= $test_binlog_format ||
 
446
          mtr_match_prefix($opt, "--binlog-format=");
 
447
      }
 
448
      # print $tinfo->{name}." uses ".$test_binlog_format."\n";
 
449
 
 
450
      # =======================================================
 
451
      # If a special binlog format was selected with
 
452
      # --mysqld=--binlog-format=x, skip all test with different
 
453
      # binlog-format
 
454
      # =======================================================
 
455
      if (defined $::used_binlog_format and
 
456
          $test_binlog_format and
 
457
          $::used_binlog_format ne $test_binlog_format)
 
458
      {
 
459
        $tinfo->{'skip'}= 1;
 
460
        $tinfo->{'comment'}= "Requires --binlog-format='$test_binlog_format'";
 
461
        next;
 
462
      }
 
463
 
 
464
      # =======================================================
 
465
      # Check that testcase supports the designated binlog-format
 
466
      # =======================================================
 
467
      if ($test_binlog_format and defined $tinfo->{'sup_binlog_formats'} )
 
468
      {
 
469
        my $supported=
 
470
          grep { $_ eq $test_binlog_format } @{$tinfo->{'sup_binlog_formats'}};
 
471
        if ( !$supported )
 
472
        {
 
473
          $tinfo->{'skip'}= 1;
 
474
          $tinfo->{'comment'}=
 
475
            "Doesn't support --binlog-format='$test_binlog_format'";
 
476
          next;
 
477
        }
 
478
      }
 
479
 
 
480
      # =======================================================
 
481
      # Use dynamic switching of binlog-format if mtr started
 
482
      # w/o --mysqld=--binlog-format=xxx and combinations.
 
483
      # =======================================================
 
484
      if (!defined $tinfo->{'combination'} and
 
485
          !defined $::used_binlog_format)
 
486
      {
 
487
        $test_binlog_format= $tinfo->{'sup_binlog_formats'}->[0];
 
488
      }
 
489
 
 
490
      # Save binlog format for dynamic switching
 
491
      $tinfo->{binlog_format}= $test_binlog_format;
 
492
    }
 
493
  }
 
494
}
 
495
 
 
496
 
 
497
##############################################################################
 
498
#
 
499
#  Collect information about a single test case
 
500
#
 
501
##############################################################################
 
502
 
 
503
 
 
504
sub collect_one_test_case($$$$$$$$$) {
 
505
  my $testdir= shift;
 
506
  my $resdir=  shift;
 
507
  my $suite=   shift;
 
508
  my $tname=   shift;
 
509
  my $elem=    shift;
 
510
  my $cases=   shift;
 
511
  my $disabled=shift;
 
512
  my $component_id= shift;
 
513
  my $suite_opts= shift;
 
514
 
 
515
  my $path= "$testdir/$elem";
 
516
 
 
517
  # ----------------------------------------------------------------------
 
518
  # Skip some tests silently
 
519
  # ----------------------------------------------------------------------
 
520
 
 
521
  if ( $::opt_start_from and $tname lt $::opt_start_from )
 
522
  {
 
523
    return;
 
524
  }
 
525
 
 
526
 
 
527
  my $tinfo= {};
 
528
  $tinfo->{'name'}= basename($suite) . ".$tname";
 
529
  if ( -f "$resdir/$::opt_engine/$tname.result")
 
530
  {
 
531
    $tinfo->{'result_file'}= "$resdir/$::opt_engine/$tname.result";
 
532
  }
 
533
  else
 
534
  {
 
535
    $tinfo->{'result_file'}= "$resdir/$tname.result";
 
536
  }
 
537
  $tinfo->{'component_id'} = $component_id;
 
538
  push(@$cases, $tinfo);
 
539
 
 
540
  # ----------------------------------------------------------------------
 
541
  # Skip some tests but include in list, just mark them to skip
 
542
  # ----------------------------------------------------------------------
 
543
 
 
544
  if ( $skip_test and $tname =~ /$skip_test/o )
 
545
  {
 
546
    $tinfo->{'skip'}= 1;
 
547
    return;
 
548
  }
 
549
 
 
550
  # ----------------------------------------------------------------------
 
551
  # Collect information about test case
 
552
  # ----------------------------------------------------------------------
 
553
 
 
554
  $tinfo->{'path'}= $path;
 
555
  $tinfo->{'timezone'}= "GMT-3"; # for UNIX_TIMESTAMP tests to work
 
556
 
 
557
  $tinfo->{'slave_num'}= 0; # Default, no slave
 
558
  $tinfo->{'master_num'}= 1; # Default, 1 master
 
559
  if ( defined mtr_match_prefix($tname,"rpl") )
 
560
  {
 
561
    if ( $::opt_skip_rpl )
 
562
    {
 
563
      $tinfo->{'skip'}= 1;
 
564
      $tinfo->{'comment'}= "No replication tests(--skip-rpl)";
 
565
      return;
 
566
    }
 
567
 
 
568
    $tinfo->{'slave_num'}= 1; # Default for rpl* tests, use one slave
 
569
 
 
570
  }
 
571
 
 
572
  if ( defined mtr_match_prefix($tname,"federated") )
 
573
  {
 
574
    # Default, federated uses the first slave as it's federated database
 
575
    $tinfo->{'slave_num'}= 1;
 
576
  }
 
577
 
 
578
  my $master_opt_file= "$testdir/$tname-master.opt";
 
579
  my $slave_opt_file=  "$testdir/$tname-slave.opt";
 
580
  my $slave_mi_file=   "$testdir/$tname.slave-mi";
 
581
  my $master_sh=       "$testdir/$tname-master.sh";
 
582
  my $slave_sh=        "$testdir/$tname-slave.sh";
 
583
  my $disabled_file=   "$testdir/$tname.disabled";
 
584
  my $im_opt_file=     "$testdir/$tname-im.opt";
 
585
 
 
586
  $tinfo->{'master_opt'}= [];
 
587
  $tinfo->{'slave_opt'}=  [];
 
588
  $tinfo->{'slave_mi'}=   [];
 
589
 
 
590
 
 
591
  # Add suite opts
 
592
  foreach my $opt ( @$suite_opts )
 
593
  {
 
594
    mtr_verbose($opt);
 
595
    push(@{$tinfo->{'master_opt'}}, $opt);
 
596
    push(@{$tinfo->{'slave_opt'}}, $opt);
 
597
  }
 
598
 
 
599
  # Add master opts
 
600
  if ( -f $master_opt_file )
 
601
  {
 
602
 
 
603
    my $master_opt= mtr_get_opts_from_file($master_opt_file);
 
604
 
 
605
    foreach my $opt ( @$master_opt )
 
606
    {
 
607
      my $value;
 
608
 
 
609
      # The opt file is used both to send special options to the mysqld
 
610
      # as well as pass special test case specific options to this
 
611
      # script
 
612
 
 
613
      $value= mtr_match_prefix($opt, "--timezone=");
 
614
      if ( defined $value )
 
615
      {
 
616
        $tinfo->{'timezone'}= $value;
 
617
        next;
 
618
      }
 
619
 
 
620
      $value= mtr_match_prefix($opt, "--slave-num=");
 
621
      if ( defined $value )
 
622
      {
 
623
        $tinfo->{'slave_num'}= $value;
 
624
        next;
 
625
      }
 
626
 
 
627
      $value= mtr_match_prefix($opt, "--result-file=");
 
628
      if ( defined $value )
 
629
      {
 
630
        # Specifies the file mysqltest should compare
 
631
        # output against
 
632
        if ( -f "r/$::opt_engine/$value.result")
 
633
        {
 
634
          $tinfo->{'result_file'}= "r/$::opt_engine/$value.result";
 
635
        }
 
636
        else
 
637
        {
 
638
          $tinfo->{'result_file'}= "r/$value.result";
 
639
        }
 
640
 
 
641
        next;
 
642
      }
 
643
 
 
644
      # If we set default time zone, remove the one we have
 
645
      $value= mtr_match_prefix($opt, "--default-time-zone=");
 
646
      if ( defined $value )
 
647
      {
 
648
        # Set timezone for this test case to something different
 
649
        $tinfo->{'timezone'}= "GMT-8";
 
650
        # Fallthrough, add the --default-time-zone option
 
651
      }
 
652
 
 
653
      # The --restart option forces a restart even if no special
 
654
      # option is set. If the options are the same as next testcase
 
655
      # there is no need to restart after the testcase
 
656
      # has completed
 
657
      if ( $opt eq "--force-restart" )
 
658
      {
 
659
        $tinfo->{'force_restart'}= 1;
 
660
        next;
 
661
      }
 
662
 
 
663
      # Ok, this was a real option, add it
 
664
      push(@{$tinfo->{'master_opt'}}, $opt);
 
665
    }
 
666
  }
 
667
 
 
668
  # Add slave opts
 
669
  if ( -f $slave_opt_file )
 
670
  {
 
671
    my $slave_opt= mtr_get_opts_from_file($slave_opt_file);
 
672
 
 
673
    foreach my $opt ( @$slave_opt )
 
674
    {
 
675
      # If we set default time zone, remove the one we have
 
676
      my $value= mtr_match_prefix($opt, "--default-time-zone=");
 
677
      $tinfo->{'slave_opt'}= [] if defined $value;
 
678
    }
 
679
    push(@{$tinfo->{'slave_opt'}}, @$slave_opt);
 
680
  }
 
681
 
 
682
  if ( -f $slave_mi_file )
 
683
  {
 
684
    $tinfo->{'slave_mi'}= mtr_get_opts_from_file($slave_mi_file);
 
685
  }
 
686
 
 
687
  if ( -f $master_sh )
 
688
  {
 
689
    if ( $::glob_win32_perl )
 
690
    {
 
691
      $tinfo->{'skip'}= 1;
 
692
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
 
693
      return;
 
694
    }
 
695
    else
 
696
    {
 
697
      $tinfo->{'master_sh'}= $master_sh;
 
698
    }
 
699
  }
 
700
 
 
701
  if ( -f $slave_sh )
 
702
  {
 
703
    if ( $::glob_win32_perl )
 
704
    {
 
705
      $tinfo->{'skip'}= 1;
 
706
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
 
707
      return;
 
708
    }
 
709
    else
 
710
    {
 
711
      $tinfo->{'slave_sh'}= $slave_sh;
 
712
    }
 
713
  }
 
714
 
 
715
  if ( -f $im_opt_file )
 
716
  {
 
717
    $tinfo->{'im_opts'} = mtr_get_opts_from_file($im_opt_file);
 
718
  }
 
719
  else
 
720
  {
 
721
    $tinfo->{'im_opts'} = [];
 
722
  }
 
723
 
 
724
  # FIXME why this late?
 
725
  my $marked_as_disabled= 0;
 
726
  if ( $disabled->{$tname} )
 
727
  {
 
728
    $marked_as_disabled= 1;
 
729
    $tinfo->{'comment'}= $disabled->{$tname};
 
730
  }
 
731
 
 
732
  if ( -f $disabled_file )
 
733
  {
 
734
    $marked_as_disabled= 1;
 
735
    $tinfo->{'comment'}= mtr_fromfile($disabled_file);
 
736
  }
 
737
 
 
738
  # If test was marked as disabled, either opt_enable_disabled is off and then
 
739
  # we skip this test, or it is on and then we run this test but warn
 
740
 
 
741
  if ( $marked_as_disabled )
 
742
  {
 
743
    if ( $::opt_enable_disabled )
 
744
    {
 
745
      $tinfo->{'dont_skip_though_disabled'}= 1;
 
746
    }
 
747
    else
 
748
    {
 
749
      $tinfo->{'skip'}= 1;
 
750
      $tinfo->{'disable'}= 1;   # Sub type of 'skip'
 
751
      return;
 
752
    }
 
753
  }
 
754
 
 
755
  if ( $component_id eq 'im' )
 
756
  {
 
757
    if ( $::glob_use_embedded_server )
 
758
    {
 
759
      $tinfo->{'skip'}= 1;
 
760
      $tinfo->{'comment'}= "No IM with embedded server";
 
761
      return;
 
762
    }
 
763
    elsif ( $::opt_ps_protocol )
 
764
    {
 
765
      $tinfo->{'skip'}= 1;
 
766
      $tinfo->{'comment'}= "No IM with --ps-protocol";
 
767
      return;
 
768
    }
 
769
    elsif ( $::opt_skip_im )
 
770
    {
 
771
      $tinfo->{'skip'}= 1;
 
772
      $tinfo->{'comment'}= "No IM tests(--skip-im)";
 
773
      return;
 
774
    }
 
775
  }
 
776
  else
 
777
  {
 
778
    mtr_options_from_test_file($tinfo,"$testdir/${tname}.test");
 
779
 
 
780
    if ( defined $::used_default_engine )
 
781
    {
 
782
      # Different default engine is used
 
783
      # tag test to require that engine
 
784
      $tinfo->{'ndb_test'}= 1
 
785
        if ( $::used_default_engine =~ /^ndb/i );
 
786
 
 
787
      $tinfo->{'innodb_test'}= 1
 
788
        if ( $::used_default_engine =~ /^innodb/i );
 
789
    }
 
790
 
 
791
    if ( $tinfo->{'big_test'} and ! $::opt_big_test )
 
792
    {
 
793
      $tinfo->{'skip'}= 1;
 
794
      $tinfo->{'comment'}= "Test need 'big-test' option";
 
795
      return;
 
796
    }
 
797
 
 
798
    if ( $tinfo->{'ndb_extra'} and ! $::opt_ndb_extra_test )
 
799
    {
 
800
      $tinfo->{'skip'}= 1;
 
801
      $tinfo->{'comment'}= "Test need 'ndb_extra' option";
 
802
      return;
 
803
    }
 
804
 
 
805
    if ( $tinfo->{'require_manager'} )
 
806
    {
 
807
      $tinfo->{'skip'}= 1;
 
808
      $tinfo->{'comment'}= "Test need the _old_ manager(to be removed)";
 
809
      return;
 
810
    }
 
811
 
 
812
    if ( $tinfo->{'need_debug'} && ! $::debug_compiled_binaries )
 
813
    {
 
814
      $tinfo->{'skip'}= 1;
 
815
      $tinfo->{'comment'}= "Test need debug binaries";
 
816
      return;
 
817
    }
 
818
 
 
819
    {
 
820
      if ( $::opt_with_ndbcluster_only )
 
821
      {
 
822
        # Only the ndb test should be run, all other should be skipped
 
823
        $tinfo->{'skip'}= 1;
 
824
        $tinfo->{'comment'}= "Only ndbcluster tests(--with-ndbcluster-only)";
 
825
        return;
 
826
      }
 
827
    }
 
828
 
 
829
    if ( $tinfo->{'need_binlog'} )
 
830
    {
 
831
      if (grep(/^--skip-log-bin/,  @::opt_extra_mysqld_opt) )
 
832
      {
 
833
        $tinfo->{'skip'}= 1;
 
834
        $tinfo->{'comment'}= "Test need binlog";
 
835
        return;
 
836
      }
 
837
    }
 
838
    else
 
839
    {
 
840
      if ( $::mysql_version_id >= 50100 )
 
841
      {
 
842
        # Test does not need binlog, add --skip-binlog to
 
843
        # the options used when starting it
 
844
        push(@{$tinfo->{'master_opt'}}, "--skip-log-bin");
 
845
      }
 
846
    }
 
847
 
 
848
  }
 
849
}
 
850
 
 
851
 
 
852
# List of tags in the .test files that if found should set
 
853
# the specified value in "tinfo"
 
854
our @tags=
 
855
(
 
856
 ["include/have_innodb.inc", "innodb_test", 1],
 
857
 ["include/have_binlog_format_row.inc", "sup_binlog_formats", ["row"]],
 
858
 ["include/have_log_bin.inc", "need_binlog", 1],
 
859
 ["include/have_binlog_format_statement.inc",
 
860
  "sup_binlog_formats", ["statement"]],
 
861
 ["include/have_binlog_format_mixed.inc", "sup_binlog_formats", ["mixed"]],
 
862
 ["include/have_binlog_format_mixed_or_row.inc",
 
863
  "sup_binlog_formats", ["mixed","row"]],
 
864
 ["include/have_binlog_format_mixed_or_statement.inc",
 
865
  "sup_binlog_formats", ["mixed","statement"]],
 
866
 ["include/have_binlog_format_row_or_statement.inc",
 
867
  "sup_binlog_formats", ["row","statement"]],
 
868
 ["include/big_test.inc", "big_test", 1],
 
869
 ["include/have_debug.inc", "need_debug", 1],
 
870
 ["require_manager", "require_manager", 1],
 
871
);
 
872
 
 
873
sub mtr_options_from_test_file($$) {
 
874
  my $tinfo= shift;
 
875
  my $file= shift;
 
876
  #mtr_verbose("$file");
 
877
  my $F= IO::File->new($file) or mtr_error("can't open file \"$file\": $!");
 
878
 
 
879
  while ( my $line= <$F> )
 
880
  {
 
881
 
 
882
    # Skip line if it start's with #
 
883
    next if ( $line =~ /^#/ );
 
884
 
 
885
    # Match this line against tag in "tags" array
 
886
    foreach my $tag (@tags)
 
887
    {
 
888
      if ( index($line, $tag->[0]) >= 0 )
 
889
      {
 
890
          # Tag matched, assign value to "tinfo"
 
891
        $tinfo->{"$tag->[1]"}= $tag->[2];
 
892
      }
 
893
    }
 
894
 
 
895
    # If test sources another file, open it as well
 
896
    if ( $line =~ /^\-\-([[:space:]]*)source(.*)$/ or
 
897
         $line =~ /^([[:space:]]*)source(.*);$/ )
 
898
    {
 
899
      my $value= $2;
 
900
      $value =~ s/^\s+//;  # Remove leading space
 
901
      $value =~ s/[[:space:]]+$//;  # Remove ending space
 
902
 
 
903
      my $sourced_file= "$::glob_mysql_test_dir/$value";
 
904
      if ( -f $sourced_file )
 
905
      {
 
906
        # Only source the file if it exists, we may get
 
907
        # false positives in the regexes above if someone
 
908
        # writes "source nnnn;" in a test case(such as mysqltest.test)
 
909
        mtr_options_from_test_file($tinfo, $sourced_file);
 
910
      }
 
911
    }
 
912
  }
 
913
}
 
914
 
 
915
 
 
916
sub print_testcases {
 
917
  my (@cases)= @_;
 
918
 
 
919
  print "=" x 60, "\n";
 
920
  foreach my $test (@cases){
 
921
    print "[", $test->{name}, "]", "\n";
 
922
    while ((my ($key, $value)) = each(%$test)) {
 
923
      print " ", $key, "=";
 
924
      if (ref $value eq "ARRAY") {
 
925
        print join(", ", @$value);
 
926
      } else {
 
927
        print $value;
 
928
      }
 
929
      print "\n";
 
930
    }
 
931
    print "\n";
 
932
  }
 
933
  print "=" x 60, "\n";
 
934
}
 
935
 
 
936
 
 
937
1;