run copyright.sh for 2011.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / relational.exp
1 # Copyright 1998, 1999, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18
19 # This file is part of the gdb testsuite
20 #
21 # tests for correctenss of relational operators, associativity and precedence
22 # with integer type variables
23 #
24
25 if $tracelevel then {
26 strace $tracelevel
27 }
28
29 #
30 # test running programs
31 #
32
33 if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
34 return -1
35 }
36
37 if [get_compiler_info not-used] {
38 return -1;
39 }
40
41 #
42 # set it up at a breakpoint so we can play with the variable values
43 #
44
45 if ![runto_main] then {
46 perror "couldn't run to breakpoint"
47 continue
48 }
49
50 #
51 # test expressions with "int" types
52 #
53
54 gdb_test_no_output "set variable x=14" "set variable x=14"
55 gdb_test_no_output "set variable y=2" "set variable y=2"
56 gdb_test_no_output "set variable z=2" "set variable z=2"
57 gdb_test_no_output "set variable w=3" "set variable w=3"
58
59 gdb_test "print x" " = 14" "print value of x"
60
61 gdb_test "print y" " = 2" "print value of y"
62
63 gdb_test "print z" " = 2" "print value of z"
64
65 gdb_test "print w" " = 3" "print value of w"
66
67 gdb_test "print x < y" "$false" "print value of x<y"
68
69 gdb_test "print x <= y" "$false" "print value of x<=y"
70
71 gdb_test "print x > y" "$true" "print value of x>y"
72
73 gdb_test "print x >= y" "$true" "print value of x>=y"
74
75 gdb_test "print x == y" "$false" "print value of x==y"
76
77 gdb_test "print x != y" "$true" "print value of x!=y"
78
79
80 # Test associativity of <, >, <=, >=, ==, !=
81
82 gdb_test_no_output "set variable x=3" "set variable x"
83 gdb_test_no_output "set variable y=5" "set variable y"
84 gdb_test_no_output "set variable z=2" "set variable z"
85
86 gdb_test "print x < y < z" "$true" "print value of x<y<z"
87
88 gdb_test "print x <= y <= z" "$true" "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 "print x >= y >= z" "$false" "print value of x>=y>=z"
93
94 gdb_test_no_output "set variable x=2" "set variable x"
95 gdb_test_no_output "set variable y=2" "set variable y"
96 gdb_test_no_output "set variable z=1" "set variable z"
97
98 gdb_test "print x == y == z" "$true" "print value of x==y==z"
99
100 gdb_test_no_output "set variable z=0" "set variable z"
101
102 gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
103
104 # test precedence rules on pairs of relational operators
105
106 gdb_test_no_output "set variable x=0" "set variable x"
107 gdb_test_no_output "set variable y=2" "set variable y"
108 gdb_test_no_output "set variable z=2" "set variable z"
109
110 gdb_test "print x < y == z" "$false" "print value of x<y==z"
111
112 # 0 2 2
113 gdb_test "print x < y != z" "$true" "print value of x<y!=z"
114
115 gdb_test_no_output "set variable x=2" "set variable x"
116 gdb_test_no_output "set variable y=3" "set variable y"
117 gdb_test_no_output "set variable z=1" "set variable z"
118
119
120 # 2 3 1
121 gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
122
123 # 2 3 1
124 gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
125
126 gdb_test_no_output "set variable z=0" " set variable z"
127
128 # 2 3 0
129 gdb_test "print x < y > z" "$true" "print value of x<y>z"
130
131 gdb_test_no_output "set variable x=1" " set variable x"
132
133 # 1 3 0
134 gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
135
136 gdb_test_no_output "set variable z=2" " set variable z"
137
138 # 1 3 2
139 gdb_test "print x > y == z" "$false" "print value of x>y==z"
140
141 gdb_test_no_output "set variable x=2" " set variable x"
142 gdb_test_no_output "set variable z=0" " set variable z"
143
144 # 2 3 0
145 gdb_test "print x > y != z" "$false" "print value of x>y!=z"
146
147 gdb_test_no_output "set variable x=4" "set x to 4"
148
149 # 4 3 0
150 gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
151
152 # 4 3 0
153 gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
154
155 gdb_test_no_output "set variable x=2" " set variable x"
156
157 # 2 3 0
158 gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
159
160 gdb_test_no_output "set variable x=0" " set variable x"
161 gdb_test_no_output "set variable z=4" " set variable z"
162
163 # 0 3 4
164 gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
165
166 # 0 3 4
167 gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
168
169 gdb_test_no_output "set variable x=2" " set variable x"
170
171 # 2 3 4
172 gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
173
174 # 2 3 4
175 gdb_test "print x == y != z" "$true" "print value of x==y!=z"
176
177
178
179 # test use of parenthesis to enforce different order of evaluation
180
181 gdb_test_no_output "set variable z=0" " set variable z"
182
183 # 2 3 0
184 gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
185
186 # 2 3 0
187 gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
188
189 # 2 3 0
190 gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
191
192 gdb_test_no_output "set variable x=1" " set variable x"
193 gdb_test_no_output "set variable z=4" " set variable z"
194
195 # 1 3 4
196 gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"
197
This page took 0.044806 seconds and 4 git commands to generate.