Skip to content

Commit 562978e

Browse files
committed
Bug #11766640 (59789) Hook the invocation of unit tests in MTR.
Added code to call 'ctest' if the needed cmake file is present Will do so unless tests/suited named on mtr command line Also add option to turn on/off Will be made to look like a test 'unit-test' which counts towards total Extracts summary report and any test failures from ctest output Addendum: added override to turn off in PB, add back in selected invocations
1 parent 1997b48 commit 562978e

File tree

7 files changed

+95
-6
lines changed

7 files changed

+95
-6
lines changed

mysql-test/collections/default.daily

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=normal --vardir=var-normal --report-features
2+
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=normal --vardir=var-normal --report-features --unit-tests
33
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=n_mix --vardir=var-n_mix --mysqld=--binlog-format=mixed
44
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=row --vardir=var-row --mysqld=--binlog-format=row
55
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=ps_row --vardir=var-ps_row --mysqld=--binlog-format=row --ps-protocol

mysql-test/collections/default.push

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
perl mysql-test-run.pl --timer --force --parallel=auto --comment=n_mix --vardir=var-n_mix --mysqld=--binlog-format=mixed --experimental=collections/default.experimental --skip-ndb --skip-test-list=collections/disabled-per-push.list
1+
perl mysql-test-run.pl --timer --force --parallel=auto --comment=n_mix --vardir=var-n_mix --mysqld=--binlog-format=mixed --experimental=collections/default.experimental --skip-ndb --skip-test-list=collections/disabled-per-push.list --unit-tests
22
perl mysql-test-run.pl --timer --force --parallel=auto --comment=ps_row --vardir=var-ps_row --ps-protocol --mysqld=--binlog-format=row --experimental=collections/default.experimental --skip-ndb --skip-test-list=collections/disabled-per-push.list
33
perl mysql-test-run.pl --timer --force --parallel=auto --comment=embedded --vardir=var-emebbed --embedded --experimental=collections/default.experimental --skip-ndb
44
perl mysql-test-run.pl --timer --force --parallel=auto --comment=rpl_binlog_row --vardir=var-rpl_binlog_row --suite=rpl,binlog --mysqld=--binlog-format=row --experimental=collections/default.experimental --skip-ndb --skip-test-list=collections/disabled-per-push.list

mysql-test/collections/test-bt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
perl mysql-test-run.pl --force --timer --parallel=auto --comment=normal --skip-ndbcluster --report-features --experimental=collections/default.experimental
1+
perl mysql-test-run.pl --force --timer --parallel=auto --comment=normal --skip-ndbcluster --report-features --experimental=collections/default.experimental --unit-tests
22
perl mysql-test-run.pl --force --timer --parallel=auto --comment=ps --skip-ndbcluster --ps-protocol --experimental=collections/default.experimental
33
perl mysql-test-run.pl --force --timer --parallel=auto --comment=funcs1+ps --suite=funcs_1 --ps-protocol --experimental=collections/default.experimental
44
perl mysql-test-run.pl --force --timer --parallel=auto --comment=funcs2 --suite=funcs_2 --experimental=collections/default.experimental

mysql-test/collections/test-bt-debug

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
perl mysql-test-run.pl --force --timer --parallel=auto --comment=debug --skip-ndbcluster --skip-rpl --report-features --experimental=collections/default.experimental
1+
perl mysql-test-run.pl --force --timer --parallel=auto --comment=debug --skip-ndbcluster --skip-rpl --report-features --experimental=collections/default.experimental --unit-tests

mysql-test/collections/test-bt-fast

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
perl mysql-test-run.pl --force --timer --parallel=auto --comment=ps --skip-ndbcluster --ps-protocol --report-features --experimental=collections/default.experimental
1+
perl mysql-test-run.pl --force --timer --parallel=auto --comment=ps --skip-ndbcluster --ps-protocol --report-features --experimental=collections/default.experimental --unit-tests
22
perl mysql-test-run.pl --force --timer --parallel=auto --comment=stress --suite=stress --experimental=collections/default.experimental

mysql-test/lib/mtr_report.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ sub _mtr_report_test_name ($) {
7272
print _name(). _timestamp();
7373
printf "%-40s ", $tname;
7474
my $worker = $tinfo->{worker};
75-
printf "w$worker " if $worker;
75+
print "w$worker " if defined $worker;
7676

7777
return $tname;
7878
}

mysql-test/mysql-test-run.pl

+89
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ END
194194
our $opt_debug_server;
195195
our @opt_cases; # The test cases names in argv
196196
our $opt_embedded_server;
197+
# -1 indicates use default, override with env.var.
198+
my $opt_ctest= env_or_val(MTR_UNIT_TESTS => -1);
199+
# Unit test report stored here for delayed printing
200+
my $ctest_report;
197201

198202
# Options used when connecting to an already running server
199203
my %opts_extern;
@@ -493,13 +497,19 @@ sub main {
493497
mtr_error("Not all tests completed");
494498
}
495499

500+
mark_time_used('init');
501+
502+
push @$completed, run_ctest() if $opt_ctest;
503+
496504
mtr_print_line();
497505

498506
if ( $opt_gcov ) {
499507
gcov_collect($basedir, $opt_gcov_exe,
500508
$opt_gcov_msg, $opt_gcov_err);
501509
}
502510

511+
print "$ctest_report\n" if $ctest_report;
512+
503513
print_total_times($opt_parallel) if $opt_report_times;
504514

505515
mtr_report_stats("Completed", $completed);
@@ -1055,6 +1065,7 @@ sub command_line_setup {
10551065
'max-connections=i' => \$opt_max_connections,
10561066
'default-myisam!' => \&collect_option,
10571067
'report-times' => \$opt_report_times,
1068+
'unit-tests!' => \$opt_ctest,
10581069

10591070
'help|h' => \$opt_usage,
10601071
# list-options is internal, not listed in help
@@ -1484,6 +1495,14 @@ sub command_line_setup {
14841495
if $opt_suites || @opt_cases;
14851496
}
14861497

1498+
# --------------------------------------------------------------------------
1499+
# Don't run ctest if tests or suites named
1500+
# --------------------------------------------------------------------------
1501+
1502+
$opt_ctest= 0 if $opt_ctest == -1 && ($opt_suites || @opt_cases);
1503+
# Override: disable if running in the PB test environment
1504+
$opt_ctest= 0 if $opt_ctest == -1 && defined $ENV{PB2WORKDIR};
1505+
14871506
# --------------------------------------------------------------------------
14881507
# Check use of wait-all
14891508
# --------------------------------------------------------------------------
@@ -5653,6 +5672,73 @@ ()
56535672
return $found_err;
56545673
}
56555674

5675+
sub run_ctest() {
5676+
my $olddir= getcwd();
5677+
chdir ($bindir) or die ("Could not chdir to $bindir");
5678+
my $tinfo;
5679+
my $no_ctest= (IS_WINDOWS) ? 256 : -1;
5680+
5681+
# Just ignore if not configured/built to run ctest
5682+
if (! -f "CTestTestfile.cmake") {
5683+
chdir($olddir);
5684+
return;
5685+
}
5686+
5687+
# Also silently ignore if we don't have ctest and didn't insist
5688+
# Now, run ctest and collect output
5689+
my $ctest_out= `ctest 2>&1`;
5690+
if ($? == $no_ctest && $opt_ctest == -1) {
5691+
chdir($olddir);
5692+
return;
5693+
}
5694+
5695+
# Create minimalistic "test" for the reporting
5696+
$tinfo = My::Test->new
5697+
(
5698+
name => 'unit_tests',
5699+
);
5700+
# Set dummy worker id to align report with normal tests
5701+
$tinfo->{worker} = 0 if $opt_parallel > 1;
5702+
5703+
my $ctfail= 0; # Did ctest fail?
5704+
if ($?) {
5705+
$ctfail= 1;
5706+
$tinfo->{result}= 'MTR_RES_FAILED';
5707+
$tinfo->{comment}= "ctest failed with exit code $?, see result below";
5708+
$ctest_out= "" unless $ctest_out;
5709+
}
5710+
my $ctfile= "$opt_vardir/ctest.log";
5711+
my $ctres= 0; # Did ctest produce report summary?
5712+
5713+
open (CTEST, " > $ctfile") or die ("Could not open output file $ctfile");
5714+
5715+
# Put ctest output in log file, while analyzing results
5716+
for (split ('\n', $ctest_out)) {
5717+
print CTEST "$_\n";
5718+
if (/tests passed/) {
5719+
$ctres= 1;
5720+
$ctest_report .= "\nUnit tests: $_\n";
5721+
}
5722+
if ( /FAILED/ or /\(Failed\)/ ) {
5723+
$ctfail= 1;
5724+
$ctest_report .= " $_\n";
5725+
}
5726+
}
5727+
close CTEST;
5728+
5729+
# Set needed 'attributes' for test reporting
5730+
$tinfo->{comment}.= "\nctest did not pruduce report summary" if ! $ctres;
5731+
$tinfo->{result}= ($ctres && !$ctfail)
5732+
? 'MTR_RES_PASSED' : 'MTR_RES_FAILED';
5733+
$ctest_report .= "Report from unit tests in $ctfile\n";
5734+
$tinfo->{failures}= ($tinfo->{result} eq 'MTR_RES_FAILED');
5735+
5736+
mark_time_used('test');
5737+
mtr_report_test($tinfo);
5738+
chdir($olddir);
5739+
return $tinfo;
5740+
}
5741+
56565742
#
56575743
# Usage
56585744
#
@@ -5871,6 +5957,9 @@ ($)
58715957
engine to InnoDB.
58725958
report-times Report how much time has been spent on different
58735959
phases of test execution.
5960+
nounit-tests Do not run unit tests. Normally run if configured
5961+
and if not running named tests/suites
5962+
unit-tests Run unit tests even if they would otherwise not be run
58745963
58755964
Some options that control enabling a feature for normal test runs,
58765965
can be turned off by prepending 'no' to the option, e.g. --notimer.

0 commit comments

Comments
 (0)