1 # Torturing Bison. -*- Autotest -*-
2 # Copyright 2001 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 AT_BANNER([[Torture Tests.]])
22 # AT_DATA_STACK_TORTURE(C-PROLOGUE)
23 # ---------------------------------
24 # A parser specialized in torturing the stack size.
25 m4_define([AT_DATA_STACK_TORTURE],
26 [# A grammar of parens growing the stack thanks to right recursion.
34 static int yylex (void);
35 static void yyerror (const char *msg);
36 #define YYPRINT(File, Type, Value) \
37 fprintf (File, " (%d, stack size = %d, max = %d)", \
38 Value, yyssp - yyss + 1, yystacksize);
44 exp: WAIT_FOR_EOF exp | ;
47 yyerror (const char *msg)
49 fprintf (stderr, "%s\n", msg);
53 /* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
54 unsigned int yylval_max;
66 main (int argc, const char **argv)
69 yylval = atoi (argv[1]);
74 AT_CHECK([bison input.y -o input.c])
75 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
79 ## -------------------------------------- ##
80 ## Exploding the Stack Size with Alloca. ##
81 ## -------------------------------------- ##
83 AT_SETUP([Exploding the Stack Size with Alloca])
87 # Below the limit of 200.
88 AT_CHECK([input 20], 0, [], [ignore])
89 # Two enlargements: 2 * 2 * 200.
90 AT_CHECK([input 900], 0, [], [ignore])
91 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
92 # multiply by two starting at 200 => 5120 is the last possible).
93 AT_CHECK([input 10000], 1, [], [ignore])
100 ## -------------------------------------- ##
101 ## Exploding the Stack Size with Malloc. ##
102 ## -------------------------------------- ##
104 AT_SETUP([Exploding the Stack Size with Malloc])
106 AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]])
108 # Below the limit of 200.
109 AT_CHECK([input 20], 0, [], [ignore])
110 # Two enlargements: 2 * 2 * 200.
111 AT_CHECK([input 900], 0, [], [ignore])
112 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
113 # multiply by two starting at 200 => 5120 is the possible).
114 AT_CHECK([input 10000], 1, [], [ignore])