Skip to content

Commit

Permalink
BUG#27557011: MTR: SUPPORT --PARALLEL AND --REPEAT OPTIONS TO WORK TO…
Browse files Browse the repository at this point in the history
…GETHER

Description:
------------
Option '--repeat=N' runs a test N number of times, but not in parallel even
though the '--parallel' option value is greater than 1.

Fix:
----
1. Extended MTR to run a test N number of times in paralle when '--repeat=N'
   option is specified and '--parallel' option value > 1.

2. Both '--big-test' and '--enable-disabled' options are enabled by default
   when tests are specified on command line.

Change-Id: I942e7c7eb5d87f1f6b279b2167c66ac8eed26527
  • Loading branch information
Pavan Naik committed Mar 13, 2018
1 parent b7ca714 commit f0bcecb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 57 deletions.
75 changes: 51 additions & 24 deletions mysql-test/lib/mtr_cases.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand Down
11 changes: 10 additions & 1 deletion mysql-test/mysql-test-run.dox
Original file line number Diff line number Diff line change
Expand Up @@ -3919,6 +3919,10 @@

If both <b>`--big-test`</b> and <b>`--only-big-tests`</b>
are given, <b>`--only-big-tests`</b> is ignored.

@note
This option is enabled by default when test cases are specified
on command line.
</li>

<li>
Expand Down Expand Up @@ -4283,6 +4287,10 @@
Ignore any <b>disabled.def</b> 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.
</li>

<li>
Expand Down Expand Up @@ -4685,7 +4693,8 @@
<li>
<tt>`--repeat`=<b>N</b></tt>

Run each test <b><em>N</em></b> number of times.
Run each test <b><em>N</em></b> number of times, in parallel if
<b>`--parallel`</b> option value is greater than 1.
</li>

<li>
Expand Down
74 changes: 42 additions & 32 deletions mysql-test/mysql-test-run.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);

# --------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f0bcecb

Please sign in to comment.