2 # This file is part of the GNU m4 testsuite
3 # Copyright (C) 2000, 2003, 2007, 2010, 2013-2014 Free Software
6 # This file is part of GNU M4.
8 # GNU M4 is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # GNU M4 is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # Script to verify that stack overflow is diagnosed properly when
24 # there is infinite macro call nesting.
25 # (causes coredump in m4-1.0.3)
27 # On some systems the ulimit command is available in ksh or bash but not sh
28 (exec 2>/dev
/null
; ulimit -HSs 300) ||
{
29 for altshell
in bash bsh ksh
; do
30 if (exec >/dev
/null
2>&1; $altshell -c 'ulimit -HSs 300') &&
33 echo "Using $altshell because it supports ulimit"
34 exec $altshell $0 running-with-
$altshell
40 PATH
=.
:..
:$PATH; export PATH
;
44 tmpfile
=`tempfile 2> /dev/null` || tmpfile
=/tmp
/t.$$
45 trap 'rm -f $tmpfile; exit 1' 1 2 3 15
49 # Generate nested define sequence
51 for ($i=0; $i<$max; $i++) {
52 print "define(X$i,\n";
54 for ($i=$max-1; $i>=0; $i--) {
55 print "body with substance no. $i)dnl\n"
59 # Limit the stack size if the shell we are running permits it
60 if (exec 2>/dev
/null
; ulimit -HSs 50)
62 (exec >/dev
/null
2>&1; ulimit -v) && ulimitdashv
=ok
65 #test -n "$ulimitdashv" && ulimit -HSv 8000
66 echo "Stack limit is `ulimit -s`K";
67 echo "Heap limit is `ulimit -d`K";
68 test -n "$ulimitdashv" &&
69 echo "VMem limit is `ulimit -v`K";
71 echo "Can't reset stack limit - this may take a while..."
73 #strace -o /tmp/aaa $M4 -L999999999 > $tmpfile 2>&1
74 $M4 -L999999999 > $tmpfile 2>&1
77 { echo "Output from $M4:"; cat $tmpfile; }
80 if test $result -eq 0 ; then
81 echo "TEST DID NOT WORK - m4 did not abort. Output:"
83 # See if stack overflow was diagnosed
84 case "`cat $tmpfile`" in
86 echo "Test succeeded.";
89 *ut
*of
*emory
*|
*emory
*xhausted
)
90 echo "*** Test is INCONCLUSIVE (ran out of heap before stack overflow)";
92 *) echo "*** Test FAILED. $M4 aborted unexpectedly. Output:";
97 if test -f core
; then
102 #(test $exitcode -ne 0) &&
103 { echo "Output from $M4:"; cat $tmpfile; }