Commit 33ae5742 authored by David Byers's avatar David Byers

Test cases to detect memory leaks

parent 5a8c2566
# $Id: Makefile.am,v 1.10 1998/10/06 07:26:50 ceder Exp $
# $Id: Makefile.am,v 1.11 1998/12/30 17:37:41 byers Exp $
# Copyright (C) 1998 Lysator Academic Computer Association.
#
# This file is part of the LysKOM server.
......@@ -34,7 +34,8 @@ EXTRA_DIST = .cvsignore \
tcpconnect.py \
l2g.0/00.exp l2g.0/01.exp
MOSTLYCLEANFILES = .gdbinit site.exp *.sum *.log
MOSTLYCLEANFILES = .gdbinit site.exp *.sum *.log usage-base.tmp \
lyskomd.*.usage lyskomd.*.base
test_l2g_SOURCES = test-l2g.c
test_l2g_LDADD = ../libcheck.a $(LDADD)
......
# Common code for leaks checking
source "config/prot-a.exp"
set blocks_base 0
set strings_base 0
set blocks_usage 0
set strings_usage 0
proc startup_leaks {{aux "lyskomd.0/aux-items.conf"}} {
lyskomd_start "$aux"
client_start 0
talk_to client 0
send "A[holl "DejaGnu Leaks Test"]\n"
simple_expect "LysKOM"
kom_accept_async "0 { }"
kom_login 5 "gazonk" 0
}
proc shutdown_leaks {} {
kom_logout
kom_login 5 "gazonk" 0
kom_enable 255
send "9999 44 0\n"
simple_expect "=9999"
client_death 0
lyskomd_death
}
proc read_memory_file {} {
set allocated_strings 0
set allocated_blocks 0
set f [ open "etc/memory-usage" ]
while { [ gets $f line] >= 0 } {
if { [regexp "Allocated blocks .grand total." $line] } {
set allocated_blocks [lindex "$line" [expr [llength "$line"] - 1]]
} elseif { [regexp "Allocated strings" $line] } {
set allocated_strings [lindex "$line" [expr [llength "$line"] - 1]]
}
}
close $f
return "$allocated_blocks $allocated_strings"
}
proc read_usage_base {} {
global blocks_base
global strings_base
set val [read_memory_file]
set blocks_base [lindex $val 0]
set strings_base [lindex $val 1]
save_memory_file "usage-base.tmp"
}
proc check_usage {test id} {
global blocks_usage
global strings_usage
global blocks_base
global strings_base
set val [read_memory_file]
set blocks_usage [lindex $val 0]
set strings_usage [lindex $val 1]
set succeed 1
if { [expr $strings_usage == $strings_base] } {
fail "$test (strings) See lyskomd.$id.\{usage,base\}"
set succeed 0
}
if { [expr $blocks_usage != $blocks_base] } {
fail "$test (blocks) See lyskomd.$id.\{base,usage\}"
set succeed 0
}
if { $succeed } {
pass "$test"
} else {
save_memory_file "lyskomd.$id.usage"
system "cp usage-base.tmp lyskomd.$id.base"
}
}
proc save_memory_file {target} {
system "cp etc/memory-usage $target"
}
# Check for memory leaks
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test for leaks in text creation
startup_leaks
send "1000 86 [holl "Memory leaks suck"] 1 { 0 5 } 1 { 1000 00000000 0 [holl "Aux-items rock!"] }\n"
simple_expect "=1000 1"
shutdown_leaks
read_usage_base
startup_leaks
kom_accept_async "2 { 0 15 }"
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr 1000 + $i] 86 [holl "Memory leaks suck"] 1 { 0 5 } 1 { 1000 00000000 0 [holl "Aux-items rock!"] }\n"
simple_expect ":16 0\[^\n\]*"
simple_expect ":18 15\[^\n\]*"
simple_expect "=[expr 1000 + $i] [expr 1 + $i]"
}
shutdown_leaks
check_usage "Text creation" "leaks00"
# Inherit a bunch of aux-items a bunch of levels
# Validate a bunch of aux-items with a regexp
# Create a bunch of confs
# ----------------------------------------------------------------------
# Test for leaks in conference creation
read_versions
source "config/leaks.exp"
startup_leaks
send "2000 88 [holl "Leaks Conference 2000"] 00000000 1 { 1000 00000000 0 [holl "Aux-items rock!"] }\n"
simple_expect "=2000 6"
shutdown_leaks
read_usage_base
startup_leaks
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr 2000 + $i] 88 [holl "Leaks Conference [expr 2000 + $i]"] 00000000 1 { 1000 00000000 0 [holl "Aux-items rock!"] }\n"
simple_expect "=[expr 2000 + $i] [expr 6 + $i]"
}
shutdown_leaks
check_usage "Conference creation" "leaks01"
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test for leaks in person creation
startup_leaks
send "3000 89 [holl "Leaky Memory 3000"] [holl "wossit"] 1 { 1000 00000000 0 [holl "Aux-items rock!"] }\n"
simple_expect "=3000 6"
shutdown_leaks
read_usage_base
startup_leaks
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr 3000 + $i] 89 [holl "Leaky Memory [expr 3000 + $i]"] [holl "wossit"] 1 { 1000 00000000 0 [holl "Aux-items rock!"] }\n"
simple_expect "=[expr 3000 + $i] [expr 6 + $i]"
}
shutdown_leaks
check_usage "Person creation" "leaks02"
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test for leaks in aux-item parsing
startup_leaks
send "1000 86 [holl "Parse me!"] 1 { 0 5 } 1 { 1000 00000000 0 [holl "Memory leaks blow!"] }\n"
simple_expect "=1000 1"
shutdown_leaks
read_usage_base
startup_leaks
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr $i + 1000 ] 86 [holl "Parse me"] 1 { 0 5 } 4 { 1000 00000000 0 [holl "Memory leaks blow!"] 1000 00000000 0 [holl "Memory leaks blow!"] 1000 00000000 0 [holl "Memory leaks blow!"] 1000 00000000 0 [holl "Memory leaks blow!"] }\n"
simple_expect "=[expr $i + 1000] [expr 1 + $i]"
}
shutdown_leaks
check_usage "Aux-item parser" "leaks03"
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test adding aux-items en masse
startup_leaks
send "1000 86 [holl "Sample test"] 1 { 0 5 } 0 { }\n"
simple_expect "=1000 1"
shutdown_leaks
read_usage_base
startup_leaks
send "1000 86 [holl "Sample test"] 1 { 0 5 } 0 { }\n"
simple_expect "=1000 1"
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr $i + 1000] 92 1 0 { } 3 { 1000 00000000 0 [holl "Lost my memory blues"] 1000 00000000 0 [holl "Lost my memory blues too"] 1000 00000000 0 [holl "Lost my memory blues again"] }\n"
simple_expect "=[expr $i + 1000]"
}
shutdown_leaks
check_usage "Adding aux-items" "leaks04"
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test adding and deleting aux-items en masse
startup_leaks
send "1000 86 [holl "Sample test"] 1 { 0 5 } 0 { }\n"
simple_expect "=1000 1"
shutdown_leaks
read_usage_base
startup_leaks
send "1000 86 [holl "Sample test"] 1 { 0 5 } 0 { }\n"
simple_expect "=1000 1"
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr $i + 1000] 92 1 0 { } 3 { 1000 00000000 0 [holl "Lost my memory blues"] 1000 00000000 0 [holl "Lost my memory blues too"] 1000 00000000 0 [holl "Lost my memory blues again"] }\n"
simple_expect "=[expr $i + 1000]"
}
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr $i + 2000] 92 1 3 { [expr $i * 3] [expr $i * 3 + 1] [expr $i * 3 + 2] } 0 { }\n"
simple_expect "=[expr $i + 2000]"
}
shutdown_leaks
check_usage "Adding and deleting aux-items" "leaks05"
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test inheriting a pile of aux-items
startup_leaks
shutdown_leaks
read_usage_base
startup_leaks
send "1000 86 [holl "Sample test"] 1 { 0 5 } 3 { 1000 01000000 0 [holl "Inherit me!"] 1000 01000000 0 [holl "Inherit me too!"] 1000 01000000 0 [holl "Inherit me three!"] }\n"
simple_expect "=1000 1"
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr 1000 + $i] 86 [holl "Sample test"] 2 { 0 5 2 [expr $i + 1] } 1 { 1000 00000000 0 [holl "Don't inherit me"] }\n"
simple_expect "=[expr 1000 + $i] [expr 2 + $i]"
}
shutdown_leaks
check_usage "Adding and inheriting items" "leaks06"
# Check for memory leaks
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test for leaks in system aux items
startup_leaks
shutdown_leaks
read_usage_base
startup_leaks
kom_enable 255
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr $i + 1000] 95 0 { } 3 { 1000 00000000 0 [holl "Lost my memory blues"] 1000 00000000 0 [holl "Lost my memory blues too"] 1000 00000000 0 [holl "Lost my memory blues again"] }\n"
simple_expect "=[expr $i + 1000]"
}
shutdown_leaks
check_usage "Adding system aux-items" leaks07
# Check for memory leaks
read_versions
source "config/leaks.exp"
# ----------------------------------------------------------------------
# Test for leaks in system aux items
startup_leaks
shutdown_leaks
read_usage_base
startup_leaks
kom_enable 255
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr $i + 1000] 95 0 { } 3 { 1000 00000000 0 [holl "Lost my memory blues"] 1000 00000000 0 [holl "Lost my memory blues too"] 1000 00000000 0 [holl "Lost my memory blues again"] }\n"
simple_expect "=[expr $i + 1000]"
}
for { set i 0 } { $i < 200 } { incr i 1 } {
send "[expr $i + 2000] 95 3 { [expr $i * 3] [expr $i * 3 + 1] [expr $i * 3 + 2] } 0 { }\n"
simple_expect "=[expr $i + 2000]"
}
shutdown_leaks
check_usage "Adding and removing system aux-items" leaks08
read_versions
source "config/leaks.exp"
startup_leaks ""
shutdown_leaks
read_usage_base
source "lyskomd.0/00.exp"
check_usage "lyskomd test 00" 00
source "lyskomd.0/01.exp"
check_usage "lyskomd test 01" 01
source "lyskomd.0/02.exp"
check_usage "lyskomd test 02" 02
source "lyskomd.0/03.exp"
check_usage "lyskomd test 03" 03
source "lyskomd.0/05.exp"
check_usage "lyskomd test 05" 05
source "lyskomd.0/06.exp"
check_usage "lyskomd test 06" 06
startup_leaks "lyskomd.0/aux-items.conf"
shutdown_leaks
read_usage_base
source "lyskomd.0/04.exp"
check_usage "lyskomd test 04" 04
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