#At file:///home/bm136801/my/unit-55/ based on revid:bjorn.munch@stripped
3163 Bjorn Munch 2011-02-07
Bug #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
modified:
mysql-test/lib/mtr_report.pm
mysql-test/mysql-test-run.pl
=== modified file 'mysql-test/lib/mtr_report.pm'
--- a/mysql-test/lib/mtr_report.pm 2011-01-18 10:21:37 +0000
+++ b/mysql-test/lib/mtr_report.pm 2011-02-07 14:43:32 +0000
@@ -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;
}
=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl 2011-01-29 21:53:17 +0000
+++ b/mysql-test/mysql-test-run.pl 2011-02-07 14:43:32 +0000
@@ -193,6 +193,10 @@ my $debug_d= "d";
my $opt_debug_common;
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;
@@ -492,6 +496,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 ) {
@@ -499,6 +507,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);
@@ -1053,6 +1063,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
@@ -1480,6 +1491,12 @@ sub command_line_setup {
}
# --------------------------------------------------------------------------
+ # Don't run ctest if tests or suites named
+ # --------------------------------------------------------------------------
+
+ $opt_ctest= 0 if $opt_ctest == -1 && ($opt_suites || @opt_cases);
+
+ # --------------------------------------------------------------------------
# Check use of wait-all
# --------------------------------------------------------------------------
@@ -5635,6 +5652,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
#
@@ -5851,6 +5935,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.
Attachment: [text/bzr-bundle] bzr/bjorn.munch@oracle.com-20110207144332-dl5xvt0ljr2cxd2s.bundle
| Thread |
|---|
| • bzr commit into mysql-5.5-mtr branch (bjorn.munch:3163) Bug#59789 | Bjorn Munch | 7 Feb |