1 # Copyright 1998, 1999, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
19 # This file is part of the gdb testsuite
21 # tests for correctenss of relational operators, associativity and precedence
22 # with integer type variables
30 # test running programs
33 if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
37 if [get_compiler_info not-used] {
42 # set it up at a breakpoint so we can play with the variable values
45 if ![runto_main] then {
46 perror "couldn't run to breakpoint"
51 # test expressions with "int" types
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"
59 gdb_test "print x" " = 14" "print value of x"
61 gdb_test "print y" " = 2" "print value of y"
63 gdb_test "print z" " = 2" "print value of z"
65 gdb_test "print w" " = 3" "print value of w"
67 gdb_test "print x < y" "$false" "print value of x<y"
69 gdb_test "print x <= y" "$false" "print value of x<=y"
71 gdb_test "print x > y" "$true" "print value of x>y"
73 gdb_test "print x >= y" "$true" "print value of x>=y"
75 gdb_test "print x == y" "$false" "print value of x==y"
77 gdb_test "print x != y" "$true" "print value of x!=y"
80 # Test associativity of <, >, <=, >=, ==, !=
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"
86 gdb_test "print x < y < z" "$true" "print value of x<y<z"
88 gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
90 gdb_test "print x > y > z" "$false" "print value of x>y>z"
92 gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
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"
98 gdb_test "print x == y == z" "$true" "print value of x==y==z"
100 gdb_test_no_output "set variable z=0" "set variable z"
102 gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
104 # test precedence rules on pairs of relational operators
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"
110 gdb_test "print x < y == z" "$false" "print value of x<y==z"
113 gdb_test "print x < y != z" "$true" "print value of x<y!=z"
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"
121 gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
124 gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
126 gdb_test_no_output "set variable z=0" " set variable z"
129 gdb_test "print x < y > z" "$true" "print value of x<y>z"
131 gdb_test_no_output "set variable x=1" " set variable x"
134 gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
136 gdb_test_no_output "set variable z=2" " set variable z"
139 gdb_test "print x > y == z" "$false" "print value of x>y==z"
141 gdb_test_no_output "set variable x=2" " set variable x"
142 gdb_test_no_output "set variable z=0" " set variable z"
145 gdb_test "print x > y != z" "$false" "print value of x>y!=z"
147 gdb_test_no_output "set variable x=4" "set x to 4"
150 gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
153 gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
155 gdb_test_no_output "set variable x=2" " set variable x"
158 gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
160 gdb_test_no_output "set variable x=0" " set variable x"
161 gdb_test_no_output "set variable z=4" " set variable z"
164 gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
167 gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
169 gdb_test_no_output "set variable x=2" " set variable x"
172 gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
175 gdb_test "print x == y != z" "$true" "print value of x==y!=z"
179 # test use of parenthesis to enforce different order of evaluation
181 gdb_test_no_output "set variable z=0" " set variable z"
184 gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
187 gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
190 gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
192 gdb_test_no_output "set variable x=1" " set variable x"
193 gdb_test_no_output "set variable z=4" " set variable z"
196 gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"