Commit 2c4f6e5c authored by Bjorn Munch's avatar Bjorn Munch

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
parent 6746a5dc
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=normal --vardir=var-normal --report-features
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=normal --vardir=var-normal --report-features --unit-tests
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
perl mysql-test-run.pl --force --timer --debug-server --parallel=auto --experimental=collections/default.experimental --comment=row --vardir=var-row --mysqld=--binlog-format=row
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
......
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
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
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
perl mysql-test-run.pl --timer --force --parallel=auto --comment=embedded --vardir=var-emebbed --embedded --experimental=collections/default.experimental --skip-ndb
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
......
perl mysql-test-run.pl --force --timer --parallel=auto --comment=normal --skip-ndbcluster --report-features --experimental=collections/default.experimental
perl mysql-test-run.pl --force --timer --parallel=auto --comment=normal --skip-ndbcluster --report-features --experimental=collections/default.experimental --unit-tests
perl mysql-test-run.pl --force --timer --parallel=auto --comment=ps --skip-ndbcluster --ps-protocol --experimental=collections/default.experimental
perl mysql-test-run.pl --force --timer --parallel=auto --comment=funcs1+ps --suite=funcs_1 --ps-protocol --experimental=collections/default.experimental
perl mysql-test-run.pl --force --timer --parallel=auto --comment=funcs2 --suite=funcs_2 --experimental=collections/default.experimental
......
perl mysql-test-run.pl --force --timer --parallel=auto --comment=debug --skip-ndbcluster --skip-rpl --report-features --experimental=collections/default.experimental
perl mysql-test-run.pl --force --timer --parallel=auto --comment=debug --skip-ndbcluster --skip-rpl --report-features --experimental=collections/default.experimental --unit-tests
perl mysql-test-run.pl --force --timer --parallel=auto --comment=ps --skip-ndbcluster --ps-protocol --report-features --experimental=collections/default.experimental
perl mysql-test-run.pl --force --timer --parallel=auto --comment=ps --skip-ndbcluster --ps-protocol --report-features --experimental=collections/default.experimental --unit-tests
perl mysql-test-run.pl --force --timer --parallel=auto --comment=stress --suite=stress --experimental=collections/default.experimental
......@@ -72,7 +72,7 @@ sub _mtr_report_test_name ($) {
print _name(). _timestamp();
printf "%-40s ", $tname;
my $worker = $tinfo->{worker};
printf "w$worker " if $worker;
print "w$worker " if defined $worker;
return $tname;
}
......
......@@ -194,6 +194,10 @@ my $opt_debug_common;
our $opt_debug_server;
our @opt_cases; # The test cases names in argv
our $opt_embedded_server;
# -1 indicates use default, override with env.var.
my $opt_ctest= env_or_val(MTR_UNIT_TESTS => -1);
# Unit test report stored here for delayed printing
my $ctest_report;
# Options used when connecting to an already running server
my %opts_extern;
......@@ -493,6 +497,10 @@ sub main {
mtr_error("Not all tests completed");
}
mark_time_used('init');
push @$completed, run_ctest() if $opt_ctest;
mtr_print_line();
if ( $opt_gcov ) {
......@@ -500,6 +508,8 @@ sub main {
$opt_gcov_msg, $opt_gcov_err);
}
print "$ctest_report\n" if $ctest_report;
print_total_times($opt_parallel) if $opt_report_times;
mtr_report_stats("Completed", $completed);
......@@ -1055,6 +1065,7 @@ sub command_line_setup {
'max-connections=i' => \$opt_max_connections,
'default-myisam!' => \&collect_option,
'report-times' => \$opt_report_times,
'unit-tests!' => \$opt_ctest,
'help|h' => \$opt_usage,
# list-options is internal, not listed in help
......@@ -1484,6 +1495,14 @@ sub command_line_setup {
if $opt_suites || @opt_cases;
}
# --------------------------------------------------------------------------
# Don't run ctest if tests or suites named
# --------------------------------------------------------------------------
$opt_ctest= 0 if $opt_ctest == -1 && ($opt_suites || @opt_cases);
# Override: disable if running in the PB test environment
$opt_ctest= 0 if $opt_ctest == -1 && defined $ENV{PB2WORKDIR};
# --------------------------------------------------------------------------
# Check use of wait-all
# --------------------------------------------------------------------------
......@@ -5653,6 +5672,73 @@ sub valgrind_exit_reports() {
return $found_err;
}
sub run_ctest() {
my $olddir= getcwd();
chdir ($bindir) or die ("Could not chdir to $bindir");
my $tinfo;
my $no_ctest= (IS_WINDOWS) ? 256 : -1;
# Just ignore if not configured/built to run ctest
if (! -f "CTestTestfile.cmake") {
chdir($olddir);
return;
}
# Also silently ignore if we don't have ctest and didn't insist
# Now, run ctest and collect output
my $ctest_out= `ctest 2>&1`;
if ($? == $no_ctest && $opt_ctest == -1) {
chdir($olddir);
return;
}
# Create minimalistic "test" for the reporting
$tinfo = My::Test->new
(
name => 'unit_tests',
);
# Set dummy worker id to align report with normal tests
$tinfo->{worker} = 0 if $opt_parallel > 1;
my $ctfail= 0; # Did ctest fail?
if ($?) {
$ctfail= 1;
$tinfo->{result}= 'MTR_RES_FAILED';
$tinfo->{comment}= "ctest failed with exit code $?, see result below";
$ctest_out= "" unless $ctest_out;
}
my $ctfile= "$opt_vardir/ctest.log";
my $ctres= 0; # Did ctest produce report summary?
open (CTEST, " > $ctfile") or die ("Could not open output file $ctfile");
# Put ctest output in log file, while analyzing results
for (split ('\n', $ctest_out)) {
print CTEST "$_\n";
if (/tests passed/) {
$ctres= 1;
$ctest_report .= "\nUnit tests: $_\n";
}
if ( /FAILED/ or /\(Failed\)/ ) {
$ctfail= 1;
$ctest_report .= " $_\n";
}
}
close CTEST;
# Set needed 'attributes' for test reporting
$tinfo->{comment}.= "\nctest did not pruduce report summary" if ! $ctres;
$tinfo->{result}= ($ctres && !$ctfail)
? 'MTR_RES_PASSED' : 'MTR_RES_FAILED';
$ctest_report .= "Report from unit tests in $ctfile\n";
$tinfo->{failures}= ($tinfo->{result} eq 'MTR_RES_FAILED');
mark_time_used('test');
mtr_report_test($tinfo);
chdir($olddir);
return $tinfo;
}
#
# Usage
#
......@@ -5871,6 +5957,9 @@ Misc options
engine to InnoDB.
report-times Report how much time has been spent on different
phases of test execution.
nounit-tests Do not run unit tests. Normally run if configured
and if not running named tests/suites
unit-tests Run unit tests even if they would otherwise not be run
Some options that control enabling a feature for normal test runs,
can be turned off by prepending 'no' to the option, e.g. --notimer.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment