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