PageRenderTime 45ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/mingw-w64-v2.0.999/binutils/src/binutils/testsuite/lib/binutils-common.exp

#
Expect | 315 lines | 242 code | 17 blank | 56 comment | 79 complexity | 214db435855f570f9be4ff3be4196d4a MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, 0BSD, LGPL-2.0, GPL-3.0, AGPL-1.0, Unlicense, GPL-2.0, BSD-3-Clause
  1. # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004, 2006, 2007,
  2. # 2009, 2010, 2011 Free Software Foundation, Inc.
  3. #
  4. # This file is part of the GNU Binutils.
  5. #
  6. # This file 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, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  19. # MA 02110-1301, USA.
  20. # True if the object format is known to be ELF.
  21. #
  22. proc 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*]
  32. && ![istarget frv-*-uclinux*]
  33. && ![istarget bfin-*-uclinux]
  34. && ![istarget sh*-*-uclinux*]
  35. && ![istarget tic6x*-*-uclinux*]
  36. && ![istarget *-*-irix5*]
  37. && ![istarget *-*-irix6*]
  38. && ![istarget *-*-netbsd*]
  39. && ![istarget *-*-openbsd*]
  40. && ![istarget *-*-solaris2*] } {
  41. return 0
  42. }
  43. if { [istarget *-*-linux*aout*]
  44. || [istarget *-*-linux*oldld*]
  45. || [istarget h8500-*-rtems*]
  46. || [istarget i960-*-rtems*]
  47. || [istarget *-*-rtemscoff*] } {
  48. return 0
  49. }
  50. if { ![istarget *-*-netbsdelf*]
  51. && ([istarget *-*-netbsd*aout*]
  52. || [istarget *-*-netbsdpe*]
  53. || [istarget arm*-*-netbsd*]
  54. || [istarget sparc-*-netbsd*]
  55. || [istarget i*86-*-netbsd*]
  56. || [istarget m68*-*-netbsd*]
  57. || [istarget vax-*-netbsd*]
  58. || [istarget ns32k-*-netbsd*]) } {
  59. return 0
  60. }
  61. if { [istarget arm-*-openbsd*]
  62. || [istarget i386-*-openbsd\[0-2\].*]
  63. || [istarget i386-*-openbsd3.\[0-2\]]
  64. || [istarget m68*-*-openbsd*]
  65. || [istarget ns32k-*-openbsd*]
  66. || [istarget sparc-*-openbsd\[0-2\].*]
  67. || [istarget sparc-*-openbsd3.\[0-1\]]
  68. || [istarget vax-*-openbsd*] } {
  69. return 0
  70. }
  71. return 1
  72. }
  73. # True if the object format is known to be a.out.
  74. #
  75. proc is_aout_format {} {
  76. if { [istarget *-*-netbsdelf]
  77. || [istarget sparc64-*-netbsd*]
  78. || [istarget sparc64-*-openbsd*] } {
  79. return 0
  80. }
  81. if { [istarget *-*-*\[ab\]out*]
  82. || [istarget *-*-linux*oldld*]
  83. || [istarget *-*-bsd*]
  84. || [istarget *-*-msdos*]
  85. || [istarget arm-*-netbsd*]
  86. || [istarget arm-*-openbsd*]
  87. || [istarget arm-*-riscix*]
  88. || [istarget i?86-*-freebsd\[12\]*]
  89. || [istarget i?86-*-netbsd*]
  90. || [istarget i?86-*-openbsd\[0-2\]*]
  91. || [istarget i?86-*-openbsd3.\[0-2\]*]
  92. || [istarget i?86-*-vsta]
  93. || [istarget i?86-*-mach*]
  94. || [istarget m68*-*-netbsd*]
  95. || [istarget m68*-*-openbsd*]
  96. || [istarget ns32k-*-*]
  97. || [istarget pdp11-*-*]
  98. || [istarget sparc*-*-sunos4*]
  99. || [istarget sparc*-*-netbsd*]
  100. || [istarget sparc*-*-openbsd\[0-2\]*]
  101. || [istarget sparc*-*-openbsd3.\[0-1\]*]
  102. || [istarget sparc*-fujitsu-none]
  103. || [istarget vax-dec-ultrix*]
  104. || [istarget vax-*-netbsd] } {
  105. return 1
  106. }
  107. return 0
  108. }
  109. # True if the object format is known to be PE COFF.
  110. #
  111. proc is_pecoff_format {} {
  112. if { ![istarget *-*-mingw*]
  113. && ![istarget *-*-cygwin*]
  114. && ![istarget *-*-cegcc*]
  115. && ![istarget *-*-pe*] } {
  116. return 0
  117. }
  118. return 1
  119. }
  120. # True if the object format is known to be 64-bit ELF.
  121. #
  122. proc is_elf64 { binary_file } {
  123. global READELF
  124. global READELFFLAGS
  125. set readelf_size ""
  126. catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
  127. if ![string match "" $got] then {
  128. return 0
  129. }
  130. if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
  131. [file_contents readelf.out] nil readelf_size] } {
  132. return 0
  133. }
  134. if { $readelf_size == "64" } {
  135. return 1
  136. }
  137. return 0
  138. }
  139. # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
  140. # is the expected output. Ignore blank lines in either file.
  141. #
  142. # FILE_2 is a series of regexps, comments and # directives. The directives
  143. # are:
  144. #
  145. # #pass
  146. # Treat the test as a PASS if everything up till this point has
  147. # matched. Ignore any remaining lines in either FILE_1 or FILE_2.
  148. #
  149. # #failif
  150. # Reverse the sense of the test: expect differences to exist.
  151. #
  152. # #...
  153. # REGEXP
  154. # Skip all lines in FILE_1 until the first that matches REGEXP.
  155. #
  156. # Other # lines are comments. Regexp lines starting with the `!' character
  157. # specify inverse matching (use `\!' for literal matching against a leading
  158. # `!'). Skip empty lines in both files.
  159. #
  160. # The first optional argument is a list of regexp substitutions of the form:
  161. #
  162. # EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
  163. #
  164. # This tells the function to apply each regexp substitution EXPi->SUBSPECi
  165. # in order to every line of FILE_2.
  166. #
  167. # Return nonzero if differences exist.
  168. proc regexp_diff { file_1 file_2 args } {
  169. set eof -1
  170. set end_1 0
  171. set end_2 0
  172. set differences 0
  173. set diff_pass 0
  174. set fail_if_match 0
  175. set ref_subst ""
  176. if { [llength $args] > 0 } {
  177. set ref_subst [lindex $args 0]
  178. }
  179. if { [llength $args] > 1 } {
  180. perror "Too many arguments to regexp_diff"
  181. return 1
  182. }
  183. if [file exists $file_1] then {
  184. set file_a [open $file_1 r]
  185. } else {
  186. perror "$file_1 doesn't exist"
  187. return 1
  188. }
  189. if [file exists $file_2] then {
  190. set file_b [open $file_2 r]
  191. } else {
  192. perror "$file_2 doesn't exist"
  193. close $file_a
  194. return 1
  195. }
  196. verbose " Regexp-diff'ing: $file_1 $file_2" 2
  197. while { 1 } {
  198. set line_a ""
  199. set line_b ""
  200. while { [string length $line_a] == 0 } {
  201. # Ignore blank line in FILE_1.
  202. if { [gets $file_a line_a] == $eof } {
  203. set end_1 1
  204. break
  205. }
  206. }
  207. while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
  208. if { [string match "#pass" $line_b] } {
  209. set end_2 1
  210. set diff_pass 1
  211. break
  212. } elseif { [string match "#failif" $line_b] } {
  213. send_log "fail if no difference\n"
  214. verbose "fail if no difference" 3
  215. set fail_if_match 1
  216. } elseif { [string match "#..." $line_b] } {
  217. if { [gets $file_b line_b] == $eof } {
  218. set end_2 1
  219. set diff_pass 1
  220. break
  221. }
  222. set negated [expr { [string index $line_b 0] == "!" }]
  223. set line_bx [string range $line_b $negated end]
  224. set n [expr { $negated ? "! " : "" }]
  225. # Substitute on the reference.
  226. foreach {name value} $ref_subst {
  227. regsub -- $name $line_bx $value line_bx
  228. }
  229. verbose "looking for $n\"^$line_bx$\"" 3
  230. while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
  231. verbose "skipping \"$line_a\"" 3
  232. if { [gets $file_a line_a] == $eof } {
  233. set end_1 1
  234. break
  235. }
  236. }
  237. break
  238. }
  239. if { [gets $file_b line_b] == $eof } {
  240. set end_2 1
  241. break
  242. }
  243. }
  244. if { $diff_pass } {
  245. break
  246. } elseif { $end_1 && $end_2 } {
  247. break
  248. } elseif { $end_1 } {
  249. send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
  250. verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
  251. set differences 1
  252. break
  253. } elseif { $end_2 } {
  254. send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
  255. verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
  256. set differences 1
  257. break
  258. } else {
  259. set negated [expr { [string index $line_b 0] == "!" }]
  260. set line_bx [string range $line_b $negated end]
  261. set n [expr { $negated ? "! " : "" }]
  262. set s [expr { $negated ? " " : "" }]
  263. # Substitute on the reference.
  264. foreach {name value} $ref_subst {
  265. regsub -- $name $line_bx $value line_bx
  266. }
  267. verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
  268. if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
  269. send_log "regexp_diff match failure\n"
  270. send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
  271. verbose "regexp_diff match failure\n" 3
  272. set differences 1
  273. }
  274. }
  275. }
  276. if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
  277. send_log "$file_1 and $file_2 are different lengths\n"
  278. verbose "$file_1 and $file_2 are different lengths" 3
  279. set differences 1
  280. }
  281. if { $fail_if_match } {
  282. if { $differences == 0 } {
  283. set differences 1
  284. } else {
  285. set differences 0
  286. }
  287. }
  288. close $file_a
  289. close $file_b
  290. return $differences
  291. }