From 6d7d248e72d61bbdb97caedcefbc6911f1e5daa0 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 12 Nov 2001 09:25:05 +0000 Subject: [PATCH] * tests/torture.at (AT_DATA_STACK_TORTURE) (Exploding the Stack Size with Alloca) (Exploding the Stack Size with Malloc): New. --- ChangeLog | 6 +++ tests/Makefile.am | 2 +- tests/testsuite.at | 1 + tests/torture.at | 117 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/torture.at diff --git a/ChangeLog b/ChangeLog index 3d660360..714a2c86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-11-12 Akim Demaille + + * tests/torture.at (AT_DATA_STACK_TORTURE) + (Exploding the Stack Size with Alloca) + (Exploding the Stack Size with Malloc): New. + 2001-11-12 Akim Demaille * src/bison.simple (YYSTACK_REALLOC): New. diff --git a/tests/Makefile.am b/tests/Makefile.am index 3613713f..aab87422 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,7 +25,7 @@ MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE) TESTSUITE_AT = \ testsuite.at \ - output.at calc.at regression.at + output.at calc.at torture.at regression.at TESTSUITE = $(srcdir)/testsuite AUTOM4TE = autom4te diff --git a/tests/testsuite.at b/tests/testsuite.at index 404f9481..c692bfb9 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -27,4 +27,5 @@ AT_TESTED([bison]) m4_include([output.at]) m4_include([calc.at]) +m4_include([torture.at]) m4_include([regression.at]) diff --git a/tests/torture.at b/tests/torture.at new file mode 100644 index 00000000..c9fe8375 --- /dev/null +++ b/tests/torture.at @@ -0,0 +1,117 @@ +# 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]) +AT_CLEANUP_FILES(input input.c) +]) + + +## -------------------------------------- ## +## 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 -- 2.45.2