print warnings in redis log when a test raises an exception (very likely to be caused by something like a failed assertion)

This commit is contained in:
Pieter Noordhuis 2010-05-15 23:48:08 +02:00
parent 85ecc65edc
commit fdfb02e7ff
3 changed files with 28 additions and 2 deletions

View File

@ -10556,7 +10556,7 @@ static void debugCommand(redisClient *c) {
static void _redisAssert(char *estr, char *file, int line) {
redisLog(REDIS_WARNING,"=== ASSERTION FAILED ===");
redisLog(REDIS_WARNING,"==> %s:%d '%s' is not true\n",file,line,estr);
redisLog(REDIS_WARNING,"==> %s:%d '%s' is not true",file,line,estr);
#ifdef HAVE_BACKTRACE
redisLog(REDIS_WARNING,"(forcing SIGSEGV in order to print the stack trace)");
*((char*)-1) = 'x';

View File

@ -7,7 +7,16 @@ proc test {name code okpattern} {
# if {$::testnum < $::first || $::testnum > $::last} return
puts -nonewline [format "#%03d %-68s " $::testnum $name]
flush stdout
set retval [uplevel 1 $code]
if {[catch {set retval [uplevel 1 $code]} error]} {
puts "ERROR\n\nLogged warnings:"
foreach file [glob tests/tmp/server.[pid].*/stdout] {
set warnings [warnings_from_file $file]
if {[string length $warnings] > 0} {
puts $warnings
}
}
exit 1
}
if {$okpattern eq $retval || [string match $okpattern $retval]} {
puts "PASSED"
incr ::passed

View File

@ -25,6 +25,23 @@ proc zlistAlikeSort {a b} {
string compare [lindex $a 1] [lindex $b 1]
}
# Return all log lines starting with the first line that contains a warning.
# Generally, this will be an assertion error with a stack trace.
proc warnings_from_file {filename} {
set lines [split [exec cat $filename] "\n"]
set matched 0
set result {}
foreach line $lines {
if {[regexp {^\[\d+\]\s+\d+\s+\w+\s+\d{2}:\d{2}:\d{2} \#} $line]} {
set matched 1
}
if {$matched} {
lappend result $line
}
}
join $result "\n"
}
# Return value for INFO property
proc status {r property} {
if {[regexp "\r\n$property:(.*?)\r\n" [$r info] _ value]} {