2
# Copyright (C) 2004-2006 MySQL AB
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 drizzle-test-run,
18
# and is part of the translation of the Bourne shell script with the
24
sub dtr_report_test_name($);
25
sub dtr_report_test_passed($);
26
sub dtr_report_test_failed($);
27
sub dtr_report_test_skipped($);
28
sub dtr_report_test_not_skipped_though_disabled($);
30
sub dtr_report_stats ($);
31
sub dtr_print_line ();
32
sub dtr_print_thick_line ();
33
sub dtr_print_header ();
37
sub dtr_child_error (@);
45
##############################################################################
49
##############################################################################
51
sub dtr_report_test_name ($) {
53
my $tname= $tinfo->{name};
55
$tname.= " '$tinfo->{combination}'"
56
if defined $tinfo->{combination};
60
printf "test: $tname\n";
62
printf "%-60s ", $tname;
66
sub dtr_report_test_skipped ($) {
68
my $tname= $tinfo->{name};
71
$tinfo->{'result'}= 'DTR_RES_SKIPPED';
72
if ( $tinfo->{'disable'} )
80
if ( $tinfo->{'comment'} )
83
dtr_report("skip: $tname [\ncause: $cause\n$tinfo->{'comment'}\n]");
85
dtr_report("[ $cause ] $tinfo->{'comment'}");
91
dtr_report("skip: $tname");
93
dtr_report("[ $cause ]");
98
sub dtr_report_tests_not_skipped_though_disabled ($) {
101
if ( $::opt_enable_disabled )
103
my @disabled_tests= grep {$_->{'dont_skip_though_disabled'}} @$tests;
104
if ( @disabled_tests )
106
print "\nTest(s) which will be run though they are marked as disabled:\n";
107
foreach my $tinfo ( sort {$a->{'name'} cmp $b->{'name'}} @disabled_tests )
109
printf " %-20s : %s\n", $tinfo->{'name'}, $tinfo->{'comment'};
115
sub dtr_report_test_passed ($) {
117
my $tname= $tinfo->{name};
120
if ( $::opt_timer and -f "$::opt_vardir/log/timer" )
122
$timer= dtr_fromfile("$::opt_vardir/log/timer");
123
$tot_real_time += ($timer/1000);
124
$timer= sprintf "%7s", $timer;
125
### XXX: How to format this as iso6801 datetime?
127
$tinfo->{'result'}= 'DTR_RES_PASSED';
128
if ($::opt_subunit) {
129
dtr_report("success: $tname");
131
dtr_report("[ pass ] $timer");
135
sub dtr_report_test_failed ($) {
137
my $tname= $tinfo->{name};
140
$tinfo->{'result'}= 'DTR_RES_FAILED';
141
if ( defined $tinfo->{'timeout'} )
143
$comment.= "timeout";
145
elsif ( $tinfo->{'comment'} )
147
# The test failure has been detected by drizzle-test-run.pl
148
# when starting the servers or due to other error, the reason for
149
# failing the test is saved in "comment"
150
$comment.= "$tinfo->{'comment'}";
152
elsif ( -f $::path_timefile )
154
# Test failure was detected by test tool and it's report
155
# about what failed has been saved to file. Display the report.
156
$comment.= dtr_fromfile($::path_timefile);
160
# Neither this script or the test tool has recorded info
161
# about why the test has failed. Should be debugged.
162
$comment.= "Unexpected termination, probably when starting drizzled";
164
if ($::opt_subunit) {
165
dtr_report("failure: $tname [\n$comment\n]");
167
dtr_report("[ fail ]\n$comment");
171
sub dtr_report_stats ($) {
174
# ----------------------------------------------------------------------
175
# Find out how we where doing
176
# ----------------------------------------------------------------------
183
my $found_problems= 0; # Some warnings in the logfiles are errors...
185
foreach my $tinfo (@$tests)
187
if ( $tinfo->{'result'} eq 'DTR_RES_SKIPPED' )
191
elsif ( $tinfo->{'result'} eq 'DTR_RES_PASSED' )
196
elsif ( $tinfo->{'result'} eq 'DTR_RES_FAILED' )
201
if ( $tinfo->{'restarted'} )
207
# ----------------------------------------------------------------------
208
# Print out a summary report to screen
209
# ----------------------------------------------------------------------
213
print "All $tot_tests tests were successful.\n";
217
my $ratio= $tot_passed * 100 / $tot_tests;
218
print "Failed $tot_failed/$tot_tests tests, ";
219
printf("%.2f", $ratio);
220
print "\% were successful.\n\n";
222
"The log files in var/log may give you some hint\n",
223
"of what went wrong.\n",
224
"If you want to report this error, go to:\n",
225
"\thttp://bugs.launchpad.net/drizzle\n";
229
print "The servers were restarted $tot_restarts times\n";
236
dtr_report("Spent", sprintf("%.3f", $tot_real_time),"of",
237
time - $BASETIME, "seconds executing testcases");
242
# Print a list of testcases that failed
243
if ( $tot_failed != 0 )
245
my $test_mode= join(" ", @::glob_test_mode) || "default";
246
print "drizzle-test-run in $test_mode mode: *** Failing the test(s):";
248
foreach my $tinfo (@$tests)
250
if ( $tinfo->{'result'} eq 'DTR_RES_FAILED' )
252
print " $tinfo->{'name'}";
259
# Print a list of check_testcases that failed(if any)
260
if ( $::opt_check_testcases )
262
my @check_testcases= ();
264
foreach my $tinfo (@$tests)
266
if ( defined $tinfo->{'check_testcase_failed'} )
268
push(@check_testcases, $tinfo->{'name'});
272
if ( @check_testcases )
274
print "Check of testcase failed for: ";
275
print join(" ", @check_testcases);
280
if ( $tot_failed != 0 || $found_problems)
282
dtr_error("there were failing test cases");
286
##############################################################################
290
##############################################################################
292
sub dtr_print_line () {
293
print '-' x 80, "\n";
296
sub dtr_print_thick_line () {
297
print '=' x 80, "\n";
300
sub dtr_print_header () {
301
print "DEFAULT STORAGE ENGINE: $::opt_engine\n";
304
printf "%-61s%-9s%10s\n","TEST","RESULT","TIME (ms)";
308
print "TEST RESULT\n";
315
##############################################################################
317
# Log and reporting functions
319
##############################################################################
323
my $log_file_ref= undef;
325
sub dtr_log_init ($) {
328
dtr_error("Log is already open") if defined $log_file_ref;
330
$log_file_ref= IO::File->new($filename, "a") or
331
dtr_warning("Could not create logfile $filename: $!");
335
print $log_file_ref join(" ", @_),"\n"
336
if defined $log_file_ref;
340
# Print message to screen and log
342
print join(" ", @_),"\n";
345
sub dtr_warning (@) {
346
# Print message to screen and log
347
_dtr_log("WARNING: ", @_);
348
print STDERR "drizzle-test-run: WARNING: ",join(" ", @_),"\n";
352
# Print message to screen and log
353
_dtr_log("ERROR: ", @_);
354
print STDERR "drizzle-test-run: *** ERROR: ",join(" ", @_),"\n";
358
sub dtr_child_error (@) {
359
# Print message to screen and log
360
_dtr_log("ERROR(child): ", @_);
361
print STDERR "drizzle-test-run: *** ERROR(child): ",join(" ", @_),"\n";
366
# Only print if --script-debug is used
367
if ( $::opt_script_debug )
369
_dtr_log("###: ", @_);
370
print STDERR "####: ",join(" ", @_),"\n";
374
sub dtr_verbose (@) {
375
# Always print to log, print to screen only when --verbose is used
377
if ( $::opt_verbose )
379
print STDERR "> ",join(" ", @_),"\n";