2 # This file is part of the GNU m4 testsuite
3 # Copyright (C) 2000, 2003, 2007-2013 Free Software Foundation, Inc.
5 # This file is part of GNU M4.
7 # GNU M4 is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GNU M4 is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Script to verify that stack overflow is diagnosed properly when
21 # there is infinite macro call nesting, provided the OS supports it.
25 # Skip this test if -L defaults to 1024 instead of 0, as that is our
26 # indicator that the OS does not support stack overflow detection.
27 ("$m4" --help | grep 'nesting.*\[0\]') >/dev/null 2>&1 \
29 echo "$0: skipping test, no stack overflow support detected in $m4"
33 # On some systems the ulimit command is available in ksh or bash but not sh
34 (exec 2>/dev/null; ulimit -Ss 300) || {
35 for altshell in bash bsh ksh zsh ; do
36 if (exec >/dev/null 2>&1; $altshell -c 'ulimit -Ss 300') && test -z "$2"
38 echo "Using $altshell because it supports ulimit"
39 exec $altshell "$0" "$@" running-with-$altshell
46 trap 'st=$?; rm -rf "$tmpdir" && exit $st' 0
47 trap '(exit $?); exit $?' 1 2 3 15
49 # Create a temporary subdirectory $tmpdir in $TMPDIR (default /tmp).
50 # Use mktemp if possible; otherwise fall back on mkdir,
51 # with $RANDOM to make collisions less likely.
55 (umask 077 && mktemp -d "$TMPDIR/m4stk-XXXXXX") 2>/dev/null
57 test -n "$tmpdir" && test -d "$tmpdir"
59 tmpdir=$TMPDIR/m4stk-$$-$RANDOM
60 (umask 077 && mkdir "$tmpdir")
62 tmpfile="$tmpdir"/m4.out
64 # Limit the stack size if the shell we are running permits it
65 if (exec 2>/dev/null; ulimit -Ss 300)
68 echo "Stack soft limit set to `ulimit -s`K";
70 echo "Can't reset stack limit - this may take a while..."
73 # Induce stack overflow.
74 echo 'define(a,a(a))a' | "$m4" > "$tmpfile" 2>&1
78 if test $result -eq 0 ; then
79 echo "Failure - $m4 did not abort"
81 # See if stack overflow was diagnosed.
82 case `cat "$tmpfile"` in
84 case `echo "$tmpdir"/*` in
88 *) echo "Failure - $m4 created unexpected core dump"
91 *) echo "Failure - $m4 aborted unexpectedly";
97 { echo "Output from $m4:"; cat $tmpfile; }