leaks.exp 3 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Test suite for lyskomd.
# Copyright (C) 1998-1999  Lysator Academic Computer Association.
#
# This file is part of the LysKOM server.
# 
# LysKOM is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by 
# the Free Software Foundation; either version 1, or (at your option) 
# any later version.
# 
# LysKOM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License
# along with LysKOM; see the file COPYING.  If not, write to
# Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
# or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
# MA 02139, USA.
#
# Please mail bug reports to bug-lyskom@lysator.liu.se. 


25 26
# Common code for leaks checking

27
source "$srcdir/config/prot-a.exp"
28 29 30 31 32 33

set blocks_base 0
set strings_base 0
set blocks_usage 0
set strings_usage 0

34
proc startup_leaks {{aux "$srcdir/lyskomd.0/aux-items.conf"} { config "" }} {
David Byers's avatar
David Byers committed
35
    lyskomd_start "$aux" "$config"
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    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
93
    if { [expr $strings_usage != $strings_base] } {
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        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"
}