Commit dccc6b10 authored by unknown's avatar unknown
Browse files

Backport from 5.1

 -Add support for detecting version and features from mysqld binary
 - Autodetect netware
 - Disable some features not available below 5.0
 - Cleanup executable_setup to look for one executable at a time, only llok for the ones that are needed based on the selected testcases and settings


mysql-test/lib/mtr_cases.pl:
  Backport from 5.1
mysql-test/lib/mtr_io.pl:
  Backport from 5.1
  Add new function mtr_appendfile_to_file
mysql-test/lib/mtr_misc.pl:
  Backport from 5.1
mysql-test/lib/mtr_process.pl:
  Backport from 5.1
mysql-test/lib/mtr_report.pl:
  Backport from 5.1
mysql-test/mysql-test-run.pl:
  Add support for detecting version and features from mysqld binary
  Autodetect netware
  Disable some features not available below 5.0
  Cleanup executable_setup to look for one executable at a time, only llok for the ones that are needed based on the selected testcases and settings
mysql-test/r/mysqltest.result:
  Update result
mysql-test/lib/mtr_im.pl:
  New BitKeeper file ``mysql-test/lib/mtr_im.pl''
mysql-test/lib/mtr_stress.pl:
  New BitKeeper file ``mysql-test/lib/mtr_stress.pl''
parent 99cfe38a
Loading
Loading
Loading
Loading
+296 −69
Original line number Diff line number Diff line
@@ -5,10 +5,13 @@
# same name.

use File::Basename;
use IO::File();
use strict;

sub collect_test_cases ($);
sub collect_one_test_case ($$$$$$);
sub collect_one_test_case ($$$$$$$);

sub mtr_options_from_test_file($$);

##############################################################################
#
@@ -37,21 +40,6 @@ sub collect_test_cases ($) {

  opendir(TESTDIR, $testdir) or mtr_error("Can't open dir \"$testdir\": $!");

  if ( @::opt_cases )
  {
    foreach my $tname ( @::opt_cases ) { # Run in specified order, no sort
      $tname= basename($tname, ".test");
      my $elem= "$tname.test";
      if ( ! -f "$testdir/$elem")
      {
        mtr_error("Test case $tname ($testdir/$elem) is not found");
      }
      collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,{});
    }
    closedir TESTDIR;
  }
  else
  {
  # ----------------------------------------------------------------------
  # Disable some tests listed in disabled.def
  # ----------------------------------------------------------------------
@@ -69,49 +57,138 @@ sub collect_test_cases ($) {
    close DISABLED;
  }

    foreach my $elem ( sort readdir(TESTDIR) ) {
      my $tname= mtr_match_extension($elem,"test");
      next if ! defined $tname;
      next if $::opt_do_test and ! defined mtr_match_prefix($elem,$::opt_do_test);
  if ( @::opt_cases )
  {
    foreach my $tname ( @::opt_cases ) { # Run in specified order, no sort
      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);

      collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,\%disabled);
      # Check if the extenstion has been specified.

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

  # To speed things up, we sort first in if the test require a restart
  # or not, second in alphanumeric order.
      # If target component is known, check that the specified test case
      # exists.
      # 
      # Otherwise, try to guess the target component.

  if ( $::opt_reorder )
      if ( $component_id )
      {
    @$cases = sort {
      if ( ! $a->{'master_restart'} and ! $b->{'master_restart'} )
        if ( ! -f "$testdir/$elem")
        {
        return $a->{'name'} cmp $b->{'name'};
          mtr_error("Test case $tname ($testdir/$elem) is not found");
        }
      }
      else
      {
        my $mysqld_test_exists = -f "$testdir/$tname.test";
        my $im_test_exists = -f "$testdir/$tname.imtest";

      if ( $a->{'master_restart'} and $b->{'master_restart'} )
        if ( $mysqld_test_exists and $im_test_exists )
        {
        my $cmp= mtr_cmp_opts($a->{'master_opt'}, $b->{'master_opt'});
        if ( $cmp == 0 )
          mtr_error("Ambiguous test case name ($tname)");
        }
        elsif ( ! $mysqld_test_exists and ! $im_test_exists )
        {
          return $a->{'name'} cmp $b->{'name'};
          mtr_error("Test case $tname is not found");
        }
        else
        elsif ( $mysqld_test_exists )
        {
          return $cmp;
          $elem= "$tname.test";
          $component_id= 'mysqld';
        }
        elsif ( $im_test_exists )
        {
          $elem= "$tname.imtest";
          $component_id= 'im';
        }
      }

      if ( $a->{'master_restart'} )
      collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,\%disabled,
        $component_id);
    }
    closedir TESTDIR;
  }
  else
  {
    foreach my $elem ( sort readdir(TESTDIR) ) {
      my $component_id= undef;
      my $tname= undef;

      if ($tname= mtr_match_extension($elem, 'test'))
      {
        $component_id = 'mysqld';
      }
      elsif ($tname= mtr_match_extension($elem, 'imtest'))
      {
        return 1;                 # Is greater
        $component_id = 'im';
      }
      else
      {
        return -1;                # Is less
        next;
      }
      
      next if $::opt_do_test and ! defined mtr_match_prefix($elem,$::opt_do_test);

      collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,\%disabled,
        $component_id);
    }
    } @$cases;
    closedir TESTDIR;
  }

  # To speed things up, we sort first in if the test require a restart
  # or not, second in alphanumeric order.

  if ( $::opt_reorder )
  {

    my %sort_criteria;
    my $tinfo;

    # 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 $tinfo (@$cases) 
    {
      my @this_criteria = ();

      # Append the criteria for sorting, in order of importance.
      push(@this_criteria, join("!", sort @{$tinfo->{'master_opt'}}) . "~");  # Ending with "~" makes empty sort later than filled
      push(@this_criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "1" : "0"));
      push(@this_criteria, "restart=" . ($tinfo->{'master_restart'} ? "1" : "0"));
      push(@this_criteria, "big_test=" . ($tinfo->{'big_test'} ? "1" : "0"));
      push(@this_criteria, join("|", sort keys %{$tinfo}));  # Group similar things together.  The values may differ substantially.  FIXME?
      push(@this_criteria, $tinfo->{'name'});   # Finally, order by the name
      
      $sort_criteria{$tinfo->{"name"}} = join(" ", @this_criteria);
    }

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

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

  return $cases;
@@ -125,13 +202,14 @@ sub collect_test_cases ($) {
##############################################################################


sub collect_one_test_case($$$$$$) {
sub collect_one_test_case($$$$$$$) {
  my $testdir= shift;
  my $resdir=  shift;
  my $tname=   shift;
  my $elem=    shift;
  my $cases=   shift;
  my $disabled=shift;
  my $component_id= shift;

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

@@ -151,6 +229,7 @@ sub collect_one_test_case($$$$$$) {
  my $tinfo= {};
  $tinfo->{'name'}= $tname;
  $tinfo->{'result_file'}= "$resdir/$tname.result";
  $tinfo->{'component_id'} = $component_id;
  push(@$cases, $tinfo);

  if ( $::opt_skip_test and defined mtr_match_prefix($tname,$::opt_skip_test) )
@@ -171,14 +250,12 @@ sub collect_one_test_case($$$$$$) {
    if ( $::opt_skip_rpl )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No replication tests(--skip-rpl)";
      return;
    }

    $tinfo->{'slave_num'}= 1;           # Default, use one slave

    # FIXME currently we always restart slaves
    $tinfo->{'slave_restart'}= 1;

    if ( $tname eq 'rpl_failsafe' or $tname eq 'rpl_chain_temp_table' )
    {
      # $tinfo->{'slave_num'}= 3;         # Not 3 ? Check old code, strange
@@ -187,32 +264,40 @@ sub collect_one_test_case($$$$$$) {

  if ( defined mtr_match_prefix($tname,"federated") )
  {
    $tinfo->{'slave_num'}= 1;           # Default, use one slave

    # FIXME currently we always restart slaves
    $tinfo->{'slave_restart'}= 1;
    # Default, federated uses the first slave as it's federated database
    $tinfo->{'slave_num'}= 1;
  }

  # Cluster is needed by test case if testname contains ndb
  if ( defined mtr_match_substring($tname,"ndb") )
  if ( $::opt_with_ndbcluster or defined mtr_match_substring($tname,"ndb") )
  {
    # This is an ndb test or all tests should be run with ndb cluster started
    $tinfo->{'ndb_test'}= 1;
    if ( $::opt_skip_ndbcluster )
    {
      # Skip all ndb tests
      # All ndb test's should be skipped
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No ndbcluster test(--skip-ndbcluster)";
      return;
    }
    if ( ! $::opt_with_ndbcluster )
    if ( ! $::opt_ndbcluster_supported )
    {
      # Ndb is not supported, skip them
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No ndbcluster support";
      return;
    }
  }
  else
  {
    # This is not a ndb test
    $tinfo->{'ndb_test'}= 0;
    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;
    }
  }

  # FIXME what about embedded_server + ndbcluster, skip ?!
@@ -223,6 +308,7 @@ sub collect_one_test_case($$$$$$) {
  my $master_sh=       "$testdir/$tname-master.sh";
  my $slave_sh=        "$testdir/$tname-slave.sh";
  my $disabled_file=   "$testdir/$tname.disabled";
  my $im_opt_file=     "$testdir/$tname-im.opt";

  $tinfo->{'master_opt'}= [];
  $tinfo->{'slave_opt'}=  [];
@@ -303,6 +389,8 @@ sub collect_one_test_case($$$$$$) {
    if ( $::glob_win32_perl )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
      return;
    }
    else
    {
@@ -316,6 +404,8 @@ sub collect_one_test_case($$$$$$) {
    if ( $::glob_win32_perl )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
      return;
    }
    else
    {
@@ -324,19 +414,106 @@ sub collect_one_test_case($$$$$$) {
    }
  }

  if ( -f $im_opt_file )
  {
    $tinfo->{'im_opts'} = mtr_get_opts_from_file($im_opt_file);
  }
  else
  {
    $tinfo->{'im_opts'} = [];
  }

  # FIXME why this late?
  my $marked_as_disabled= 0;
  if ( $disabled->{$tname} )
  {
    $tinfo->{'skip'}= 1;
    $tinfo->{'disable'}= 1;   # Sub type of 'skip'
    $tinfo->{'comment'}= $disabled->{$tname} if $disabled->{$tname};
    $marked_as_disabled= 1;
    $tinfo->{'comment'}= $disabled->{$tname};
  }

  if ( -f $disabled_file )
  {
    $marked_as_disabled= 1;
    $tinfo->{'comment'}= mtr_fromfile($disabled_file);
  }

  # 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'
    $tinfo->{'comment'}= mtr_fromfile($disabled_file);
      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");

    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;
      $tinfo->{'comment'}= "Not running with binlog format '$tinfo->{'binlog_format'}'";
      return;
    }

    if ( $tinfo->{'need_debug'} && ! $::debug_compiled_binaries )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "Test need debug binaries";
      return;
    }
  }

  # We can't restart a running server that may be in use
@@ -345,8 +522,58 @@ sub collect_one_test_case($$$$$$) {
       ( $tinfo->{'master_restart'} or $tinfo->{'slave_restart'} ) )
  {
    $tinfo->{'skip'}= 1;
    $tinfo->{'comment'}= "Can't restart a running server";
    return;
  }

}


# 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"],
 ["include/have_binlog_format_statement.inc", "binlog_format", "stmt"],
 ["include/big_test.inc", "big_test", 1],
 ["include/have_debug.inc", "need_debug", 1],
 ["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> )
  {
    next if ( $line !~ /^--/ );

    # 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
    if ( $line =~ /^\-\-([[:space:]]*)source(.*)$/ )
    {
      my $value= $2;
      $value =~ s/^\s+//;  # Remove leading space
      $value =~ s/[[:space:]]+$//;  # Remove ending space

      my $sourced_file= "$::glob_mysql_test_dir/$value";
      mtr_options_from_test_file($tinfo, $sourced_file);
    }

  }
}

1;
+761 −0

File added.

Preview size limit exceeded, changes collapsed.

+60 −6
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ sub mtr_get_opts_from_file ($);
sub mtr_fromfile ($);
sub mtr_tofile ($@);
sub mtr_tonewfile($@);
sub mtr_lastlinefromfile($);
sub mtr_appendfile_to_file ($$);

##############################################################################
#
@@ -19,13 +21,39 @@ sub mtr_tonewfile($@);
##############################################################################

sub mtr_get_pid_from_file ($) {
  my $file=  shift;
  my $pid_file_path=  shift;
  my $TOTAL_ATTEMPTS= 30;
  my $timeout= 1;

  # We should read from the file until we get correct pid. As it is
  # stated in BUG#21884, pid file can be empty at some moment. So, we should
  # read it until we get valid data.

  for (my $cur_attempt= 1; $cur_attempt <= $TOTAL_ATTEMPTS; ++$cur_attempt)
  {
    mtr_debug("Reading pid file '$pid_file_path' " .
              "($cur_attempt of $TOTAL_ATTEMPTS)...");

    open(FILE, '<', $pid_file_path)
      or mtr_error("can't open file \"$pid_file_path\": $!");

  open(FILE,"<",$file) or mtr_error("can't open file \"$file\": $!");
    my $pid= <FILE>;
  chomp($pid);

    chomp($pid) if defined $pid;

    close FILE;
  return $pid;

    return $pid if defined $pid && $pid ne '';

    mtr_debug("Pid file '$pid_file_path' is empty. " .
              "Sleeping $timeout second(s)...");

    sleep(1);
  }

  mtr_error("Pid file '$pid_file_path' is corrupted. " .
            "Can not retrieve PID in " .
            ($timeout * $TOTAL_ATTEMPTS) . " seconds.");
}

sub mtr_get_opts_from_file ($) {
@@ -113,6 +141,20 @@ sub mtr_fromfile ($) {
  return $text;
}

sub mtr_lastlinefromfile ($) {
  my $file=  shift;
  my $text;

  open(FILE,"<",$file) or mtr_error("can't open file \"$file\": $!");
  while (my $line= <FILE>)
  {
    $text= $line;
  }
  close FILE;
  return $text;
}


sub mtr_tofile ($@) {
  my $file=  shift;

@@ -129,5 +171,17 @@ sub mtr_tonewfile ($@) {
  close FILE;
}

sub mtr_appendfile_to_file ($$) {
  my $from_file=  shift;
  my $to_file=  shift;

  open(TOFILE,">>",$to_file) or mtr_error("can't open file \"$to_file\": $!");
  open(FROMFILE,">>",$from_file)
    or mtr_error("can't open file \"$from_file\": $!");
  print TOFILE while (<FROMFILE>);
  close FROMFILE;
  close TOFILE;
}


1;
+30 −10
Original line number Diff line number Diff line
@@ -9,9 +9,10 @@ use strict;
sub mtr_full_hostname ();
sub mtr_short_hostname ();
sub mtr_init_args ($);
sub mtr_add_arg ($$);
sub mtr_add_arg ($$@);
sub mtr_path_exists(@);
sub mtr_script_exists(@);
sub mtr_file_exists(@);
sub mtr_exe_exists(@);
sub mtr_copy_dir($$);
sub mtr_same_opts($$);
@@ -54,7 +55,7 @@ sub mtr_init_args ($) {
  $$args = [];                            # Empty list
}

sub mtr_add_arg ($$) {
sub mtr_add_arg ($$@) {
  my $args=   shift;
  my $format= shift;
  my @fargs = @_;
@@ -101,6 +102,14 @@ sub mtr_script_exists (@) {
  }
}

sub mtr_file_exists (@) {
  foreach my $path ( @_ )
  {
    return $path if -e $path;
  }
  return "";
}

sub mtr_exe_exists (@) {
  my @path= @_;
  map {$_.= ".exe"} @path if $::glob_win32;
@@ -125,19 +134,30 @@ sub mtr_exe_exists (@) {
  }
}


sub mtr_copy_dir($$) {
  my $srcdir= shift;
  my $dstdir= shift;
  my $from_dir= shift;
  my $to_dir= shift;

#  mtr_verbose("Copying from $from_dir to $to_dir");

  # Create destination directory
  mkpath($dstdir);
  find(\&mtr_copy_one_file, $dstdir);
  mkpath("$to_dir");
  opendir(DIR, "$from_dir")
    or mtr_error("Can't find $from_dir$!");
  for(readdir(DIR)) {
    next if "$_" eq "." or "$_" eq "..";
    if ( -d "$from_dir/$_" )
    {
      mtr_copy_dir("$from_dir/$_", "$to_dir/$_");
      next;
    }
    copy("$from_dir/$_", "$to_dir/$_");
  }
  closedir(DIR);

sub mtr_copy_one_file {
  print $File::Find::name, "\n";
}


sub mtr_same_opts ($$) {
  my $l1= shift;
  my $l2= shift;
+452 −223

File changed.

Preview size limit exceeded, changes collapsed.

Loading