2
# Copyright 2004-2008 MySQL AB, 2008 Sun Microsystems, Inc.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
# This is a library file used by the Perl version of mysql-test-run,
18
# and is part of the translation of the Bourne shell script with the
24
use base qw(Exporter);
25
our @EXPORT= qw(report_option mtr_print_line mtr_print_thick_line
26
mtr_print_header mtr_report mtr_report_stats
27
mtr_warning mtr_error mtr_debug mtr_verbose
28
mtr_verbose_restart mtr_report_test_passed
29
mtr_report_test_skipped mtr_print
34
use POSIX qw[ _exit ];
43
our $verbose_restart= 0;
47
my ($opt, $value)= @_;
49
# Evaluate $opt as string to use "Getopt::Long::Callback legacy API"
50
my $opt_name = "$opt";
52
# Convert - to _ in option name
59
return $name ? $name." " : undef;
62
sub _mtr_report_test_name ($) {
64
my $tname= $tinfo->{name};
66
return unless defined $verbose;
68
# Add combination name if any
69
$tname.= " '$tinfo->{combination}'"
70
if defined $tinfo->{combination};
72
print _name(). _timestamp();
73
printf "%-40s ", $tname;
74
my $worker = $tinfo->{worker};
75
printf "w$worker " if $worker;
81
sub mtr_report_test_skipped ($) {
83
$tinfo->{'result'}= 'MTR_RES_SKIPPED';
85
mtr_report_test($tinfo);
89
sub mtr_report_test_passed ($) {
92
# Save the timer value
94
if ( $timer and -f "$::opt_vardir/log/timer" )
96
$timer_str= mtr_fromfile("$::opt_vardir/log/timer");
97
$tinfo->{timer}= $timer_str;
100
# Big warning if status already set
101
if ( $tinfo->{'result'} ){
102
mtr_warning("mtr_report_test_passed: Test result",
103
"already set to '", $tinfo->{'result'}, ",");
106
$tinfo->{'result'}= 'MTR_RES_PASSED';
108
mtr_report_test($tinfo);
112
sub mtr_report_test ($) {
114
my $test_name = _mtr_report_test_name($tinfo);
116
my $comment= $tinfo->{'comment'};
117
my $logfile= $tinfo->{'logfile'};
118
my $warnings= $tinfo->{'warnings'};
119
my $result= $tinfo->{'result'};
120
my $retry= $tinfo->{'retries'} ? "retry-" : "";
122
if ($result eq 'MTR_RES_FAILED'){
124
my $timest = format_time();
127
if ( $::opt_experimental )
129
# Find out if this test case is an experimental one, so we can treat
130
# the failure as an expected failure instead of a regression.
131
for my $exp ( @$::experimental_test_cases ) {
132
if ( $exp ne $test_name ) {
133
# if the expression is not the name of this test case, but has
134
# an asterisk at the end, determine if the characters up to
135
# but excluding the asterisk are the same
136
if ( $exp ne "" && substr($exp, -1, 1) eq "*" ) {
137
my $nexp = substr($exp, 0, length($exp) - 1);
138
if ( substr($test_name, 0, length($nexp)) ne $nexp ) {
139
# no match, try next entry
142
# if yes, fall through to set the exp-fail status
144
# no match, try next entry
149
$tinfo->{exp_fail}= 1;
156
mtr_report("[ $retry$fail ] Found warnings/errors in server log file!");
157
mtr_report(" Test ended at $timest");
158
mtr_report($warnings);
161
my $timeout= $tinfo->{'timeout'};
164
mtr_report("[ $retry$fail ] timeout after $timeout seconds");
165
mtr_report(" Test ended at $timest");
166
mtr_report("\n$tinfo->{'comment'}");
171
mtr_report("[ $retry$fail ]\n Test ended at $timest");
176
# Test failure was detected by test tool and its report
177
# about what failed has been saved to file. Display the report.
178
mtr_report("\n$logfile\n");
182
# The test failure has been detected by mysql-test-run.pl
183
# when starting the servers or due to other error, the reason for
184
# failing the test is saved in "comment"
185
mtr_report("\n$comment\n");
188
if ( !$logfile and !$comment )
190
# Neither this script or the test tool has recorded info
191
# about why the test has failed. Should be debugged.
192
mtr_report("\nUnknown result, neither 'comment' or 'logfile' set");
195
elsif ($result eq 'MTR_RES_SKIPPED')
197
if ( $tinfo->{'disable'} )
199
mtr_report("[ disabled ] $comment");
203
mtr_report("[ skipped ] $comment");
207
mtr_report("[ skipped ]");
210
elsif ($result eq 'MTR_RES_PASSED')
212
my $timer_str= $tinfo->{timer} || "";
213
$tot_real_time += ($timer_str/1000);
214
mtr_report("[ ${retry}pass ] ", sprintf("%5s", $timer_str));
216
# Show any problems check-testcase found
217
if ( defined $tinfo->{'check'} )
219
mtr_report($tinfo->{'check'});
225
sub mtr_report_stats ($$;$) {
226
my ($prefix, $tests, $dont_error)= @_;
228
# ----------------------------------------------------------------------
229
# Find out how we where doing
230
# ----------------------------------------------------------------------
237
my $found_problems= 0;
239
foreach my $tinfo (@$tests)
241
if ( $tinfo->{failures} )
243
# Test has failed at least one time
247
elsif ( $tinfo->{'result'} eq 'MTR_RES_SKIPPED' )
252
elsif ( $tinfo->{'result'} eq 'MTR_RES_PASSED' )
259
if ( $tinfo->{'restarted'} )
261
# Servers was restarted
265
# Add counts for repeated runs, if any.
266
# Note that the last run has already been counted above.
267
my $num_repeat = $tinfo->{'repeat'} - 1;
268
if ( $num_repeat > 0 )
270
$tot_tests += $num_repeat;
271
my $rep_failed = $tinfo->{'rep_failures'} || 0;
272
$tot_failed += $rep_failed;
273
$tot_passed += $num_repeat - $rep_failed;
276
# Look for warnings produced by mysqltest
277
my $base_file= mtr_match_extension($tinfo->{'result_file'},
278
"result"); # Trim extension
279
my $warning_file= "$base_file.warnings";
280
if ( -f $warning_file )
283
mtr_warning("Check myqltest warnings in '$warning_file'");
287
# ----------------------------------------------------------------------
288
# Print out a summary report to screen
289
# ----------------------------------------------------------------------
290
print "The servers were restarted $tot_restarts times\n";
296
mtr_report("Spent", sprintf("%.3f", $tot_real_time),"of",
297
time - $BASETIME, "seconds executing testcases");
301
my $warnlog= "$::opt_vardir/log/warnings";
304
mtr_warning("Got errors/warnings while running tests, please examine",
305
"'$warnlog' for details.");
310
# Print a list of check_testcases that failed(if any)
311
if ( $::opt_check_testcases )
315
foreach my $tinfo (@$tests)
317
if ( defined $tinfo->{'check_testcase_failed'} )
319
$check_testcases{$tinfo->{'name'}}= 1;
323
if ( keys %check_testcases )
325
print "Check of testcase failed for: ";
326
print join(" ", keys %check_testcases);
331
# Print summary line prefix
334
# Print a list of testcases that failed
335
if ( $tot_failed != 0 )
338
# Print each failed test, again
339
#foreach my $test ( @$tests ){
340
# if ( $test->{failures} ) {
341
# mtr_report_test($test);
345
my $ratio= $tot_passed * 100 / $tot_tests;
346
print "Failed $tot_failed/$tot_tests tests, ";
347
printf("%.2f", $ratio);
348
print "\% were successful.\n\n";
350
# Print the list of test that failed in a format
351
# that can be copy pasted to rerun only failing tests
352
print "Failing test(s):";
355
foreach my $tinfo (@$tests)
357
my $tname= $tinfo->{'name'};
358
if ( ($tinfo->{failures} || $tinfo->{rep_failures}) and ! $seen{$tname})
366
# Print info about reporting the error
368
"The log files in var/log may give you some hint of what went wrong.\n\n",
369
"If you want to report this error, please read first ",
370
"the documentation\n",
371
"at http://dev.mysql.com/doc/mysql/en/mysql-test-suite.html\n\n";
376
print "All $tot_tests tests were successful.\n\n";
379
if ( $tot_failed != 0 || $found_problems)
381
mtr_error("there were failing test cases") unless $dont_error;
386
##############################################################################
390
##############################################################################
392
sub mtr_print_line () {
393
print '-' x 60 . "\n";
397
sub mtr_print_thick_line {
398
my $char= shift || '=';
399
print $char x 78 . "\n";
403
sub mtr_print_header () {
408
print "TIME (ms)" if $timer;
415
##############################################################################
417
# Log and reporting functions
419
##############################################################################
423
use Time::HiRes qw(gettimeofday);
427
return sprintf("%4d-%02d-%02d %02d:%02d:%02d",
428
$tm->year + 1900, $tm->mon+1, $tm->mday,
429
$tm->hour, $tm->min, $tm->sec);
432
my $t0= gettimeofday();
435
return "" unless $timestamp;
439
my $t1= gettimeofday();
440
my $elapsed= $t1 - $t0;
442
$diff= sprintf(" +%02.3f", $elapsed);
444
# Save current time for next lap
450
return sprintf("%02d%02d%02d %2d:%02d:%02d%s ",
451
$tm->year % 100, $tm->mon+1, $tm->mday,
452
$tm->hour, $tm->min, $tm->sec, $diff);
455
# Always print message to screen
457
print _name(). join(" ", @_). "\n";
461
# Print message to screen if verbose is defined
463
if (defined $verbose)
465
print _name(). join(" ", @_). "\n";
470
# Print warning to screen
471
sub mtr_warning (@) {
472
print STDERR _name(). _timestamp().
473
"mysql-test-run: WARNING: ". join(" ", @_). "\n";
477
# Print error to screen and then exit
479
print STDERR _name(). _timestamp().
480
"mysql-test-run: *** ERROR: ". join(" ", @_). "\n";
495
print STDERR _name().
496
_timestamp(). "####: ". join(" ", @_). "\n";
501
sub mtr_verbose (@) {
504
print STDERR _name(). _timestamp().
505
"> ".join(" ", @_)."\n";
510
sub mtr_verbose_restart (@) {
511
my ($server, @args)= @_;
512
my $proc= $server->{proc};
513
if ( $verbose_restart )
515
print STDERR _name()._timestamp().
516
"> Restart $proc - ".join(" ", @args)."\n";