1 # Copyright (C) 2000, 2002, 2003, 2005, 2007, 2008
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
18 # Various utilities for scanning dump output, used by gcc-dg.exp and
21 # This is largely borrowed from scanasm.exp.
23 # Extract the constant part of the dump file suffix from the regexp.
24 # Argument 0 is the regular expression.
25 proc dump-suffix { arg } {
26 set idx [expr [string last "." $arg] + 1]
27 return [string range $arg $idx end]
30 # Utility for scanning compiler result, invoked via dg-final.
31 # Call pass if pattern is present, otherwise fail.
33 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
34 # Argument 1 is the regexp to match.
35 # Argument 2 is the suffix for the dump file
36 # Argument 3 handles expected failures and the like
37 proc scan-dump { args } {
39 if { [llength $args] >= 4 } {
40 switch [dg-process-target [lindex $args 3]] {
43 "F" { setup_xfail "*-*-*" }
48 set testcase [testname-for-summary]
50 set printable_pattern [make_pattern_printable [lindex $args 1]]
51 set suf [dump-suffix [lindex $args 2]]
52 set testname "$testcase scan-[lindex $args 0]-dump $suf \"$printable_pattern\""
53 set src [file tail [lindex $testcase 0]]
54 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
55 if { $output_file == "" } {
56 verbose -log "$testcase: dump file does not exist"
57 unresolved "$testname"
61 set fd [open $output_file r]
65 if [regexp -- [lindex $args 1] $text] {
72 # Call pass if pattern is present given number of times, otherwise fail.
73 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
74 # Argument 1 is the regexp to match.
75 # Argument 2 is number of times the regexp must be found
76 # Argument 3 is the suffix for the dump file
77 # Argument 4 handles expected failures and the like
78 proc scan-dump-times { args } {
80 if { [llength $args] >= 5 } {
81 switch [dg-process-target [lindex $args 4]] {
84 "F" { setup_xfail "*-*-*" }
89 set testcase [testname-for-summary]
90 set suf [dump-suffix [lindex $args 3]]
91 set printable_pattern [make_pattern_printable [lindex $args 1]]
92 set testname "$testcase scan-[lindex $args 0]-dump-times $suf \"$printable_pattern\" [lindex $args 2]"
93 set src [file tail [lindex $testcase 0]]
94 set output_file "[glob -nocomplain $src.[lindex $args 3]]"
95 if { $output_file == "" } {
96 verbose -log "$testcase: dump file does not exist"
97 unresolved "$testname"
101 set fd [open $output_file r]
105 if { [llength [regexp -inline -all -- [lindex $args 1] $text]] == [lindex $args 2]} {
112 # Call pass if pattern is not present, otherwise fail.
114 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
115 # Argument 1 is the regexp to match.
116 # Argument 2 is the suffix for the dump file
117 # Argument 3 handles expected failures and the like
118 proc scan-dump-not { args } {
120 if { [llength $args] >= 4 } {
121 switch [dg-process-target [lindex $args 3]] {
124 "F" { setup_xfail "*-*-*" }
129 set testcase [testname-for-summary]
130 set printable_pattern [make_pattern_printable [lindex $args 1]]
131 set suf [dump-suffix [lindex $args 2]]
132 set testname "$testcase scan-[lindex $args 0]-dump-not $suf \"$printable_pattern\""
133 set src [file tail [lindex $testcase 0]]
134 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
135 if { $output_file == "" } {
136 verbose -log "$testcase: dump file does not exist"
137 unresolved "$testname"
141 set fd [open $output_file r]
145 if ![regexp -- [lindex $args 1] $text] {
152 # Utility for scanning demangled compiler result, invoked via dg-final.
153 # Call pass if pattern is present, otherwise fail.
155 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
156 # Argument 1 is the regexp to match.
157 # Argument 2 is the suffix for the dump file
158 # Argument 3 handles expected failures and the like
159 proc scan-dump-dem { args } {
163 if { [llength $args] >= 4 } {
164 switch [dg-process-target [lindex $args 3]] {
167 "F" { setup_xfail "*-*-*" }
172 # Find c++filt like we find g++ in g++.exp.
173 if ![info exists cxxfilt] {
174 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
175 $base_dir/../../../binutils/cxxfilt \
176 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
177 [findfile $base_dir/c++filt $base_dir/c++filt \
178 [transform c++filt]]]]
179 verbose -log "c++filt is $cxxfilt"
182 set testcase [testname-for-summary]
183 set printable_pattern [make_pattern_printable [lindex $args 1]]
184 set suf [dump-suffix [lindex $args 2]]
185 set testname "$testcase scan-[lindex $args 0]-dump-dem $suf \"$printable_pattern\""
186 set src [file tail [lindex $testcase 0]]
187 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
188 if { $output_file == "" } {
189 verbose -log "$testcase: dump file does not exist"
190 unresolved "$testname"
194 set fd [open "| $cxxfilt < $output_file" r]
198 if [regexp -- [lindex $args 1] $text] {
205 # Call pass if demangled pattern is not present, otherwise fail.
207 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
208 # Argument 1 is the regexp to match.
209 # Argument 2 is the suffix for the dump file
210 # Argument 3 handles expected failures and the like
211 proc scan-dump-dem-not { args } {
215 if { [llength $args] >= 4 } {
216 switch [dg-process-target [lindex $args 3]] {
219 "F" { setup_xfail "*-*-*" }
224 # Find c++filt like we find g++ in g++.exp.
225 if ![info exists cxxfilt] {
226 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
227 $base_dir/../../../binutils/cxxfilt \
228 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
229 [findfile $base_dir/c++filt $base_dir/c++filt \
230 [transform c++filt]]]]
231 verbose -log "c++filt is $cxxfilt"
234 set testcase [testname-for-summary]
235 set printable_pattern [make_pattern_printable [lindex $args 1]
236 set suf [dump-suffix [lindex $args 2]]
237 set testname "$testcase scan-[lindex $args 0]-dump-dem-not $suf \"$printable_pattern\""
238 set src [file tail [lindex $testcase 0]]
239 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
240 if { $output_file == "" } {
241 verbose -log "$testcase: dump file does not exist"
242 unresolved "$testname"
246 set fd [open "| $cxxfilt < $output_file" r]
250 if ![regexp -- [lindex $args 1] $text] {