OSDN Git Service

* lib/compat.exp: Handle dg-options per source file.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gcc-defs.exp
1 # Copyright (C) 2001, 2003 Free Software Foundation, Inc.
2
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 2 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.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 #
18 # ${tool}_check_compile -- Reports and returns pass/fail for a compilation
19 #
20
21 proc ${tool}_check_compile {testcase option objname gcc_output} {
22     global tool
23     set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
24  
25     if [string match "$fatal_signal 6" $gcc_output] then {
26         ${tool}_fail $testcase "Got Signal 6, $option"
27         return 0
28     }
29
30     if [string match "$fatal_signal 11" $gcc_output] then {
31         ${tool}_fail $testcase "Got Signal 11, $option"
32         return 0
33     }
34
35     # We shouldn't get these because of -w, but just in case.
36     if [string match "*cc:*warning:*" $gcc_output] then {
37         warning "$testcase: (with warnings) $option"
38         send_log "$gcc_output\n"
39         unresolved "$testcase, $option"
40         return 0
41     }
42
43     set gcc_output [prune_warnings $gcc_output]
44
45     set unsupported_message [${tool}_check_unsupported_p $gcc_output]
46     if { $unsupported_message != "" } {
47         unsupported "$testcase: $unsupported_message"
48         return 0
49     }
50
51     # remove any leftover LF/CR to make sure any output is legit
52     regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
53
54     # If any message remains, we fail.
55     if ![string match "" $gcc_output] then {
56         ${tool}_fail $testcase $option
57         return 0
58     }
59
60     # fail if the desired object file doesn't exist.
61     # FIXME: there's no way of checking for existence on a remote host.
62     if {$objname != "" && ![is3way] && ![file exists $objname]} {
63         ${tool}_fail $testcase $option
64         return 0
65     }
66
67     ${tool}_pass $testcase $option
68     return 1
69 }
70
71 #
72 # ${tool}_pass -- utility to record a testcase passed
73 #
74
75 proc ${tool}_pass { testcase cflags } {
76     if { "$cflags" == "" } {
77         pass "$testcase"
78     } else {
79         pass "$testcase, $cflags"
80     }
81 }
82
83 #
84 # ${tool}_fail -- utility to record a testcase failed
85 #
86
87 proc ${tool}_fail { testcase cflags } {
88     if { "$cflags" == "" } {
89         fail "$testcase"
90     } else {
91         fail "$testcase, $cflags"
92     }
93 }
94
95 #
96 # ${tool}_finish -- called at the end of every script that calls ${tool}_init
97 #
98 # Hide all quirks of the testing environment from the testsuites.  Also
99 # undo anything that ${tool}_init did that needs undoing.
100 #
101
102 proc ${tool}_finish { } {
103     # The testing harness apparently requires this.
104     global errorInfo;
105
106     if [info exists errorInfo] then {
107         unset errorInfo
108     }
109
110     # Might as well reset these (keeps our caller from wondering whether
111     # s/he has to or not).
112     global prms_id bug_id
113     set prms_id 0
114     set bug_id 0
115 }
116
117 #
118 # ${tool}_exit -- Does final cleanup when testing is complete
119 #
120
121 proc ${tool}_exit { } {
122     global gluefile;
123
124     if [info exists gluefile] {
125         file_on_build delete $gluefile;
126         unset gluefile;
127     }
128 }
129     
130 #
131 # ${tool}_check_unsupported_p -- Check the compiler(/assembler/linker) output 
132 #       for text indicating that the testcase should be marked as "unsupported"
133 #
134 # Utility used by mike-gcc.exp and c-torture.exp.
135 # When dealing with a large number of tests, it's difficult to weed out the
136 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
137 # of memory).  There are various ways to deal with this.  Here's one.
138 # Fortunately, all of the cases where this is likely to happen will be using
139 # gld so we can tell what the error text will look like.
140 #
141
142 proc ${tool}_check_unsupported_p { output } {
143     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
144         return "memory full"
145     }
146     return ""
147 }
148
149 #
150 # runtest_file_p -- Provide a definition for older dejagnu releases
151 #                   and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
152 #                   (delete after next dejagnu release).
153 #
154
155 if { [info procs runtest_file_p] == "" } then {
156     proc runtest_file_p { runtests testcase } {
157         if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
158             if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
159                 return 1
160             } else {
161                 return 0
162             }
163         }
164         return 1
165     }
166 }
167
168 # Record additional sources files that must be compiled along with the
169 # main source file.
170
171 set additional_sources ""
172
173 proc dg-additional-sources { args } {
174     global additional_sources
175     set additional_sources [lindex $args 1]
176 }
177
178 # Record additional files -- other than source files -- that must be
179 # present on the system where the compiler runs.
180
181 set additional_files ""
182
183 proc dg-additional-files { args } {
184     global additional_files
185     set additional_files [lindex $args 1]
186 }
187
188 # Return an updated version of OPTIONS that mentions any additional
189 # source files registered with dg-additional-sources.  SOURCE is the
190 # name of the test case.
191
192 proc dg-additional-files-options { options source } {
193     global additional_sources
194     global additional_files
195     set to_download [list]
196     if { $additional_sources != "" } then {
197         if [is_remote host] {
198             lappend options "additional_flags=$additional_sources"
199         }
200         regsub -all "^| " $additional_sources " [file dirname $source]/" additional_sources
201         if ![is_remote host] {
202             lappend options "additional_flags=$additional_sources"
203         }
204         set to_download [concat $to_download $additional_sources]
205         set additional_sources ""
206     }
207     if { $additional_files != "" } then { 
208         regsub -all " " $additional_files " [file dirname $source]/" additional_files
209         set to_download [concat $to_download $additional_files]
210         set additional_files ""
211     }
212     if [is_remote host] {
213         foreach file $to_download {
214             remote_download host $file
215         }
216     }
217
218     return $options
219 }