mtr_cases.pl

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PL 代码 · 共 682 行 · 第 1/2 页

PL
682
字号
# -*- cperl -*-# 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# 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.use File::Basename;use IO::File();use strict;sub collect_test_cases ($);sub collect_one_test_case ($$$$$$$);sub mtr_options_from_test_file($$);################################################################################  Collect information about test cases we are to run###############################################################################sub collect_test_cases ($) {  my $suite= shift;             # Test suite name  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";  }  my $cases = [];           # Array of hash, will be array of C struct  opendir(TESTDIR, $testdir) or mtr_error("Can't open dir \"$testdir\": $!");  # ----------------------------------------------------------------------  # Disable some tests listed in disabled.def  # ----------------------------------------------------------------------  my %disabled;  if ( open(DISABLED, "$testdir/disabled.def" ) )  {    while ( <DISABLED> )      {        chomp;        if ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )          {            $disabled{$1}= $2;          }      }    close DISABLED;  }  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);      # 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.      #      # 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      {        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 )        {          mtr_error("Test case $tname is not found");        }        elsif ( $mysqld_test_exists )        {          $elem= "$tname.test";          $component_id= 'mysqld';        }        elsif ( $im_test_exists )        {          $elem= "$tname.imtest";          $component_id= 'im';        }      }      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'))      {        $component_id = 'im';      }      else      {        next;      }      # Skip tests that does not match the --do-test= filter      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);    }    closedir TESTDIR;  }  # Reorder the test cases in an order that will make them faster to run  if ( $::opt_reorder )  {    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;}################################################################################  Collect information about a single 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";  # ----------------------------------------------------------------------  # Skip some tests silently  # ----------------------------------------------------------------------  if ( $::opt_start_from and $tname lt $::opt_start_from )  {    return;  }  my $tinfo= {};  $tinfo->{'name'}= $tname;  $tinfo->{'result_file'}= "$resdir/$tname.result";  $tinfo->{'component_id'} = $component_id;  push(@$cases, $tinfo);  # ----------------------------------------------------------------------  # Skip some tests but include in list, just mark them to skip  # ----------------------------------------------------------------------  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  $tinfo->{'slave_num'}= 0; # Default, no slave  $tinfo->{'master_num'}= 1; # Default, 1 master  if ( defined mtr_match_prefix($tname,"rpl") )  {    if ( $::opt_skip_rpl )    {      $tinfo->{'skip'}= 1;      $tinfo->{'comment'}= "No replication tests(--skip-rpl)";      return;    }    $tinfo->{'slave_num'}= 1; # Default for rpl* tests, use one slave  }  if ( defined mtr_match_prefix($tname,"federated") )  {    # Default, federated uses the first slave as it's federated database    $tinfo->{'slave_num'}= 1;  }  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";  my $disabled_file=   "$testdir/$tname.disabled";  my $im_opt_file=     "$testdir/$tname-im.opt";  $tinfo->{'master_opt'}= [];  $tinfo->{'slave_opt'}=  [];  $tinfo->{'slave_mi'}=   [];  if ( -f $master_opt_file )  {    my $master_opt= mtr_get_opts_from_file($master_opt_file);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?