Commit eea47993 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Handle the VALGRIND command line argument.

(spawn_lyskomd): New proc, that knows how to use valgrind.
(lyskomd_fail_start): Use spawn_lyskomd.
(parse_valgrind_leak): New proc.
(check_valgrind): New proc.
(lyskomd_death): Call check_valgrind.
parent fd998c7d
......@@ -17,6 +17,10 @@ if { ![info exists EFENCE] } {
set EFENCE 0
}
if { ![info exists VALGRIND] } {
set VALGRIND 0
}
# The attach option
......@@ -33,6 +37,13 @@ if { $EFENCE == "yes" } {
set efence 0
}
# Set this to 1 if valgrind should be used.
if { $VALGRIND == "yes" } {
set valgrind 1
} else {
set valgrind 0
}
# Set MEMTRACE to the file where the trace should be sent.
# This is typically the tty where you are running the attached gdb.
......@@ -67,6 +78,8 @@ set meta_line_leader ""
# Values that show up in protocol messages
set lyskomd_host [exec python -c "import socket\nprint socket.gethostbyaddr(\"127.0.0.1\")\[0\]"]
# valgrind support
set valgrindix 0
proc efence_blurb {} {
global efence
......@@ -312,6 +325,31 @@ proc unanchored_expect {regex testname} {
unset test
}
proc spawn_lyskomd {arg} {
global valgrind
global spawn_id
set cmd "spawn"
if {$valgrind} {
set cmd "$cmd sh -c \"valgrind"
set cmd "$cmd -v"
set cmd "$cmd --num-callers=40"
set cmd "$cmd --leak-check=yes"
set cmd "$cmd --logfile-fd=25 25>valgrind.log"
}
set cmd "$cmd ../lyskomd"
if { $arg == "" } {
set cmd "$cmd -d config/lyskomd-config"
} else {
set cmd "$cmd $arg"
}
if {$valgrind} {
set cmd "$cmd\""
}
set pid [eval $cmd]
return $pid
}
proc lyskomd_start {{aux_item_conf_file ""} \
{extra_config ""} \
{base_config ""} \
......@@ -366,12 +404,7 @@ proc lyskomd_start {{aux_item_conf_file ""} \
puts $cf $extra_config
close $cf
if { $args == "" } {
set pid [spawn ../lyskomd -d config/lyskomd-config]
} else {
set pid [spawn ../lyskomd $args]
}
set pid [spawn_lyskomd $args]
set lyskomd_pid $pid
set server_id $spawn_id
......@@ -538,6 +571,86 @@ proc check_memory_usage {} {
}
}
proc parse_valgrind_leak {f} {
if {[gets $f line] < 0} {
fail "valgrind EOF in leak summary"
return 999
}
if {[regexp ": *\[0-9\]* bytes in (\[0-9\]*) block" "$line" all blocks]} {
return $blocks
}
fail "valgrind leak report parse error"
return 998
}
proc check_valgrind {} {
global valgrindix
global valgrind
if {$valgrind == 0} {
return
}
set errfound 0
set memfound 0
set errcount 0
set leakcount 0
set tracefile "valgrind.log"
set f [open $tracefile]
while {[gets $f line] >= 0} {
if {[regexp "ERROR SUMMARY: (\[0-9\]*) errors" $line match errs]} {
if {$errfound} {
fail "check_valgrind logic error 1"
} else {
set errfound 1
set errcount $errs
}
}
if {[regexp "LEAK SUMMARY:" $line]} {
set definite [parse_valgrind_leak $f]
set possible [parse_valgrind_leak $f]
set reachable [parse_valgrind_leak $f]
set leakcount [expr $definite + $possible]
# Ignore up to 10 reachable blocks. libc leaks some blocks...
if {$reachable > 10} {
set leakcount "$reachable"
}
}
}
close $f
if {$errfound == 0} {
fail "no error summary in valgrind output"
}
if {$errcount + $leakcount > 0} {
while {[file exists "valgrind-$valgrindix.log"]} {
set valgrindix [expr $valgrindix + 1]
}
set saved "valgrind-$valgrindix.log"
system "mv $tracefile $saved"
}
if {$errcount == 0} {
pass "valgrind found no errors"
} else {
fail "valgrind found $errcount error(s). See $saved."
}
if {$leakcount == 0} {
pass "valgrind found no leaks"
} else {
if {$definite} {
fail "valgrind found $definite definite leaks. See $saved."
}
if {$possible} {
fail "valgrind found $possible possible leaks. See $saved."
}
if {$reachable} {
fail "valgrind found $reachable reachable blocks. See $saved."
}
}
}
proc lyskomd_death {} {
global spawn_id
global server_id
......@@ -555,6 +668,7 @@ proc lyskomd_death {} {
}
system "cat etc/memory-usage >> usage.all"
check_memory_usage
check_valgrind
dbck_run
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment