relational.exp revision 1.8
1# Copyright 1998-2019 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
49gdb_test_no_output "set variable x=14" "set variable x=14"
50gdb_test_no_output "set variable y=2" "set variable y=2"
51gdb_test_no_output "set variable z=2" "set variable z=2"
52gdb_test_no_output "set variable w=3" "set variable w=3"
53
54gdb_test "print x" " = 14" "print value of x"
55
56gdb_test "print y" " = 2" "print value of y"
57
58gdb_test "print z" " = 2" "print value of z"
59
60gdb_test "print w" " = 3" "print value of w"
61
62gdb_test "print x < y" "$false" "print value of x<y"
63
64gdb_test "print x <= y" "$false" "print value of x<=y"
65
66gdb_test "print x > y" "$true" "print value of x>y"
67
68gdb_test "print x >= y" "$true" "print value of x>=y"
69
70gdb_test "print x == y" "$false" "print value of x==y"
71
72gdb_test "print x != y" "$true" "print value of x!=y"
73
74
75# Test associativity of <, >, <=, >=, ==, !=
76
77gdb_test_no_output "set variable x=3" "set variable x"
78gdb_test_no_output "set variable y=5" "set variable y"
79gdb_test_no_output "set variable z=2" "set variable z"
80
81gdb_test "print x < y < z" "$true" "print value of x<y<z"
82
83gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
84
85gdb_test "print x > y > z" "$false" "print value of x>y>z"
86
87gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
88
89gdb_test_no_output "set variable x=2" "set variable x"
90gdb_test_no_output "set variable y=2" "set variable y"
91gdb_test_no_output "set variable z=1" "set variable z"
92
93gdb_test "print x == y == z" "$true" "print value of x==y==z"
94
95gdb_test_no_output "set variable z=0" "set variable z"
96
97gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
98
99# test precedence rules on pairs of relational operators
100
101gdb_test_no_output "set variable x=0" "set variable x"
102gdb_test_no_output "set variable y=2" "set variable y"
103gdb_test_no_output "set variable z=2" "set variable z"
104
105gdb_test "print x < y == z" "$false" "print value of x<y==z"
106
107# 0  2  2
108gdb_test "print x < y != z" "$true" "print value of x<y!=z"
109
110gdb_test_no_output "set variable x=2" "set variable x"
111gdb_test_no_output "set variable y=3" "set variable y"
112gdb_test_no_output "set variable z=1" "set variable z"
113
114
115# 2 3 1
116gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
117
118# 2 3 1
119gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
120
121gdb_test_no_output "set variable z=0" " set variable z"
122
123# 2 3 0
124gdb_test "print x < y > z" "$true" "print value of x<y>z"
125
126gdb_test_no_output "set variable x=1" " set variable x"
127
128# 1 3 0
129gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
130
131gdb_test_no_output "set variable z=2" " set variable z"
132
133# 1 3 2
134gdb_test "print x > y == z" "$false" "print value of x>y==z"
135
136gdb_test_no_output "set variable x=2" " set variable x"
137gdb_test_no_output "set variable z=0" " set variable z"
138
139# 2 3 0
140gdb_test "print x > y != z" "$false" "print value of x>y!=z"
141
142gdb_test_no_output "set variable x=4" "set x to 4"
143
144# 4 3 0
145gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
146
147# 4 3 0
148gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
149
150gdb_test_no_output "set variable x=2" " set variable x"
151
152# 2 3 0
153gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
154
155gdb_test_no_output "set variable x=0" " set variable x"
156gdb_test_no_output "set variable z=4" " set variable z"
157
158# 0 3 4
159gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
160
161# 0 3 4
162gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
163
164gdb_test_no_output "set variable x=2" " set variable x"
165
166# 2 3 4
167gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
168
169# 2 3 4
170gdb_test "print x == y != z" "$true" "print value of x==y!=z"
171
172
173
174# test use of parenthesis to enforce different order of evaluation
175
176gdb_test_no_output "set variable z=0" " set variable z"
177
178# 2 3 0
179gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
180
181# 2 3 0
182gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
183
184# 2 3 0
185gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
186
187gdb_test_no_output "set variable x=1" " set variable x"
188gdb_test_no_output "set variable z=4" " set variable z"
189
190# 1 3 4
191gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"
192
193