New gdb.reverse test case for aarch64 instructions
[deliverable/binutils-gdb.git] / binutils / testsuite / lib / binutils-common.exp
CommitLineData
b90efa5b 1# Copyright (C) 1993-2015 Free Software Foundation, Inc.
f3097f33
RS
2#
3# This file is part of the GNU Binutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18# MA 02110-1301, USA.
19
20# True if the object format is known to be ELF.
21#
22proc is_elf_format {} {
23 if { ![istarget *-*-sysv4*]
24 && ![istarget *-*-unixware*]
25 && ![istarget *-*-elf*]
26 && ![istarget *-*-eabi*]
27 && ![istarget *-*-rtems*]
28 && ![istarget hppa*64*-*-hpux*]
29 && ![istarget ia64-*-hpux*]
30 && ![istarget *-*-linux*]
31 && ![istarget *-*-gnu*]
5a68afcf 32 && ![istarget *-*-nacl*]
f3097f33
RS
33 && ![istarget frv-*-uclinux*]
34 && ![istarget bfin-*-uclinux]
35 && ![istarget sh*-*-uclinux*]
ac145307 36 && ![istarget tic6x*-*-uclinux*]
f3097f33
RS
37 && ![istarget *-*-irix5*]
38 && ![istarget *-*-irix6*]
39 && ![istarget *-*-netbsd*]
40 && ![istarget *-*-openbsd*]
41 && ![istarget *-*-solaris2*] } {
42 return 0
43 }
44
45 if { [istarget *-*-linux*aout*]
df26367c 46 || [istarget *-*-linux*ecoff*]
f3097f33
RS
47 || [istarget *-*-linux*oldld*]
48 || [istarget h8500-*-rtems*]
49 || [istarget i960-*-rtems*]
50 || [istarget *-*-rtemscoff*] } {
51 return 0
52 }
53
54 if { ![istarget *-*-netbsdelf*]
55 && ([istarget *-*-netbsd*aout*]
56 || [istarget *-*-netbsdpe*]
57 || [istarget arm*-*-netbsd*]
58 || [istarget sparc-*-netbsd*]
59 || [istarget i*86-*-netbsd*]
60 || [istarget m68*-*-netbsd*]
61 || [istarget vax-*-netbsd*]
62 || [istarget ns32k-*-netbsd*]) } {
63 return 0
64 }
65
66 if { [istarget arm-*-openbsd*]
67 || [istarget i386-*-openbsd\[0-2\].*]
68 || [istarget i386-*-openbsd3.\[0-2\]]
69 || [istarget m68*-*-openbsd*]
70 || [istarget ns32k-*-openbsd*]
71 || [istarget sparc-*-openbsd\[0-2\].*]
72 || [istarget sparc-*-openbsd3.\[0-1\]]
73 || [istarget vax-*-openbsd*] } {
74 return 0
75 }
76
77 return 1
78}
79
80# True if the object format is known to be a.out.
81#
82proc is_aout_format {} {
83 if { [istarget *-*-netbsdelf]
84 || [istarget sparc64-*-netbsd*]
85 || [istarget sparc64-*-openbsd*] } {
86 return 0
87 }
88 if { [istarget *-*-*\[ab\]out*]
89 || [istarget *-*-linux*oldld*]
90 || [istarget *-*-bsd*]
91 || [istarget *-*-msdos*]
92 || [istarget arm-*-netbsd*]
93 || [istarget arm-*-openbsd*]
94 || [istarget arm-*-riscix*]
95 || [istarget i?86-*-freebsd\[12\]*]
96 || [istarget i?86-*-netbsd*]
97 || [istarget i?86-*-openbsd\[0-2\]*]
98 || [istarget i?86-*-openbsd3.\[0-2\]*]
99 || [istarget i?86-*-vsta]
100 || [istarget i?86-*-mach*]
101 || [istarget m68*-*-netbsd*]
102 || [istarget m68*-*-openbsd*]
103 || [istarget ns32k-*-*]
104 || [istarget pdp11-*-*]
105 || [istarget sparc*-*-sunos4*]
106 || [istarget sparc*-*-netbsd*]
107 || [istarget sparc*-*-openbsd\[0-2\]*]
108 || [istarget sparc*-*-openbsd3.\[0-1\]*]
109 || [istarget sparc*-fujitsu-none]
110 || [istarget vax-dec-ultrix*]
111 || [istarget vax-*-netbsd] } {
112 return 1
113 }
114 return 0
115}
116
117# True if the object format is known to be PE COFF.
118#
119proc is_pecoff_format {} {
120 if { ![istarget *-*-mingw*]
121 && ![istarget *-*-cygwin*]
122 && ![istarget *-*-cegcc*]
123 && ![istarget *-*-pe*] } {
124 return 0
125 }
126
127 return 1
128}
129
130# True if the object format is known to be 64-bit ELF.
131#
132proc is_elf64 { binary_file } {
133 global READELF
134 global READELFFLAGS
135
136 set readelf_size ""
137 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
138
139 if ![string match "" $got] then {
140 return 0
141 }
142
143 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
144 [file_contents readelf.out] nil readelf_size] } {
145 return 0
146 }
147
148 if { $readelf_size == "64" } {
149 return 1
150 }
151
152 return 0
153}
eb22018c
RS
154
155# Compare two files line-by-line. FILE_1 is the actual output and FILE_2
156# is the expected output. Ignore blank lines in either file.
157#
158# FILE_2 is a series of regexps, comments and # directives. The directives
159# are:
160#
161# #pass
162# Treat the test as a PASS if everything up till this point has
163# matched. Ignore any remaining lines in either FILE_1 or FILE_2.
164#
165# #failif
166# Reverse the sense of the test: expect differences to exist.
167#
168# #...
169# REGEXP
170# Skip all lines in FILE_1 until the first that matches REGEXP.
171#
738f4d98
MR
172# Other # lines are comments. Regexp lines starting with the `!' character
173# specify inverse matching (use `\!' for literal matching against a leading
174# `!'). Skip empty lines in both files.
eb22018c
RS
175#
176# The first optional argument is a list of regexp substitutions of the form:
177#
178# EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
179#
180# This tells the function to apply each regexp substitution EXPi->SUBSPECi
181# in order to every line of FILE_2.
182#
183# Return nonzero if differences exist.
184proc regexp_diff { file_1 file_2 args } {
185 set eof -1
186 set end_1 0
187 set end_2 0
188 set differences 0
189 set diff_pass 0
190 set fail_if_match 0
191 set ref_subst ""
192 if { [llength $args] > 0 } {
193 set ref_subst [lindex $args 0]
194 }
195 if { [llength $args] > 1 } {
196 perror "Too many arguments to regexp_diff"
197 return 1
198 }
199
200 if [file exists $file_1] then {
201 set file_a [open $file_1 r]
202 } else {
203 perror "$file_1 doesn't exist"
204 return 1
205 }
206
207 if [file exists $file_2] then {
208 set file_b [open $file_2 r]
209 } else {
210 perror "$file_2 doesn't exist"
211 close $file_a
212 return 1
213 }
214
215 verbose " Regexp-diff'ing: $file_1 $file_2" 2
216
217 while { 1 } {
218 set line_a ""
219 set line_b ""
220 while { [string length $line_a] == 0 } {
221 # Ignore blank line in FILE_1.
222 if { [gets $file_a line_a] == $eof } {
223 set end_1 1
224 break
225 }
226 }
227 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
228 if { [string match "#pass" $line_b] } {
229 set end_2 1
230 set diff_pass 1
231 break
232 } elseif { [string match "#failif" $line_b] } {
233 send_log "fail if no difference\n"
234 verbose "fail if no difference" 3
235 set fail_if_match 1
236 } elseif { [string match "#..." $line_b] } {
237 if { [gets $file_b line_b] == $eof } {
238 set end_2 1
239 set diff_pass 1
240 break
241 }
47a50e5b 242 set negated [expr { [string index $line_b 0] == "!" }]
738f4d98
MR
243 set line_bx [string range $line_b $negated end]
244 set n [expr { $negated ? "! " : "" }]
eb22018c
RS
245 # Substitute on the reference.
246 foreach {name value} $ref_subst {
738f4d98 247 regsub -- $name $line_bx $value line_bx
eb22018c 248 }
738f4d98
MR
249 verbose "looking for $n\"^$line_bx$\"" 3
250 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
eb22018c
RS
251 verbose "skipping \"$line_a\"" 3
252 if { [gets $file_a line_a] == $eof } {
253 set end_1 1
254 break
255 }
256 }
257 break
258 }
259 if { [gets $file_b line_b] == $eof } {
260 set end_2 1
261 break
262 }
263 }
264
265 if { $diff_pass } {
266 break
267 } elseif { $end_1 && $end_2 } {
268 break
269 } elseif { $end_1 } {
270 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
271 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
272 set differences 1
273 break
274 } elseif { $end_2 } {
275 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
276 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
277 set differences 1
278 break
279 } else {
47a50e5b 280 set negated [expr { [string index $line_b 0] == "!" }]
738f4d98
MR
281 set line_bx [string range $line_b $negated end]
282 set n [expr { $negated ? "! " : "" }]
283 set s [expr { $negated ? " " : "" }]
eb22018c
RS
284 # Substitute on the reference.
285 foreach {name value} $ref_subst {
738f4d98 286 regsub -- $name $line_bx $value line_bx
eb22018c 287 }
738f4d98
MR
288 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
289 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
eb22018c 290 send_log "regexp_diff match failure\n"
738f4d98 291 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
eb22018c
RS
292 verbose "regexp_diff match failure\n" 3
293 set differences 1
294 }
295 }
296 }
297
298 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
299 send_log "$file_1 and $file_2 are different lengths\n"
300 verbose "$file_1 and $file_2 are different lengths" 3
301 set differences 1
302 }
303
304 if { $fail_if_match } {
305 if { $differences == 0 } {
306 set differences 1
307 } else {
308 set differences 0
309 }
310 }
311
312 close $file_a
313 close $file_b
314
315 return $differences
316}
This page took 0.230803 seconds and 4 git commands to generate.