1# Copyright 1998, 1999 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 2 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, write to the Free Software 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 17# Please email any bugs, comments, and/or additions to this file to: 18# bug-gdb@prep.ai.mit.edu 19 20# This file was written by Elena Zannoni (ezannoni@cygnus.com) 21 22# This file is part of the gdb testsuite 23# 24# tests for correctenss of relational operators, associativity and precedence 25# with integer type variables 26# 27 28if $tracelevel then { 29 strace $tracelevel 30 } 31 32# 33# test running programs 34# 35set prms_id 0 36set bug_id 0 37 38set testfile "int-type" 39set srcfile ${testfile}.c 40set binfile ${objdir}/${subdir}/${testfile} 41if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } { 42 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 43 } 44 45if [get_compiler_info ${binfile}] { 46 return -1; 47} 48 49gdb_exit 50gdb_start 51gdb_reinitialize_dir $srcdir/$subdir 52gdb_load ${binfile} 53 54 55# 56# set it up at a breakpoint so we can play with the variable values 57# 58 59if ![runto_main] then { 60 perror "couldn't run to breakpoint" 61 continue 62} 63 64# 65# test expressions with "int" types 66# 67 68gdb_test "set variable x=14" "" "set variable x=14" 69gdb_test "set variable y=2" "" "set variable y=2" 70gdb_test "set variable z=2" "" "set variable z=2" 71gdb_test "set variable w=3" "" "set variable w=3" 72 73send_gdb "print x\n" 74gdb_expect { 75 -re ".*14.*$gdb_prompt $" { 76 pass "print value of x" 77 } 78 -re ".*$gdb_prompt $" { fail "print value of x" } 79 timeout { fail "(timeout) print value of x" } 80 } 81 82 83send_gdb "print y\n" 84gdb_expect { 85 -re ".*2.*$gdb_prompt $" { 86 pass "print value of y" 87 } 88 -re ".*$gdb_prompt $" { fail "print value of y" } 89 timeout { fail "(timeout) print value of y" } 90 } 91 92send_gdb "print z\n" 93gdb_expect { 94 -re ".*2.*$gdb_prompt $" { 95 pass "print value of z" 96 } 97 -re ".*$gdb_prompt $" { fail "print value of z" } 98 timeout { fail "(timeout) print value of z" } 99 } 100 101send_gdb "print w\n" 102gdb_expect { 103 -re ".*3.*$gdb_prompt $" { 104 pass "print value of w" 105 } 106 -re ".*$gdb_prompt $" { fail "print value of w" } 107 timeout { fail "(timeout) print value of w" } 108 } 109 110 111 112send_gdb "print x < y\n" 113gdb_expect { 114 -re ".*$false.*$gdb_prompt $" { 115 pass "print value of x<y" 116 } 117 -re ".*$gdb_prompt $" { fail "print value of x<y" } 118 timeout { fail "(timeout) print value of x<y" } 119 } 120 121send_gdb "print x <= y\n" 122gdb_expect { 123 -re ".*$false.*$gdb_prompt $" { 124 pass "print value of x<=y" 125 } 126 -re ".*$gdb_prompt $" { fail "print value of x<=y" } 127 timeout { fail "(timeout) print value of x<=y" } 128 } 129 130send_gdb "print x > y\n" 131gdb_expect { 132 -re ".*$true.*$gdb_prompt $" { 133 pass "print value of x>y" 134 } 135 -re ".*$gdb_prompt $" { fail "print value of x>y" } 136 timeout { fail "(timeout) print value of x>y" } 137 } 138 139send_gdb "print x >= y\n" 140gdb_expect { 141 -re ".*$true.*$gdb_prompt $" { 142 pass "print value of x>=y" 143 } 144 -re ".*$gdb_prompt $" { fail "print value of x>=y" } 145 timeout { fail "(timeout) print value of x>=y" } 146 } 147 148send_gdb "print x == y\n" 149gdb_expect { 150 -re ".*$false.*$gdb_prompt $" { 151 pass "print value of x==y" 152 } 153 -re ".*$gdb_prompt $" { fail "print value of x==y" } 154 timeout { fail "(timeout) print value of x==y" } 155 } 156 157send_gdb "print x != y\n" 158gdb_expect { 159 -re ".*$true.*$gdb_prompt $" { 160 pass "print value of x!=y" 161 } 162 -re ".*$gdb_prompt $" { fail "print value of x!=y" } 163 timeout { fail "(timeout) print value of x!=y" } 164 } 165 166 167 168# Test associativity of <, >, <=, >=, ==, != 169 170gdb_test "set variable x=3" "" "set variable x" 171gdb_test "set variable y=5" "" "set variable y" 172gdb_test "set variable z=2" "" "set variable z" 173 174 175 176send_gdb "print x < y < z\n" 177gdb_expect { 178 -re ".*$true.*\r\n$gdb_prompt $" { 179 pass "print value of x<y<z" 180 } 181 -re ".*$gdb_prompt $" { fail "print value of x<y<z" } 182 timeout { fail "(timeout) print value of x<y<z" } 183 } 184 185send_gdb "print x <= y <= z\n" 186gdb_expect { 187 -re ".*$true\r\n$gdb_prompt $" { 188 pass "print value of x<=y<=z" 189 } 190 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" } 191 timeout { fail "(timeout) print value of x<=y<=z" } 192 } 193 194send_gdb "print x > y > z\n" 195gdb_expect { 196 -re ".*$false.*\r\n$gdb_prompt $" { 197 pass "print value of x>y>z" 198 } 199 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" } 200 timeout { fail "(timeout) print value of x>y>z" } 201 } 202 203send_gdb "print x >= y >= z\n" 204gdb_expect { 205 -re ".*$false.*\r\n$gdb_prompt $" { 206 pass "print value of x>=y>=z" 207 } 208 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" } 209 timeout { fail "(timeout) print value of x>=y>=z" } 210 } 211 212gdb_test "set variable x=2" "" "set variable x" 213gdb_test "set variable y=2" "" "set variable y" 214gdb_test "set variable z=1" "" "set variable z" 215 216 217send_gdb "print x == y == z\n" 218gdb_expect { 219 -re ".*$true.*$gdb_prompt $" { 220 pass "print value of x==y==z" 221 } 222 -re ".*$gdb_prompt $" { fail "print value of x==y==z" } 223 timeout { fail "(timeout) print value of x==y==z" } 224 } 225 226gdb_test "set variable z=0" "" "set variable z" 227 228 229send_gdb "print x != y != z\n" 230gdb_expect { 231 -re ".*$false\r\n$gdb_prompt $" { 232 pass "print value of x!=y!=z" 233 } 234 -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" } 235 timeout { fail "(timeout) print value of x!=y!=z" } 236 } 237 238 239# test precedence rules on pairs of relational operators 240 241gdb_test "set variable x=0" "" "set variable x" 242gdb_test "set variable y=2" "" "set variable y" 243gdb_test "set variable z=2" "" "set variable z" 244 245 246send_gdb "print x < y == z\n" 247gdb_expect { 248 -re ".*$false.*$gdb_prompt $" { 249 pass "print value of x<y==z" 250 } 251 -re ".*$gdb_prompt $" { fail "print value of x<y==z" } 252 timeout { fail "(timeout) print value of x<y==z" } 253 } 254 255# 0 2 2 256send_gdb "print x < y != z\n" 257gdb_expect { 258 -re ".*$true.*$gdb_prompt $" { 259 pass "print value of x<y!=z" 260 } 261 -re ".*$gdb_prompt $" { fail "print value of x<y!=z" } 262 timeout { fail "(timeout) print value of x<y!=z" } 263 } 264 265gdb_test "set variable x=2" "" "set variable x" 266gdb_test "set variable y=3" "" "set variable y" 267gdb_test "set variable z=1" "" "set variable z" 268 269 270# 2 3 1 271send_gdb "print x < y <= z\n" 272gdb_expect { 273 -re ".*$true.*$gdb_prompt $" { 274 pass "print value of x<y<=z" 275 } 276 -re ".*$gdb_prompt $" { fail "print value of x<y<=z" } 277 timeout { fail "(timeout) print value of x<y<=z" } 278 } 279 280 281# 2 3 1 282send_gdb "print x < y >= z\n" 283gdb_expect { 284 -re ".*$true.*$gdb_prompt $" { 285 pass "print value of x<y>=z" 286 } 287 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" } 288 timeout { fail "(timeout) print value of x<y>=z" } 289 } 290 291 292gdb_test "set variable z=0" "" " set variable z" 293 294 295# 2 3 0 296send_gdb "print x < y > z\n" 297gdb_expect { 298 -re ".*$true.*$gdb_prompt $" { 299 pass "print value of x<y>z" 300 } 301 -re ".*$gdb_prompt $" { fail "print value of x<y>z" } 302 timeout { fail "(timeout) print value of x<y>z" } 303 } 304 305 306gdb_test "set variable x=1" "" " set variable x" 307 308# 1 3 0 309send_gdb "print x > y >= z\n" 310gdb_expect { 311 -re ".*$true.*$gdb_prompt $" { 312 pass "print value of x>y>=z" 313 } 314 -re ".*$gdb_prompt $" { fail "print value of x>y>=z" } 315 timeout { fail "(timeout) print value of x>y>=z" } 316 } 317 318 319gdb_test "set variable z=2" "" " set variable z" 320 321# 1 3 2 322send_gdb "print x > y == z\n" 323gdb_expect { 324 -re ".*$false.*$gdb_prompt $" { 325 pass "print value of x>y==z" 326 } 327 -re ".*$gdb_prompt $" { fail "print value of x>y==z" } 328 timeout { fail "(timeout) print value of x>y==z" } 329 } 330 331 332gdb_test "set variable x=2" "" " set variable x" 333gdb_test "set variable z=0" "" " set variable z" 334 335# 2 3 0 336send_gdb "print x > y != z\n" 337gdb_expect { 338 -re ".*$false.*$gdb_prompt $" { 339 pass "print value of x>y!=z" 340 } 341 -re ".*$gdb_prompt $" { fail "print value of x>y!=z" } 342 timeout { fail "(timeout) print value of x>y!=z" } 343 } 344 345 346gdb_test "set variable x=4" "" "set x to 4" 347 348# 4 3 0 349send_gdb "print x > y <= z\n" 350gdb_expect { 351 -re ".*$false.*$gdb_prompt $" { 352 pass "print value of x>y<=z" 353 } 354 -re ".*$gdb_prompt $" { fail "print value of x>y<=z" } 355 timeout { fail "(timeout) print value of x>y<=z" } 356 } 357 358# 4 3 0 359send_gdb "print x >= y == z\n" 360gdb_expect { 361 -re ".*$false\r\n$gdb_prompt $" { 362 pass "print value of x>=y==z" 363 } 364 -re ".*$gdb_prompt $" { fail "print value of x>=y==z" } 365 timeout { fail "(timeout) print value of x>=y==z" } 366 } 367 368 369gdb_test "set variable x=2" "" " set variable x" 370 371# 2 3 0 372send_gdb "print x >= y != z\n" 373gdb_expect { 374 -re ".*$false\r\n$gdb_prompt $" { 375 pass "print value of x>=y!=z" 376 } 377 -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" } 378 timeout { fail "(timeout) print value of x>=y!=z" } 379 } 380 381 382gdb_test "set variable x=0" "" " set variable x" 383gdb_test "set variable z=4" "" " set variable z" 384 385# 0 3 4 386send_gdb "print x >= y <= z\n" 387gdb_expect { 388 -re ".*$true\r\n$gdb_prompt $" { 389 pass "print value of x>=y<=z" 390 } 391 -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" } 392 timeout { fail "(timeout) print value of x>=y<=z" } 393 } 394 395# 0 3 4 396send_gdb "print x <= y == z\n" 397gdb_expect { 398 -re ".*$false\r\n$gdb_prompt $" { 399 pass "print value of x<=y==z" 400 } 401 -re ".*$gdb_prompt $" { fail "print value of x<=y==z" } 402 timeout { fail "(timeout) print value of x<=y==z" } 403 } 404 405gdb_test "set variable x=2" "" " set variable x" 406 407# 2 3 4 408send_gdb "print x <= y != z\n" 409gdb_expect { 410 -re ".*$true\r\n$gdb_prompt $" { 411 pass "print value of x<=y!=z" 412 } 413 -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" } 414 timeout { fail "(timeout) print value of x<=y!=z" } 415 } 416 417 418# 2 3 4 419send_gdb "print x == y != z\n" 420gdb_expect { 421 -re ".*$true\r\n$gdb_prompt $" { 422 pass "print value of x==y!=z" 423 } 424 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" } 425 timeout { fail "(timeout) print value of x==y!=z" } 426 } 427 428 429 430# test use of parenthesis to enforce different order of evaluation 431 432 433gdb_test "set variable z=0" "" " set variable z" 434 435# 2 3 0 436send_gdb "print x >= (y < z)\n" 437gdb_expect { 438 -re ".*$true\r\n$gdb_prompt $" { 439 pass "print value of x>=(y<z)" 440 } 441 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" } 442 timeout { fail "(timeout) print value of x>=(y<z)" } 443 } 444 445 446# 2 3 0 447send_gdb "print x >= (y != z)\n" 448gdb_expect { 449 -re ".*$true\r\n$gdb_prompt $" { 450 pass "print value of x>=(y!=z)" 451 } 452 -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" } 453 timeout { fail "(timeout) print value of x>=(y!=z)" } 454 } 455 456# 2 3 0 457send_gdb "print x == (y == z)\n" 458gdb_expect { 459 -re ".*$false\r\n$gdb_prompt $" { 460 pass "print value of x==(y==z)" 461 } 462 -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" } 463 timeout { fail "(timeout) print value of x==(y==z)" } 464 } 465 466 467gdb_test "set variable x=1" "" " set variable x" 468gdb_test "set variable z=4" "" " set variable z" 469 470# 1 3 4 471send_gdb "print (x == y) < z\n" 472gdb_expect { 473 -re ".*$true\r\n$gdb_prompt $" { 474 pass "print value of (x==y)<z" 475 } 476 -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" } 477 timeout { fail "(timeout) print value of (x==y)<z" } 478 } 479 480 481 482 483 484 485