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, "\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 # I have been able to go up to 2000 on my machine.
133 # I tried 3000, a 29Mb grammar file, but then my system killed bison.
134 AT_DATA_TRIANGULAR_GRAMMAR([input.y], [500])
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_HORIZONTAL_GRAMMAR(FILE-NAME, SIZE)
144 # -------------------------------------------
145 # Create FILE-NAME, containing a self checking parser for a huge
146 # horizontal grammar.
147 # FIXME: The `10 *' below are there to avoid clashes with predefined
148 # tokens. These clashes should be exercised, I'm afraid something
149 # is broken wrt previous Bisons.
150 m4_define([AT_DATA_HORIZONTAL_GRAMMAR],
151 [AT_DATA([[gengram.pl]],
152 [[#! /usr/bin/perl -w
155 my $max = $ARGV[0] || 10;
163 #define YYERROR_VERBOSE 1
166 static int yylex (void);
167 static void yyerror (const char *msg);
171 for my $size (1 .. $max)
173 print "%token \"$size\" ", $size, "\n";
183 (map { "\"$_\"" } (1 .. $max)), ";"),
191 static int counter = 1;
199 yyerror (const char *msg)
201 fprintf (stderr, "%s\\n", msg);
207 yydebug = !!getenv ("YYDEBUG");
213 AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout])
218 ## ---------------- ##
219 ## Big horizontal. ##
220 ## ---------------- ##
222 AT_SETUP([Big horizontal])
224 # I have been able to go up to 10000 on my machine, but I had to
225 # increase the maximum stack size (* 100). It gave:
231 # gengram.pl 10000 0.70s user 0.01s sys 99% cpu 0.711 total
232 # bison input.y 730.56s user 0.53s sys 99% cpu 12:12.34 total
233 # gcc -Wall input.tab.c -o input 5.81s user 0.20s sys 100% cpu 6.01 total
234 # ./input 0.00s user 0.01s sys 108% cpu 0.01 total
236 AT_DATA_HORIZONTAL_GRAMMAR([input.y], [1000])
237 AT_CHECK([bison input.y -v -o input.c])
238 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
245 # AT_DATA_STACK_TORTURE(C-PROLOGUE)
246 # ---------------------------------
247 # A parser specialized in torturing the stack size.
248 m4_define([AT_DATA_STACK_TORTURE],
249 [# A grammar of parens growing the stack thanks to right recursion.
257 static int yylex (void);
258 static void yyerror (const char *msg);
259 #define YYPRINT(File, Type, Value) \
260 fprintf (File, " (%d, stack size = %d, max = %d)", \
261 Value, yyssp - yyss + 1, yystacksize);
267 exp: WAIT_FOR_EOF exp | ;
270 yyerror (const char *msg)
272 fprintf (stderr, "%s\n", msg);
276 /* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
277 unsigned int yylval_max;
289 main (int argc, const char **argv)
292 yylval = atoi (argv[1]);
297 AT_CHECK([bison input.y -o input.c])
298 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
302 ## -------------------------------------- ##
303 ## Exploding the Stack Size with Alloca. ##
304 ## -------------------------------------- ##
306 AT_SETUP([Exploding the Stack Size with Alloca])
308 AT_DATA_STACK_TORTURE
310 # Below the limit of 200.
311 AT_CHECK([./input 20], 0, [], [ignore])
312 # Two enlargements: 2 * 2 * 200.
313 AT_CHECK([./input 900], 0, [], [ignore])
314 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
315 # multiply by two starting at 200 => 5120 is the last possible).
316 AT_CHECK([./input 10000], 1, [], [ignore])
323 ## -------------------------------------- ##
324 ## Exploding the Stack Size with Malloc. ##
325 ## -------------------------------------- ##
327 AT_SETUP([Exploding the Stack Size with Malloc])
329 AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]])
331 # Below the limit of 200.
332 AT_CHECK([./input 20], 0, [], [ignore])
333 # Two enlargements: 2 * 2 * 200.
334 AT_CHECK([./input 900], 0, [], [ignore])
335 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
336 # multiply by two starting at 200 => 5120 is the possible).
337 AT_CHECK([./input 10000], 1, [], [ignore])