maint: run update-copyright for 2014.
[m4/ericb.git] / tests / stackovf.test
blobf0ebc67b631207bcd57f8df802a04b765752ce84
1 #!/bin/sh
2 # This file is part of the GNU m4 testsuite
3 # Copyright (C) 2000, 2003, 2007, 2010, 2013-2014 Free Software
4 # Foundation, Inc.
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/>.
21 exit 77
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') &&
31 test -z "$1"
32 then
33 echo "Using $altshell because it supports ulimit"
34 exec $altshell $0 running-with-$altshell
35 exit 9
37 done
40 PATH=.:..:$PATH; export PATH;
41 : ${M4=../../src/m4}
42 type $M4
44 tmpfile=`tempfile 2> /dev/null` || tmpfile=/tmp/t.$$
45 trap 'rm -f $tmpfile; exit 1' 1 2 3 15
47 rm -f core
48 perl -e '
49 # Generate nested define sequence
50 $max=1000000;
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"
57 ' | \
59 # Limit the stack size if the shell we are running permits it
60 if (exec 2>/dev/null; ulimit -HSs 50)
61 then
62 (exec >/dev/null 2>&1; ulimit -v) && ulimitdashv=ok
63 ulimit -HSs 50
64 #ulimit -HSd 8000
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";
70 else
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
76 result=$?
77 { echo "Output from $M4:"; cat $tmpfile; }
79 exitcode=1
80 if test $result -eq 0 ; then
81 echo "TEST DID NOT WORK - m4 did not abort. Output:"
82 else
83 # See if stack overflow was diagnosed
84 case "`cat $tmpfile`" in
85 *overflow*)
86 echo "Test succeeded.";
87 exitcode=0
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:";
94 esac
97 if test -f core ; then
98 ls -l core
99 exitcode=1
102 #(test $exitcode -ne 0) &&
103 { echo "Output from $M4:"; cat $tmpfile; }
105 exit $exitcode