Skip to content

Commit f0bcecb

Browse files
author
Pavan Naik
committed
BUG#27557011: MTR: SUPPORT --PARALLEL AND --REPEAT OPTIONS TO WORK TOGETHER
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
1 parent b7ca714 commit f0bcecb

File tree

3 files changed

+103
-57
lines changed

3 files changed

+103
-57
lines changed

mysql-test/lib/mtr_cases.pm

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,10 @@ sub collect_test_cases ($$$$) {
148148
# This also effects some logic in the loop following this.
149149
if ($opt_reorder or !@$opt_cases)
150150
{
151-
my $sys_info= My::SysInfo->new();
152-
my $parallel= $sys_info->num_cpus();
153-
$parallel= $::opt_parallel if ($::opt_parallel ne "auto" and
154-
$::opt_parallel < $parallel);
155-
$parallel= 1 if $quick_collect;
156-
$parallel= 1 if @$opt_cases;
151+
my $parallel = $ENV{NUMBER_OF_CPUS};
152+
$parallel = $::opt_parallel if ($::opt_parallel < $parallel);
153+
$parallel = 1 if $quick_collect;
154+
$parallel = 1 if @$opt_cases;
157155

158156
if ($parallel == 1 or !$threads_support or !$threads_shared_support)
159157
{
@@ -316,25 +314,57 @@ sub collect_test_cases ($$$$) {
316314
}
317315

318316
@$cases = sort {$a->{criteria} cmp $b->{criteria}; } @$cases;
317+
}
319318

320-
# For debugging the sort-order
321-
# foreach my $tinfo (@$cases)
322-
# {
323-
# my $tname= $tinfo->{name} . ' ' . $tinfo->{combination};
324-
# my $crit= $tinfo->{criteria};
325-
# print("$tname\n\t$crit\n");
326-
# }
319+
# When $opt_repeat > 1 and $opt_parallel > 1, duplicate each test
320+
# $opt_repeat number of times to allow them running in parallel.
321+
if ($::opt_repeat > 1 and $::opt_parallel > 1) {
322+
$cases = duplicate_test_cases($cases);
327323
}
328324

329-
if (defined $print_testcases){
325+
if (defined $print_testcases) {
330326
print_testcases(@$cases);
331327
exit(1);
332328
}
333329

334330
return $cases;
331+
}
332+
333+
# Duplicate each test $opt_repeat number of times
334+
sub duplicate_test_cases($) {
335+
my $tests = shift;
336+
337+
my $new_tests;
338+
foreach my $test (@$tests) {
339+
# Don't repeat the test if 'skip' flag is enabled.
340+
if ($test->{'skip'}) {
341+
push(@{$new_tests}, $test);
342+
} else {
343+
for (my $i = 1; $i <= $::opt_repeat; $i++) {
344+
# Create a duplicate test object
345+
push(@{$new_tests}, create_duplicate_test($test));
346+
}
347+
}
348+
}
335349

350+
return $new_tests;
336351
}
337352

353+
# Create a new test object identical to the original one.
354+
sub create_duplicate_test($) {
355+
my $test = shift;
356+
357+
my $new_test = My::Test->new();
358+
while (my ($key, $value) = each(%$test)) {
359+
if (ref $value eq "ARRAY") {
360+
push(@{$new_test->{$key}}, @$value);
361+
} else {
362+
$new_test->{$key} = $value;
363+
}
364+
}
365+
366+
return $new_test;
367+
}
338368

339369
# Returns (suitename, testname, extension)
340370
sub split_testname {
@@ -1048,18 +1078,15 @@ sub collect_one_test_case {
10481078
$tinfo->{'comment'}= mtr_fromfile($disabled_file);
10491079
}
10501080

1051-
if ( $marked_as_disabled )
1052-
{
1053-
if ( $enable_disabled )
1054-
{
1081+
if ($marked_as_disabled) {
1082+
if ($enable_disabled or @::opt_cases) {
10551083
# User has selected to run all disabled tests
1056-
mtr_report(" - $tinfo->{name} wil be run although it's been disabled\n",
1057-
" due to '$tinfo->{comment}'");
1058-
}
1059-
else
1060-
{
1084+
mtr_report(" - Running test $tinfo->{name} even though it's been",
1085+
"disabled due to '$tinfo->{comment}'.");
1086+
} else {
10611087
$tinfo->{'skip'}= 1;
1062-
$tinfo->{'disable'}= 1; # Sub type of 'skip'
1088+
# Disable the test case
1089+
$tinfo->{'disable'}= 1;
10631090
return $tinfo;
10641091
}
10651092
}

mysql-test/mysql-test-run.dox

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3919,6 +3919,10 @@
39193919

39203920
If both <b>`--big-test`</b> and <b>`--only-big-tests`</b>
39213921
are given, <b>`--only-big-tests`</b> is ignored.
3922+
3923+
@note
3924+
This option is enabled by default when test cases are specified
3925+
on command line.
39223926
</li>
39233927

39243928
<li>
@@ -4283,6 +4287,10 @@
42834287
Ignore any <b>disabled.def</b> file, and run also tests marked
42844288
as disbaled. Success or failure of those tests will be reported
42854289
the same way as other tests.
4290+
4291+
@note
4292+
This option is enabled by default when test cases are specified
4293+
on command line.
42864294
</li>
42874295

42884296
<li>
@@ -4685,7 +4693,8 @@
46854693
<li>
46864694
<tt>`--repeat`=<b>N</b></tt>
46874695

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

46914700
<li>

mysql-test/mysql-test-run.pl

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ END
292292

293293
my $opt_wait_all;
294294
my $opt_user_args;
295-
my $opt_repeat= 1;
295+
our $opt_repeat= 1;
296296
my $opt_retry= 3;
297297
my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2);
298298
our $opt_report_unstable_tests;
@@ -445,6 +445,21 @@ sub main {
445445
}
446446
}
447447

448+
# Environment variable to hold number of CPUs
449+
my $sys_info = My::SysInfo->new();
450+
$ENV{NUMBER_OF_CPUS} = $sys_info->num_cpus();
451+
452+
if ($opt_parallel eq "auto") {
453+
# Try to find a suitable value for number of workers
454+
$opt_parallel = $ENV{NUMBER_OF_CPUS};
455+
456+
if(defined $ENV{MTR_MAX_PARALLEL}) {
457+
my $max_par = $ENV{MTR_MAX_PARALLEL};
458+
$opt_parallel = $max_par if ($opt_parallel > $max_par);
459+
}
460+
$opt_parallel = 1 if ($opt_parallel < 1);
461+
}
462+
448463
init_timers();
449464

450465
mtr_report("Collecting tests...");
@@ -474,23 +489,6 @@ sub main {
474489
$num_tests_for_report = $num_tests * $opt_repeat;
475490
$remaining= $num_tests_for_report;
476491

477-
# Environment variable to hold number of CPUs
478-
my $sys_info= My::SysInfo->new();
479-
$ENV{NUMBER_OF_CPUS}= $sys_info->num_cpus();
480-
481-
if ($opt_parallel eq "auto")
482-
{
483-
# Try to find a suitable value for number of workers
484-
$opt_parallel= $ENV{NUMBER_OF_CPUS};
485-
486-
if(defined $ENV{MTR_MAX_PARALLEL})
487-
{
488-
my $max_par= $ENV{MTR_MAX_PARALLEL};
489-
$opt_parallel= $max_par if ($opt_parallel > $max_par);
490-
}
491-
$opt_parallel= 1 if ($opt_parallel < 1);
492-
}
493-
494492
# Limit parallel workers to number of tests to avoid idle workers
495493
$opt_parallel= $num_tests if ($num_tests > 0 and $opt_parallel > $num_tests);
496494
$ENV{MTR_PARALLEL} = $opt_parallel;
@@ -867,19 +865,25 @@ ($$$)
867865
}
868866
}
869867

870-
# Repeat test $opt_repeat number of times
871-
my $repeat= $result->{repeat} || 1;
872-
# Don't repeat if test was skipped
873-
if ($repeat < $opt_repeat && $result->{'result'} ne 'MTR_RES_SKIPPED')
874-
{
875-
$result->{retries}= 0;
876-
$result->{rep_failures}++ if $result->{failures};
877-
$result->{failures}= 0;
878-
delete($result->{result});
879-
$result->{repeat}= $repeat+1;
880-
$result->write_test($sock, 'TESTCASE');
881-
next;
882-
}
868+
# Tests are already duplicated in the list if parallel value is
869+
# greater than 1. Following code is needed only when parallel
870+
# value is 1.
871+
if ($opt_parallel == 1) {
872+
# Repeat the test $opt_repeat number of times
873+
my $repeat = $result->{repeat} || 1;
874+
875+
# Don't repeat if test was skipped
876+
if ($repeat < $opt_repeat && $result->{'result'} ne 'MTR_RES_SKIPPED')
877+
{
878+
$result->{retries} = 0;
879+
$result->{rep_failures}++ if $result->{failures};
880+
$result->{failures} = 0;
881+
delete($result->{result});
882+
$result->{repeat} = $repeat+1;
883+
$result->write_test($sock, 'TESTCASE');
884+
next;
885+
}
886+
}
883887

884888
# Remove from list of running
885889
mtr_error("'", $result->{name},"' is not known to be running")
@@ -1873,6 +1877,11 @@ sub command_line_setup {
18731877
$opt_only_big_test= 0;
18741878
}
18751879

1880+
# Enable --big-test and option when test cases are specified command line.
1881+
if (@opt_cases) {
1882+
$opt_big_test = 1 if !$opt_big_test;
1883+
}
1884+
18761885
$ENV{'BIG_TEST'}= 1 if ($opt_big_test or $opt_only_big_test);
18771886

18781887
# --------------------------------------------------------------------------
@@ -7865,7 +7874,8 @@ ($)
78657874
Use parallel=auto for auto-setting of N
78667875
non-parallel-test Also run tests marked as 'non-parallel'. Tests sourcing
78677876
'not_parallel.inc' are marked as 'non-parallel' tests.
7868-
repeat=N Run each test N number of times
7877+
repeat=N Run each test N number of times, in parallel if
7878+
--parallel option value is > 1.
78697879
retry=N Retry tests that fail N times, limit number of failures
78707880
to $opt_retry_failure
78717881
retry-failure=N Limit number of retries for a failed test

0 commit comments

Comments
 (0)