bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02-fyi-torture-stack-test.patch


From: Akim Demaille
Subject: 02-fyi-torture-stack-test.patch
Date: Mon, 12 Nov 2001 10:06:40 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        
        * tests/torture.at (AT_DATA_STACK_TORTURE)
        (Exploding the Stack Size with Alloca)
        (Exploding the Stack Size with Malloc): New.
        
Index: tests/Makefile.am
--- tests/Makefile.am Fri, 02 Nov 2001 19:28:01 +0100 akim
+++ tests/Makefile.am Fri, 09 Nov 2001 23:51:42 +0100 akim
@@ -25,7 +25,7 @@
 
 TESTSUITE_AT = \
        testsuite.at \
-       output.at calc.at regression.at
+       output.at calc.at torture.at regression.at
 TESTSUITE = $(srcdir)/testsuite
 
 AUTOTEST = $(AUTOM4TE) --language=autotest
Index: tests/testsuite.at
--- tests/testsuite.at Thu, 11 Oct 2001 19:02:23 +0200 akim
+++ tests/testsuite.at Fri, 09 Nov 2001 23:51:23 +0100 akim
@@ -27,4 +27,5 @@
 
 m4_include([output.at])
 m4_include([calc.at])
+m4_include([torture.at])
 m4_include([regression.at])
Index: tests/torture.at
--- tests/torture.at Sat, 10 Nov 2001 11:01:19 +0100 akim
+++ tests/torture.at Sat, 10 Nov 2001 11:01:05 +0100 akim
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+]$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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]