Commit | Line | Data |
---|---|---|
16def8c8 SS |
1 | # Copyright (C) 1992 Free Software Foundation, Inc. |
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 2 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, write to the Free Software | |
15 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Fred Fish. (fnf@cygnus.com) | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | set prms_id 0 | |
27 | set bug_id 0 | |
28 | ||
29 | # Set the current language to chill. This counts as a test. If it | |
30 | # fails, then we skip the other tests. | |
31 | ||
32 | proc set_lang_chill {} { | |
33 | global prompt | |
34 | ||
35 | send "set language chill\n" | |
36 | expect { | |
37 | -re ".*$prompt $" {} | |
38 | timeout { fail "set language chill (timeout)" ; return 0 } | |
39 | } | |
40 | ||
41 | send "show language\n" | |
42 | expect { | |
43 | -re ".* source language is \"chill\".*$prompt $" { | |
44 | pass "set language to \"chill\"" | |
45 | return 1 | |
46 | } | |
47 | -re ".*$prompt $" { | |
48 | fail "setting language to \"chill\"" | |
49 | return 0 | |
50 | } | |
51 | timeout { | |
52 | fail "can't show language (timeout)" | |
53 | return 0 | |
54 | } | |
55 | } | |
56 | } | |
57 | ||
16def8c8 SS |
58 | proc test_integer_literals_accepted {} { |
59 | global prompt | |
16def8c8 SS |
60 | |
61 | # Test various decimal values. | |
62 | ||
63 | test_print_accept "p 123" "123" | |
64 | test_print_accept "p -123" "-123" | |
65 | test_print_accept "p D'123" "123" | |
66 | test_print_accept "p d'123" "123" | |
67 | test_print_accept "p -D'123" "-123" | |
68 | test_print_accept "p -d'123" "-123" | |
69 | test_print_accept "p 123_456" "123456" | |
70 | test_print_accept "p __1_2_3__" "123" | |
71 | test_print_accept "p/d 123" "D'123" | |
72 | ||
73 | # Test various binary values. | |
74 | ||
75 | test_print_accept "p B'111" "7" | |
76 | test_print_accept "p b'111" "7" | |
77 | test_print_accept "p -B'111" "-7" | |
78 | test_print_accept "p B'0111" "7" | |
79 | test_print_accept "p b'0111" "7" | |
80 | test_print_accept "p -b'0111" "-7" | |
81 | test_print_accept "p B'_0_1_1_1_" "7" | |
82 | test_print_accept "p b'_0_1_1_1_" "7" | |
83 | test_print_accept "p -b'_0_1_1_1_" "-7" | |
84 | test_print_accept "p/t B'111" "B'111" | |
85 | ||
86 | # Test various octal values. | |
87 | ||
88 | test_print_accept "p O'123" "83" | |
89 | test_print_accept "p o'123" "83" | |
90 | test_print_accept "p -o'0123" "-83" | |
91 | test_print_accept "p O'0123" "83" | |
92 | test_print_accept "p o'0123" "83" | |
93 | test_print_accept "p -o'123" "-83" | |
94 | test_print_accept "p O'_1_2_3_" "83" | |
95 | test_print_accept "p o'_1_2_3_" "83" | |
96 | test_print_accept "p -o'_1_2_3_" "-83" | |
97 | test_print_accept "p/o O'123" "O'123" | |
98 | ||
99 | # Test various hexadecimal values. | |
100 | ||
101 | test_print_accept "p H'123" "291" | |
102 | test_print_accept "p h'123" "291" | |
103 | test_print_accept "p -h'123" "-291" | |
104 | test_print_accept "p H'0123" "291" | |
105 | test_print_accept "p h'0123" "291" | |
106 | test_print_accept "p -h'0123" "-291" | |
107 | test_print_accept "p H'_1_2_3_" "291" | |
108 | test_print_accept "p h'_1_2_3_" "291" | |
109 | test_print_accept "p -h'_1_2_3_" "-291" | |
110 | test_print_accept "p H'ABCDEF" "11259375" | |
111 | test_print_accept "p H'abcdef" "11259375" | |
112 | test_print_accept "p H'AbCdEf" "11259375" | |
113 | test_print_accept "p H'_A_b_C_d_E_f_" "11259375" | |
114 | test_print_accept "p/x H'123" "H'123" | |
16def8c8 SS |
115 | } |
116 | ||
117 | proc test_character_literals_accepted {} { | |
118 | global prompt | |
16def8c8 SS |
119 | |
120 | # Test various decimal values. | |
121 | ||
122 | test_print_accept "p 'a'" "'a'" | |
123 | test_print_accept "p/x 'a'" "H'61" | |
124 | test_print_accept "p/d 'a'" "D'97" | |
125 | test_print_accept "p/t 'a'" "B'1100001" | |
126 | # test_print_accept "p '^(97)'" "'a'" (not in GNU Chill) | |
127 | test_print_accept "p C'61'" "'a'" | |
128 | test_print_accept "p c'61'" "'a'" | |
129 | test_print_accept "p/x C'FF'" "H'ff" | |
130 | # test_print_accept "p/x '^(H'FF)'" "H'ff" (not in GNU Chill) | |
131 | # test_print_accept "p/x '^(D'255)'" "H'ff" (not in GNU Chill) | |
16def8c8 SS |
132 | } |
133 | ||
134 | proc test_integer_literals_rejected {} { | |
135 | global prompt | |
16def8c8 SS |
136 | |
137 | # These are valid integer literals in Z.200, but not GNU-Chill. | |
138 | ||
139 | test_print_reject "p _" | |
140 | test_print_reject "p __" | |
141 | ||
142 | test_print_reject "p D'" | |
143 | test_print_reject "p D'_" | |
144 | test_print_reject "p D'__" | |
145 | ||
146 | test_print_reject "p B'" | |
147 | test_print_reject "p B'_" | |
148 | test_print_reject "p B'__" | |
149 | ||
150 | test_print_reject "p O'" | |
151 | test_print_reject "p O'_" | |
152 | test_print_reject "p O'__" | |
153 | ||
154 | test_print_reject "p H'" | |
155 | test_print_reject "p H'_" | |
156 | test_print_reject "p H'__" | |
157 | ||
158 | # Test various decimal values. | |
159 | ||
160 | test_print_reject "p D'DEADBEEF" | |
161 | test_print_reject "p D'123DEADBEEF" | |
162 | ||
163 | # Test various binary values. | |
164 | ||
165 | test_print_reject "p B'2" | |
166 | test_print_reject "p B'12" | |
167 | ||
168 | # Test various octal values. | |
169 | ||
170 | test_print_reject "p O'9" | |
171 | test_print_reject "p O'79" | |
172 | ||
173 | # Test various hexadecimal values. | |
174 | ||
175 | test_print_reject "p H'G" | |
176 | test_print_reject "p H'AG" | |
16def8c8 SS |
177 | } |
178 | ||
179 | proc test_boolean_literals_accepted {} { | |
180 | global prompt | |
16def8c8 SS |
181 | |
182 | # Test the only possible values for a boolean, TRUE and FALSE. | |
183 | ||
184 | test_print_accept "p TRUE" "TRUE" | |
185 | test_print_accept "p FALSE" "FALSE" | |
16def8c8 SS |
186 | } |
187 | ||
188 | proc test_float_literals_accepted {} { | |
189 | global prompt | |
16def8c8 SS |
190 | |
191 | # Test various floating point formats | |
192 | ||
193 | test_print_accept "p .44 < .45" "1" | |
194 | test_print_accept "p .44 > .45" "0" | |
195 | test_print_accept "p 0.44 < 0.45" "1" | |
196 | test_print_accept "p 0.44 > 0.45" "0" | |
197 | test_print_accept "p 44. < 45." "1" | |
198 | test_print_accept "p 44. > 45." "0" | |
199 | test_print_accept "p 44.0 < 45.0" "1" | |
200 | test_print_accept "p 44.0 > 45.0" "0" | |
201 | test_print_accept "p 10D20 < 10D21" "1" | |
202 | test_print_accept "p 10D20 > 10D21" "0" | |
203 | test_print_accept "p 10d20 < 10d21" "1" | |
204 | test_print_accept "p 10d20 > 10d21" "0" | |
205 | test_print_accept "p 10E20 < 10E21" "1" | |
206 | test_print_accept "p 10E20 > 10E21" "0" | |
207 | test_print_accept "p 10e20 < 10e21" "1" | |
208 | test_print_accept "p 10e20 > 10e21" "0" | |
209 | test_print_accept "p 10.D20 < 10.D21" "1" | |
210 | test_print_accept "p 10.D20 > 10.D21" "0" | |
211 | test_print_accept "p 10.d20 < 10.d21" "1" | |
212 | test_print_accept "p 10.d20 > 10.d21" "0" | |
213 | test_print_accept "p 10.E20 < 10.E21" "1" | |
214 | test_print_accept "p 10.E20 > 10.E21" "0" | |
215 | test_print_accept "p 10.e20 < 10.e21" "1" | |
216 | test_print_accept "p 10.e20 > 10.e21" "0" | |
217 | test_print_accept "p 10.0D20 < 10.0D21" "1" | |
218 | test_print_accept "p 10.0D20 > 10.0D21" "0" | |
219 | test_print_accept "p 10.0d20 < 10.0d21" "1" | |
220 | test_print_accept "p 10.0d20 > 10.0d21" "0" | |
221 | test_print_accept "p 10.0E20 < 10.0E21" "1" | |
222 | test_print_accept "p 10.0E20 > 10.0E21" "0" | |
223 | test_print_accept "p 10.0e20 < 10.0e21" "1" | |
224 | test_print_accept "p 10.0e20 > 10.0e21" "0" | |
225 | test_print_accept "p 10.0D+20 < 10.0D+21" "1" | |
226 | test_print_accept "p 10.0D+20 > 10.0D+21" "0" | |
227 | test_print_accept "p 10.0d+20 < 10.0d+21" "1" | |
228 | test_print_accept "p 10.0d+20 > 10.0d+21" "0" | |
229 | test_print_accept "p 10.0E+20 < 10.0E+21" "1" | |
230 | test_print_accept "p 10.0E+20 > 10.0E+21" "0" | |
231 | test_print_accept "p 10.0e+20 < 10.0e+21" "1" | |
232 | test_print_accept "p 10.0e+20 > 10.0e+21" "0" | |
233 | test_print_accept "p 10.0D-11 < 10.0D-10" "1" | |
234 | test_print_accept "p 10.0D-11 > 10.0D-10" "0" | |
235 | test_print_accept "p 10.0d-11 < 10.0d-10" "1" | |
236 | test_print_accept "p 10.0d-11 > 10.0d-10" "0" | |
237 | test_print_accept "p 10.0E-11 < 10.0E-10" "1" | |
238 | test_print_accept "p 10.0E-11 > 10.0E-10" "0" | |
239 | test_print_accept "p 10.0e-11 < 10.0e-10" "1" | |
240 | test_print_accept "p 10.0e-11 > 10.0e-10" "0" | |
241 | # looks funny, but apparently legal | |
242 | test_print_accept "p _.1e+10 < _.1e+11" "1" | |
243 | test_print_accept "p _.1e+10 > _.1e+11" "0" | |
244 | test_print_accept "p __.1e-12 < __.1e-11" "1" | |
245 | test_print_accept "p __.1e-12 > __.1e-11" "0" | |
16def8c8 SS |
246 | } |
247 | ||
248 | proc test_convenience_variables {} { | |
249 | global prompt | |
250 | ||
251 | gdb_test "set \\\$foo := 101" " := 101" \ | |
252 | "Set a new convenience variable" | |
253 | ||
254 | gdb_test "print \\\$foo" " = 101" \ | |
255 | "Print contents of new convenience variable" | |
256 | ||
257 | gdb_test "set \\\$foo := 301" " := 301" \ | |
258 | "Set convenience variable to a new value" | |
259 | ||
260 | gdb_test "print \\\$foo" " = 301" \ | |
261 | "Print new contents of convenience variable" | |
262 | ||
263 | gdb_test "set \\\$_ := 11" " := 11" \ | |
264 | "Set convenience variable \$_" | |
265 | ||
266 | gdb_test "print \\\$_" " = 11" \ | |
267 | "Print contents of convenience variable \$_" | |
268 | ||
269 | gdb_test "print \\\$foo + 10" " = 311" \ | |
270 | "Use convenience variable in arithmetic expression" | |
271 | ||
272 | gdb_test "print (\\\$foo := 32) + 4" " = 36" \ | |
273 | "Use convenience variable assignment in arithmetic expression" | |
274 | ||
275 | gdb_test "print \\\$bar" " = void" \ | |
276 | "Print contents of uninitialized convenience variable" | |
277 | } | |
278 | ||
279 | proc test_value_history {} { | |
280 | global prompt | |
281 | ||
282 | gdb_test "print 101" "\\\$1 = 101" \ | |
283 | "Set value-history\[1\] using \$1" | |
284 | ||
285 | gdb_test "print 102" "\\\$2 = 102" \ | |
286 | "Set value-history\[2\] using \$2" | |
287 | ||
288 | gdb_test "print 103" "\\\$3 = 103" \ | |
289 | "Set value-history\[3\] using \$3" | |
290 | ||
291 | gdb_test "print \\\$\\\$" "\\\$4 = 102" \ | |
292 | "Print value-history\[MAX-1\] using inplicit index \$\$" | |
293 | ||
294 | gdb_test "print \\\$\\\$" "\\\$5 = 103" \ | |
295 | "Print value-history\[MAX-1\] again using implicit index \$\$" | |
296 | ||
297 | gdb_test "print \\\$" "\\\$6 = 103" \ | |
298 | "Print value-history\[MAX\] using implicit index \$" | |
299 | ||
300 | gdb_test "print \\\$\\\$2" "\\\$7 = 102" \ | |
301 | "Print value-history\[MAX-2\] using explicit index \$\$2" | |
302 | ||
303 | gdb_test "print \\\$0" "\\\$8 = 102" \ | |
304 | "Print value-history\[MAX\] using explicit index \$0" | |
305 | ||
306 | gdb_test "print 108" "\\\$9 = 108" "" | |
307 | ||
308 | gdb_test "print \\\$\\\$0" "\\\$10 = 108" \ | |
309 | "Print value-history\[MAX\] using explicit index \$\$0" | |
310 | ||
311 | gdb_test "print \\\$1" "\\\$11 = 101" \ | |
312 | "Print value-history\[1\] using explicit index \$1" | |
313 | ||
314 | gdb_test "print \\\$2" "\\\$12 = 102" \ | |
315 | "Print value-history\[2\] using explicit index \$2" | |
316 | ||
317 | gdb_test "print \\\$3" "\\\$13 = 103" \ | |
318 | "Print value-history\[3\] using explicit index \$3" | |
319 | ||
320 | gdb_test "print \\\$-3" "\\\$14 = 100" \ | |
321 | "Print (value-history\[MAX\] - 3) using implicit index \$" | |
322 | ||
323 | gdb_test "print \\\$1 + 3" "\\\$15 = 104" \ | |
324 | "Use value-history element in arithmetic expression" | |
325 | } | |
326 | ||
327 | proc test_arithmetic_expressions {} { | |
328 | global prompt | |
16def8c8 SS |
329 | |
330 | # Test unary minus with various operands | |
331 | ||
332 | # test_print_accept "p -(TRUE)" "-1" "unary minus applied to bool" | |
333 | # test_print_accept "p -('a')" "xxx" "unary minus applied to char" | |
334 | test_print_accept "p -(1)" "-1" "unary minus applied to int" | |
335 | test_print_accept "p -(1.0)" "-1" "unary minus applied to real" | |
336 | ||
337 | # Test addition with various operands | |
338 | ||
339 | test_print_accept "p TRUE + 1" "2" "bool plus int" | |
340 | test_print_accept "p 'a' + 1" "98" "char plus int" | |
341 | test_print_accept "p 1 + 1" "2" "int plus int" | |
342 | test_print_accept "p 1.0 + 1" "2" "real plus int" | |
343 | test_print_accept "p 1.0 + 2.0" "3" "real plus real" | |
344 | ||
345 | # Test subtraction with various operands | |
346 | ||
347 | test_print_accept "p TRUE - 1" "0" "bool minus int" | |
348 | test_print_accept "p 'b' - 1" "97" "char minus int" | |
349 | test_print_accept "p 3 - 1" "2" "int minus int" | |
350 | test_print_accept "p 3.0 - 1" "2" "real minus int" | |
351 | test_print_accept "p 5.0 - 2.0" "3" "real minus real" | |
352 | ||
353 | # Test multiplication with various operands | |
354 | ||
355 | test_print_accept "p TRUE * 1" "1" "bool times int" | |
356 | test_print_accept "p 'a' * 2" "194" "char times int" | |
357 | test_print_accept "p 2 * 3" "6" "int times int" | |
358 | test_print_accept "p 2.0 * 3" "6" "real times int" | |
359 | test_print_accept "p 2.0 * 3.0" "6" "real times real" | |
360 | ||
361 | # Test division with various operands | |
362 | ||
363 | test_print_accept "p TRUE / 1" "1" "bool divided by int" | |
364 | test_print_accept "p 'a' / 2" "48" "char divided by int" | |
365 | test_print_accept "p 6 / 3" "2" "int divided by int" | |
366 | test_print_accept "p 6.0 / 3" "2" "real divided by int" | |
367 | test_print_accept "p 6.0 / 3.0" "2" "real divided by real" | |
368 | ||
369 | # Test modulo with various operands | |
370 | ||
371 | test_print_accept "p TRUE MOD 1" "0" "bool modulo int" | |
372 | test_print_accept "p 'a' MOD 2" "1" "char modulo int" | |
373 | test_print_accept "p -5 MOD 3" "1" "negative int modulo int" | |
374 | test_print_accept "p 5 MOD 1" "0" "int modulo int" | |
375 | test_print_accept "p 5 MOD 2" "1" "int modulo int" | |
376 | test_print_accept "p 5 MOD 3" "2" "int modulo int" | |
377 | test_print_accept "p 5 MOD 4" "1" "int modulo int" | |
378 | test_print_accept "p 5 MOD 5" "0" "int modulo int" | |
379 | test_print_accept "p 0 MOD 1" "0" "int modulo int" | |
380 | test_print_accept "p 0 MOD 2" "0" "int modulo int" | |
381 | test_print_accept "p 0 MOD 3" "0" "int modulo int" | |
382 | test_print_accept "p 0 MOD 4" "0" "int modulo int" | |
383 | test_print_accept "p -5 MOD 1" "0" "int modulo int" | |
384 | test_print_accept "p -5 MOD 2" "1" "int modulo int" | |
385 | test_print_accept "p -5 MOD 3" "1" "int modulo int" | |
386 | test_print_accept "p -5 MOD 4" "3" "int modulo int" | |
387 | test_print_accept "p -5 MOD 5" "0" "int modulo int" | |
388 | test_print_accept "p -5 MOD 5" "0" "int modulo int" | |
389 | test_print_reject "p 6.0 MOD 3" \ | |
390 | "Integer-only operation on floating point number.*" | |
391 | test_print_reject "p 6.0 MOD 3.0" \ | |
392 | "Integer-only operation on floating point number.*" | |
393 | test_print_reject "p -5 MOD -1" \ | |
394 | "Second operand of MOD must be greater than zero.*" | |
395 | test_print_reject "p -5 MOD 0" \ | |
396 | "Second operand of MOD must be greater than zero.*" | |
397 | ||
398 | # Test remainder with various operands | |
399 | ||
400 | test_print_accept "p TRUE REM 1" "0" "bool remainder int" | |
401 | test_print_accept "p 'a' REM 2" "1" "char remainder int" | |
402 | test_print_accept "p 5 REM 5" "0" "int remainder int" | |
403 | test_print_accept "p 5 REM 4" "1" "int remainder int" | |
404 | test_print_accept "p 5 REM 3" "2" "int remainder int" | |
405 | test_print_accept "p 5 REM 2" "1" "int remainder int" | |
406 | test_print_accept "p 5 REM 1" "0" "int remainder int" | |
407 | test_print_accept "p 5 REM -1" "0" "int remainder int" | |
408 | test_print_accept "p 5 REM -2" "1" "int remainder int" | |
409 | test_print_accept "p 5 REM -3" "2" "int remainder int" | |
410 | test_print_accept "p 5 REM -4" "1" "int remainder int" | |
411 | test_print_accept "p 5 REM -5" "0" "int remainder int" | |
412 | test_print_accept "p -5 REM 5" "0" "int remainder int" | |
413 | test_print_accept "p -5 REM 4" "-1" "int remainder int" | |
414 | test_print_accept "p -5 REM 3" "-2" "int remainder int" | |
415 | test_print_accept "p -5 REM 2" "-1" "int remainder int" | |
416 | test_print_accept "p -5 REM 1" "0" "int remainder int" | |
417 | test_print_accept "p -5 REM -1" "0" "int remainder int" | |
418 | test_print_accept "p -5 REM -2" "-1" "int remainder int" | |
419 | test_print_accept "p -5 REM -3" "-2" "int remainder int" | |
420 | test_print_accept "p -5 REM -4" "-1" "int remainder int" | |
421 | test_print_accept "p -5 REM -5" "0" "int remainder int" | |
422 | test_print_accept "p 6 REM 3" "0" "int remainder int" | |
423 | test_print_reject "p 6.0 REM 3" \ | |
424 | "Integer-only operation on floating point number.*" | |
425 | test_print_reject "p 6.0 REM 3.0" \ | |
426 | "Integer-only operation on floating point number.*" | |
16def8c8 SS |
427 | } |
428 | ||
429 | # Start with a fresh gdb. | |
430 | ||
431 | gdb_exit | |
432 | gdb_start | |
433 | gdb_reinitialize_dir $srcdir/$subdir | |
434 | ||
435 | send "set print sevenbit-strings\n" ; expect -re ".*$prompt $" | |
436 | ||
437 | if [set_lang_chill] then { | |
438 | test_value_history | |
439 | test_convenience_variables | |
440 | test_integer_literals_accepted | |
441 | test_integer_literals_rejected | |
442 | test_boolean_literals_accepted | |
443 | test_character_literals_accepted | |
444 | test_float_literals_accepted | |
445 | test_arithmetic_expressions | |
446 | } else { | |
447 | warning "$test_name tests suppressed." | |
448 | } |