~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/lib/v1/mtr_cases.pl

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

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