# Torturing Bison. -*- Autotest -*- # Copyright 2001 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. AT_BANNER([[Torture Tests.]]) # AT_DATA_STACK_TORTURE(C-PROLOGUE) # --------------------------------- # A parser specialized in torturing the stack size. m4_define([AT_DATA_STACK_TORTURE], [# A grammar of parens growing the stack thanks to right recursion. # exp: AT_DATA([input.y], [[%{ #include #include #include ]$1[ static int yylex (void); static void yyerror (const char *msg); #define YYERROR_VERBOSE 1 #define YYPRINT(File, Type, Value) \ fprintf (File, " (%d, stack size = %d, max = %d)", \ Value, yyssp - yyss + 1, yystacksize); %} %debug %token WAIT_FOR_EOF %% exp: WAIT_FOR_EOF exp | ; %% static void yyerror (const char *msg) { fprintf (stderr, "%s\n", msg); exit (1); } /* There are YYLVAL_MAX of WAIT_FOR_EOFs. */ unsigned int yylval_max; static int yylex (void) { if (yylval--) return WAIT_FOR_EOF; else return EOF; } int main (int argc, const char **argv) { assert (argc == 2); yylval = atoi (argv[1]); yydebug = 1; return yyparse (); } ]]) AT_CHECK([bison input.y -o input.c]) AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) ]) ## -------------------------------------- ## ## Exploding the Stack Size with Alloca. ## ## -------------------------------------- ## AT_SETUP([Exploding the Stack Size with Alloca]) AT_DATA_STACK_TORTURE # Below the limit of 200. AT_CHECK([input 20], 0, [], [ignore]) # Two enlargements: 2 * 2 * 200. AT_CHECK([input 900], 0, [], [ignore]) # Fails: beyond the limit of 10,000 (which we don't reach anyway since we # multiply by two starting at 200 => 5120 is the last possible). AT_CHECK([input 10000], 1, [], [ignore]) AT_CLEANUP ## -------------------------------------- ## ## Exploding the Stack Size with Malloc. ## ## -------------------------------------- ## AT_SETUP([Exploding the Stack Size with Malloc]) AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA_ALLOCA 0]]) # Below the limit of 200. AT_CHECK([input 20], 0, [], [ignore]) # Two enlargements: 2 * 2 * 200. AT_CHECK([input 900], 0, [], [ignore]) # Fails: beyond the limit of 10,000 (which we don't reach anyway since we # multiply by two starting at 200 => 5120 is the possible). AT_CHECK([input 10000], 1, [], [ignore]) AT_CLEANUP