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 YYERROR_VERBOSE 1
37 #define YYPRINT(File, Type, Value) \
38 fprintf (File, " (%d, stack size = %d, max = %d)", \
39 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])
76 AT_CLEANUP_FILES(input input.c)
80 ## -------------------------------------- ##
81 ## Exploding the Stack Size with Alloca. ##
82 ## -------------------------------------- ##
84 AT_SETUP([Exploding the Stack Size with Alloca])
88 # Below the limit of 200.
89 AT_CHECK([input 20], 0, [], [ignore])
90 # Two enlargements: 2 * 2 * 200.
91 AT_CHECK([input 900], 0, [], [ignore])
92 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
93 # multiply by two starting at 200 => 5120 is the last possible).
94 AT_CHECK([input 10000], 1, [], [ignore])
101 ## -------------------------------------- ##
102 ## Exploding the Stack Size with Malloc. ##
103 ## -------------------------------------- ##
105 AT_SETUP([Exploding the Stack Size with Malloc])
107 AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA_ALLOCA 0]])
109 # Below the limit of 200.
110 AT_CHECK([input 20], 0, [], [ignore])
111 # Two enlargements: 2 * 2 * 200.
112 AT_CHECK([input 900], 0, [], [ignore])
113 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
114 # multiply by two starting at 200 => 5120 is the possible).
115 AT_CHECK([input 10000], 1, [], [ignore])