diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm index 7dc5810a2574..bbc6d4e7aa36 100644 --- a/mysql-test/lib/mtr_cases.pm +++ b/mysql-test/lib/mtr_cases.pm @@ -148,12 +148,10 @@ sub collect_test_cases ($$$$) { # This also effects some logic in the loop following this. if ($opt_reorder or !@$opt_cases) { - my $sys_info= My::SysInfo->new(); - my $parallel= $sys_info->num_cpus(); - $parallel= $::opt_parallel if ($::opt_parallel ne "auto" and - $::opt_parallel < $parallel); - $parallel= 1 if $quick_collect; - $parallel= 1 if @$opt_cases; + my $parallel = $ENV{NUMBER_OF_CPUS}; + $parallel = $::opt_parallel if ($::opt_parallel < $parallel); + $parallel = 1 if $quick_collect; + $parallel = 1 if @$opt_cases; if ($parallel == 1 or !$threads_support or !$threads_shared_support) { @@ -316,25 +314,57 @@ sub collect_test_cases ($$$$) { } @$cases = sort {$a->{criteria} cmp $b->{criteria}; } @$cases; + } - # For debugging the sort-order - # foreach my $tinfo (@$cases) - # { - # my $tname= $tinfo->{name} . ' ' . $tinfo->{combination}; - # my $crit= $tinfo->{criteria}; - # print("$tname\n\t$crit\n"); - # } + # When $opt_repeat > 1 and $opt_parallel > 1, duplicate each test + # $opt_repeat number of times to allow them running in parallel. + if ($::opt_repeat > 1 and $::opt_parallel > 1) { + $cases = duplicate_test_cases($cases); } - if (defined $print_testcases){ + if (defined $print_testcases) { print_testcases(@$cases); exit(1); } return $cases; +} + +# Duplicate each test $opt_repeat number of times +sub duplicate_test_cases($) { + my $tests = shift; + + my $new_tests; + foreach my $test (@$tests) { + # Don't repeat the test if 'skip' flag is enabled. + if ($test->{'skip'}) { + push(@{$new_tests}, $test); + } else { + for (my $i = 1; $i <= $::opt_repeat; $i++) { + # Create a duplicate test object + push(@{$new_tests}, create_duplicate_test($test)); + } + } + } + return $new_tests; } +# Create a new test object identical to the original one. +sub create_duplicate_test($) { + my $test = shift; + + my $new_test = My::Test->new(); + while (my ($key, $value) = each(%$test)) { + if (ref $value eq "ARRAY") { + push(@{$new_test->{$key}}, @$value); + } else { + $new_test->{$key} = $value; + } + } + + return $new_test; +} # Returns (suitename, testname, extension) sub split_testname { @@ -1048,18 +1078,15 @@ sub collect_one_test_case { $tinfo->{'comment'}= mtr_fromfile($disabled_file); } - if ( $marked_as_disabled ) - { - if ( $enable_disabled ) - { + if ($marked_as_disabled) { + if ($enable_disabled or @::opt_cases) { # User has selected to run all disabled tests - mtr_report(" - $tinfo->{name} wil be run although it's been disabled\n", - " due to '$tinfo->{comment}'"); - } - else - { + mtr_report(" - Running test $tinfo->{name} even though it's been", + "disabled due to '$tinfo->{comment}'."); + } else { $tinfo->{'skip'}= 1; - $tinfo->{'disable'}= 1; # Sub type of 'skip' + # Disable the test case + $tinfo->{'disable'}= 1; return $tinfo; } } diff --git a/mysql-test/mysql-test-run.dox b/mysql-test/mysql-test-run.dox index 4d09f56c677a..4e972cf7a4fd 100644 --- a/mysql-test/mysql-test-run.dox +++ b/mysql-test/mysql-test-run.dox @@ -3919,6 +3919,10 @@ If both `--big-test` and `--only-big-tests` are given, `--only-big-tests` is ignored. + + @note + This option is enabled by default when test cases are specified + on command line.
  • @@ -4283,6 +4287,10 @@ Ignore any disabled.def file, and run also tests marked as disbaled. Success or failure of those tests will be reported the same way as other tests. + + @note + This option is enabled by default when test cases are specified + on command line.
  • @@ -4685,7 +4693,8 @@
  • `--repeat`=N - Run each test N number of times. + Run each test N number of times, in parallel if + `--parallel` option value is greater than 1.
  • diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index e0d853e357eb..8fa162bbad35 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -292,7 +292,7 @@ END my $opt_wait_all; my $opt_user_args; -my $opt_repeat= 1; +our $opt_repeat= 1; my $opt_retry= 3; my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2); our $opt_report_unstable_tests; @@ -445,6 +445,21 @@ sub main { } } + # Environment variable to hold number of CPUs + my $sys_info = My::SysInfo->new(); + $ENV{NUMBER_OF_CPUS} = $sys_info->num_cpus(); + + if ($opt_parallel eq "auto") { + # Try to find a suitable value for number of workers + $opt_parallel = $ENV{NUMBER_OF_CPUS}; + + if(defined $ENV{MTR_MAX_PARALLEL}) { + my $max_par = $ENV{MTR_MAX_PARALLEL}; + $opt_parallel = $max_par if ($opt_parallel > $max_par); + } + $opt_parallel = 1 if ($opt_parallel < 1); + } + init_timers(); mtr_report("Collecting tests..."); @@ -474,23 +489,6 @@ sub main { $num_tests_for_report = $num_tests * $opt_repeat; $remaining= $num_tests_for_report; - # Environment variable to hold number of CPUs - my $sys_info= My::SysInfo->new(); - $ENV{NUMBER_OF_CPUS}= $sys_info->num_cpus(); - - if ($opt_parallel eq "auto") - { - # Try to find a suitable value for number of workers - $opt_parallel= $ENV{NUMBER_OF_CPUS}; - - if(defined $ENV{MTR_MAX_PARALLEL}) - { - my $max_par= $ENV{MTR_MAX_PARALLEL}; - $opt_parallel= $max_par if ($opt_parallel > $max_par); - } - $opt_parallel= 1 if ($opt_parallel < 1); - } - # Limit parallel workers to number of tests to avoid idle workers $opt_parallel= $num_tests if ($num_tests > 0 and $opt_parallel > $num_tests); $ENV{MTR_PARALLEL} = $opt_parallel; @@ -867,19 +865,25 @@ ($$$) } } - # Repeat test $opt_repeat number of times - my $repeat= $result->{repeat} || 1; - # Don't repeat if test was skipped - if ($repeat < $opt_repeat && $result->{'result'} ne 'MTR_RES_SKIPPED') - { - $result->{retries}= 0; - $result->{rep_failures}++ if $result->{failures}; - $result->{failures}= 0; - delete($result->{result}); - $result->{repeat}= $repeat+1; - $result->write_test($sock, 'TESTCASE'); - next; - } + # Tests are already duplicated in the list if parallel value is + # greater than 1. Following code is needed only when parallel + # value is 1. + if ($opt_parallel == 1) { + # Repeat the test $opt_repeat number of times + my $repeat = $result->{repeat} || 1; + + # Don't repeat if test was skipped + if ($repeat < $opt_repeat && $result->{'result'} ne 'MTR_RES_SKIPPED') + { + $result->{retries} = 0; + $result->{rep_failures}++ if $result->{failures}; + $result->{failures} = 0; + delete($result->{result}); + $result->{repeat} = $repeat+1; + $result->write_test($sock, 'TESTCASE'); + next; + } + } # Remove from list of running mtr_error("'", $result->{name},"' is not known to be running") @@ -1873,6 +1877,11 @@ sub command_line_setup { $opt_only_big_test= 0; } + # Enable --big-test and option when test cases are specified command line. + if (@opt_cases) { + $opt_big_test = 1 if !$opt_big_test; + } + $ENV{'BIG_TEST'}= 1 if ($opt_big_test or $opt_only_big_test); # -------------------------------------------------------------------------- @@ -7865,7 +7874,8 @@ ($) Use parallel=auto for auto-setting of N non-parallel-test Also run tests marked as 'non-parallel'. Tests sourcing 'not_parallel.inc' are marked as 'non-parallel' tests. - repeat=N Run each test N number of times + repeat=N Run each test N number of times, in parallel if + --parallel option value is > 1. retry=N Retry tests that fail N times, limit number of failures to $opt_retry_failure retry-failure=N Limit number of retries for a failed test