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 fail "$testname: dump file does not exist"
62 set fd [open $output_file r]
66 if [regexp -- [lindex $args 1] $text] {
73 # Call pass if pattern is present given number of times, otherwise fail.
74 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
75 # Argument 1 is the regexp to match.
76 # Argument 2 is number of times the regexp must be found
77 # Argument 3 is the suffix for the dump file
78 # Argument 4 handles expected failures and the like
79 proc scan-dump-times { args } {
81 if { [llength $args] >= 5 } {
82 switch [dg-process-target [lindex $args 4]] {
85 "F" { setup_xfail "*-*-*" }
90 # This assumes that we are three frames down from dg-test, and that
91 # it still stores the filename of the testcase in a local variable "name".
92 # A cleaner solution would require a new DejaGnu release.
95 set suf [dump-suffix [lindex $args 3]]
96 set testname "$testcase scan-[lindex $args 0]-dump-times $suf \"[lindex $args 1]\" [lindex $args 2]"
97 set src [file tail [lindex $testcase 0]]
98 set output_file "[glob -nocomplain $src.[lindex $args 3]]"
99 if { $output_file == "" } {
100 fail "$testname: dump file does not exist"
104 set fd [open $output_file r]
108 if { [llength [regexp -inline -all -- [lindex $args 1] $text]] == [lindex $args 2]} {
115 # Call pass if pattern is not present, otherwise fail.
117 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
118 # Argument 1 is the regexp to match.
119 # Argument 2 is the suffix for the dump file
120 # Argument 3 handles expected failures and the like
121 proc scan-dump-not { args } {
123 if { [llength $args] >= 4 } {
124 switch [dg-process-target [lindex $args 3]] {
127 "F" { setup_xfail "*-*-*" }
132 # This assumes that we are three frames down from dg-test, and that
133 # it still stores the filename of the testcase in a local variable "name".
134 # A cleaner solution would require a new DejaGnu release.
135 upvar 3 name testcase
137 set suf [dump-suffix [lindex $args 2]]
138 set testname "$testcase scan-[lindex $args 0]-dump-not $suf \"[lindex $args 1]\""
139 set src [file tail [lindex $testcase 0]]
140 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
141 if { $output_file == "" } {
142 fail "$testname: dump file does not exist"
146 set fd [open $output_file r]
150 if ![regexp -- [lindex $args 1] $text] {
157 # Utility for scanning demangled compiler result, invoked via dg-final.
158 # Call pass if pattern is present, otherwise fail.
160 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
161 # Argument 1 is the regexp to match.
162 # Argument 2 is the suffix for the dump file
163 # Argument 3 handles expected failures and the like
164 proc scan-dump-dem { args } {
168 if { [llength $args] >= 4 } {
169 switch [dg-process-target [lindex $args 3]] {
172 "F" { setup_xfail "*-*-*" }
177 # Find c++filt like we find g++ in g++.exp.
178 if ![info exists cxxfilt] {
179 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
180 $base_dir/../../../binutils/cxxfilt \
181 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
182 [findfile $base_dir/c++filt $base_dir/c++filt \
183 [transform c++filt]]]]
184 verbose -log "c++filt is $cxxfilt"
187 upvar 3 name testcase
188 set suf [dump-suffix [lindex $args 2]]
189 set testname "$testcase scan-[lindex $args 0]-dump-dem $suf \"[lindex $args 1]\""
190 set src [file tail [lindex $testcase 0]]
191 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
192 if { $output_file == "" } {
193 fail "$testname: dump file does not exist"
197 set fd [open "| $cxxfilt < $output_file" r]
201 if [regexp -- [lindex $args 1] $text] {
208 # Call pass if demangled pattern is not present, otherwise fail.
210 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
211 # Argument 1 is the regexp to match.
212 # Argument 2 is the suffix for the dump file
213 # Argument 3 handles expected failures and the like
214 proc scan-dump-dem-not { args } {
218 if { [llength $args] >= 4 } {
219 switch [dg-process-target [lindex $args 3]] {
222 "F" { setup_xfail "*-*-*" }
227 # Find c++filt like we find g++ in g++.exp.
228 if ![info exists cxxfilt] {
229 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
230 $base_dir/../../../binutils/cxxfilt \
231 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
232 [findfile $base_dir/c++filt $base_dir/c++filt \
233 [transform c++filt]]]]
234 verbose -log "c++filt is $cxxfilt"
237 upvar 3 name testcase
239 set suf [dump-suffix [lindex $args 2]]
240 set testname "$testcase scan-[lindex $args 0]-dump-dem-not $suf \"[lindex $args 1]\""
241 set src [file tail [lindex $testcase 0]]
242 set output_file "[glob -nocomplain $src.[lindex $args 2]]"
243 if { $output_file == "" } {
244 fail "$testname: dump file does not exist"
248 set fd [open "| $cxxfilt < $output_file" r]
252 if ![regexp -- [lindex $args 1] $text] {