mtr_cases.pl 18.2 KB
Newer Older
kent@mysql.com's avatar
kent@mysql.com committed
1
# -*- cperl -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright (C) 2005-2006 MySQL AB
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
kent@mysql.com's avatar
kent@mysql.com committed
16 17 18 19 20

# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.

kent@mysql.com's avatar
kent@mysql.com committed
21
use File::Basename;
22
use IO::File();
kent@mysql.com's avatar
kent@mysql.com committed
23 24 25
use strict;

sub collect_test_cases ($);
26 27
sub collect_one_suite ($$);
sub collect_one_test_case ($$$$$$$$$);
28 29

sub mtr_options_from_test_file($$);
kent@mysql.com's avatar
kent@mysql.com committed
30 31 32 33 34 35 36 37

##############################################################################
#
#  Collect information about test cases we are to run
#
##############################################################################

sub collect_test_cases ($) {
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  my $suites= shift; # Semicolon separated list of test suites
  my $cases = [];    # Array of hash

  foreach my $suite (split(",", $suites))
  {
    collect_one_suite($suite, $cases);
  }


  if ( @::opt_cases )
  {
    # Check that the tests specified was found
    # in at least one suite
    foreach my $tname ( @::opt_cases )
    {
      my $found= 0;
      foreach my $test ( @$cases )
      {
	if ( mtr_match_extension($test->{'name'}, $tname) )
	{
	  $found= 1;
	}
      }
      if ( not $found )
      {
	mtr_error("Could not find $tname in any suite");
      }
    }
  }

  if ( $::opt_reorder )
  {
    # Reorder the test cases in an order that will make them faster to run
    my %sort_criteria;

    # Make a mapping of test name to a string that represents how that test
    # should be sorted among the other tests.  Put the most important criterion
    # first, then a sub-criterion, then sub-sub-criterion, et c.
    foreach my $tinfo (@$cases)
    {
      my @criteria = ();

      # Look for tests that muct be in run in a defined order
      # that is defined by test having the same name except for
      # the ending digit

      # Put variables into hash
      my $test_name= $tinfo->{'name'};
      my $depend_on_test_name;
      if ( $test_name =~ /^([\D]+)([0-9]{1})$/ )
      {
	my $base_name= $1;
	my $idx= $2;
	mtr_verbose("$test_name =>  $base_name idx=$idx");
	if ( $idx > 1 )
	{
	  $idx-= 1;
	  $base_name= "$base_name$idx";
	  mtr_verbose("New basename $base_name");
	}

	foreach my $tinfo2 (@$cases)
	{
	  if ( $tinfo2->{'name'} eq $base_name )
	  {
	    mtr_verbose("found dependent test $tinfo2->{'name'}");
	    $depend_on_test_name=$base_name;
	  }
	}
      }

      if ( defined $depend_on_test_name )
      {
	mtr_verbose("Giving $test_name same critera as $depend_on_test_name");
	$sort_criteria{$test_name} = $sort_criteria{$depend_on_test_name};
      }
      else
      {
	#
	# Append the criteria for sorting, in order of importance.
	#
	push(@criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "1" : "0"));
	# Group test with equal options together.
	# Ending with "~" makes empty sort later than filled
	push(@criteria, join("!", sort @{$tinfo->{'master_opt'}}) . "~");

	$sort_criteria{$test_name} = join(" ", @criteria);
      }
    }

    @$cases = sort {
      $sort_criteria{$a->{'name'}} . $a->{'name'} cmp
	$sort_criteria{$b->{'name'}} . $b->{'name'}; } @$cases;

    if ( $::opt_script_debug )
    {
      # For debugging the sort-order
      foreach my $tinfo (@$cases)
      {
	print("$sort_criteria{$tinfo->{'name'}} -> \t$tinfo->{'name'}\n");
      }
    }
  }

  return $cases;

}

sub collect_one_suite($$)
{
  my $suite= shift;  # Test suite name
  my $cases= shift;  # List of test cases

  mtr_verbose("Collecting: $suite");
kent@mysql.com's avatar
kent@mysql.com committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

  my $testdir;
  my $resdir;

  if ( $suite eq "main" )
  {
    $testdir= "$::glob_mysql_test_dir/t";
    $resdir=  "$::glob_mysql_test_dir/r";
  }
  else
  {
    $testdir= "$::glob_mysql_test_dir/suite/$suite/t";
    $resdir=  "$::glob_mysql_test_dir/suite/$suite/r";
  }

167
  # ----------------------------------------------------------------------
168
  # Build a hash of disabled testcases for this suite
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
  # ----------------------------------------------------------------------
  my %disabled;
  if ( open(DISABLED, "$testdir/disabled.def" ) )
  {
    while ( <DISABLED> )
      {
        chomp;
        if ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )
          {
            $disabled{$1}= $2;
          }
      }
    close DISABLED;
  }

184 185 186 187 188 189 190 191
  # Read suite.opt file
  my $suite_opt_file=  "$testdir/suite.opt";
  my $suite_opts= [];
  if ( -f $suite_opt_file )
  {
    $suite_opts= mtr_get_opts_from_file($suite_opt_file);
  }

kent@mysql.com's avatar
kent@mysql.com committed
192 193
  if ( @::opt_cases )
  {
194
    # Collect in specified order, no sort
195 196
    foreach my $tname ( @::opt_cases )
    {
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
      my $elem= undef;
      my $component_id= undef;

      # Get rid of directory part (path). Leave the extension since it is used
      # to understand type of the test.

      $tname = basename($tname);

      # Check if the extenstion has been specified.

      if ( mtr_match_extension($tname, "test") )
      {
        $elem= $tname;
        $tname=~ s/\.test$//;
        $component_id= 'mysqld';
      }
      elsif ( mtr_match_extension($tname, "imtest") )
      {
        $elem= $tname;
        $tname =~ s/\.imtest$//;
        $component_id= 'im';
      }

      # If target component is known, check that the specified test case
      # exists.
222
      #
223 224 225 226 227 228 229 230 231 232
      # Otherwise, try to guess the target component.

      if ( $component_id )
      {
        if ( ! -f "$testdir/$elem")
        {
          mtr_error("Test case $tname ($testdir/$elem) is not found");
        }
      }
      else
kent@mysql.com's avatar
kent@mysql.com committed
233
      {
234 235 236 237 238 239 240 241 242
        my $mysqld_test_exists = -f "$testdir/$tname.test";
        my $im_test_exists = -f "$testdir/$tname.imtest";

        if ( $mysqld_test_exists and $im_test_exists )
        {
          mtr_error("Ambiguous test case name ($tname)");
        }
        elsif ( ! $mysqld_test_exists and ! $im_test_exists )
        {
243 244
	  # Silently skip, could exist in another suite
	  next;
245 246 247 248 249 250 251 252 253 254 255
        }
        elsif ( $mysqld_test_exists )
        {
          $elem= "$tname.test";
          $component_id= 'mysqld';
        }
        elsif ( $im_test_exists )
        {
          $elem= "$tname.imtest";
          $component_id= 'im';
        }
kent@mysql.com's avatar
kent@mysql.com committed
256
      }
257

258 259 260
      collect_one_test_case($testdir,$resdir,$suite,$tname,
                            $elem,$cases,\%disabled,$component_id,
			    $suite_opts);
kent@mysql.com's avatar
kent@mysql.com committed
261 262 263 264
    }
  }
  else
  {
265 266
    opendir(TESTDIR, $testdir) or mtr_error("Can't open dir \"$testdir\": $!");

267 268
    foreach my $elem ( sort readdir(TESTDIR) )
    {
269 270 271 272
      my $component_id= undef;
      my $tname= undef;

      if ($tname= mtr_match_extension($elem, 'test'))
kent@mysql.com's avatar
kent@mysql.com committed
273
      {
274
        $component_id = 'mysqld';
kent@mysql.com's avatar
kent@mysql.com committed
275
      }
276 277 278 279 280 281 282 283
      elsif ($tname= mtr_match_extension($elem, 'imtest'))
      {
        $component_id = 'im';
      }
      else
      {
        next;
      }
284

285 286 287
      # Skip tests that does not match the --do-test= filter
      next if $::opt_do_test and
	! defined mtr_match_prefix($elem,$::opt_do_test);
kent@mysql.com's avatar
kent@mysql.com committed
288

289 290 291
      collect_one_test_case($testdir,$resdir,$suite,$tname,
                            $elem,$cases,\%disabled,$component_id,
			    $suite_opts);
kent@mysql.com's avatar
kent@mysql.com committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
    }
    closedir TESTDIR;
  }

  return $cases;
}


##############################################################################
#
#  Collect information about a single test case
#
##############################################################################


307
sub collect_one_test_case($$$$$$$$$) {
kent@mysql.com's avatar
kent@mysql.com committed
308 309
  my $testdir= shift;
  my $resdir=  shift;
310
  my $suite=   shift;
kent@mysql.com's avatar
kent@mysql.com committed
311 312 313
  my $tname=   shift;
  my $elem=    shift;
  my $cases=   shift;
kent@mysql.com's avatar
kent@mysql.com committed
314
  my $disabled=shift;
315
  my $component_id= shift;
316
  my $suite_opts= shift;
kent@mysql.com's avatar
kent@mysql.com committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330

  my $path= "$testdir/$elem";

  # ----------------------------------------------------------------------
  # Skip some tests silently
  # ----------------------------------------------------------------------

  if ( $::opt_start_from and $tname lt $::opt_start_from )
  {
    return;
  }


  my $tinfo= {};
331
  $tinfo->{'name'}= "$suite.$tname";
kent@mysql.com's avatar
kent@mysql.com committed
332
  $tinfo->{'result_file'}= "$resdir/$tname.result";
333
  $tinfo->{'component_id'} = $component_id;
kent@mysql.com's avatar
kent@mysql.com committed
334 335
  push(@$cases, $tinfo);

336 337 338 339
  # ----------------------------------------------------------------------
  # Skip some tests but include in list, just mark them to skip
  # ----------------------------------------------------------------------

kent@mysql.com's avatar
kent@mysql.com committed
340 341 342 343 344 345 346 347 348 349 350 351 352
  if ( $::opt_skip_test and defined mtr_match_prefix($tname,$::opt_skip_test) )
  {
    $tinfo->{'skip'}= 1;
    return;
  }

  # ----------------------------------------------------------------------
  # Collect information about test case
  # ----------------------------------------------------------------------

  $tinfo->{'path'}= $path;
  $tinfo->{'timezone'}= "GMT-3"; # for UNIX_TIMESTAMP tests to work

353
  $tinfo->{'slave_num'}= 0; # Default, no slave
354
  $tinfo->{'master_num'}= 1; # Default, 1 master
kent@mysql.com's avatar
kent@mysql.com committed
355 356 357 358 359
  if ( defined mtr_match_prefix($tname,"rpl") )
  {
    if ( $::opt_skip_rpl )
    {
      $tinfo->{'skip'}= 1;
360
      $tinfo->{'comment'}= "No replication tests(--skip-rpl)";
kent@mysql.com's avatar
kent@mysql.com committed
361 362 363
      return;
    }

364
    $tinfo->{'slave_num'}= 1; # Default for rpl* tests, use one slave
kent@mysql.com's avatar
kent@mysql.com committed
365 366 367

  }

kent@mysql.com's avatar
kent@mysql.com committed
368 369
  if ( defined mtr_match_prefix($tname,"federated") )
  {
370 371
    # Default, federated uses the first slave as it's federated database
    $tinfo->{'slave_num'}= 1;
kent@mysql.com's avatar
kent@mysql.com committed
372 373
  }

kent@mysql.com's avatar
kent@mysql.com committed
374 375 376 377 378
  my $master_opt_file= "$testdir/$tname-master.opt";
  my $slave_opt_file=  "$testdir/$tname-slave.opt";
  my $slave_mi_file=   "$testdir/$tname.slave-mi";
  my $master_sh=       "$testdir/$tname-master.sh";
  my $slave_sh=        "$testdir/$tname-slave.sh";
kent@mysql.com's avatar
kent@mysql.com committed
379
  my $disabled_file=   "$testdir/$tname.disabled";
380
  my $im_opt_file=     "$testdir/$tname-im.opt";
kent@mysql.com's avatar
kent@mysql.com committed
381

382 383
  $tinfo->{'master_opt'}= [];
  $tinfo->{'slave_opt'}=  [];
kent@mysql.com's avatar
kent@mysql.com committed
384 385
  $tinfo->{'slave_mi'}=   [];

386 387 388 389 390 391 392 393 394
  # Add suite opts
  foreach my $opt ( @$suite_opts )
  {
    mtr_verbose($opt);
    push(@{$tinfo->{'master_opt'}}, $opt);
    push(@{$tinfo->{'slave_opt'}}, $opt);
  }

  # Add master opts
kent@mysql.com's avatar
kent@mysql.com committed
395 396 397
  if ( -f $master_opt_file )
  {

398
    my $master_opt= mtr_get_opts_from_file($master_opt_file);
kent@mysql.com's avatar
kent@mysql.com committed
399

400 401 402
    foreach my $opt ( @$master_opt )
    {
      my $value;
kent@mysql.com's avatar
kent@mysql.com committed
403

404 405 406
      # The opt file is used both to send special options to the mysqld
      # as well as pass special test case specific options to this
      # script
kent@mysql.com's avatar
kent@mysql.com committed
407

408 409 410 411 412 413
      $value= mtr_match_prefix($opt, "--timezone=");
      if ( defined $value )
      {
	$tinfo->{'timezone'}= $value;
	next;
      }
kent@mysql.com's avatar
kent@mysql.com committed
414

415 416 417 418 419 420 421
      $value= mtr_match_prefix($opt, "--slave-num=");
      if ( defined $value )
      {
	$tinfo->{'slave_num'}= $value;
	next;
      }

422 423 424 425 426 427 428 429
      $value= mtr_match_prefix($opt, "--result-file=");
      if ( defined $value )
      {
	# Specifies the file mysqltest should compare
	# output against
	$tinfo->{'result_file'}= "r/$value.result";
	next;
      }
kent@mysql.com's avatar
kent@mysql.com committed
430

431 432 433 434
      # If we set default time zone, remove the one we have
      $value= mtr_match_prefix($opt, "--default-time-zone=");
      if ( defined $value )
      {
435 436 437
	# Set timezone for this test case to something different
	$tinfo->{'timezone'}= "GMT-8";
	# Fallthrough, add the --default-time-zone option
438
      }
kent@mysql.com's avatar
kent@mysql.com committed
439

440 441 442 443 444 445 446 447
      # The --restart option forces a restart even if no special
      # option is set. If the options are the same as next testcase
      # there is no need to restart after the testcase
      # has completed
      if ( $opt eq "--force-restart" )
      {
	$tinfo->{'force_restart'}= 1;
	next;
kent@mysql.com's avatar
kent@mysql.com committed
448
      }
kent@mysql.com's avatar
kent@mysql.com committed
449

450 451
      # Ok, this was a real option, add it
      push(@{$tinfo->{'master_opt'}}, $opt);
kent@mysql.com's avatar
kent@mysql.com committed
452 453 454
    }
  }

455
  # Add slave opts
kent@mysql.com's avatar
kent@mysql.com committed
456 457
  if ( -f $slave_opt_file )
  {
kent@mysql.com's avatar
kent@mysql.com committed
458 459 460 461 462 463 464 465 466
    my $slave_opt= mtr_get_opts_from_file($slave_opt_file);

    foreach my $opt ( @$slave_opt )
    {
      # If we set default time zone, remove the one we have
      my $value= mtr_match_prefix($opt, "--default-time-zone=");
      $tinfo->{'slave_opt'}= [] if defined $value;
    }
    push(@{$tinfo->{'slave_opt'}}, @$slave_opt);
kent@mysql.com's avatar
kent@mysql.com committed
467 468 469 470 471 472 473 474 475 476 477 478
  }

  if ( -f $slave_mi_file )
  {
    $tinfo->{'slave_mi'}= mtr_get_opts_from_file($slave_mi_file);
  }

  if ( -f $master_sh )
  {
    if ( $::glob_win32_perl )
    {
      $tinfo->{'skip'}= 1;
479 480
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
      return;
kent@mysql.com's avatar
kent@mysql.com committed
481 482 483 484 485 486 487 488 489 490 491 492
    }
    else
    {
      $tinfo->{'master_sh'}= $master_sh;
    }
  }

  if ( -f $slave_sh )
  {
    if ( $::glob_win32_perl )
    {
      $tinfo->{'skip'}= 1;
493 494
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
      return;
kent@mysql.com's avatar
kent@mysql.com committed
495 496 497 498 499 500 501
    }
    else
    {
      $tinfo->{'slave_sh'}= $slave_sh;
    }
  }

502 503 504 505 506 507 508 509 510
  if ( -f $im_opt_file )
  {
    $tinfo->{'im_opts'} = mtr_get_opts_from_file($im_opt_file);
  }
  else
  {
    $tinfo->{'im_opts'} = [];
  }

kent@mysql.com's avatar
kent@mysql.com committed
511
  # FIXME why this late?
512
  my $marked_as_disabled= 0;
kent@mysql.com's avatar
kent@mysql.com committed
513
  if ( $disabled->{$tname} )
kent@mysql.com's avatar
kent@mysql.com committed
514
  {
515 516
    $marked_as_disabled= 1;
    $tinfo->{'comment'}= $disabled->{$tname};
kent@mysql.com's avatar
kent@mysql.com committed
517 518
  }

kent@mysql.com's avatar
kent@mysql.com committed
519
  if ( -f $disabled_file )
kent@mysql.com's avatar
kent@mysql.com committed
520
  {
521
    $marked_as_disabled= 1;
kent@mysql.com's avatar
kent@mysql.com committed
522
    $tinfo->{'comment'}= mtr_fromfile($disabled_file);
kent@mysql.com's avatar
kent@mysql.com committed
523 524
  }

525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  # If test was marked as disabled, either opt_enable_disabled is off and then
  # we skip this test, or it is on and then we run this test but warn

  if ( $marked_as_disabled )
  {
    if ( $::opt_enable_disabled )
    {
      $tinfo->{'dont_skip_though_disabled'}= 1;
    }
    else
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'disable'}= 1;   # Sub type of 'skip'
      return;
    }
  }

  if ( $component_id eq 'im' )
  {
    if ( $::glob_use_embedded_server )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No IM with embedded server";
      return;
    }
    elsif ( $::opt_ps_protocol )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No IM with --ps-protocol";
      return;
    }
    elsif ( $::opt_skip_im )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No IM tests(--skip-im)";
      return;
    }
  }
  else
  {
    mtr_options_from_test_file($tinfo,"$testdir/${tname}.test");

567 568 569 570 571 572 573 574 575 576 577
    if ( defined $::used_default_engine )
    {
      # Different default engine is used
      # tag test to require that engine
      $tinfo->{'ndb_test'}= 1
	if ( $::used_default_engine =~ /^ndb/i );

      $tinfo->{'innodb_test'}= 1
	if ( $::used_default_engine =~ /^innodb/i );
    }

578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
    if ( $tinfo->{'big_test'} and ! $::opt_big_test )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "Test need 'big-test' option";
      return;
    }

    if ( $tinfo->{'ndb_extra'} and ! $::opt_ndb_extra_test )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "Test need 'ndb_extra' option";
      return;
    }

    if ( $tinfo->{'require_manager'} )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "Test need the _old_ manager(to be removed)";
      return;
    }

    if ( defined $tinfo->{'binlog_format'} and
	 ! ( $tinfo->{'binlog_format'} eq $::used_binlog_format ) )
    {
      $tinfo->{'skip'}= 1;
603
      $tinfo->{'comment'}= "Requiring binlog format '$tinfo->{'binlog_format'}'";
604 605 606 607 608 609 610 611 612
      return;
    }

    if ( $tinfo->{'need_debug'} && ! $::debug_compiled_binaries )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "Test need debug binaries";
      return;
    }
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630

    if ( $tinfo->{'ndb_test'} )
    {
      # This is a NDB test
      if ( ! $::glob_ndbcluster_supported )
      {
	# Ndb is not supported, skip it
	$tinfo->{'skip'}= 1;
	$tinfo->{'comment'}= "No ndbcluster support";
	return;
      }
      elsif ( $::opt_skip_ndbcluster )
      {
	# All ndb test's should be skipped
	$tinfo->{'skip'}= 1;
	$tinfo->{'comment'}= "No ndbcluster tests(--skip-ndbcluster)";
	return;
      }
631 632
      # Ndb tests run with two mysqld masters
      $tinfo->{'master_num'}= 2;
633 634 635 636 637 638 639 640 641 642 643 644 645
    }
    else
    {
      # This is not a ndb test
      if ( $::opt_with_ndbcluster_only )
      {
	# Only the ndb test should be run, all other should be skipped
	$tinfo->{'skip'}= 1;
	$tinfo->{'comment'}= "Only ndbcluster tests(--with-ndbcluster-only)";
	return;
      }
    }

646 647
    if ( $tinfo->{'innodb_test'} )
    {
648
      # This is a test that need innodb
649
      if ( $::mysqld_variables{'innodb'} ne "TRUE" )
650 651 652 653 654 655 656 657
      {
	# innodb is not supported, skip it
	$tinfo->{'skip'}= 1;
	$tinfo->{'comment'}= "No innodb support";
	return;
      }
    }

658 659 660 661 662 663 664 665 666 667 668
    if ( $tinfo->{'need_binlog'} )
    {
      if (grep(/^--skip-log-bin/,  @::opt_extra_mysqld_opt) )
      {
	$tinfo->{'skip'}= 1;
	$tinfo->{'comment'}= "Test need binlog";
	return;
      }
    }
    else
    {
669 670 671 672 673 674
      if ( $::mysql_version_id >= 50100 )
      {
	# Test does not need binlog, add --skip-binlog to
	# the options used when starting it
	push(@{$tinfo->{'master_opt'}}, "--skip-log-bin");
      }
675 676
    }

677
  }
kent@mysql.com's avatar
kent@mysql.com committed
678 679 680
}


681 682 683 684 685 686
# List of tags in the .test files that if found should set
# the specified value in "tinfo"
our @tags=
(
 ["include/have_innodb.inc", "innodb_test", 1],
 ["include/have_binlog_format_row.inc", "binlog_format", "row"],
msvensson@pilot.(none)'s avatar
msvensson@pilot.(none) committed
687
 ["include/have_log_bin.inc", "need_binlog", 1],
688
 ["include/have_binlog_format_statement.inc", "binlog_format", "statement"],
689
 ["include/have_binlog_format_mixed.inc", "binlog_format", "mixed"],
690 691
 ["include/big_test.inc", "big_test", 1],
 ["include/have_debug.inc", "need_debug", 1],
692
 ["include/have_ndb.inc", "ndb_test", 1],
693 694 695 696 697 698 699 700 701 702 703 704
 ["include/have_ndb_extra.inc", "ndb_extra", 1],
 ["require_manager", "require_manager", 1],
);

sub mtr_options_from_test_file($$) {
  my $tinfo= shift;
  my $file= shift;
  #mtr_verbose("$file");
  my $F= IO::File->new($file) or mtr_error("can't open file \"$file\": $!");

  while ( my $line= <$F> )
  {
705 706 707 708

    # Skip line if it start's with #
    next if ( $line =~ /^#/ );

709 710 711 712 713 714 715 716 717 718 719
    # Match this line against tag in "tags" array
    foreach my $tag (@tags)
    {
      if ( index($line, $tag->[0]) >= 0 )
      {
	# Tag matched, assign value to "tinfo"
	$tinfo->{"$tag->[1]"}= $tag->[2];
      }
    }

    # If test sources another file, open it as well
720 721
    if ( $line =~ /^\-\-([[:space:]]*)source(.*)$/ or
	 $line =~ /^([[:space:]]*)source(.*);$/ )
722 723 724 725 726 727
    {
      my $value= $2;
      $value =~ s/^\s+//;  # Remove leading space
      $value =~ s/[[:space:]]+$//;  # Remove ending space

      my $sourced_file= "$::glob_mysql_test_dir/$value";
728 729 730 731 732 733 734
      if ( -f $sourced_file )
      {
	# Only source the file if it exists, we may get
	# false positives in the regexes above if someone
	# writes "source nnnn;" in a test case(such as mysqltest.test)
	mtr_options_from_test_file($tinfo, $sourced_file);
      }
735 736 737 738 739
    }

  }
}

kent@mysql.com's avatar
kent@mysql.com committed
740
1;