]> git.saurik.com Git - bison.git/blame - tests/torture.at
* tests/torture.at (AT_DATA_STACK_TORTURE)
[bison.git] / tests / torture.at
CommitLineData
6d7d248e
AD
1# Torturing Bison. -*- Autotest -*-
2# Copyright 2001 Free Software Foundation, Inc.
3
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)
7# any later version.
8
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.
13
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
17# 02111-1307, USA.
18
19AT_BANNER([[Torture Tests.]])
20
21
22# AT_DATA_STACK_TORTURE(C-PROLOGUE)
23# ---------------------------------
24# A parser specialized in torturing the stack size.
25m4_define([AT_DATA_STACK_TORTURE],
26[# A grammar of parens growing the stack thanks to right recursion.
27# exp:
28AT_DATA([input.y],
29[[%{
30#include <stdio.h>
31#include <stdlib.h>
32#include <assert.h>
33]$1[
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);
40%}
41%debug
42%token WAIT_FOR_EOF
43%%
44exp: WAIT_FOR_EOF exp | ;
45%%
46static void
47yyerror (const char *msg)
48{
49 fprintf (stderr, "%s\n", msg);
50 exit (1);
51}
52
53/* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
54unsigned int yylval_max;
55
56static int
57yylex (void)
58{
59 if (yylval--)
60 return WAIT_FOR_EOF;
61 else
62 return EOF;
63}
64
65int
66main (int argc, const char **argv)
67{
68 assert (argc == 2);
69 yylval = atoi (argv[1]);
70 yydebug = 1;
71 return yyparse ();
72}
73]])
74AT_CHECK([bison input.y -o input.c])
75AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
76AT_CLEANUP_FILES(input input.c)
77])
78
79
80## -------------------------------------- ##
81## Exploding the Stack Size with Alloca. ##
82## -------------------------------------- ##
83
84AT_SETUP([Exploding the Stack Size with Alloca])
85
86AT_DATA_STACK_TORTURE
87
88# Below the limit of 200.
89AT_CHECK([input 20], 0, [], [ignore])
90# Two enlargements: 2 * 2 * 200.
91AT_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).
94AT_CHECK([input 10000], 1, [], [ignore])
95
96AT_CLEANUP
97
98
99
100
101## -------------------------------------- ##
102## Exploding the Stack Size with Malloc. ##
103## -------------------------------------- ##
104
105AT_SETUP([Exploding the Stack Size with Malloc])
106
107AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA_ALLOCA 0]])
108
109# Below the limit of 200.
110AT_CHECK([input 20], 0, [], [ignore])
111# Two enlargements: 2 * 2 * 200.
112AT_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).
115AT_CHECK([input 10000], 1, [], [ignore])
116
117AT_CLEANUP