scandump.exp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. # Copyright (C) 2000-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # Various utilities for scanning dump output, used by gcc-dg.exp and
  16. # g++-dg.exp.
  17. #
  18. # This is largely borrowed from scanasm.exp.
  19. # Extract the constant part of the dump file suffix from the regexp.
  20. # Argument 0 is the regular expression.
  21. proc dump-suffix { arg } {
  22. set idx [expr [string last "." $arg] + 1]
  23. return [string range $arg $idx end]
  24. }
  25. # Utility for scanning compiler result, invoked via dg-final.
  26. # Call pass if pattern is present, otherwise fail.
  27. #
  28. # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
  29. # Argument 1 is the regexp to match.
  30. # Argument 2 is the suffix for the dump file
  31. # Argument 3 handles expected failures and the like
  32. proc scan-dump { args } {
  33. if { [llength $args] >= 4 } {
  34. switch [dg-process-target [lindex $args 3]] {
  35. "S" { }
  36. "N" { return }
  37. "F" { setup_xfail "*-*-*" }
  38. "P" { }
  39. }
  40. }
  41. set testcase [testname-for-summary]
  42. set printable_pattern [make_pattern_printable [lindex $args 1]]
  43. set suf [dump-suffix [lindex $args 2]]
  44. set testname "$testcase scan-[lindex $args 0]-dump $suf \"$printable_pattern\""
  45. set src [file tail [lindex $testcase 0]]
  46. set output_file "[glob -nocomplain $src.[lindex $args 2]]"
  47. if { $output_file == "" } {
  48. verbose -log "$testcase: dump file does not exist"
  49. unresolved "$testname"
  50. return
  51. }
  52. set fd [open $output_file r]
  53. set text [read $fd]
  54. close $fd
  55. if [regexp -- [lindex $args 1] $text] {
  56. pass "$testname"
  57. } else {
  58. fail "$testname"
  59. }
  60. }
  61. # Call pass if pattern is present given number of times, otherwise fail.
  62. # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
  63. # Argument 1 is the regexp to match.
  64. # Argument 2 is number of times the regexp must be found
  65. # Argument 3 is the suffix for the dump file
  66. # Argument 4 handles expected failures and the like
  67. proc scan-dump-times { args } {
  68. if { [llength $args] >= 5 } {
  69. switch [dg-process-target [lindex $args 4]] {
  70. "S" { }
  71. "N" { return }
  72. "F" { setup_xfail "*-*-*" }
  73. "P" { }
  74. }
  75. }
  76. set testcase [testname-for-summary]
  77. set suf [dump-suffix [lindex $args 3]]
  78. set printable_pattern [make_pattern_printable [lindex $args 1]]
  79. set testname "$testcase scan-[lindex $args 0]-dump-times $suf \"$printable_pattern\" [lindex $args 2]"
  80. set src [file tail [lindex $testcase 0]]
  81. set output_file "[glob -nocomplain $src.[lindex $args 3]]"
  82. if { $output_file == "" } {
  83. verbose -log "$testcase: dump file does not exist"
  84. unresolved "$testname"
  85. return
  86. }
  87. set fd [open $output_file r]
  88. set text [read $fd]
  89. close $fd
  90. if { [llength [regexp -inline -all -- [lindex $args 1] $text]] == [lindex $args 2]} {
  91. pass "$testname"
  92. } else {
  93. fail "$testname"
  94. }
  95. }
  96. # Call pass if pattern is not present, otherwise fail.
  97. #
  98. # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
  99. # Argument 1 is the regexp to match.
  100. # Argument 2 is the suffix for the dump file
  101. # Argument 3 handles expected failures and the like
  102. proc scan-dump-not { args } {
  103. if { [llength $args] >= 4 } {
  104. switch [dg-process-target [lindex $args 3]] {
  105. "S" { }
  106. "N" { return }
  107. "F" { setup_xfail "*-*-*" }
  108. "P" { }
  109. }
  110. }
  111. set testcase [testname-for-summary]
  112. set printable_pattern [make_pattern_printable [lindex $args 1]]
  113. set suf [dump-suffix [lindex $args 2]]
  114. set testname "$testcase scan-[lindex $args 0]-dump-not $suf \"$printable_pattern\""
  115. set src [file tail [lindex $testcase 0]]
  116. set output_file "[glob -nocomplain $src.[lindex $args 2]]"
  117. if { $output_file == "" } {
  118. verbose -log "$testcase: dump file does not exist"
  119. unresolved "$testname"
  120. return
  121. }
  122. set fd [open $output_file r]
  123. set text [read $fd]
  124. close $fd
  125. if ![regexp -- [lindex $args 1] $text] {
  126. pass "$testname"
  127. } else {
  128. fail "$testname"
  129. }
  130. }
  131. # Utility for scanning demangled compiler result, invoked via dg-final.
  132. # Call pass if pattern is present, otherwise fail.
  133. #
  134. # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
  135. # Argument 1 is the regexp to match.
  136. # Argument 2 is the suffix for the dump file
  137. # Argument 3 handles expected failures and the like
  138. proc scan-dump-dem { args } {
  139. global cxxfilt
  140. global base_dir
  141. if { [llength $args] >= 4 } {
  142. switch [dg-process-target [lindex $args 3]] {
  143. "S" { }
  144. "N" { return }
  145. "F" { setup_xfail "*-*-*" }
  146. "P" { }
  147. }
  148. }
  149. # Find c++filt like we find g++ in g++.exp.
  150. if ![info exists cxxfilt] {
  151. set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
  152. $base_dir/../../../binutils/cxxfilt \
  153. [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
  154. [findfile $base_dir/c++filt $base_dir/c++filt \
  155. [transform c++filt]]]]
  156. verbose -log "c++filt is $cxxfilt"
  157. }
  158. set testcase [testname-for-summary]
  159. set printable_pattern [make_pattern_printable [lindex $args 1]]
  160. set suf [dump-suffix [lindex $args 2]]
  161. set testname "$testcase scan-[lindex $args 0]-dump-dem $suf \"$printable_pattern\""
  162. set src [file tail [lindex $testcase 0]]
  163. set output_file "[glob -nocomplain $src.[lindex $args 2]]"
  164. if { $output_file == "" } {
  165. verbose -log "$testcase: dump file does not exist"
  166. unresolved "$testname"
  167. return
  168. }
  169. set fd [open "| $cxxfilt < $output_file" r]
  170. set text [read $fd]
  171. close $fd
  172. if [regexp -- [lindex $args 1] $text] {
  173. pass "$testname"
  174. } else {
  175. fail "$testname"
  176. }
  177. }
  178. # Call pass if demangled pattern is not present, otherwise fail.
  179. #
  180. # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
  181. # Argument 1 is the regexp to match.
  182. # Argument 2 is the suffix for the dump file
  183. # Argument 3 handles expected failures and the like
  184. proc scan-dump-dem-not { args } {
  185. global cxxfilt
  186. global base_dir
  187. if { [llength $args] >= 4 } {
  188. switch [dg-process-target [lindex $args 3]] {
  189. "S" { }
  190. "N" { return }
  191. "F" { setup_xfail "*-*-*" }
  192. "P" { }
  193. }
  194. }
  195. # Find c++filt like we find g++ in g++.exp.
  196. if ![info exists cxxfilt] {
  197. set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
  198. $base_dir/../../../binutils/cxxfilt \
  199. [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
  200. [findfile $base_dir/c++filt $base_dir/c++filt \
  201. [transform c++filt]]]]
  202. verbose -log "c++filt is $cxxfilt"
  203. }
  204. set testcase [testname-for-summary]
  205. set printable_pattern [make_pattern_printable [lindex $args 1]
  206. set suf [dump-suffix [lindex $args 2]]
  207. set testname "$testcase scan-[lindex $args 0]-dump-dem-not $suf \"$printable_pattern\""
  208. set src [file tail [lindex $testcase 0]]
  209. set output_file "[glob -nocomplain $src.[lindex $args 2]]"
  210. if { $output_file == "" } {
  211. verbose -log "$testcase: dump file does not exist"
  212. unresolved "$testname"
  213. return
  214. }
  215. set fd [open "| $cxxfilt < $output_file" r]
  216. set text [read $fd]
  217. close $fd
  218. if ![regexp -- [lindex $args 1] $text] {
  219. pass "$testname"
  220. } else {
  221. fail "$testname"
  222. }
  223. }