xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/relational.exp (revision 70f7362772ba52b749c976fb5e86e39a8b2c9afc)
1# Copyright 1998-2020 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 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 <http://www.gnu.org/licenses/>.
15
16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
18# This file is part of the gdb testsuite
19#
20# tests for correctenss of relational operators, associativity and precedence
21# with integer type variables
22#
23
24#
25# test running programs
26#
27
28if { [prepare_for_testing "failed to prepare" relational int-type.c {debug nowarnings}] } {
29    return -1
30}
31
32if [get_compiler_info] {
33    return -1
34}
35
36#
37# set it up at a breakpoint so we can play with the variable values
38#
39
40if ![runto_main] then {
41    perror "couldn't run to breakpoint"
42    continue
43}
44
45#
46# test expressions with "int" types
47#
48
49with_test_prefix "int types" {
50
51    gdb_test_no_output "set variable x=14" "set variable x=14"
52    gdb_test_no_output "set variable y=2" "set variable y=2"
53    gdb_test_no_output "set variable z=2" "set variable z=2"
54    gdb_test_no_output "set variable w=3" "set variable w=3"
55
56    gdb_test "print x" " = 14" "print value of x"
57
58    gdb_test "print y" " = 2" "print value of y"
59
60    gdb_test "print z" " = 2" "print value of z"
61
62    gdb_test "print w" " = 3" "print value of w"
63
64    gdb_test "print x < y" "$false" "print value of x<y"
65
66    gdb_test "print x <= y" "$false" "print value of x<=y"
67
68    gdb_test "print x > y" "$true" "print value of x>y"
69
70    gdb_test "print x >= y" "$true" "print value of x>=y"
71
72    gdb_test "print x == y" "$false" "print value of x==y"
73
74    gdb_test "print x != y" "$true" "print value of x!=y"
75}
76
77# Test associativity of <, >, <=, >=, ==, !=
78with_test_prefix "basic associativity" {
79
80    gdb_test_no_output "set variable x=3" "set variable x=3"
81    gdb_test_no_output "set variable y=5" "set variable y=5"
82    gdb_test_no_output "set variable z=2" "set variable z=2"
83
84    gdb_test "print x < y < z" "$true" "print value of x<y<z"
85
86    gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
87
88    gdb_test "print x > y > z" "$false" "print value of x>y>z"
89
90    gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
91
92    gdb_test_no_output "set variable x=2" "set variable x=2"
93    gdb_test_no_output "set variable y=2" "set variable y=2"
94    gdb_test_no_output "set variable z=1" "set variable z=1"
95
96    gdb_test "print x == y == z" "$true" "print value of x==y==z"
97
98    gdb_test_no_output "set variable z=0" "set variable z"
99
100    gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
101}
102
103# Test precedence rules on pairs of relational operators.  The use of
104# with_test_prefix with keys 1, 2, 3, etc is only to ensure that the
105# test names are unique.  Each nested group of tests starts at a
106# location where we are setting a variable to a value it has had in
107# the past, which would result in a test name repeating.
108with_test_prefix "pair associativity" {
109    with_test_prefix "1" {
110	gdb_test_no_output "set variable x=0" "set variable x=0"
111	gdb_test_no_output "set variable y=2" "set variable y=2"
112	gdb_test_no_output "set variable z=2" "set variable z=2"
113
114	gdb_test "print x < y == z" "$false" "print value of x<y==z"
115
116	# 0  2  2
117	gdb_test "print x < y != z" "$true" "print value of x<y!=z"
118
119	gdb_test_no_output "set variable x=2" "set variable x=2"
120	gdb_test_no_output "set variable y=3" "set variable y=3"
121	gdb_test_no_output "set variable z=1" "set variable z=1"
122
123	# 2 3 1
124	gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
125
126	# 2 3 1
127	gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
128
129	gdb_test_no_output "set variable z=0" " set variable z=0"
130
131	# 2 3 0
132	gdb_test "print x < y > z" "$true" "print value of x<y>z"
133
134	gdb_test_no_output "set variable x=1" " set variable x=1"
135
136	# 1 3 0
137	gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
138    }
139
140    with_test_prefix "2" {
141	gdb_test_no_output "set variable z=2" " set variable z=2"
142
143	# 1 3 2
144	gdb_test "print x > y == z" "$false" "print value of x>y==z"
145
146	gdb_test_no_output "set variable x=2" " set variable x=2"
147	gdb_test_no_output "set variable z=0" " set variable z=0"
148
149	# 2 3 0
150	gdb_test "print x > y != z" "$false" "print value of x>y!=z"
151
152	gdb_test_no_output "set variable x=4" "set variable x=4"
153
154	# 4 3 0
155	gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
156
157	# 4 3 0
158	gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
159    }
160
161    with_test_prefix "3" {
162	gdb_test_no_output "set variable x=2" " set variable x=2"
163
164	# 2 3 0
165	gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
166
167	gdb_test_no_output "set variable x=0" " set variable x=0"
168	gdb_test_no_output "set variable z=4" " set variable z=4"
169
170	# 0 3 4
171	gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
172
173	# 0 3 4
174	gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
175    }
176
177    with_test_prefix "4" {
178	gdb_test_no_output "set variable x=2" " set variable x=2"
179
180	# 2 3 4
181	gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
182
183	# 2 3 4
184	gdb_test "print x == y != z" "$true" "print value of x==y!=z"
185    }
186}
187
188# test use of parenthesis to enforce different order of evaluation
189with_test_prefix "with parenthesis" {
190    gdb_test_no_output "set variable z=0" " set variable z=0"
191
192    # 2 3 0
193    gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
194
195    # 2 3 0
196    gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
197
198    # 2 3 0
199    gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
200
201    gdb_test_no_output "set variable x=1" " set variable x=1"
202    gdb_test_no_output "set variable z=4" " set variable z=4"
203
204    # 1 3 4
205    gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"
206}
207
208