3 # Script to verify that stack overflow is diagnosed properly when
4 # there is infinite macro call nesting.
5 # (causes coredump in m4-1.0.3)
7 # On some systems the ulimit command is available in ksh or bash but not sh
8 (exec 2>/dev
/null
; ulimit -HSs 300) ||
{
9 for altshell
in bash bsh ksh
; do
10 if (exec >/dev
/null
2>&1; $altshell -c 'ulimit -HSs 300') &&
13 echo "Using $altshell because it supports ulimit"
14 exec $altshell $0 running-with-
$altshell
20 PATH
=.
:..
:$PATH; export PATH
;
24 tmpfile
=`tempfile 2> /dev/null` || tmpfile
=/tmp
/t.$$
25 trap 'rm -f $tmpfile; exit 1' 1 2 3 15
29 # Generate nested define sequence
31 for ($i=0; $i<$max; $i++) {
32 print "define(X$i,\n";
34 for ($i=$max-1; $i>=0; $i--) {
35 print "body with substance no. $i)dnl\n"
39 # Limit the stack size if the shell we are running permits it
40 if (exec 2>/dev
/null
; ulimit -HSs 50)
42 (exec >/dev
/null
2>&1; ulimit -v) && ulimitdashv
=ok
45 #test -n "$ulimitdashv" && ulimit -HSv 8000
46 echo "Stack limit is `ulimit -s`K";
47 echo "Heap limit is `ulimit -d`K";
48 test -n "$ulimitdashv" &&
49 echo "VMem limit is `ulimit -v`K";
51 echo "Can't reset stack limit - this may take a while..."
53 $M4 -L999999999 > $tmpfile 2>&1
58 if test $result -eq 0 ; then
59 echo "TEST DID NOT WORK - m4 did not abort. Output:"
61 # See if stack overflow was diagnosed
62 case "`cat $tmpfile`" in
64 echo "Test succeeded.";
68 echo "*** Test is INCONCLUSIVE (ran out of heap before stack overflow)";
70 *) echo "*** Test FAILED. $M4 aborted unexpectedly. Output:";
75 if test -f core
; then
80 #(test $exitcode -ne 0) &&
81 { echo "Output from $M4:"; cat $tmpfile; }