OSDN Git Service

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