diff options
author | Bjorn Munch <bjorn.munch@oracle.com> | 2011-02-21 13:56:43 +0100 |
---|---|---|
committer | Bjorn Munch <bjorn.munch@oracle.com> | 2011-02-21 13:56:43 +0100 |
commit | 2c4f6e5c632f02880490191f5a8ea407f4d35ade (patch) | |
tree | 996faa658cd4d6655682a62a444ee70e355c0838 /mysql-test/mysql-test-run.pl | |
parent | 6746a5dc0fdd2f9b8bd33ad8bc48cd844eaa50d5 (diff) | |
download | mariadb-git-2c4f6e5c632f02880490191f5a8ea407f4d35ade.tar.gz |
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
Diffstat (limited to 'mysql-test/mysql-test-run.pl')
-rwxr-xr-x | mysql-test/mysql-test-run.pl | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index a1e02a56164..05bfd4eae02 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -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 @@ -1485,6 +1496,14 @@ sub command_line_setup { } # -------------------------------------------------------------------------- + # 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. |