]> git.draconx.ca Git - cdecl99.git/blob - tests/stress.at
3ee72d931c7cae04f8b9581fa5c0f7b5f81666d0
[cdecl99.git] / tests / stress.at
1 # Copyright © 2012, 2020, 2022-2024 Nick Bowler
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16 AT_BANNER([Stress tests])
17
18 dnl Verify the RNG implementation
19 TEST_TAP_SIMPLE([xoshiro256p sanity], [rng-test],
20   [TEST_NEED_PROGRAM([rng-test])])
21
22 dnl Verify that randomdecl actually produces all keywords and a variety
23 dnl of different declarations.
24 AT_SETUP([randomdecl sanity])
25
26 TEST_NEED_PROGRAM([randomdecl])
27
28 m4_define([sanity_tests], [dnl
29   [[^declare], [declaration of an identifier]],
30   [[^type], [type name]],
31   [[inline], [inline function specifier]],
32   [[inline inline], [redundant function specifiers]],
33   [[function [(]@<:@]]RE_ALNUM()_[[@:>@* as], [named function parameter]],
34   [[function [(]void[)]], [empty prototype declaration]],
35   [[function returning], [non-prototype function declaration]],
36   [[\.\.\.], [variadic function]],
37   [[const], [const qualifier]],
38   [[volatile], [volatile qualifier]],
39   [[restrict], [restrict qualifier]],
40   [[const const], [redundant type qualifiers]],
41   [[variable-length array], [variable-length array]],
42   [[static], [static storage-class specifier]],
43   [[extern], [extern storage-class specifier]],
44   [[typedef], [typedef storage-class specifier]],
45   [[auto], [auto storage-class specifier]],
46   [[register], [register storage-class specifier]],
47   [[void], [void type specifier]],
48   [[char], [char type specifier]],
49   [[short], [short type specifier]],
50   [[int], [int type specifier]],
51   [[long], [long type specifier]],
52   [[float], [float type specifier]],
53   [[double], [double type specifier]],
54   [[signed], [signed type specifier]],
55   [[unsigned], [unsigned type specifier]],
56   [[_Bool], [_Bool type specifier]],
57   [[_Complex], [_Complex type specifier]],
58   [[_Imaginary], [_Imaginary type specifier]],
59   [[union], [union type specifier]],
60   [[enum], [enum type specifier]],
61   [[pointer to array], [pointer to an array]],
62   [[pointer to function], [pointer to a function]],
63 ])
64
65 m4_define([sanity_awk], [[/$1/ { found["$2"] = 1; }
66 ]])AT_DATA([sanity.awk],
67 [# We don't need any field splitting, so choose a character that does not
68 # appear in C code to avoid tripping over 199-field limit in HP-UX 11 awk.
69 BEGIN { FS = "@"; }
70 m4_map([sanity_awk], [sanity_tests])dnl
71 END { for (k in found) print "FOUND", k; }
72 ])
73
74 m4_define([sanity_exp], [[FOUND $2
75 ]])
76 LC_ALL=C sort >expout <<'EOF'
77 m4_map([sanity_exp], [sanity_tests])dnl
78 EOF
79
80 AS_ECHO(["Using seed $random_seed"]) >&AS_MESSAGE_LOG_FD
81 AT_CHECK([randomdecl -En 10000 -s "$random_seed" >decls], [0])
82 AT_CHECK([$AWK -f sanity.awk decls | LC_ALL=C sort], [0], [expout])
83
84 AT_CLEANUP
85
86 AT_SETUP([Random crossparse])
87
88 TEST_NEED_PROGRAM([randomdecl])
89 TEST_NEED_PROGRAM([crossparse])
90
91 AS_ECHO(["Using seed $random_seed"]) >&AS_MESSAGE_LOG_FD
92 AT_CHECK([randomdecl -n "$random_iter" -s "$random_seed"],, [stdout-nolog])
93 AT_CHECK([crossparse -f stdout])
94 AT_CLEANUP
95
96 # Check that we can parse declarations with more than 10000 specifiers.
97 AT_SETUP([Excessive specifiers])
98
99 s="const"
100 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
101   AS_VAR_APPEND([s], [" $s"])
102 done
103
104 cat >test.dat <<EOF
105 explain $s int
106 explain int $s
107 type $s int
108 type int $s
109 EOF
110
111 s="inline"
112 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
113   AS_VAR_APPEND([s], [" $s"])
114 done
115 cat >>test.dat <<EOF
116 declare f as $s function returning int
117 EOF
118
119 AT_CHECK([cdecl99 -f test.dat], [0],
120 [[type const int
121 type const int
122 const int
123 const int
124 inline int f()
125 ]])
126
127 AT_CLEANUP
128
129 # Check that we can parse declarations with more than 10000 declarators.
130 AT_SETUP([Excessive declarators])
131
132 AT_DATA([check.awk],
133 [[# We don't need any field splitting, so choose a character that does not
134 # appear in C code to avoid tripping over 199-field limit in HP-UX 11 awk.
135 BEGIN { FS = "@"; runstart = 0; }
136 END { finish_run(NR); }
137
138 gsub(/,[^,)]*/, "~") {
139   while (match($0, /~+/) > 0) {
140     l = substr($0, 1, RSTART-1);
141     r = substr($0, RSTART+RLENGTH);
142     $0 = l ", [plus " RLENGTH " more parameters]" r;
143   }
144 }
145
146 $0 != lastline {
147   finish_run(NR-1);
148   lastline = $0;
149   runstart = NR;
150   print;
151 }
152
153 function finish_run(nr) {
154   count = nr - runstart;
155   if (count > 0)
156     print "[repeated " count " more times]";
157 }
158 ]])
159
160 a="a"
161 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
162   AS_VAR_APPEND([a], [",$a"])
163 done
164
165 cat >test.dat <<EOF
166 explain int $a
167 explain int ($a)
168 type function ($a) returning int
169 EOF
170
171 AT_CHECK([cdecl99 -f test.dat >test.out; status=$?;
172 $AWK -f check.awk test.out
173 exit $status], [0],
174 [[declare a as int
175 [repeated 16383 more times]
176 type function (a, [plus 16383 more parameters]) returning int
177 int (a, [plus 16383 more parameters])
178 ]])
179
180 AT_CLEANUP