Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / gcc / testsuite / lib / scanasm.exp
blob24de1871b6a3d3e90c48fdabe9f884e690655920
1 # Copyright (C) 2000, 2002, 2003, 2007, 2008 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # Various utilities for scanning assembler output, used by gcc-dg.exp and
18 # g++-dg.exp.
20 # Utility for scanning compiler result, invoked via dg-final.
22 # Scan the OUTPUT_FILE for a pattern. If it is present and POSITIVE
23 # is non-zero, or it is not present and POSITIVE is zero, the test
24 # passes. The ORIG_ARGS is the list of arguments provided by dg-final
25 # to scan-assembler. The first element in ORIG_ARGS is the regular
26 # expression to look for in the file. The second element, if present,
27 # is a DejaGNU target selector.
29 proc dg-scan { name positive testcase output_file orig_args } {
30 if { [llength $orig_args] < 1 } {
31 error "$name: too few arguments"
32 return
34 if { [llength $orig_args] > 2 } {
35 error "$name: too many arguments"
36 return
38 if { [llength $orig_args] >= 2 } {
39 switch [dg-process-target [lindex $orig_args 1]] {
40 "S" { }
41 "N" { return }
42 "F" { setup_xfail "*-*-*" }
43 "P" { }
47 if { [is_remote host] } {
48 remote_upload host "$output_file"
50 set fd [open $output_file r]
51 set text [read $fd]
52 close $fd
54 set pattern [lindex $orig_args 0]
55 set printable_pattern [string map {\t \\t \n \\n \r \\r \\ \\\\} $pattern]
57 set match [regexp -- $pattern $text]
58 if { $match == $positive } {
59 pass "$testcase $name $printable_pattern"
60 } else {
61 fail "$testcase $name $printable_pattern"
65 # Look for a pattern in the .s file produced by the compiler. See
66 # dg-scan for details.
68 proc scan-assembler { args } {
69 upvar 2 name testcase
70 set testcase [lindex $testcase 0]
71 set output_file "[file rootname [file tail $testcase]].s"
73 dg-scan "scan-assembler" 1 $testcase $output_file $args
76 # Check that a pattern is not present in the .s file produced by the
77 # compiler. See dg-scan for details.
79 proc scan-assembler-not { args } {
80 upvar 2 name testcase
81 set testcase [lindex $testcase 0]
82 set output_file "[file rootname [file tail $testcase]].s"
84 dg-scan "scan-assembler-not" 0 $testcase $output_file $args
87 # Return the scan for the assembly for hidden visibility.
89 proc hidden-scan-for { symbol } {
91 set objformat [gcc_target_object_format]
93 switch $objformat {
94 elf { return "hidden\[ \t_\]*$symbol" }
95 mach-o { return "private_extern\[ \t_\]*_?$symbol" }
96 default { return "" }
102 # Check that a symbol is defined as a hidden symbol in the .s file
103 # produced by the compiler.
105 proc scan-hidden { args } {
106 upvar 2 name testcase
107 set testcase [lindex $testcase 0]
108 set output_file "[file rootname [file tail $testcase]].s"
110 set symbol [lindex $args 0]
112 set hidden_scan [hidden-scan-for $symbol]
114 set args [lreplace $args 0 0 "$hidden_scan"]
116 dg-scan "scan-hidden" 1 $testcase $output_file $args
119 # Check that a symbol is not defined as a hidden symbol in the .s file
120 # produced by the compiler.
122 proc scan-not-hidden { args } {
123 upvar 2 name testcase
124 set testcase [lindex $testcase 0]
125 set output_file "[file rootname [file tail $testcase]].s"
127 set symbol [lindex $args 0]
128 set hidden_scan [hidden-scan-for $symbol]
130 set args [lreplace $args 0 0 "$hidden_scan"]
132 dg-scan "scan-not-hidden" 0 $testcase $output_file $args
135 # Look for a pattern in OUTPUT_FILE. See dg-scan for details.
137 proc scan-file { output_file args } {
138 upvar 2 name testcase
139 set testcase [lindex $testcase 0]
140 dg-scan "scan-file" 1 $testcase $output_file $args
143 # Check that a pattern is not present in the OUTPUT_FILE. See dg-scan
144 # for details.
146 proc scan-file-not { output_file args } {
147 upvar 2 name testcase
148 set testcase [lindex $testcase 0]
149 dg-scan "scan-file-not" 0 $testcase $output_file $args
152 # Call pass if pattern is present given number of times, otherwise fail.
153 proc scan-assembler-times { args } {
154 if { [llength $args] < 2 } {
155 error "scan-assembler: too few arguments"
156 return
158 if { [llength $args] > 3 } {
159 error "scan-assembler: too many arguments"
160 return
162 if { [llength $args] >= 3 } {
163 switch [dg-process-target [lindex $args 2]] {
164 "S" { }
165 "N" { return }
166 "F" { setup_xfail "*-*-*" }
167 "P" { }
171 # This assumes that we are two frames down from dg-test, and that
172 # it still stores the filename of the testcase in a local variable "name".
173 # A cleaner solution would require a new dejagnu release.
174 upvar 2 name testcase
175 set testcase [lindex $testcase 0]
177 # This must match the rule in gcc-dg.exp.
178 set output_file "[file rootname [file tail $testcase]].s"
180 set fd [open $output_file r]
181 set text [read $fd]
182 close $fd
184 if { [llength [regexp -inline -all -- [lindex $args 0] $text]] == [lindex $args 1]} {
185 pass "$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
186 } else {
187 fail "$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
191 # Utility for scanning demangled compiler result, invoked via dg-final.
192 # Call pass if pattern is present, otherwise fail.
193 proc scan-assembler-dem { args } {
194 global cxxfilt
195 global base_dir
197 if { [llength $args] < 1 } {
198 error "scan-assembler-dem: too few arguments"
199 return
201 if { [llength $args] > 2 } {
202 error "scan-assembler-dem: too many arguments"
203 return
205 if { [llength $args] >= 2 } {
206 switch [dg-process-target [lindex $args 1]] {
207 "S" { }
208 "N" { return }
209 "F" { setup_xfail "*-*-*" }
210 "P" { }
214 # Find c++filt like we find g++ in g++.exp.
215 if ![info exists cxxfilt] {
216 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
217 $base_dir/../../../binutils/cxxfilt \
218 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
219 [findfile $base_dir/c++filt $base_dir/c++filt \
220 [transform c++filt]]]]
221 verbose -log "c++filt is $cxxfilt"
224 upvar 2 name testcase
225 set testcase [lindex $testcase 0]
226 set output_file "[file rootname [file tail $testcase]].s"
228 set output [remote_exec host "$cxxfilt" "" "$output_file"]
229 set text [lindex $output 1]
231 if [regexp -- [lindex $args 0] $text] {
232 pass "$testcase scan-assembler-dem [lindex $args 0]"
233 } else {
234 fail "$testcase scan-assembler-dem [lindex $args 0]"
238 # Call pass if demangled pattern is not present, otherwise fail.
239 proc scan-assembler-dem-not { args } {
240 global cxxfilt
241 global base_dir
243 if { [llength $args] < 1 } {
244 error "scan-assembler-dem-not: too few arguments"
245 return
247 if { [llength $args] > 2 } {
248 error "scan-assembler-dem-not: too many arguments"
249 return
251 if { [llength $args] >= 2 } {
252 switch [dg-process-target [lindex $args 1]] {
253 "S" { }
254 "N" { return }
255 "F" { setup_xfail "*-*-*" }
256 "P" { }
260 # Find c++filt like we find g++ in g++.exp.
261 if ![info exists cxxfilt] {
262 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
263 $base_dir/../../../binutils/cxxfilt \
264 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
265 [findfile $base_dir/c++filt $base_dir/c++filt \
266 [transform c++filt]]]]
267 verbose -log "c++filt is $cxxfilt"
270 upvar 2 name testcase
271 set testcase [lindex $testcase 0]
272 set output_file "[file rootname [file tail $testcase]].s"
274 set output [remote_exec host "$cxxfilt" "" "$output_file"]
275 set text [lindex $output 1]
277 if ![regexp -- [lindex $args 0] $text] {
278 pass "$testcase scan-assembler-dem-not [lindex $args 0]"
279 } else {
280 fail "$testcase scan-assembler-dem-not [lindex $args 0]"