1 # Copyright 1998-2022 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 "failed to prepare" 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 with_test_prefix "int types" {
51 gdb_test_no_output "set variable x=14" "set variable x=14"
52 gdb_test_no_output "set variable y=2" "set variable y=2"
53 gdb_test_no_output "set variable z=2" "set variable z=2"
54 gdb_test_no_output "set variable w=3" "set variable w=3"
56 gdb_test "print x" " = 14" "print value of x"
58 gdb_test "print y" " = 2" "print value of y"
60 gdb_test "print z" " = 2" "print value of z"
62 gdb_test "print w" " = 3" "print value of w"
64 gdb_test "print x < y" "$false" "print value of x<y"
66 gdb_test "print x <= y" "$false" "print value of x<=y"
68 gdb_test "print x > y" "$true" "print value of x>y"
70 gdb_test "print x >= y" "$true" "print value of x>=y"
72 gdb_test "print x == y" "$false" "print value of x==y"
74 gdb_test "print x != y" "$true" "print value of x!=y"
77 # Test associativity of <, >, <=, >=, ==, !=
78 with_test_prefix "basic associativity" {
80 gdb_test_no_output "set variable x=3" "set variable x=3"
81 gdb_test_no_output "set variable y=5" "set variable y=5"
82 gdb_test_no_output "set variable z=2" "set variable z=2"
84 gdb_test "print x < y < z" "$true" "print value of x<y<z"
86 gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
88 gdb_test "print x > y > z" "$false" "print value of x>y>z"
90 gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
92 gdb_test_no_output "set variable x=2" "set variable x=2"
93 gdb_test_no_output "set variable y=2" "set variable y=2"
94 gdb_test_no_output "set variable z=1" "set variable z=1"
96 gdb_test "print x == y == z" "$true" "print value of x==y==z"
98 gdb_test_no_output "set variable z=0" "set variable z"
100 gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
103 # Test precedence rules on pairs of relational operators. The use of
104 # with_test_prefix with keys 1, 2, 3, etc is only to ensure that the
105 # test names are unique. Each nested group of tests starts at a
106 # location where we are setting a variable to a value it has had in
107 # the past, which would result in a test name repeating.
108 with_test_prefix "pair associativity" {
109 with_test_prefix "1" {
110 gdb_test_no_output "set variable x=0" "set variable x=0"
111 gdb_test_no_output "set variable y=2" "set variable y=2"
112 gdb_test_no_output "set variable z=2" "set variable z=2"
114 gdb_test "print x < y == z" "$false" "print value of x<y==z"
117 gdb_test "print x < y != z" "$true" "print value of x<y!=z"
119 gdb_test_no_output "set variable x=2" "set variable x=2"
120 gdb_test_no_output "set variable y=3" "set variable y=3"
121 gdb_test_no_output "set variable z=1" "set variable z=1"
124 gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
127 gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
129 gdb_test_no_output "set variable z=0" " set variable z=0"
132 gdb_test "print x < y > z" "$true" "print value of x<y>z"
134 gdb_test_no_output "set variable x=1" " set variable x=1"
137 gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
140 with_test_prefix "2" {
141 gdb_test_no_output "set variable z=2" " set variable z=2"
144 gdb_test "print x > y == z" "$false" "print value of x>y==z"
146 gdb_test_no_output "set variable x=2" " set variable x=2"
147 gdb_test_no_output "set variable z=0" " set variable z=0"
150 gdb_test "print x > y != z" "$false" "print value of x>y!=z"
152 gdb_test_no_output "set variable x=4" "set variable x=4"
155 gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
158 gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
161 with_test_prefix "3" {
162 gdb_test_no_output "set variable x=2" " set variable x=2"
165 gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
167 gdb_test_no_output "set variable x=0" " set variable x=0"
168 gdb_test_no_output "set variable z=4" " set variable z=4"
171 gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
174 gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
177 with_test_prefix "4" {
178 gdb_test_no_output "set variable x=2" " set variable x=2"
181 gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
184 gdb_test "print x == y != z" "$true" "print value of x==y!=z"
188 # test use of parenthesis to enforce different order of evaluation
189 with_test_prefix "with parenthesis" {
190 gdb_test_no_output "set variable z=0" " set variable z=0"
193 gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
196 gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
199 gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
201 gdb_test_no_output "set variable x=1" " set variable x=1"
202 gdb_test_no_output "set variable z=4" " set variable z=4"
205 gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"