1 # Torturing Bison. -*- Autotest -*-
2 # Copyright (C) 2001, 2002 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 ## ------------------------------------- ##
23 ## Creating a large artificial grammar. ##
24 ## ------------------------------------- ##
26 # AT_DATA_TRIANGULAR_GRAMMAR(FILE-NAME, SIZE)
27 # -------------------------------------------
28 # Create FILE-NAME, containing a self checking parser for a huge
30 # FIXME: The `10 *' below are there to avoid clashes with predefined
31 # tokens. These clashes should be exercised, I'm afraid something
32 # is broken wrt previous Bisons.
33 m4_define([AT_DATA_TRIANGULAR_GRAMMAR],
34 [AT_DATA([[gengram.pl]],
38 my $max = $ARGV[0] || 10;
46 #define YYERROR_VERBOSE 1
49 static int yylex (void);
50 static void yyerror (const char *msg);
61 for my $size (1 .. $max)
63 print "%token \"$size\" ", $size * 10, "\n";
69 exp { assert (\@S|@1 == 0); \$\$ = \@S|@1; }
70 | input exp { assert (\@S|@2 == \@S|@1 + 1); \$\$ = \@S|@2; }
78 for my $size (1 .. $max)
81 print wrap ("| ", " ",
82 (map { "\"$_\"" } (1 .. $size)),
84 " { \$\$ = $size; }\n";
97 else if (inner > outer)
107 yyerror (const char *msg)
109 fprintf (stderr, "%s\\n", msg);
115 yydebug = !!getenv ("YYDEBUG");
121 AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout])
130 # Arg, the upper limit, currently, is 124. Afterwards, the
131 # executable dumps core...
132 AT_SETUP([Big triangle])
134 AT_DATA_TRIANGULAR_GRAMMAR([input.y], [124])
135 AT_CHECK([bison input.y -v -o input.c])
136 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
143 # AT_DATA_STACK_TORTURE(C-PROLOGUE)
144 # ---------------------------------
145 # A parser specialized in torturing the stack size.
146 m4_define([AT_DATA_STACK_TORTURE],
147 [# A grammar of parens growing the stack thanks to right recursion.
155 static int yylex (void);
156 static void yyerror (const char *msg);
157 #define YYPRINT(File, Type, Value) \
158 fprintf (File, " (%d, stack size = %d, max = %d)", \
159 Value, yyssp - yyss + 1, yystacksize);
165 exp: WAIT_FOR_EOF exp | ;
168 yyerror (const char *msg)
170 fprintf (stderr, "%s\n", msg);
174 /* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
175 unsigned int yylval_max;
187 main (int argc, const char **argv)
190 yylval = atoi (argv[1]);
195 AT_CHECK([bison input.y -o input.c])
196 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
200 ## -------------------------------------- ##
201 ## Exploding the Stack Size with Alloca. ##
202 ## -------------------------------------- ##
204 AT_SETUP([Exploding the Stack Size with Alloca])
206 AT_DATA_STACK_TORTURE
208 # Below the limit of 200.
209 AT_CHECK([./input 20], 0, [], [ignore])
210 # Two enlargements: 2 * 2 * 200.
211 AT_CHECK([./input 900], 0, [], [ignore])
212 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
213 # multiply by two starting at 200 => 5120 is the last possible).
214 AT_CHECK([./input 10000], 1, [], [ignore])
221 ## -------------------------------------- ##
222 ## Exploding the Stack Size with Malloc. ##
223 ## -------------------------------------- ##
225 AT_SETUP([Exploding the Stack Size with Malloc])
227 AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]])
229 # Below the limit of 200.
230 AT_CHECK([./input 20], 0, [], [ignore])
231 # Two enlargements: 2 * 2 * 200.
232 AT_CHECK([./input 900], 0, [], [ignore])
233 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
234 # multiply by two starting at 200 => 5120 is the possible).
235 AT_CHECK([./input 10000], 1, [], [ignore])