~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/dtr_report.pl

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- cperl -*-
2
 
# Copyright (C) 2004-2006 MySQL AB
3
 
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.
7
 
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.
12
 
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
16
 
 
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
19
 
# same name.
20
 
 
21
 
use strict;
22
 
use warnings;
23
 
 
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($);
29
 
 
30
 
sub dtr_report_stats ($);
31
 
sub dtr_print_line ();
32
 
sub dtr_print_thick_line ();
33
 
sub dtr_print_header ();
34
 
sub dtr_report (@);
35
 
sub dtr_warning (@);
36
 
sub dtr_error (@);
37
 
sub dtr_child_error (@);
38
 
sub dtr_debug (@);
39
 
sub dtr_verbose (@);
40
 
 
41
 
my $tot_real_time= 0;
42
 
 
43
 
 
44
 
 
45
 
##############################################################################
46
 
#
47
 
#  
48
 
#
49
 
##############################################################################
50
 
 
51
 
sub dtr_report_test_name ($) {
52
 
  my $tinfo= shift;
53
 
  my $tname= $tinfo->{name};
54
 
 
55
 
  $tname.= " '$tinfo->{combination}'"
56
 
    if defined $tinfo->{combination};
57
 
 
58
 
  _dtr_log($tname);
59
 
  if ($::opt_subunit) {
60
 
    printf "test: $tname\n";
61
 
  } else {
62
 
    printf "%-60s ", $tname;
63
 
  }
64
 
}
65
 
 
66
 
sub dtr_report_test_skipped ($) {
67
 
  my $tinfo= shift;
68
 
  my $tname= $tinfo->{name};
69
 
  my $cause= "";
70
 
 
71
 
  $tinfo->{'result'}= 'DTR_RES_SKIPPED';
72
 
  if ( $tinfo->{'disable'} )
73
 
  {
74
 
    $cause.= "disable";
75
 
  }
76
 
  else
77
 
  {
78
 
    $cause.= "skipped";
79
 
  }
80
 
  if ( $tinfo->{'comment'} )
81
 
  {
82
 
    if ($::opt_subunit) {
83
 
      dtr_report("skip: $tname [\ncause: $cause\n$tinfo->{'comment'}\n]");
84
 
    } else { 
85
 
      dtr_report("[ $cause ]   $tinfo->{'comment'}");
86
 
    }
87
 
  }
88
 
  else
89
 
  {
90
 
    if ($::opt_subunit) {
91
 
      dtr_report("skip: $tname");
92
 
    } else {
93
 
      dtr_report("[ $cause ]");
94
 
    }
95
 
  }
96
 
}
97
 
 
98
 
sub dtr_report_tests_not_skipped_though_disabled ($) {
99
 
  my $tests= shift;
100
 
 
101
 
  if ( $::opt_enable_disabled )
102
 
  {
103
 
    my @disabled_tests= grep {$_->{'dont_skip_though_disabled'}} @$tests;
104
 
    if ( @disabled_tests )
105
 
    {
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 )
108
 
      {
109
 
        printf "  %-20s : %s\n", $tinfo->{'name'}, $tinfo->{'comment'};
110
 
      }
111
 
    }
112
 
  }
113
 
}
114
 
 
115
 
sub dtr_report_test_passed ($) {
116
 
  my $tinfo= shift;
117
 
  my $tname= $tinfo->{name};
118
 
 
119
 
  my $timer=  "";
120
 
  if ( $::opt_timer and -f "$::opt_vardir/log/timer" )
121
 
  {
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?
126
 
  }
127
 
  $tinfo->{'result'}= 'DTR_RES_PASSED';
128
 
  if ($::opt_subunit) {
129
 
    dtr_report("success: $tname");
130
 
  } else {
131
 
    dtr_report("[ pass ] $timer");
132
 
  }
133
 
}
134
 
 
135
 
sub dtr_report_test_failed ($) {
136
 
  my $tinfo= shift;
137
 
  my $tname= $tinfo->{name};
138
 
  my $comment= "";
139
 
 
140
 
  $tinfo->{'result'}= 'DTR_RES_FAILED';
141
 
  if ( defined $tinfo->{'timeout'} )
142
 
  {
143
 
    $comment.= "timeout";
144
 
  }
145
 
  elsif ( $tinfo->{'comment'} )
146
 
  {
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'}";
151
 
  }
152
 
  elsif ( -f $::path_timefile )
153
 
  {
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);
157
 
  }
158
 
  else
159
 
  {
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";
163
 
  }
164
 
  if ($::opt_subunit) {
165
 
    dtr_report("failure: $tname [\n$comment\n]");
166
 
  } else {
167
 
    dtr_report("[ fail ]\n$comment");
168
 
  }
169
 
}
170
 
 
171
 
sub dtr_report_stats ($) {
172
 
  my $tests= shift;
173
 
 
174
 
  # ----------------------------------------------------------------------
175
 
  # Find out how we where doing
176
 
  # ----------------------------------------------------------------------
177
 
 
178
 
  my $tot_skiped= 0;
179
 
  my $tot_passed= 0;
180
 
  my $tot_failed= 0;
181
 
  my $tot_tests=  0;
182
 
  my $tot_restarts= 0;
183
 
  my $found_problems= 0; # Some warnings in the logfiles are errors...
184
 
 
185
 
  foreach my $tinfo (@$tests)
186
 
  {
187
 
    if ( $tinfo->{'result'} eq 'DTR_RES_SKIPPED' )
188
 
    {
189
 
      $tot_skiped++;
190
 
    }
191
 
    elsif ( $tinfo->{'result'} eq 'DTR_RES_PASSED' )
192
 
    {
193
 
      $tot_tests++;
194
 
      $tot_passed++;
195
 
    }
196
 
    elsif ( $tinfo->{'result'} eq 'DTR_RES_FAILED' )
197
 
    {
198
 
      $tot_tests++;
199
 
      $tot_failed++;
200
 
    }
201
 
    if ( $tinfo->{'restarted'} )
202
 
    {
203
 
      $tot_restarts++;
204
 
    }
205
 
  }
206
 
 
207
 
  # ----------------------------------------------------------------------
208
 
  # Print out a summary report to screen
209
 
  # ----------------------------------------------------------------------
210
 
 
211
 
  if ( ! $tot_failed )
212
 
  {
213
 
    print "All $tot_tests tests were successful.\n";
214
 
  }
215
 
  else
216
 
  {
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";
221
 
    print
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";
226
 
  }
227
 
  if (!$::opt_extern)
228
 
  {
229
 
    print "The servers were restarted $tot_restarts times\n";
230
 
  }
231
 
 
232
 
  if ( $::opt_timer )
233
 
  {
234
 
    use English;
235
 
 
236
 
    dtr_report("Spent", sprintf("%.3f", $tot_real_time),"of",
237
 
               time - $BASETIME, "seconds executing testcases");
238
 
  }
239
 
 
240
 
  print "\n";
241
 
 
242
 
  # Print a list of testcases that failed
243
 
  if ( $tot_failed != 0 )
244
 
  {
245
 
    my $test_mode= join(" ", @::glob_test_mode) || "default";
246
 
    print "drizzle-test-run in $test_mode mode: *** Failing the test(s):";
247
 
 
248
 
    foreach my $tinfo (@$tests)
249
 
    {
250
 
      if ( $tinfo->{'result'} eq 'DTR_RES_FAILED' )
251
 
      {
252
 
        print " $tinfo->{'name'}";
253
 
      }
254
 
    }
255
 
    print "\n";
256
 
 
257
 
  }
258
 
 
259
 
  # Print a list of check_testcases that failed(if any)
260
 
  if ( $::opt_check_testcases )
261
 
  {
262
 
    my @check_testcases= ();
263
 
 
264
 
    foreach my $tinfo (@$tests)
265
 
    {
266
 
      if ( defined $tinfo->{'check_testcase_failed'} )
267
 
      {
268
 
        push(@check_testcases, $tinfo->{'name'});
269
 
      }
270
 
    }
271
 
 
272
 
    if ( @check_testcases )
273
 
    {
274
 
      print "Check of testcase failed for: ";
275
 
      print join(" ", @check_testcases);
276
 
      print "\n\n";
277
 
    }
278
 
  }
279
 
 
280
 
  if ( $tot_failed != 0 || $found_problems)
281
 
  {
282
 
    dtr_error("there were failing test cases");
283
 
  }
284
 
}
285
 
 
286
 
##############################################################################
287
 
#
288
 
#  Text formatting
289
 
#
290
 
##############################################################################
291
 
 
292
 
sub dtr_print_line () {
293
 
  print '-' x 80, "\n";
294
 
}
295
 
 
296
 
sub dtr_print_thick_line () {
297
 
  print '=' x 80, "\n";
298
 
}
299
 
 
300
 
sub dtr_print_header () {
301
 
  print "DEFAULT STORAGE ENGINE: $::opt_engine\n";
302
 
  if ( $::opt_timer )
303
 
  {
304
 
    printf "%-61s%-9s%10s\n","TEST","RESULT","TIME (ms)";
305
 
  }
306
 
  else
307
 
  {
308
 
    print "TEST                           RESULT\n";
309
 
  }
310
 
  dtr_print_line();
311
 
  print "\n";
312
 
}
313
 
 
314
 
 
315
 
##############################################################################
316
 
#
317
 
#  Log and reporting functions
318
 
#
319
 
##############################################################################
320
 
 
321
 
use IO::File;
322
 
 
323
 
my $log_file_ref= undef;
324
 
 
325
 
sub dtr_log_init ($) {
326
 
  my ($filename)= @_;
327
 
 
328
 
  dtr_error("Log is already open") if defined $log_file_ref;
329
 
 
330
 
  $log_file_ref= IO::File->new($filename, "a") or
331
 
    dtr_warning("Could not create logfile $filename: $!");
332
 
}
333
 
 
334
 
sub _dtr_log (@) {
335
 
  print $log_file_ref join(" ", @_),"\n"
336
 
    if defined $log_file_ref;
337
 
}
338
 
 
339
 
sub dtr_report (@) {
340
 
  # Print message to screen and log
341
 
  _dtr_log(@_);
342
 
  print join(" ", @_),"\n";
343
 
}
344
 
 
345
 
sub dtr_warning (@) {
346
 
  # Print message to screen and log
347
 
  _dtr_log("WARNING: ", @_);
348
 
  print STDERR "drizzle-test-run: WARNING: ",join(" ", @_),"\n";
349
 
}
350
 
 
351
 
sub dtr_error (@) {
352
 
  # Print message to screen and log
353
 
  _dtr_log("ERROR: ", @_);
354
 
  print STDERR "drizzle-test-run: *** ERROR: ",join(" ", @_),"\n";
355
 
  dtr_exit(1);
356
 
}
357
 
 
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";
362
 
  exit(1);
363
 
}
364
 
 
365
 
sub dtr_debug (@) {
366
 
  # Only print if --script-debug is used
367
 
  if ( $::opt_script_debug )
368
 
  {
369
 
    _dtr_log("###: ", @_);
370
 
    print STDERR "####: ",join(" ", @_),"\n";
371
 
  }
372
 
}
373
 
 
374
 
sub dtr_verbose (@) {
375
 
  # Always print to log, print to screen only when --verbose is used
376
 
  _dtr_log("> ",@_);
377
 
  if ( $::opt_verbose )
378
 
  {
379
 
    print STDERR "> ",join(" ", @_),"\n";
380
 
  }
381
 
}
382
 
 
383
 
1;