source: trunk/essentials/sys-devel/m4/examples/stackovf.sh

Last change on this file was 3090, checked in by bird, 18 years ago

m4 1.4.8

File size: 1.9 KB
Line 
1#!/bin/sh
2
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)
6
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') &&
11 test -z "$1"
12 then
13 echo "Using $altshell because it supports ulimit"
14 exec $altshell $0 running-with-$altshell
15 exit 9
16 fi
17 done
18}
19
20PATH=.:..:$PATH; export PATH;
21M4=m4
22type $M4
23
24tmpfile=`tempfile 2> /dev/null` || tmpfile=/tmp/t.$$
25trap 'rm -f $tmpfile; exit 1' 1 2 3 15
26
27rm -f core
28perl -e '
29# Generate nested define sequence
30$max=1000000;
31for ($i=0; $i<$max; $i++) {
32 print "define(X$i,\n";
33}
34for ($i=$max-1; $i>=0; $i--) {
35 print "body with substance no. $i)dnl\n"
36}
37' | \
38(
39# Limit the stack size if the shell we are running permits it
40if (exec 2>/dev/null; ulimit -HSs 50)
41then
42 (exec >/dev/null 2>&1; ulimit -v) && ulimitdashv=ok
43 ulimit -HSs 50
44 #ulimit -HSd 8000
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";
50else
51 echo "Can't reset stack limit - this may take a while..."
52fi
53$M4 -L999999999 > $tmpfile 2>&1
54)
55result=$?
56
57exitcode=1
58if test $result -eq 0 ; then
59 echo "TEST DID NOT WORK - m4 did not abort. Output:"
60else
61 # See if stack overflow was diagnosed
62 case "`cat $tmpfile`" in
63 *overflow*)
64 echo "Test succeeded.";
65 exitcode=0
66 ;;
67 *ut*of*emory*)
68 echo "*** Test is INCONCLUSIVE (ran out of heap before stack overflow)";
69 ;;
70 *) echo "*** Test FAILED. $M4 aborted unexpectedly. Output:";
71 ;;
72 esac
73fi
74
75if test -f core ; then
76 ls -l core
77 exitcode=1
78fi
79
80#(test $exitcode -ne 0) &&
81 { echo "Output from $M4:"; cat $tmpfile; }
82
83exit $exitcode
Note: See TracBrowser for help on using the repository browser.