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 |
|
|
19 |
|
AT_BANNER([[Torture Tests.]]) |
20 |
|
|
21 |
|
|
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. |
27 |
|
# exp: |
28 |
|
AT_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 |
|
%% |
44 |
|
exp: WAIT_FOR_EOF exp | ; |
45 |
|
%% |
46 |
|
static void |
47 |
|
yyerror (const char *msg) |
48 |
|
{ |
49 |
|
fprintf (stderr, "%s\n", msg); |
50 |
|
exit (1); |
51 |
|
} |
52 |
|
|
53 |
|
/* There are YYLVAL_MAX of WAIT_FOR_EOFs. */ |
54 |
|
unsigned int yylval_max; |
55 |
|
|
56 |
|
static int |
57 |
|
yylex (void) |
58 |
|
{ |
59 |
|
if (yylval--) |
60 |
|
return WAIT_FOR_EOF; |
61 |
|
else |
62 |
|
return EOF; |
63 |
|
} |
64 |
|
|
65 |
|
int |
66 |
|
main (int argc, const char **argv) |
67 |
|
{ |
68 |
|
assert (argc == 2); |
69 |
|
yylval = atoi (argv[1]); |
70 |
|
yydebug = 1; |
71 |
|
return yyparse (); |
72 |
|
} |
73 |
|
]]) |
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) |
77 |
|
]) |
78 |
|
|
79 |
|
|
80 |
|
## -------------------------------------- ## |
81 |
|
## Exploding the Stack Size with Alloca. ## |
82 |
|
## -------------------------------------- ## |
83 |
|
|
84 |
|
AT_SETUP([Exploding the Stack Size with Alloca]) |
85 |
|
|
86 |
|
AT_DATA_STACK_TORTURE |
87 |
|
|
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]) |
95 |
|
|
96 |
|
AT_CLEANUP |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
## -------------------------------------- ## |
102 |
|
## Exploding the Stack Size with Malloc. ## |
103 |
|
## -------------------------------------- ## |
104 |
|
|
105 |
|
AT_SETUP([Exploding the Stack Size with Malloc]) |
106 |
|
|
107 |
|
AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA_ALLOCA 0]]) |
108 |
|
|
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]) |
116 |
|
|
117 |
|
AT_CLEANUP |