diff options
Diffstat (limited to 'mysql-test/lib/mtr_cases.pl')
-rw-r--r-- | mysql-test/lib/mtr_cases.pl | 303 |
1 files changed, 191 insertions, 112 deletions
diff --git a/mysql-test/lib/mtr_cases.pl b/mysql-test/lib/mtr_cases.pl index 0d705104303..d9ba9466482 100644 --- a/mysql-test/lib/mtr_cases.pl +++ b/mysql-test/lib/mtr_cases.pl @@ -22,8 +22,10 @@ use File::Basename; use IO::File(); use strict; +use My::Config; + sub collect_test_cases ($); -sub collect_one_suite ($$); +sub collect_one_suite ($); sub collect_one_test_case ($$$$$$$$$); sub mtr_options_from_test_file($$); @@ -61,7 +63,7 @@ sub collect_test_cases ($) { foreach my $suite (split(",", $suites)) { - collect_one_suite($suite, $cases); + push(@$cases, collect_one_suite($suite)); } @@ -205,51 +207,24 @@ sub split_testname { } -sub collect_one_suite($$) +sub collect_one_suite($) { my $suite= shift; # Test suite name - my $cases= shift; # List of test cases + my @cases; # Array of hash mtr_verbose("Collecting: $suite"); - my $combination_file= "combinations"; - my $combinations = []; - my $suitedir= "$::glob_mysql_test_dir"; # Default - my $combination_file= "$::glob_mysql_test_dir/$combination_file"; if ( $suite ne "main" ) { $suitedir= mtr_path_exists("$suitedir/suite/$suite", "$suitedir/$suite"); mtr_verbose("suitedir: $suitedir"); - $combination_file= "$suitedir/$combination_file"; } my $testdir= "$suitedir/t"; my $resdir= "$suitedir/r"; - if (!@::opt_combination) - { - # Read combinations file - if ( open(COMB,$combination_file) ) - { - while (<COMB>) - { - chomp; - s/\ +/ /g; - push (@$combinations, $_) unless ($_ eq ''); - } - close COMB; - } - } - else - { - # take the combination from command-line - @$combinations = @::opt_combination; - } - # Remember last element position - my $begin_index = $#{@$cases} + 1; - # ---------------------------------------------------------------------- # Build a hash of disabled testcases for this suite # ---------------------------------------------------------------------- @@ -324,7 +299,7 @@ sub collect_one_suite($$) } collect_one_test_case($testdir,$resdir,$suite,$tname, - "$tname.$extension",$cases,\%disabled, + "$tname.$extension",\@cases,\%disabled, $component_id,$suite_opts); } } @@ -354,85 +329,168 @@ sub collect_one_suite($$) next if ($do_test and not $tname =~ /$do_test/o); collect_one_test_case($testdir,$resdir,$suite,$tname, - $elem,$cases,\%disabled,$component_id, + $elem,\@cases,\%disabled,$component_id, $suite_opts); } closedir TESTDIR; } + + # Return empty list if no testcases found + return if (@cases == 0); + # ---------------------------------------------------------------------- - # Proccess combinations only if new tests were added + # Read combinations for this suite and build testcases x combinations + # if any combinations exists # ---------------------------------------------------------------------- - if (0 and $combinations && $begin_index <= $#{@$cases}) - { - my $end_index = $#{@$cases}; - my $is_copy; - # Keep original master/slave options - my @orig_opts; - for (my $idx = $begin_index; $idx <= $end_index; $idx++) - { - foreach my $param (('master_opt','slave_opt','slave_mi')) - { - @{$orig_opts[$idx]{$param}} = @{$cases->[$idx]->{$param}}; + if ( ! $::opt_skip_combination ) + { + my @combinations; + my $combination_file= "$suitedir/combinations"; + #print "combination_file: $combination_file\n"; + if (@::opt_combinations) + { + # take the combination from command-line + mtr_verbose("Take the combination from command line"); + foreach my $combination (@::opt_combinations) { + my $comb= {}; + $comb->{name}= $combination; + push(@{$comb->{comb_opt}}, $combination); + push(@combinations, $comb); + } + } + elsif (-f $combination_file ) + { + # Read combinations file in my.cnf format + mtr_verbose("Read combinations file"); + my $config= My::Config->new($combination_file); + + foreach my $group ($config->groups()) { + my $comb= {}; + $comb->{name}= $group->name(); + foreach my $option ( $group->options() ) { + push(@{$comb->{comb_opt}}, $option->name()."=".$option->value()); + } + push(@combinations, $comb); } } - my $comb_index = 1; - # Copy original test cases - foreach my $comb_set (@$combinations) - { - for (my $idx = $begin_index; $idx <= $end_index; $idx++) + + if (@combinations) + { + print " - adding combinations\n"; + #print_testcases(@cases); + + my @new_cases; + foreach my $comb (@combinations) { - my $test = $cases->[$idx]; - my $copied_test = {}; - foreach my $param (keys %{$test}) - { - # Scalar. Copy as is. - $copied_test->{$param} = $test->{$param}; - # Array. Copy reference instead itself - if ($param =~ /(master_opt|slave_opt|slave_mi)/) - { - my $new_arr = []; - @$new_arr = @{$orig_opts[$idx]{$param}}; - $copied_test->{$param} = $new_arr; - } - elsif ($param =~ /(comment|combinations)/) - { - $copied_test->{$param} = ''; - } - } - if ($is_copy) - { - push(@$cases, $copied_test); - $test = $cases->[$#{@$cases}]; - } - foreach my $comb_opt (split(/ /,$comb_set)) - { - push(@{$test->{'master_opt'}},$comb_opt); - push(@{$test->{'slave_opt'}},$comb_opt); - # Enable rpl if added option is --binlog-format and test case supports that - if ($comb_opt =~ /^--binlog-format=.+$/) - { - my @opt_pairs = split(/=/, $comb_opt); - if ($test->{'binlog_format'} =~ /^$opt_pairs[1]$/ || $test->{'binlog_format'} eq '') - { - $test->{'skip'} = 0; - $test->{'comment'} = ''; - } - else - { - $test->{'skip'} = 1; - $test->{'comment'} = "Requiring binlog format '$test->{'binlog_format'}'";; - } - } - } - $test->{'combination'} = $comb_set; - } - $is_copy = 1; - $comb_index++; - } + foreach my $test (@cases) + { + #print $test->{name}, " ", $comb, "\n"; + my $new_test= {}; + + while (my ($key, $value) = each(%$test)) { + if (ref $value eq "ARRAY") { + push(@{$new_test->{$key}}, @$value); + } else { + $new_test->{$key}= $value; + } + } + + # Append the combination options to master_opt and slave_opt + push(@{$new_test->{master_opt}}, @{$comb->{comb_opt}}); + push(@{$new_test->{slave_opt}}, @{$comb->{comb_opt}}); + + # Add combination name shrt name + $new_test->{combination}= $comb->{name}; + + # Add the new test to new test cases list + push(@new_cases, $new_test); + } + } + #print_testcases(@new_cases); + @cases= @new_cases; + #print_testcases(@cases); + } } - return $cases; + optimize_cases(\@cases); + #print_testcases(@cases); + + return @cases; +} + + +# +# Loop through all test cases +# - optimize which test to run by skipping unnecessary ones +# - update settings if necessary +# +sub optimize_cases { + my ($cases)= @_; + + foreach my $tinfo ( @$cases ) + { + # Skip processing if already marked as skipped + next if $tinfo->{skip}; + + # Replication test needs an adjustment of binlog format + if (mtr_match_prefix($tinfo->{'name'}, "rpl")) + { + + # ======================================================= + # Get binlog-format used by this test from master_opt + # ======================================================= + my $test_binlog_format; + foreach my $opt ( @{$tinfo->{master_opt}} ) { + $test_binlog_format= $test_binlog_format || + mtr_match_prefix($opt, "--binlog-format="); + } + # print $tinfo->{name}." uses ".$test_binlog_format."\n"; + + # ======================================================= + # If a special binlog format was selected with + # --mysqld=--binlog-format=x, skip all test with different + # binlog-format + # ======================================================= + if (defined $::used_binlog_format and + $test_binlog_format and + $::used_binlog_format ne $test_binlog_format) + { + $tinfo->{'skip'}= 1; + $tinfo->{'comment'}= "Requires --binlog-format='$test_binlog_format'"; + next; + } + + # ======================================================= + # Check that testcase supports the designated binlog-format + # ======================================================= + if ($test_binlog_format and defined $tinfo->{'sup_binlog_formats'} ) + { + my $supported= + grep { $_ eq $test_binlog_format } @{$tinfo->{'sup_binlog_formats'}}; + if ( !$supported ) + { + $tinfo->{'skip'}= 1; + $tinfo->{'comment'}= + "Doesn't support --binlog-format='$test_binlog_format'"; + next; + } + } + + # ======================================================= + # Use dynamic switching of binlog-format if mtr started + # w/o --mysqld=--binlog-format=xxx and combinations. + # ======================================================= + if (!defined $tinfo->{'combination'} and + !defined $::used_binlog_format) + { + $test_binlog_format= $tinfo->{'sup_binlog_formats'}->[0]; + } + + # Save binlog format for dynamic switching + $tinfo->{binlog_format}= $test_binlog_format; + } + } } @@ -522,6 +580,7 @@ sub collect_one_test_case($$$$$$$$$) { $tinfo->{'slave_opt'}= []; $tinfo->{'slave_mi'}= []; + # Add suite opts foreach my $opt ( @$suite_opts ) { @@ -735,14 +794,6 @@ sub collect_one_test_case($$$$$$$$$) { return; } - if ( defined $tinfo->{'binlog_format'} and - ! ( $tinfo->{'binlog_format'} eq $::used_binlog_format ) ) - { - $tinfo->{'skip'}= 1; - $tinfo->{'comment'}= "Requiring binlog format '$tinfo->{'binlog_format'}'"; - return; - } - if ( $tinfo->{'need_debug'} && ! $::debug_compiled_binaries ) { $tinfo->{'skip'}= 1; @@ -822,10 +873,17 @@ sub collect_one_test_case($$$$$$$$$) { our @tags= ( ["include/have_innodb.inc", "innodb_test", 1], - ["include/have_binlog_format_row.inc", "binlog_format", "row"], + ["include/have_binlog_format_row.inc", "sup_binlog_formats", ["row"]], ["include/have_log_bin.inc", "need_binlog", 1], - ["include/have_binlog_format_statement.inc", "binlog_format", "statement"], - ["include/have_binlog_format_mixed.inc", "binlog_format", "mixed"], + ["include/have_binlog_format_statement.inc", + "sup_binlog_formats", ["statement"]], + ["include/have_binlog_format_mixed.inc", "sup_binlog_formats", ["mixed"]], + ["include/have_binlog_format_mixed_or_row.inc", + "sup_binlog_formats", ["mixed","row"]], + ["include/have_binlog_format_mixed_or_statement.inc", + "sup_binlog_formats", ["mixed","statement"]], + ["include/have_binlog_format_row_or_statement.inc", + "sup_binlog_formats", ["row","statement"]], ["include/big_test.inc", "big_test", 1], ["include/have_debug.inc", "need_debug", 1], ["include/have_ndb.inc", "ndb_test", 1], @@ -851,8 +909,8 @@ sub mtr_options_from_test_file($$) { { if ( index($line, $tag->[0]) >= 0 ) { - # Tag matched, assign value to "tinfo" - $tinfo->{"$tag->[1]"}= $tag->[2]; + # Tag matched, assign value to "tinfo" + $tinfo->{"$tag->[1]"}= $tag->[2]; } } @@ -873,8 +931,29 @@ sub mtr_options_from_test_file($$) { mtr_options_from_test_file($tinfo, $sourced_file); } } + } +} + +sub print_testcases { + my (@cases)= @_; + + print "=" x 60, "\n"; + foreach my $test (@cases){ + print "[", $test->{name}, "]", "\n"; + while ((my ($key, $value)) = each(%$test)) { + print " ", $key, "="; + if (ref $value eq "ARRAY") { + print join(", ", @$value); + } else { + print $value; + } + print "\n"; + } + print "\n"; } + print "=" x 60, "\n"; } + 1; |