summaryrefslogtreecommitdiff
path: root/src/cmd/ksh93/tests/leaks.sh
blob: 8d89b05ed6d35099c832f3b952abb463b54ee2aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
########################################################################
#                                                                      #
#               This software is part of the ast package               #
#          Copyright (c) 1982-2011 AT&T Intellectual Property          #
#                      and is licensed under the                       #
#                 Eclipse Public License, Version 1.0                  #
#                    by AT&T Intellectual Property                     #
#                                                                      #
#                A copy of the License is available at                 #
#          http://www.eclipse.org/org/documents/epl-v10.html           #
#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
#                                                                      #
#              Information and Software Systems Research               #
#                            AT&T Research                             #
#                           Florham Park NJ                            #
#                                                                      #
#                  David Korn <dgk@research.att.com>                   #
#                                                                      #
########################################################################
builtin vmstate 2>/dev/null || exit 0

function err_exit
{
	print -u2 -n "\t"
	print -u2 -r ${Command}[$1]: "${@:2}"
	let Errors+=1
}
alias err_exit='err_exit $LINENO'

Command=${0##*/}
integer Errors=0

# test for variable reset leak #

function test_reset
{
	integer i n=$1

	for ((i = 0; i < n; i++))
	do	u=$i
	done
}

n=1000

# one round to get to steady state -- sensitive to -x

test_reset $n
a=0$(vmstate --format='+%(size)u')
b=0$(vmstate --format='+%(size)u')

test_reset $n
a=0$(vmstate --format='+%(size)u')
test_reset $n
b=0$(vmstate --format='+%(size)u')

if	(( b > a ))
then	err_exit "variable value reset memory leak -- $((b-a)) bytes after $n iterations"
fi

# buffer boundary tests

for exp in 65535 65536
do	got=$($SHELL -c 'x=$(printf "%.*c" '$exp' x); print ${#x}' 2>&1)
	[[ $got == $exp ]] || err_exit "large command substitution failed -- expected $exp, got $got"
done

exit $((Errors<125?Errors:125))