mtr_report.pl 6.88 KB
Newer Older
unknown's avatar
unknown 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($);
unknown's avatar
unknown committed
13
sub mtr_report_test_disabled($);
unknown's avatar
unknown committed
14 15 16 17

sub mtr_show_failed_diff ($);
sub mtr_report_stats ($);
sub mtr_print_line ();
unknown's avatar
unknown committed
18
sub mtr_print_thick_line ();
unknown's avatar
unknown committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
sub mtr_print_header ();
sub mtr_report (@);
sub mtr_warning (@);
sub mtr_error (@);
sub mtr_debug (@);


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

# 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";
  my $eval_file=    "r/$tname.eval";

  if ( -f $eval_file )
  { 
    $result_file=  $eval_file;
  }
  elsif ( $::opt_result_ext and
          ( $::opt_record or -f "$result_file$::opt_result_ext" ))
  {
    # If we have an special externsion for result files we use it if we are
    # recording or a result file with that extension exists.
    $result_file=  "$result_file$::opt_result_ext";
  }

unknown's avatar
unknown committed
53 54
  my $diffopts= $::opt_udiff ? "-u" : "-c";

unknown's avatar
unknown committed
55 56 57 58 59
  if ( -f $reject_file )
  {
    print "Below are the diffs between actual and expected results:\n";
    print "-------------------------------------------------------\n";
    # FIXME check result code?!
unknown's avatar
unknown committed
60
    mtr_run("diff",[$diffopts,$result_file,$reject_file], "", "", "", "");
unknown's avatar
unknown committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    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";
  }
}

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

  printf "%-31s ", $tinfo->{'name'};
}

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

  $tinfo->{'result'}= 'MTR_RES_SKIPPED';
unknown's avatar
unknown committed
78 79 80 81 82 83 84 85
  if ( $tinfo->{'disable'} )
  {
    print "[ disabled ]  $tinfo->{'comment'}\n";
  }
  else
  {
    print "[ skipped ]\n";
  }
unknown's avatar
unknown committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
}

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

  my $timer=  "";
# FIXME
#  if ( $::opt_timer and -f "$::glob_mysql_test_dir/var/log/timer" )
#  {
#    $timer=  `cat var/log/timer`;
#    $timer=  sprintf "%13s", $timer;
#  }
  $tinfo->{'result'}= 'MTR_RES_PASSED';
  print "[ pass ]   $timer\n";
}

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

  $tinfo->{'result'}= 'MTR_RES_FAILED';
  print "[ fail ]\n";

unknown's avatar
unknown committed
108 109 110 111 112 113 114 115 116 117 118 119
  # FIXME Instead of this test, and meaningless error message in 'else'
  # we should write out into $::path_timefile when the error occurs.
  if ( -f $::path_timefile )
  {
    print "Errors are (from $::path_timefile) :\n";
    print mtr_fromfile($::path_timefile); # FIXME print_file() instead
    print "\n(the last lines may be the most important ones)\n";
  }
  else
  {
    print "Unexpected termination, probably when starting mysqld\n";
  }
unknown's avatar
unknown committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
}

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;

  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++;
    }
  }

  # ----------------------------------------------------------------------
  # 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, " .
164
      "%.2f\% were successful.\n\n", $ratio;
unknown's avatar
unknown committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
    print
      "The log files in var/log may give you some hint\n",
      "of what when wrong.\n",
      "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";
  }

  # ----------------------------------------------------------------------
  # ----------------------------------------------------------------------

  if ( ! $::glob_use_running_server )
  {

    # Report if there was any fatal warnings/errors in the log files
    #
    unlink("$::glob_mysql_test_dir/var/log/warnings");
    unlink("$::glob_mysql_test_dir/var/log/warnings.tmp");
    # Remove some non fatal warnings from the log files

# FIXME what is going on ????? ;-)
#    sed -e 's!Warning:  Table:.* on delete!!g' -e 's!Warning: Setting lower_case_table_names=2!!g' -e 's!Warning: One can only use the --user.*root!!g' \
#        var/log/*.err \
#        | sed -e 's!Warning:  Table:.* on rename!!g' \
#        > var/log/warnings.tmp;
#
#    found_error=0;
#    # Find errors
#    for i in "^Warning:" "^Error:" "^==.* at 0x"
#    do
#      if ( $GREP "$i" var/log/warnings.tmp >> var/log/warnings )
#    {
#        found_error=1
#      }
#    done
#    unlink("$::glob_mysql_test_dir/var/log/warnings.tmp");
#    if ( $found_error=  "1" )
#      {
#      print "WARNING: Got errors/warnings while running tests. Please examine\n"
#      print "$::glob_mysql_test_dir/var/log/warnings for details.\n"
#    }
#  }
  }

  print "\n";

  if ( $tot_failed != 0 )
  {
    print "mysql-test-run: *** Failing the test(s):";

    foreach my $tinfo (@$tests)
    {
      if ( $tinfo->{'result'} eq 'MTR_RES_FAILED' )
      {
        print " $tinfo->{'name'}";
      }
    }
    print "\n";
    mtr_error("there where failing test cases");
  }
}

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

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

unknown's avatar
unknown committed
237 238 239 240
sub mtr_print_thick_line () {
  print '=' x 55, "\n";
}

unknown's avatar
unknown committed
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
sub mtr_print_header () {
  print "\n";
  if ( $::opt_timer )
  {
    print "TEST                            RESULT        TIME (ms)\n";
  }
  else
  {
    print "TEST                            RESULT\n";
  }
  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 (@) {
  die "mysql-test-run: *** ERROR: ",join(" ", @_),"\n";
}

sub mtr_debug (@) {
  if ( $::opt_script_debug )
  {
unknown's avatar
unknown committed
277
    print STDERR "####: ",join(" ", @_),"\n";
unknown's avatar
unknown committed
278 279 280 281
  }
}

1;