2 # $Id: xmalloc.t 5379 2002-03-31 21:45:12Z rra $
4 # Test suite for xmalloc and friends.
6 # The count starts at 1 and is updated each time ok is printed. printcount
7 # takes "ok" or "not ok".
11 count=`expr $count + 1`
14 # Run a program expected to succeed, and print ok if it does.
16 output=`$xmalloc "$1" "$2" "$3" 2>&1 >/dev/null`
18 if test $status = 0 && test -z "$output" ; then
21 if test $status = 2 ; then
22 printcount "ok" "# skip - no data limit support"
30 # Run a program expected to fail and make sure it fails with an exit status
31 # of 2 and the right failure message. Strip the colon and everything after
32 # it off the error message since it's system-specific.
34 output=`$xmalloc "$1" "$2" "$3" 2>&1 >/dev/null`
36 output=`echo "$output" | sed 's/:.*//'`
37 if test $status = 1 && test x"$output" = x"$4" ; then
40 if test $status = 2 ; then
41 printcount "ok" "# skip - no data limit support"
50 # Find where the helper program is.
52 for file in ./xmalloc lib/xmalloc ../xmalloc ; do
53 [ -x $file ] && xmalloc=$file
59 # First run the tests expected to succeed.
60 runsuccess "m" "21" "0"
61 runsuccess "m" "128000" "0"
62 runsuccess "m" "0" "0"
63 runsuccess "r" "21" "0"
64 runsuccess "r" "128000" "0"
65 runsuccess "s" "21" "0"
66 runsuccess "s" "128000" "0"
67 runsuccess "n" "21" "0"
68 runsuccess "n" "128000" "0"
69 runsuccess "c" "24" "0"
70 runsuccess "c" "128000" "0"
72 # Now limit our memory to 96KB and then try the large ones again, all of
74 runfailure "m" "128000" "96000" \
75 "failed to malloc 128000 bytes at lib/xmalloc.c line 36"
76 runfailure "r" "128000" "96000" \
77 "failed to realloc 128000 bytes at lib/xmalloc.c line 62"
78 runfailure "s" "64000" "96000" \
79 "failed to strdup 64000 bytes at lib/xmalloc.c line 91"
80 runfailure "n" "64000" "96000" \
81 "failed to strndup 64000 bytes at lib/xmalloc.c line 115"
82 runfailure "c" "128000" "96000" \
83 "failed to calloc 128000 bytes at lib/xmalloc.c line 137"
85 # Check our custom error handler.
86 runfailure "M" "128000" "96000" "malloc 128000 lib/xmalloc.c 36"
87 runfailure "R" "128000" "96000" "realloc 128000 lib/xmalloc.c 62"
88 runfailure "S" "64000" "96000" "strdup 64000 lib/xmalloc.c 91"
89 runfailure "N" "64000" "96000" "strndup 64000 lib/xmalloc.c 115"
90 runfailure "C" "128000" "96000" "calloc 128000 lib/xmalloc.c 137"
92 # Check the smaller ones again just for grins.
93 runsuccess "m" "21" "96000"
94 runsuccess "r" "32" "96000"
95 runsuccess "s" "64" "96000"
96 runsuccess "n" "20" "96000"
97 runsuccess "c" "24" "96000"