1 # Copyright 1998-2016 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18 # This file is part of the gdb testsuite
20 # tests for correctenss of relational operators, associativity and precedence
21 # with integer type variables
25 # test running programs
28 if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
32 if [get_compiler_info] {
37 # set it up at a breakpoint so we can play with the variable values
40 if ![runto_main] then {
41 perror "couldn't run to breakpoint"
46 # test expressions with "int" types
49 gdb_test_no_output "set variable x=14" "set variable x=14"
50 gdb_test_no_output "set variable y=2" "set variable y=2"
51 gdb_test_no_output "set variable z=2" "set variable z=2"
52 gdb_test_no_output "set variable w=3" "set variable w=3"
54 gdb_test "print x" " = 14" "print value of x"
56 gdb_test "print y" " = 2" "print value of y"
58 gdb_test "print z" " = 2" "print value of z"
60 gdb_test "print w" " = 3" "print value of w"
62 gdb_test "print x < y" "$false" "print value of x<y"
64 gdb_test "print x <= y" "$false" "print value of x<=y"
66 gdb_test "print x > y" "$true" "print value of x>y"
68 gdb_test "print x >= y" "$true" "print value of x>=y"
70 gdb_test "print x == y" "$false" "print value of x==y"
72 gdb_test "print x != y" "$true" "print value of x!=y"
75 # Test associativity of <, >, <=, >=, ==, !=
77 gdb_test_no_output "set variable x=3" "set variable x"
78 gdb_test_no_output "set variable y=5" "set variable y"
79 gdb_test_no_output "set variable z=2" "set variable z"
81 gdb_test "print x < y < z" "$true" "print value of x<y<z"
83 gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
85 gdb_test "print x > y > z" "$false" "print value of x>y>z"
87 gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
89 gdb_test_no_output "set variable x=2" "set variable x"
90 gdb_test_no_output "set variable y=2" "set variable y"
91 gdb_test_no_output "set variable z=1" "set variable z"
93 gdb_test "print x == y == z" "$true" "print value of x==y==z"
95 gdb_test_no_output "set variable z=0" "set variable z"
97 gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
99 # test precedence rules on pairs of relational operators
101 gdb_test_no_output "set variable x=0" "set variable x"
102 gdb_test_no_output "set variable y=2" "set variable y"
103 gdb_test_no_output "set variable z=2" "set variable z"
105 gdb_test "print x < y == z" "$false" "print value of x<y==z"
108 gdb_test "print x < y != z" "$true" "print value of x<y!=z"
110 gdb_test_no_output "set variable x=2" "set variable x"
111 gdb_test_no_output "set variable y=3" "set variable y"
112 gdb_test_no_output "set variable z=1" "set variable z"
116 gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
119 gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
121 gdb_test_no_output "set variable z=0" " set variable z"
124 gdb_test "print x < y > z" "$true" "print value of x<y>z"
126 gdb_test_no_output "set variable x=1" " set variable x"
129 gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
131 gdb_test_no_output "set variable z=2" " set variable z"
134 gdb_test "print x > y == z" "$false" "print value of x>y==z"
136 gdb_test_no_output "set variable x=2" " set variable x"
137 gdb_test_no_output "set variable z=0" " set variable z"
140 gdb_test "print x > y != z" "$false" "print value of x>y!=z"
142 gdb_test_no_output "set variable x=4" "set x to 4"
145 gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
148 gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
150 gdb_test_no_output "set variable x=2" " set variable x"
153 gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
155 gdb_test_no_output "set variable x=0" " set variable x"
156 gdb_test_no_output "set variable z=4" " set variable z"
159 gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
162 gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
164 gdb_test_no_output "set variable x=2" " set variable x"
167 gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
170 gdb_test "print x == y != z" "$true" "print value of x==y!=z"
174 # test use of parenthesis to enforce different order of evaluation
176 gdb_test_no_output "set variable z=0" " set variable z"
179 gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
182 gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
185 gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
187 gdb_test_no_output "set variable x=1" " set variable x"
188 gdb_test_no_output "set variable z=4" " set variable z"
191 gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"