]>
Commit | Line | Data |
---|---|---|
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 | ||
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); | |
6d7d248e AD |
36 | #define YYPRINT(File, Type, Value) \ |
37 | fprintf (File, " (%d, stack size = %d, max = %d)", \ | |
38 | Value, yyssp - yyss + 1, yystacksize); | |
39 | %} | |
04d843a2 | 40 | %error-verbose |
6d7d248e AD |
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]) | |
6d7d248e AD |
76 | ]) |
77 | ||
78 | ||
79 | ## -------------------------------------- ## | |
80 | ## Exploding the Stack Size with Alloca. ## | |
81 | ## -------------------------------------- ## | |
82 | ||
83 | AT_SETUP([Exploding the Stack Size with Alloca]) | |
84 | ||
85 | AT_DATA_STACK_TORTURE | |
86 | ||
87 | # Below the limit of 200. | |
88 | AT_CHECK([input 20], 0, [], [ignore]) | |
89 | # Two enlargements: 2 * 2 * 200. | |
90 | AT_CHECK([input 900], 0, [], [ignore]) | |
91 | # Fails: beyond the limit of 10,000 (which we don't reach anyway since we | |
92 | # multiply by two starting at 200 => 5120 is the last possible). | |
93 | AT_CHECK([input 10000], 1, [], [ignore]) | |
94 | ||
95 | AT_CLEANUP | |
96 | ||
97 | ||
98 | ||
99 | ||
100 | ## -------------------------------------- ## | |
101 | ## Exploding the Stack Size with Malloc. ## | |
102 | ## -------------------------------------- ## | |
103 | ||
104 | AT_SETUP([Exploding the Stack Size with Malloc]) | |
105 | ||
000f1a3c | 106 | AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]]) |
6d7d248e AD |
107 | |
108 | # Below the limit of 200. | |
109 | AT_CHECK([input 20], 0, [], [ignore]) | |
110 | # Two enlargements: 2 * 2 * 200. | |
111 | AT_CHECK([input 900], 0, [], [ignore]) | |
112 | # Fails: beyond the limit of 10,000 (which we don't reach anyway since we | |
113 | # multiply by two starting at 200 => 5120 is the possible). | |
114 | AT_CHECK([input 10000], 1, [], [ignore]) | |
115 | ||
116 | AT_CLEANUP |