Commit | Line | Data |
---|---|---|
f7d690e5 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
7b6bb8da | 3 | # Copyright 1998, 1999, 2004, 2007, 2008, 2009, 2010, 2011 |
4c38e0a4 | 4 | # Free Software Foundation, Inc. |
c906108c SS |
5 | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 8 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 9 | # (at your option) any later version. |
e22f8b7c | 10 | # |
c906108c SS |
11 | # This program is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
e22f8b7c | 15 | # |
c906108c | 16 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 18 | |
c906108c SS |
19 | # This file was written by Elena Zannoni (ezannoni@cygnus.com) |
20 | ||
f7d690e5 AC |
21 | # Tests for correctenss of logical operators, associativity and |
22 | # precedence with integer type variables | |
c906108c | 23 | |
c906108c SS |
24 | |
25 | if $tracelevel then { | |
f7d690e5 AC |
26 | strace $tracelevel |
27 | } | |
c906108c SS |
28 | |
29 | # | |
30 | # test running programs | |
31 | # | |
c906108c SS |
32 | |
33 | set testfile "int-type" | |
34 | set srcfile ${testfile}.c | |
35 | set binfile ${objdir}/${subdir}/${testfile} | |
36 | ||
fc91c6c2 | 37 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { |
b60f0898 JB |
38 | untested logical.exp |
39 | return -1 | |
f7d690e5 | 40 | } |
c906108c | 41 | |
085dd6e6 JM |
42 | if [get_compiler_info ${binfile}] { |
43 | return -1; | |
44 | } | |
c906108c SS |
45 | |
46 | gdb_exit | |
47 | gdb_start | |
48 | gdb_reinitialize_dir $srcdir/$subdir | |
49 | gdb_load ${binfile} | |
50 | ||
51 | ||
52 | # | |
53 | # set it up at a breakpoint so we can play with the variable values | |
54 | # | |
55 | ||
56 | if ![runto_main] then { | |
57 | perror "couldn't run to breakpoint" | |
58 | continue | |
59 | } | |
60 | ||
f7d690e5 AC |
61 | proc evaluate { vars ops } { |
62 | for {set vari 0} {$vari < [llength $vars]} {incr vari} { | |
63 | set var [lindex $vars $vari] | |
64 | for {set opi 0} {$opi < [llength $ops]} {incr opi} { | |
65 | set op [lindex [lindex $ops $opi] 0] | |
66 | set val [lindex [lindex $ops $opi] [expr $vari + 1]] | |
67 | gdb_test "print $var, $op" " = $val" "evaluate $op; variables $var; expecting $val" | |
68 | } | |
69 | } | |
70 | } | |
c906108c | 71 | |
f7d690e5 | 72 | # Unary |
c906108c | 73 | |
f7d690e5 AC |
74 | evaluate { |
75 | {x = 0} {x = 1} | |
76 | } { | |
77 | { {x} 0 1 } | |
78 | { {!x} 1 0 } | |
79 | { {!!x} 0 1 } | |
80 | } | |
c906108c | 81 | |
f7d690e5 AC |
82 | # Binary (with unary) |
83 | ||
84 | evaluate { | |
85 | {x = 0, y = 0} {x = 0, y = 1} {x = 1, y = 0} {x = 1, y = 1} | |
86 | } { | |
87 | { {x && y} 0 0 0 1 } | |
88 | { {!x && y} 0 1 0 0 } | |
89 | { {x && !y} 0 0 1 0 } | |
90 | { {!x && !y} 1 0 0 0 } | |
91 | ||
92 | { {x || y} 0 1 1 1 } | |
93 | { {!x || y} 1 1 0 1 } | |
94 | { {x || !y} 1 0 1 1 } | |
95 | { {!x || !y} 1 1 1 0 } | |
96 | ||
97 | { {x < y} 0 1 0 0 } | |
98 | { {x <= y} 1 1 0 1 } | |
99 | { {x == y} 1 0 0 1 } | |
100 | { {x != y} 0 1 1 0 } | |
101 | { {x >= y} 1 0 1 1 } | |
102 | { {x > y} 0 0 1 0 } | |
103 | } | |
c906108c | 104 | |
f7d690e5 | 105 | # Full table of &&, || combinations, followed by random mix of unary ops |
c906108c | 106 | |
f7d690e5 AC |
107 | evaluate { |
108 | {x = 0, y = 0, z = 0} {x = 0, y = 0, z = 1} {x = 0, y = 1, z = 0} {x = 0, y = 1, z = 1} | |
109 | {x = 1, y = 0, z = 0} {x = 1, y = 0, z = 1} {x = 1, y = 1, z = 0} {x = 1, y = 1, z = 1} | |
110 | } { | |
111 | { {x && y && z} 0 0 0 0 0 0 0 1 } | |
112 | { {x || y && z} 0 0 0 1 1 1 1 1 } | |
113 | { {x && y || z} 0 1 0 1 0 1 1 1 } | |
114 | { {x || y || z} 0 1 1 1 1 1 1 1 } | |
c906108c | 115 | |
f7d690e5 AC |
116 | { {x || !y && z} 0 1 0 0 1 1 1 1 } |
117 | { {!x || y && z} 1 1 1 1 0 0 0 1 } | |
118 | { {!x || y && !z} 1 1 1 1 0 0 1 0 } | |
119 | } | |
c906108c | 120 | |
f7d690e5 | 121 | # More complex operations |
c906108c | 122 | |
f7d690e5 AC |
123 | evaluate { |
124 | {x = 1, y = 2, w = 3, z = 3} | |
125 | {x = 1, y = 2, w = 1, z = 3} | |
126 | {x = 2, y = 2, w = 2, z = 3} | |
127 | } { | |
128 | { {x > y || w == z} 1 0 0 } | |
129 | { {x >= y && w != z} 0 0 1 } | |
130 | { {! x > y || w + z} 1 1 1 } | |
131 | } |