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 AT_SETUP([Big triangle])
132 AT_DATA_TRIANGULAR_GRAMMAR([input.y], [253])
133 AT_CHECK([bison input.y -v -o input.c])
134 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
141 # AT_DATA_STACK_TORTURE(C-PROLOGUE)
142 # ---------------------------------
143 # A parser specialized in torturing the stack size.
144 m4_define([AT_DATA_STACK_TORTURE],
145 [# A grammar of parens growing the stack thanks to right recursion.
153 static int yylex (void);
154 static void yyerror (const char *msg);
155 #define YYPRINT(File, Type, Value) \
156 fprintf (File, " (%d, stack size = %d, max = %d)", \
157 Value, yyssp - yyss + 1, yystacksize);
163 exp: WAIT_FOR_EOF exp | ;
166 yyerror (const char *msg)
168 fprintf (stderr, "%s\n", msg);
172 /* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
173 unsigned int yylval_max;
185 main (int argc, const char **argv)
188 yylval = atoi (argv[1]);
193 AT_CHECK([bison input.y -o input.c])
194 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
198 ## -------------------------------------- ##
199 ## Exploding the Stack Size with Alloca. ##
200 ## -------------------------------------- ##
202 AT_SETUP([Exploding the Stack Size with Alloca])
204 AT_DATA_STACK_TORTURE
206 # Below the limit of 200.
207 AT_CHECK([./input 20], 0, [], [ignore])
208 # Two enlargements: 2 * 2 * 200.
209 AT_CHECK([./input 900], 0, [], [ignore])
210 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
211 # multiply by two starting at 200 => 5120 is the last possible).
212 AT_CHECK([./input 10000], 1, [], [ignore])
219 ## -------------------------------------- ##
220 ## Exploding the Stack Size with Malloc. ##
221 ## -------------------------------------- ##
223 AT_SETUP([Exploding the Stack Size with Malloc])
225 AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]])
227 # Below the limit of 200.
228 AT_CHECK([./input 20], 0, [], [ignore])
229 # Two enlargements: 2 * 2 * 200.
230 AT_CHECK([./input 900], 0, [], [ignore])
231 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
232 # multiply by two starting at 200 => 5120 is the possible).
233 AT_CHECK([./input 10000], 1, [], [ignore])