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 # This assumes that we are three frames down from dg-test, and that
49 # it still stores the filename of the testcase in a local variable "name".
50 # A cleaner solution would require a new DejaGnu release.
53 set suf [dump-suffix [lindex $args 2]]
54 set testname "$testcase scan-[lindex $args 0]-dump $suf \"[lindex $args 1]\""
55 set src [file tail [lindex $testcase 0]]
56 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
57 if { $output_file == "" } {
58 verbose -log "$testcase: dump file does not exist"
59 unresolved "$testname"
63 set fd [open $output_file r]
67 if [regexp -- [lindex $args 1] $text] {
74 # Call pass if pattern is present given number of times, otherwise fail.
75 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
76 # Argument 1 is the regexp to match.
77 # Argument 2 is number of times the regexp must be found
78 # Argument 3 is the suffix for the dump file
79 # Argument 4 handles expected failures and the like
80 proc scan-dump-times { args } {
82 if { [llength $args] >= 5 } {
83 switch [dg-process-target [lindex $args 4]] {
86 "F" { setup_xfail "*-*-*" }
91 # This assumes that we are three frames down from dg-test, and that
92 # it still stores the filename of the testcase in a local variable "name".
93 # A cleaner solution would require a new DejaGnu release.
96 set suf [dump-suffix [lindex $args 3]]
97 set testname "$testcase scan-[lindex $args 0]-dump-times $suf \"[lindex $args 1]\" [lindex $args 2]"
98 set src [file tail [lindex $testcase 0]]
99 set output_file "[glob -nocomplain $src.[lindex $args 3]]"
100 if { $output_file == "" } {
101 verbose -log "$testcase: dump file does not exist"
102 unresolved "$testname"
106 set fd [open $output_file r]
110 if { [llength [regexp -inline -all -- [lindex $args 1] $text]] == [lindex $args 2]} {
117 # Call pass if pattern is not present, otherwise fail.
119 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
120 # Argument 1 is the regexp to match.
121 # Argument 2 is the suffix for the dump file
122 # Argument 3 handles expected failures and the like
123 proc scan-dump-not { args } {
125 if { [llength $args] >= 4 } {
126 switch [dg-process-target [lindex $args 3]] {
129 "F" { setup_xfail "*-*-*" }
134 # This assumes that we are three frames down from dg-test, and that
135 # it still stores the filename of the testcase in a local variable "name".
136 # A cleaner solution would require a new DejaGnu release.
137 upvar 3 name testcase
139 set suf [dump-suffix [lindex $args 2]]
140 set testname "$testcase scan-[lindex $args 0]-dump-not $suf \"[lindex $args 1]\""
141 set src [file tail [lindex $testcase 0]]
142 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
143 if { $output_file == "" } {
144 verbose -log "$testcase: dump file does not exist"
145 unresolved "$testname"
149 set fd [open $output_file r]
153 if ![regexp -- [lindex $args 1] $text] {
160 # Utility for scanning demangled compiler result, invoked via dg-final.
161 # Call pass if pattern is present, otherwise fail.
163 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
164 # Argument 1 is the regexp to match.
165 # Argument 2 is the suffix for the dump file
166 # Argument 3 handles expected failures and the like
167 proc scan-dump-dem { args } {
171 if { [llength $args] >= 4 } {
172 switch [dg-process-target [lindex $args 3]] {
175 "F" { setup_xfail "*-*-*" }
180 # Find c++filt like we find g++ in g++.exp.
181 if ![info exists cxxfilt] {
182 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
183 $base_dir/../../../binutils/cxxfilt \
184 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
185 [findfile $base_dir/c++filt $base_dir/c++filt \
186 [transform c++filt]]]]
187 verbose -log "c++filt is $cxxfilt"
190 upvar 3 name testcase
191 set suf [dump-suffix [lindex $args 2]]
192 set testname "$testcase scan-[lindex $args 0]-dump-dem $suf \"[lindex $args 1]\""
193 set src [file tail [lindex $testcase 0]]
194 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
195 if { $output_file == "" } {
196 verbose -log "$testcase: dump file does not exist"
197 unresolved "$testname"
201 set fd [open "| $cxxfilt < $output_file" r]
205 if [regexp -- [lindex $args 1] $text] {
212 # Call pass if demangled pattern is not present, otherwise fail.
214 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
215 # Argument 1 is the regexp to match.
216 # Argument 2 is the suffix for the dump file
217 # Argument 3 handles expected failures and the like
218 proc scan-dump-dem-not { args } {
222 if { [llength $args] >= 4 } {
223 switch [dg-process-target [lindex $args 3]] {
226 "F" { setup_xfail "*-*-*" }
231 # Find c++filt like we find g++ in g++.exp.
232 if ![info exists cxxfilt] {
233 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
234 $base_dir/../../../binutils/cxxfilt \
235 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
236 [findfile $base_dir/c++filt $base_dir/c++filt \
237 [transform c++filt]]]]
238 verbose -log "c++filt is $cxxfilt"
241 upvar 3 name testcase
243 set suf [dump-suffix [lindex $args 2]]
244 set testname "$testcase scan-[lindex $args 0]-dump-dem-not $suf \"[lindex $args 1]\""
245 set src [file tail [lindex $testcase 0]]
246 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
247 if { $output_file == "" } {
248 verbose -log "$testcase: dump file does not exist"
249 unresolved "$testname"
253 set fd [open "| $cxxfilt < $output_file" r]
257 if ![regexp -- [lindex $args 1] $text] {