mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-15 04:32:24 +00:00
tests/leaks.sh: Avoid spurious leak results
Due to the mysterious workings of vmalloc(3), occasionally a spurious leak result still showed up. The leak is always smaller in bytes than the number of test iterations, so it can't be a leak in the thing tested. src/cmd/ksh93/tests/leaks.sh: - Run each test N=512 times. - Use a 'err_exit_if_leak' function to add a tolerance of N/4 (128) bytes to each test result check. Resolves: https://github.com/ksh93/ksh/issues/100
This commit is contained in:
parent
05081dfc1c
commit
3fb04b2807
1 changed files with 21 additions and 16 deletions
|
@ -37,7 +37,6 @@ function getmem
|
||||||
{
|
{
|
||||||
vmstate --format='%(busy_size)u'
|
vmstate --format='%(busy_size)u'
|
||||||
}
|
}
|
||||||
unit=bytes
|
|
||||||
n=$(getmem)
|
n=$(getmem)
|
||||||
if ! let "($n) == ($n) && n > 0" # not a non-zero number?
|
if ! let "($n) == ($n) && n > 0" # not a non-zero number?
|
||||||
then err\_exit "$LINENO" "vmstate built-in command not functioning; tests cannot be run"
|
then err\_exit "$LINENO" "vmstate built-in command not functioning; tests cannot be run"
|
||||||
|
@ -58,7 +57,18 @@ function test_reset
|
||||||
# Initialise variables used below to avoid false leaks
|
# Initialise variables used below to avoid false leaks
|
||||||
before=0 after=0 i=0 u=0
|
before=0 after=0 i=0 u=0
|
||||||
|
|
||||||
N=1000
|
# Number of iterations for each test
|
||||||
|
N=512
|
||||||
|
|
||||||
|
# Check results. Add a tolerance of N/4 bytes to avoid false leaks.
|
||||||
|
# The function has 'err_exit' in the name so that shtests counts each call as at test.
|
||||||
|
function err_exit_if_leak
|
||||||
|
{
|
||||||
|
if ((after > before + N / 4))
|
||||||
|
then err\_exit "$1" "$2 (leaked $((after - before)) bytes after $N iterations)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
alias err_exit_if_leak='err_exit_if_leak "$LINENO"'
|
||||||
|
|
||||||
# one round to get to steady state -- sensitive to -x
|
# one round to get to steady state -- sensitive to -x
|
||||||
|
|
||||||
|
@ -67,10 +77,7 @@ test_reset $N
|
||||||
before=$(getmem)
|
before=$(getmem)
|
||||||
test_reset $N
|
test_reset $N
|
||||||
after=$(getmem)
|
after=$(getmem)
|
||||||
|
err_exit_if_leak "variable value reset memory leak"
|
||||||
if (( after > before ))
|
|
||||||
then err_exit "variable value reset memory leak -- $((after - before)) $unit after $N iterations"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# buffer boundary tests
|
# buffer boundary tests
|
||||||
|
|
||||||
|
@ -82,32 +89,32 @@ done
|
||||||
data="(v=;sid=;di=;hi=;ti='1328244300';lv='o';id='172.3.161.178';var=(k='conn_num._total';u=;fr=;l='Number of Connections';n='22';t='number';))"
|
data="(v=;sid=;di=;hi=;ti='1328244300';lv='o';id='172.3.161.178';var=(k='conn_num._total';u=;fr=;l='Number of Connections';n='22';t='number';))"
|
||||||
read -C stat <<< "$data"
|
read -C stat <<< "$data"
|
||||||
before=$(getmem)
|
before=$(getmem)
|
||||||
for ((i=0; i < 100; i++))
|
for ((i=0; i < N; i++))
|
||||||
do print -r -- "$data"
|
do print -r -- "$data"
|
||||||
done | while read -u$n -C stat
|
done | while read -u$n -C stat
|
||||||
do :
|
do :
|
||||||
done {n}<&0-
|
done {n}<&0-
|
||||||
after=$(getmem)
|
after=$(getmem)
|
||||||
(( after > before )) && err_exit "memory leak with read -C when deleting compound variable (leaked $((after - before)) $unit)"
|
err_exit_if_leak "memory leak with read -C when deleting compound variable"
|
||||||
|
|
||||||
# extra 'read's to get to steady state
|
# extra 'read's to get to steady state
|
||||||
for ((i=0; i < 10; i++))
|
for ((i=0; i < 10; i++))
|
||||||
do read -C stat <<< "$data"
|
do read -C stat <<< "$data"
|
||||||
done
|
done
|
||||||
before=$(getmem)
|
before=$(getmem)
|
||||||
for ((i=0; i < 100; i++))
|
for ((i=0; i < N; i++))
|
||||||
do read -C stat <<< "$data"
|
do read -C stat <<< "$data"
|
||||||
done
|
done
|
||||||
after=$(getmem)
|
after=$(getmem)
|
||||||
# this test can show minor variations in memory usage when run with shcomp: https://github.com/ksh93/ksh/issues/70
|
# this test can show minor variations in memory usage when run with shcomp: https://github.com/ksh93/ksh/issues/70
|
||||||
(( after > before+128 )) && err_exit "memory leak with read -C when using <<< (leaked $((after - before)) $unit)"
|
err_exit_if_leak "memory leak with read -C when using <<<"
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
# Unsetting an associative array shouldn't cause a memory leak
|
# Unsetting an associative array shouldn't cause a memory leak
|
||||||
# See https://www.mail-archive.com/ast-users@lists.research.att.com/msg01016.html
|
# See https://www.mail-archive.com/ast-users@lists.research.att.com/msg01016.html
|
||||||
typeset -A stuff
|
typeset -A stuff
|
||||||
before=$(getmem)
|
before=$(getmem)
|
||||||
for (( i=0; i<100; i++ ))
|
for (( i=0; i < N; i++ ))
|
||||||
do
|
do
|
||||||
unset stuff[xyz]
|
unset stuff[xyz]
|
||||||
typeset -A stuff[xyz]
|
typeset -A stuff[xyz]
|
||||||
|
@ -119,8 +126,7 @@ do
|
||||||
done
|
done
|
||||||
unset stuff
|
unset stuff
|
||||||
after=$(getmem)
|
after=$(getmem)
|
||||||
(( after > before )) && err_exit 'unset of associative array causes memory leak' \
|
err_exit_if_leak 'unset of associative array causes memory leak'
|
||||||
"(leaked $((after - before)) $unit)"
|
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
# Memory leak when resetting PATH and clearing hash table
|
# Memory leak when resetting PATH and clearing hash table
|
||||||
|
@ -129,13 +135,12 @@ command -v ls >/dev/null # add something to hash table
|
||||||
PATH=/dev/null true # set/restore PATH & clear hash table
|
PATH=/dev/null true # set/restore PATH & clear hash table
|
||||||
# ...test for leak:
|
# ...test for leak:
|
||||||
before=$(getmem)
|
before=$(getmem)
|
||||||
for ((i=0; i<100; i++))
|
for ((i=0; i < N; i++))
|
||||||
do PATH=/dev/null true # set/restore PATH & clear hash table
|
do PATH=/dev/null true # set/restore PATH & clear hash table
|
||||||
command -v ls # do PATH search, add to hash table
|
command -v ls # do PATH search, add to hash table
|
||||||
done >/dev/null
|
done >/dev/null
|
||||||
after=$(getmem)
|
after=$(getmem)
|
||||||
(( after > before+32 )) && err_exit 'memory leak on PATH reset before subshell PATH search' \
|
err_exit_if_leak 'memory leak on PATH reset before subshell PATH search'
|
||||||
"(leaked $((after - before)) $unit)"
|
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
Loading…
Reference in a new issue