~drizzle-trunk/drizzle/development

1 by brian
clean slate
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 mysql-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 mtr_report_test_name($);
25
sub mtr_report_test_passed($);
26
sub mtr_report_test_failed($);
27
sub mtr_report_test_skipped($);
28
sub mtr_report_test_not_skipped_though_disabled($);
29
30
sub mtr_report_stats ($);
31
sub mtr_print_line ();
32
sub mtr_print_thick_line ();
33
sub mtr_print_header ();
34
sub mtr_report (@);
35
sub mtr_warning (@);
36
sub mtr_error (@);
37
sub mtr_child_error (@);
38
sub mtr_debug (@);
39
sub mtr_verbose (@);
40
41
my $tot_real_time= 0;
42
43
44
45
##############################################################################
46
#
47
#  
48
#
49
##############################################################################
50
51
sub mtr_report_test_name ($) {
52
  my $tinfo= shift;
53
  my $tname= $tinfo->{name};
54
55
  $tname.= " '$tinfo->{combination}'"
56
    if defined $tinfo->{combination};
57
58
  _mtr_log($tname);
59
  printf "%-30s ", $tname;
60
}
61
62
sub mtr_report_test_skipped ($) {
63
  my $tinfo= shift;
64
65
  $tinfo->{'result'}= 'MTR_RES_SKIPPED';
66
  if ( $tinfo->{'disable'} )
67
  {
68
    mtr_report("[ disabled ]  $tinfo->{'comment'}");
69
  }
70
  elsif ( $tinfo->{'comment'} )
71
  {
72
    mtr_report("[ skipped ]   $tinfo->{'comment'}");
73
  }
74
  else
75
  {
76
    mtr_report("[ skipped ]");
77
  }
78
}
79
80
sub mtr_report_tests_not_skipped_though_disabled ($) {
81
  my $tests= shift;
82
83
  if ( $::opt_enable_disabled )
84
  {
85
    my @disabled_tests= grep {$_->{'dont_skip_though_disabled'}} @$tests;
86
    if ( @disabled_tests )
87
    {
88
      print "\nTest(s) which will be run though they are marked as disabled:\n";
89
      foreach my $tinfo ( sort {$a->{'name'} cmp $b->{'name'}} @disabled_tests )
90
      {
91
        printf "  %-20s : %s\n", $tinfo->{'name'}, $tinfo->{'comment'};
92
      }
93
    }
94
  }
95
}
96
97
sub mtr_report_test_passed ($) {
98
  my $tinfo= shift;
99
100
  my $timer=  "";
101
  if ( $::opt_timer and -f "$::opt_vardir/log/timer" )
102
  {
103
    $timer= mtr_fromfile("$::opt_vardir/log/timer");
104
    $tot_real_time += ($timer/1000);
105
    $timer= sprintf "%12s", $timer;
106
  }
107
  $tinfo->{'result'}= 'MTR_RES_PASSED';
108
  mtr_report("[ pass ]   $timer");
109
}
110
111
sub mtr_report_test_failed ($) {
112
  my $tinfo= shift;
113
114
  $tinfo->{'result'}= 'MTR_RES_FAILED';
115
  if ( defined $tinfo->{'timeout'} )
116
  {
117
    mtr_report("[ fail ]  timeout");
118
    return;
119
  }
120
  else
121
  {
122
    mtr_report("[ fail ]");
123
  }
124
125
  if ( $tinfo->{'comment'} )
126
  {
127
    # The test failure has been detected by mysql-test-run.pl
128
    # when starting the servers or due to other error, the reason for
129
    # failing the test is saved in "comment"
130
    mtr_report("\nERROR: $tinfo->{'comment'}");
131
  }
132
  elsif ( -f $::path_timefile )
133
  {
134
    # Test failure was detected by test tool and it's report
135
    # about what failed has been saved to file. Display the report.
136
    print "\n";
137
    print mtr_fromfile($::path_timefile); # FIXME print_file() instead
138
    print "\n";
139
  }
140
  else
141
  {
142
    # Neither this script or the test tool has recorded info
143
    # about why the test has failed. Should be debugged.
144
    mtr_report("\nUnexpected termination, probably when starting mysqld");;
145
  }
146
}
147
148
sub mtr_report_stats ($) {
149
  my $tests= shift;
150
151
  # ----------------------------------------------------------------------
152
  # Find out how we where doing
153
  # ----------------------------------------------------------------------
154
155
  my $tot_skiped= 0;
156
  my $tot_passed= 0;
157
  my $tot_failed= 0;
158
  my $tot_tests=  0;
159
  my $tot_restarts= 0;
160
  my $found_problems= 0; # Some warnings in the logfiles are errors...
161
162
  foreach my $tinfo (@$tests)
163
  {
164
    if ( $tinfo->{'result'} eq 'MTR_RES_SKIPPED' )
165
    {
166
      $tot_skiped++;
167
    }
168
    elsif ( $tinfo->{'result'} eq 'MTR_RES_PASSED' )
169
    {
170
      $tot_tests++;
171
      $tot_passed++;
172
    }
173
    elsif ( $tinfo->{'result'} eq 'MTR_RES_FAILED' )
174
    {
175
      $tot_tests++;
176
      $tot_failed++;
177
    }
178
    if ( $tinfo->{'restarted'} )
179
    {
180
      $tot_restarts++;
181
    }
182
  }
183
184
  # ----------------------------------------------------------------------
185
  # Print out a summary report to screen
186
  # ----------------------------------------------------------------------
187
188
  if ( ! $tot_failed )
189
  {
190
    print "All $tot_tests tests were successful.\n";
191
  }
192
  else
193
  {
194
    my $ratio=  $tot_passed * 100 / $tot_tests;
195
    print "Failed $tot_failed/$tot_tests tests, ";
196
    printf("%.2f", $ratio);
197
    print "\% were successful.\n\n";
198
    print
199
      "The log files in var/log may give you some hint\n",
200
      "of what went wrong.\n",
873.2.7 by Monty Taylor
Fixed error message.
201
      "If you want to report this error, go to:\n",
202
      "\thttp://bugs.launchpad.net/drizzle\n";
1 by brian
clean slate
203
  }
204
  if (!$::opt_extern)
205
  {
206
    print "The servers were restarted $tot_restarts times\n";
207
  }
208
209
  if ( $::opt_timer )
210
  {
211
    use English;
212
213
    mtr_report("Spent", sprintf("%.3f", $tot_real_time),"of",
214
	       time - $BASETIME, "seconds executing testcases");
215
  }
216
217
  # ----------------------------------------------------------------------
218
  # If a debug run, there might be interesting information inside
219
  # the "var/log/*.err" files. We save this info in "var/log/warnings"
220
  # ----------------------------------------------------------------------
221
222
  if ( ! $::glob_use_running_server )
223
  {
224
    # Save and report if there was any fatal warnings/errors in err logs
225
226
    my $warnlog= "$::opt_vardir/log/warnings";
227
228
    unless ( open(WARN, ">$warnlog") )
229
    {
230
      mtr_warning("can't write to the file \"$warnlog\": $!");
231
    }
232
    else
233
    {
234
      # We report different types of problems in order
235
      foreach my $pattern ( "^Warning:",
236
			    "\\[Warning\\]",
237
			    "\\[ERROR\\]",
238
			    "^Error:", "^==.* at 0x",
239
			    "InnoDB: Warning",
240
			    "InnoDB: Error",
241
			    "^safe_mutex:",
242
			    "missing DBUG_RETURN",
243
			    "mysqld: Warning",
244
			    "allocated at line",
245
			    "Attempting backtrace", "Assertion .* failed" )
246
      {
247
        foreach my $errlog ( sort glob("$::opt_vardir/log/*.err") )
248
        {
249
	  my $testname= "";
250
          unless ( open(ERR, $errlog) )
251
          {
252
            mtr_warning("can't read $errlog");
253
            next;
254
          }
255
          my $leak_reports_expected= undef;
256
          while ( <ERR> )
257
          {
258
            # There is a test case that purposely provokes a
259
            # SAFEMALLOC leak report, even though there is no actual
260
            # leak. We need to detect this, and ignore the warning in
261
            # that case.
262
            if (/Begin safemalloc memory dump:/) {
263
              $leak_reports_expected= 1;
264
            } elsif (/End safemalloc memory dump./) {
265
              $leak_reports_expected= undef;
266
            }
267
268
            # Skip some non fatal warnings from the log files
269
            if (
270
		/\"SELECT UNIX_TIMESTAMP\(\)\" failed on master/ or
271
		/Aborted connection/ or
272
		/Client requested master to start replication from impossible position/ or
273
		/Could not find first log file name in binary log/ or
274
		/Enabling keys got errno/ or
275
		/Error reading master configuration/ or
276
		/Error reading packet/ or
277
		/Event Scheduler/ or
278
		/Failed to open log/ or
279
		/Failed to open the existing master info file/ or
280
		/Forcing shutdown of [0-9]* plugins/ or
281
                /Can't open shared library .*\bha_example\b/ or
282
                /Couldn't load plugin .*\bha_example\b/ or
283
284
		# Due to timing issues, it might be that this warning
285
		# is printed when the server shuts down and the
286
		# computer is loaded.
287
		/Forcing close of thread \d+  user: '.*?'/ or
288
289
		/Got error [0-9]* when reading table/ or
290
		/Incorrect definition of table/ or
291
		/Incorrect information in file/ or
292
		/InnoDB: Warning: we did not need to do crash recovery/ or
293
		/Invalid \(old\?\) table or database name/ or
294
		/Lock wait timeout exceeded/ or
295
		/Log entry on master is longer than max_allowed_packet/ or
296
                /unknown option '--loose-/ or
297
                /unknown variable 'loose-/ or
298
		/You have forced lower_case_table_names to 0 through a command-line option/ or
299
		/Setting lower_case_table_names=2/ or
300
		/NDB Binlog:/ or
301
		/NDB: failed to setup table/ or
302
		/NDB: only row based binary logging/ or
303
		/Neither --relay-log nor --relay-log-index were used/ or
304
		/Query partially completed/ or
305
		/Slave I.O thread aborted while waiting for relay log/ or
306
		/Slave SQL thread is stopped because UNTIL condition/ or
307
		/Slave SQL thread retried transaction/ or
308
		/Slave \(additional info\)/ or
309
		/Slave: .*Duplicate column name/ or
310
		/Slave: .*master may suffer from/ or
311
		/Slave: According to the master's version/ or
312
		/Slave: Column [0-9]* type mismatch/ or
313
                /Slave: Can't DROP 'c7'; check that column.key exists Error_code: 1091/ or
314
                /Slave: Unknown column 'c7' in 't15' Error_code: 1054/ or
315
                /Slave: Key column 'c6' doesn't exist in table Error_code: 1072/ or
316
		/Slave: Error .* doesn't exist/ or
317
		/Slave: Error .*Deadlock found/ or
318
		/Slave: Error .*Unknown table/ or
319
		/Slave: Error in Write_rows event: / or
320
		/Slave: Field .* of table .* has no default value/ or
321
                /Slave: Field .* doesn't have a default value/ or
322
		/Slave: Query caused different errors on master and slave/ or
323
		/Slave: Table .* doesn't exist/ or
324
		/Slave: Table width mismatch/ or
325
		/Slave: The incident LOST_EVENTS occured on the master/ or
326
		/Slave: Unknown error.* 1105/ or
327
		/Slave: Can't drop database.* database doesn't exist/ or
328
                /Slave SQL:.*(?:Error_code: \d+|Query:.*)/ or
329
		
330
		# backup_errors test is supposed to trigger lots of backup related errors
331
		($testname eq 'main.backup_errors') and
332
		(
333
		  /Backup:/ or /Restore:/ or /Can't open the online backup progress tables/
334
		) or
335
		# The tablespace test triggers error below on purpose
336
		($testname eq 'main.backup_tablespace') and
337
		(
338
		  /Restore: Tablespace .* needed by tables being restored has changed on the server/
339
		) or
340
		
341
		/Sort aborted/ or
342
		/Time-out in NDB/ or
343
		/One can only use the --user.*root/ or
344
		/Setting lower_case_table_names=2/ or
345
		/Table:.* on (delete|rename)/ or
346
		/You have an error in your SQL syntax/ or
347
		/deprecated/ or
348
		/description of time zone/ or
349
		/equal MySQL server ids/ or
350
		/error .*connecting to master/ or
351
		/error reading log entry/ or
352
		/lower_case_table_names is set/ or
353
		/skip-name-resolve mode/ or
354
		/slave SQL thread aborted/ or
355
		/Slave: .*Duplicate entry/ or
356
		# Special case for Bug #26402 in show_check.test
357
		# Question marks are not valid file name parts
358
		# on Windows platforms. Ignore this error message. 
359
		/\QCan't find file: '.\test\????????.frm'\E/ or
360
		# Special case, made as specific as possible, for:
361
		# Bug #28436: Incorrect position in SHOW BINLOG EVENTS causes
362
		#             server coredump
363
		/\QError in Log_event::read_log_event(): 'Sanity check failed', data_len: 258, event_type: 49\E/ or
364
                /Statement is not safe to log in statement format/ or
365
366
                # test case for Bug#bug29807 copies a stray frm into database
367
                /InnoDB: Error: table `test`.`bug29807` does not exist in the InnoDB internal/ or
368
                /Cannot find or open table test\/bug29807 from/ or
369
370
                # innodb foreign key tests that fail in ALTER or RENAME produce this
371
                /InnoDB: Error: in ALTER TABLE `test`.`t[12]`/ or
372
                /InnoDB: Error: in RENAME TABLE table `test`.`t1`/ or
373
                /InnoDB: Error: table `test`.`t[12]` does not exist in the InnoDB internal/ or
374
375
                # Test case for Bug#14233 produces the following warnings:
376
                /Stored routine 'test'.'bug14233_1': invalid value in column mysql.proc/ or
377
                /Stored routine 'test'.'bug14233_2': invalid value in column mysql.proc/ or
378
                /Stored routine 'test'.'bug14233_3': invalid value in column mysql.proc/ or
379
380
                # BUG#29839 - lowercase_table3.test: Cannot find table test/T1
381
                #             from the internal data dictiona
382
                /Cannot find table test\/BUG29839 from the internal data dictionary/ or
383
                # BUG#32080 - Excessive warnings on Solaris: setrlimit could not
384
                #             change the size of core files
385
                /setrlimit could not change the size of core files to 'infinity'/ or
386
387
                # rpl_ndb_basic expects this error
388
                /Slave: Got error 146 during COMMIT Error_code: 1180/ or
389
390
		# rpl_extrColmaster_*.test, the slave thread produces warnings
391
		# when it get updates to a table that has more columns on the
392
		# master
393
		/Slave: Unknown column 'c7' in 't15' Error_code: 1054/ or
394
		/Slave: Can't DROP 'c7'.* 1091/ or
395
		/Slave: Key column 'c6'.* 1072/ or
396
397
                # BUG#32080 - Excessive warnings on Solaris: setrlimit could not
398
                #             change the size of core files
399
                /setrlimit could not change the size of core files to 'infinity'/ or
400
		# rpl_idempotency.test produces warnings for the slave.
401
		($testname eq 'rpl.rpl_idempotency' and
402
		 (/Slave: Can\'t find record in \'t1\' Error_code: 1032/ or
403
                  /Slave: Cannot add or update a child row: a foreign key constraint fails .* Error_code: 1452/
404
		 )) or
405
406
		# These tests does "kill" on queries, causing sporadic errors when writing to logs
407
		(($testname eq 'rpl.rpl_skip_error' or
408
		  $testname eq 'rpl.rpl_err_ignoredtable' or
409
		  $testname eq 'binlog.binlog_killed_simulate' or
410
		  $testname eq 'binlog.binlog_killed') and
411
		 (/Failed to write to mysql\.\w+_log/
412
		 )) or
413
414
		# rpl_bug33931 has deliberate failures
415
		($testname eq 'rpl.rpl_bug33931' and
416
		 (/Failed during slave.*thread initialization/
417
		  )) or
418
419
		# rpl_temporary has an error on slave that can be ignored
420
		($testname eq 'rpl.rpl_temporary' and
421
		 (/Slave: Can\'t find record in \'user\' Error_code: 1032/
422
		 )) or
423
424
                # Test case for Bug#31590 produces the following error:
425
                /Out of sort memory; increase server sort buffer size/
426
		)
427
            {
428
              next;                       # Skip these lines
429
            }
430
	    if ( /CURRENT_TEST: (.*)/ )
431
	    {
432
	      $testname= $1;
433
	    }
434
            if ( /$pattern/ )
435
            {
436
              if ($leak_reports_expected) {
437
                next;
438
              }
439
              $found_problems= 1;
440
              print WARN basename($errlog) . ": $testname: $_";
441
            }
442
          }
443
        }
444
      }
445
446
      if ( $::opt_check_testcases )
447
      {
448
        # Look for warnings produced by mysqltest in testname.warnings
449
        foreach my $test_warning_file
450
	  ( glob("$::glob_mysql_test_dir/r/*.warnings") )
451
        {
452
          $found_problems= 1;
453
	  print WARN "Check myqltest warnings in $test_warning_file\n";
454
        }
455
      }
456
457
      if ( $found_problems )
458
      {
459
	mtr_warning("Got errors/warnings while running tests, please examine",
460
		    "\"$warnlog\" for details.");
461
      }
462
    }
463
  }
464
465
  print "\n";
466
467
  # Print a list of testcases that failed
468
  if ( $tot_failed != 0 )
469
  {
470
    my $test_mode= join(" ", @::glob_test_mode) || "default";
471
    print "mysql-test-run in $test_mode mode: *** Failing the test(s):";
472
473
    foreach my $tinfo (@$tests)
474
    {
475
      if ( $tinfo->{'result'} eq 'MTR_RES_FAILED' )
476
      {
477
        print " $tinfo->{'name'}";
478
      }
479
    }
480
    print "\n";
481
482
  }
483
484
  # Print a list of check_testcases that failed(if any)
485
  if ( $::opt_check_testcases )
486
  {
487
    my @check_testcases= ();
488
489
    foreach my $tinfo (@$tests)
490
    {
491
      if ( defined $tinfo->{'check_testcase_failed'} )
492
      {
493
	push(@check_testcases, $tinfo->{'name'});
494
      }
495
    }
496
497
    if ( @check_testcases )
498
    {
499
      print "Check of testcase failed for: ";
500
      print join(" ", @check_testcases);
501
      print "\n\n";
502
    }
503
  }
504
505
  if ( $tot_failed != 0 || $found_problems)
506
  {
507
    mtr_error("there were failing test cases");
508
  }
509
}
510
511
##############################################################################
512
#
513
#  Text formatting
514
#
515
##############################################################################
516
517
sub mtr_print_line () {
518
  print '-' x 55, "\n";
519
}
520
521
sub mtr_print_thick_line () {
522
  print '=' x 55, "\n";
523
}
524
525
sub mtr_print_header () {
496.1.1 by Paul McCullagh
Added --engine option to drizzle-test-run (default innodb)
526
  print "DEFAULT STORAGE ENGINE: $::opt_engine\n";
1 by brian
clean slate
527
  if ( $::opt_timer )
528
  {
529
    print "TEST                           RESULT         TIME (ms)\n";
530
  }
531
  else
532
  {
533
    print "TEST                           RESULT\n";
534
  }
535
  mtr_print_line();
536
  print "\n";
537
}
538
539
540
##############################################################################
541
#
542
#  Log and reporting functions
543
#
544
##############################################################################
545
546
use IO::File;
547
548
my $log_file_ref= undef;
549
550
sub mtr_log_init ($) {
551
  my ($filename)= @_;
552
553
  mtr_error("Log is already open") if defined $log_file_ref;
554
555
  $log_file_ref= IO::File->new($filename, "a") or
556
    mtr_warning("Could not create logfile $filename: $!");
557
}
558
559
sub _mtr_log (@) {
560
  print $log_file_ref join(" ", @_),"\n"
561
    if defined $log_file_ref;
562
}
563
564
sub mtr_report (@) {
565
  # Print message to screen and log
566
  _mtr_log(@_);
567
  print join(" ", @_),"\n";
568
}
569
570
sub mtr_warning (@) {
571
  # Print message to screen and log
572
  _mtr_log("WARNING: ", @_);
573
  print STDERR "mysql-test-run: WARNING: ",join(" ", @_),"\n";
574
}
575
576
sub mtr_error (@) {
577
  # Print message to screen and log
578
  _mtr_log("ERROR: ", @_);
579
  print STDERR "mysql-test-run: *** ERROR: ",join(" ", @_),"\n";
580
  mtr_exit(1);
581
}
582
583
sub mtr_child_error (@) {
584
  # Print message to screen and log
585
  _mtr_log("ERROR(child): ", @_);
586
  print STDERR "mysql-test-run: *** ERROR(child): ",join(" ", @_),"\n";
587
  exit(1);
588
}
589
590
sub mtr_debug (@) {
591
  # Only print if --script-debug is used
592
  if ( $::opt_script_debug )
593
  {
594
    _mtr_log("###: ", @_);
595
    print STDERR "####: ",join(" ", @_),"\n";
596
  }
597
}
598
599
sub mtr_verbose (@) {
600
  # Always print to log, print to screen only when --verbose is used
601
  _mtr_log("> ",@_);
602
  if ( $::opt_verbose )
603
  {
604
    print STDERR "> ",join(" ", @_),"\n";
605
  }
606
}
607
608
1;