mtr_report.pl 9.13 KB
Newer Older
kent@mysql.com's avatar
kent@mysql.com committed
1 2 3 4 5 6 7 8 9 10 11 12
# -*- cperl -*-

# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.

use strict;

sub mtr_report_test_name($);
sub mtr_report_test_passed($);
sub mtr_report_test_failed($);
sub mtr_report_test_skipped($);
13
sub mtr_report_test_not_skipped_though_disabled($);
kent@mysql.com's avatar
kent@mysql.com committed
14 15 16 17

sub mtr_show_failed_diff ($);
sub mtr_report_stats ($);
sub mtr_print_line ();
kent@mysql.com's avatar
kent@mysql.com committed
18
sub mtr_print_thick_line ();
kent@mysql.com's avatar
kent@mysql.com committed
19 20 21 22
sub mtr_print_header ();
sub mtr_report (@);
sub mtr_warning (@);
sub mtr_error (@);
23
sub mtr_child_error (@);
kent@mysql.com's avatar
kent@mysql.com committed
24
sub mtr_debug (@);
25
sub mtr_verbose (@);
kent@mysql.com's avatar
kent@mysql.com committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40


##############################################################################
#
#  
#
##############################################################################

# We can't use diff -u or diff -a as these are not portable

sub mtr_show_failed_diff ($) {
  my $tname=  shift;

  my $reject_file=  "r/$tname.reject";
  my $result_file=  "r/$tname.result";
41
  my $log_file=  "r/$tname.log";
kent@mysql.com's avatar
kent@mysql.com committed
42 43
  my $eval_file=    "r/$tname.eval";

kent@mysql.com's avatar
kent@mysql.com committed
44 45 46 47 48
  if ( $::opt_suite ne "main" )
  {
    $reject_file= "$::glob_mysql_test_dir/suite/$::opt_suite/$reject_file";
    $result_file= "$::glob_mysql_test_dir/suite/$::opt_suite/$result_file";
    $eval_file=   "$::glob_mysql_test_dir/suite/$::opt_suite/$eval_file";
49
    $log_file=   "$::glob_mysql_test_dir/suite/$::opt_suite/$log_file";
kent@mysql.com's avatar
kent@mysql.com committed
50 51
  }

kent@mysql.com's avatar
kent@mysql.com committed
52
  if ( -f $eval_file )
53
  {
kent@mysql.com's avatar
kent@mysql.com committed
54 55 56
    $result_file=  $eval_file;
  }

kent@mysql.com's avatar
kent@mysql.com committed
57 58
  my $diffopts= $::opt_udiff ? "-u" : "-c";

kent@mysql.com's avatar
kent@mysql.com committed
59 60 61 62 63
  if ( -f $reject_file )
  {
    print "Below are the diffs between actual and expected results:\n";
    print "-------------------------------------------------------\n";
    # FIXME check result code?!
kent@mysql.com's avatar
kent@mysql.com committed
64
    mtr_run("diff",[$diffopts,$result_file,$reject_file], "", "", "", "");
kent@mysql.com's avatar
kent@mysql.com committed
65 66 67 68 69
    print "-------------------------------------------------------\n";
    print "Please follow the instructions outlined at\n";
    print "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html\n";
    print "to find the reason to this problem and how to report this.\n\n";
  }
70 71 72 73 74 75

  if ( -f $log_file )
  {
    print "Result from queries before failure can be found in $log_file\n";
    # FIXME Maybe a tail -f -n 10 $log_file here
  }
kent@mysql.com's avatar
kent@mysql.com committed
76 77 78 79 80
}

sub mtr_report_test_name ($) {
  my $tinfo= shift;

81
  printf "%-30s ", $tinfo->{'name'};
kent@mysql.com's avatar
kent@mysql.com committed
82 83 84 85 86 87
}

sub mtr_report_test_skipped ($) {
  my $tinfo= shift;

  $tinfo->{'result'}= 'MTR_RES_SKIPPED';
kent@mysql.com's avatar
kent@mysql.com committed
88 89 90 91 92 93
  if ( $tinfo->{'disable'} )
  {
    print "[ disabled ]  $tinfo->{'comment'}\n";
  }
  else
  {
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    print "[ skipped ]   $tinfo->{'comment'}\n";
  }
}

sub mtr_report_tests_not_skipped_though_disabled ($) {
  my $tests= shift;

  if ( $::opt_enable_disabled )
  {
    my @disabled_tests= grep {$_->{'dont_skip_though_disabled'}} @$tests;
    if ( @disabled_tests )
    {
      print "\nTest(s) which will be run though they are marked as disabled:\n";
      foreach my $tinfo ( sort {$a->{'name'} cmp $b->{'name'}} @disabled_tests )
      {
        printf "  %-20s : %s\n", $tinfo->{'name'}, $tinfo->{'comment'};
      }
    }
kent@mysql.com's avatar
kent@mysql.com committed
112
  }
kent@mysql.com's avatar
kent@mysql.com committed
113 114 115 116 117 118
}

sub mtr_report_test_passed ($) {
  my $tinfo= shift;

  my $timer=  "";
119
  if ( $::opt_timer and -f "$::opt_vardir/log/timer" )
kent@mysql.com's avatar
kent@mysql.com committed
120
  {
121
    $timer= mtr_fromfile("$::opt_vardir/log/timer");
122
    $::glob_tot_real_time += ($timer/1000);
kent@mysql.com's avatar
kent@mysql.com committed
123 124
    $timer= sprintf "%12s", $timer;
  }
kent@mysql.com's avatar
kent@mysql.com committed
125 126 127 128 129 130 131 132
  $tinfo->{'result'}= 'MTR_RES_PASSED';
  print "[ pass ]   $timer\n";
}

sub mtr_report_test_failed ($) {
  my $tinfo= shift;

  $tinfo->{'result'}= 'MTR_RES_FAILED';
133 134 135 136
  if ( $tinfo->{'timeout'} )
  {
    print "[ fail ]  timeout\n";
  }
137 138 139 140 141
  elsif ( $tinfo->{'ndb_test'} and $::cluster->[0]->{'installed_ok'} eq "NO")
  {
    print "[ fail ]  ndbcluster start failure\n";
    return;
  }
142 143 144 145
  else
  {
    print "[ fail ]\n";
  }
kent@mysql.com's avatar
kent@mysql.com committed
146

147 148 149 150 151
  if ( $tinfo->{'comment'} )
  {
    print "\nERROR: $tinfo->{'comment'}\n";
  }
  elsif ( -f $::path_timefile )
kent@mysql.com's avatar
kent@mysql.com committed
152
  {
153
    print "\nErrors are (from $::path_timefile) :\n";
kent@mysql.com's avatar
kent@mysql.com committed
154 155 156 157 158
    print mtr_fromfile($::path_timefile); # FIXME print_file() instead
    print "\n(the last lines may be the most important ones)\n";
  }
  else
  {
159
    print "\nUnexpected termination, probably when starting mysqld\n";
kent@mysql.com's avatar
kent@mysql.com committed
160
  }
kent@mysql.com's avatar
kent@mysql.com committed
161 162 163 164 165 166 167 168 169 170 171 172 173
}

sub mtr_report_stats ($) {
  my $tests= shift;

  # ----------------------------------------------------------------------
  # Find out how we where doing
  # ----------------------------------------------------------------------

  my $tot_skiped= 0;
  my $tot_passed= 0;
  my $tot_failed= 0;
  my $tot_tests=  0;
174 175
  my $tot_restarts= 0;
  my $found_problems= 0;            # Some warnings are errors...
kent@mysql.com's avatar
kent@mysql.com committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

  foreach my $tinfo (@$tests)
  {
    if ( $tinfo->{'result'} eq 'MTR_RES_SKIPPED' )
    {
      $tot_skiped++;
    }
    elsif ( $tinfo->{'result'} eq 'MTR_RES_PASSED' )
    {
      $tot_tests++;
      $tot_passed++;
    }
    elsif ( $tinfo->{'result'} eq 'MTR_RES_FAILED' )
    {
      $tot_tests++;
      $tot_failed++;
    }
193 194 195 196
    if ( $tinfo->{'restarted'} )
    {
      $tot_restarts++;
    }
kent@mysql.com's avatar
kent@mysql.com committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210
  }

  # ----------------------------------------------------------------------
  # Print out a summary report to screen
  # ----------------------------------------------------------------------

  if ( ! $tot_failed )
  {
    print "All $tot_tests tests were successful.\n";
  }
  else
  {
    my $ratio=  $tot_passed * 100 / $tot_tests;
    printf "Failed $tot_failed/$tot_tests tests, " .
211
      "%.2f\% were successful.\n\n", $ratio;
kent@mysql.com's avatar
kent@mysql.com committed
212 213
    print
      "The log files in var/log may give you some hint\n",
214
      "of what went wrong.\n",
kent@mysql.com's avatar
kent@mysql.com committed
215 216 217 218
      "If you want to report this error, please read first ",
      "the documentation at\n",
      "http://www.mysql.com/doc/en/MySQL_test_suite.html\n";
  }
219 220 221 222 223 224 225 226
  print
      "The servers were restarted $tot_restarts times\n";

  if ( $::opt_timer )
  {
    print
      "Spent $::glob_tot_real_time seconds actually executing testcases\n"
  }
kent@mysql.com's avatar
kent@mysql.com committed
227 228

  # ----------------------------------------------------------------------
229 230
  # If a debug run, there might be interesting information inside
  # the "var/log/*.err" files. We save this info in "var/log/warnings"
kent@mysql.com's avatar
kent@mysql.com committed
231 232 233 234
  # ----------------------------------------------------------------------

  if ( ! $::glob_use_running_server )
  {
235
    # Save and report if there was any fatal warnings/errors in err logs
kent@mysql.com's avatar
kent@mysql.com committed
236

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    my $warnlog= "$::opt_vardir/log/warnings";

    unless ( open(WARN, ">$warnlog") )
    {
      mtr_warning("can't write to the file \"$warnlog\": $!");
    }
    else
    {
      # We report different types of problems in order
      foreach my $pattern ( "^Warning:", "^Error:", "^==.* at 0x",
			    "InnoDB: Warning", "missing DBUG_RETURN",
			    "mysqld: Warning",
			    "Attempting backtrace", "Assertion .* failed" )
      {
        foreach my $errlog ( sort glob("$::opt_vardir/log/*.err") )
        {
          unless ( open(ERR, $errlog) )
          {
            mtr_warning("can't read $errlog");
            next;
          }
          while ( <ERR> )
          {
            # Skip some non fatal warnings from the log files
            if ( /Warning:\s+Table:.* on (delete|rename)/ or
                 /Warning:\s+Setting lower_case_table_names=2/ or
                 /Warning:\s+One can only use the --user.*root/ or
	         /InnoDB: Warning: we did not need to do crash recovery/)
            {
              next;                       # Skip these lines
            }
            if ( /$pattern/ )
            {
              $found_problems= 1;
              print WARN $_;
            }
          }
        }
      }
      if ( $found_problems )
      {
	mtr_warning("Got errors/warnings while running tests, please examine",
		    "\"$warnlog\" for details.");
      }
    }
kent@mysql.com's avatar
kent@mysql.com committed
282 283 284 285 286 287
  }

  print "\n";

  if ( $tot_failed != 0 )
  {
288 289
    my $test_mode= join(" ", @::glob_test_mode) || "default";
    print "mysql-test-run in $test_mode mode: *** Failing the test(s):";
kent@mysql.com's avatar
kent@mysql.com committed
290 291 292 293 294 295 296 297 298

    foreach my $tinfo (@$tests)
    {
      if ( $tinfo->{'result'} eq 'MTR_RES_FAILED' )
      {
        print " $tinfo->{'name'}";
      }
    }
    print "\n";
299 300 301
  }
  if ( $tot_failed != 0 || $found_problems)
  {
kent@mysql.com's avatar
kent@mysql.com committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315
    mtr_error("there where failing test cases");
  }
}

##############################################################################
#
#  Text formatting
#
##############################################################################

sub mtr_print_line () {
  print '-' x 55, "\n";
}

kent@mysql.com's avatar
kent@mysql.com committed
316 317 318 319
sub mtr_print_thick_line () {
  print '=' x 55, "\n";
}

kent@mysql.com's avatar
kent@mysql.com committed
320 321 322 323
sub mtr_print_header () {
  print "\n";
  if ( $::opt_timer )
  {
kent@mysql.com's avatar
kent@mysql.com committed
324
    print "TEST                           RESULT         TIME (ms)\n";
kent@mysql.com's avatar
kent@mysql.com committed
325 326 327
  }
  else
  {
kent@mysql.com's avatar
kent@mysql.com committed
328
    print "TEST                           RESULT\n";
kent@mysql.com's avatar
kent@mysql.com committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
  }
  mtr_print_line();
  print "\n";
}


##############################################################################
#
#  Misc
#
##############################################################################

sub mtr_report (@) {
  print join(" ", @_),"\n";
}

sub mtr_warning (@) {
  print STDERR "mysql-test-run: WARNING: ",join(" ", @_),"\n";
}

sub mtr_error (@) {
kent@mysql.com's avatar
kent@mysql.com committed
350 351
  print STDERR "mysql-test-run: *** ERROR: ",join(" ", @_),"\n";
  mtr_exit(1);
kent@mysql.com's avatar
kent@mysql.com committed
352 353
}

354 355 356 357 358
sub mtr_child_error (@) {
  print STDERR "mysql-test-run: *** ERROR(child): ",join(" ", @_),"\n";
  exit(1);
}

kent@mysql.com's avatar
kent@mysql.com committed
359 360 361
sub mtr_debug (@) {
  if ( $::opt_script_debug )
  {
kent@mysql.com's avatar
kent@mysql.com committed
362
    print STDERR "####: ",join(" ", @_),"\n";
kent@mysql.com's avatar
kent@mysql.com committed
363 364
  }
}
365 366 367 368 369 370
sub mtr_verbose (@) {
  if ( $::opt_verbose )
  {
    print STDERR "> ",join(" ", @_),"\n";
  }
}
kent@mysql.com's avatar
kent@mysql.com committed
371 372

1;