runtime: allow preemption in fast syscall return
[official-gcc.git] / gcc / testsuite / lib / gcc-defs.exp
blobaaff8774fefb0fd7582d0f430ae84002f8424ea0
1 # Copyright (C) 2001-2018 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 load_lib target-libpath.exp
19 load_lib wrapper.exp
21 load_lib target-utils.exp
24 # ${tool}_check_compile -- Reports and returns pass/fail for a compilation
27 proc ${tool}_check_compile {testcase option objname gcc_output} {
28 global tool
29 set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
31 if [string match "$fatal_signal 6" $gcc_output] then {
32 ${tool}_fail $testcase "Got Signal 6, $option"
33 return 0
36 if [string match "$fatal_signal 11" $gcc_output] then {
37 ${tool}_fail $testcase "Got Signal 11, $option"
38 return 0
41 if [string match "*internal compiler error*" $gcc_output] then {
42 ${tool}_fail $testcase "$option (internal compiler error)"
43 return 0
46 # We shouldn't get these because of -w, but just in case.
47 if [string match "*cc:*warning:*" $gcc_output] then {
48 warning "$testcase: (with warnings) $option"
49 send_log "$gcc_output\n"
50 unresolved "$testcase, $option"
51 return 0
54 set gcc_output [prune_warnings $gcc_output]
56 if { [info proc ${tool}-dg-prune] != "" } {
57 global target_triplet
58 set gcc_output [${tool}-dg-prune $target_triplet $gcc_output]
59 if [string match "*::unsupported::*" $gcc_output] then {
60 regsub -- "::unsupported::" $gcc_output "" gcc_output
61 unsupported "$testcase: $gcc_output"
62 return 0
64 } else {
65 set unsupported_message [${tool}_check_unsupported_p $gcc_output]
66 if { $unsupported_message != "" } {
67 unsupported "$testcase: $unsupported_message"
68 return 0
72 # remove any leftover LF/CR to make sure any output is legit
73 regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
75 # If any message remains, we fail.
76 if ![string match "" $gcc_output] then {
77 ${tool}_fail $testcase $option
78 return 0
81 # fail if the desired object file doesn't exist.
82 # FIXME: there's no way of checking for existence on a remote host.
83 if {$objname != "" && ![is3way] && ![file exists $objname]} {
84 ${tool}_fail $testcase $option
85 return 0
88 ${tool}_pass $testcase $option
89 return 1
93 # ${tool}_pass -- utility to record a testcase passed
96 proc ${tool}_pass { testcase cflags } {
97 if { "$cflags" == "" } {
98 pass "$testcase"
99 } else {
100 pass "$testcase, $cflags"
105 # ${tool}_fail -- utility to record a testcase failed
108 proc ${tool}_fail { testcase cflags } {
109 if { "$cflags" == "" } {
110 fail "$testcase"
111 } else {
112 fail "$testcase, $cflags"
117 # ${tool}_finish -- called at the end of every script that calls ${tool}_init
119 # Hide all quirks of the testing environment from the testsuites. Also
120 # undo anything that ${tool}_init did that needs undoing.
123 proc ${tool}_finish { } {
124 # The testing harness apparently requires this.
125 global errorInfo
127 if [info exists errorInfo] then {
128 unset errorInfo
131 # Might as well reset these (keeps our caller from wondering whether
132 # s/he has to or not).
133 global prms_id bug_id
134 set prms_id 0
135 set bug_id 0
139 # ${tool}_exit -- Does final cleanup when testing is complete
142 proc ${tool}_exit { } {
143 global gluefile
145 if [info exists gluefile] {
146 file_on_build delete $gluefile
147 unset gluefile
152 # runtest_file_p -- Provide a definition for older dejagnu releases
153 # and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
154 # (delete after next dejagnu release).
157 if { [info procs runtest_file_p] == "" } then {
158 proc runtest_file_p { runtests testcase } {
159 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
160 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
161 return 1
162 } else {
163 return 0
166 return 1
170 if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \
171 && [info procs runtest_file_p] != [list] \
172 && [info procs gcc_parallelize_saved_runtest_file_p] == [list] } then {
173 global gcc_runtest_parallelize_counter
174 global gcc_runtest_parallelize_counter_minor
175 global gcc_runtest_parallelize_enable
176 global gcc_runtest_parallelize_dir
177 global gcc_runtest_parallelize_last
179 set gcc_runtest_parallelize_counter 0
180 set gcc_runtest_parallelize_counter_minor 0
181 set gcc_runtest_parallelize_enable 1
182 set gcc_runtest_parallelize_dir [getenv GCC_RUNTEST_PARALLELIZE_DIR]
183 set gcc_runtest_parallelize_last 0
185 proc gcc_parallel_test_run_p { testcase } {
186 global gcc_runtest_parallelize_counter
187 global gcc_runtest_parallelize_counter_minor
188 global gcc_runtest_parallelize_enable
189 global gcc_runtest_parallelize_dir
190 global gcc_runtest_parallelize_last
192 if { $gcc_runtest_parallelize_enable == 0 } {
193 return 1
196 # Only test the filesystem every 10th iteration
197 incr gcc_runtest_parallelize_counter_minor
198 if { $gcc_runtest_parallelize_counter_minor == 10 } {
199 set gcc_runtest_parallelize_counter_minor 0
201 if { $gcc_runtest_parallelize_counter_minor != 1 } {
202 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter $gcc_runtest_parallelize_last"
203 return $gcc_runtest_parallelize_last
206 set path $gcc_runtest_parallelize_dir/$gcc_runtest_parallelize_counter
208 if {![catch {open $path {RDWR CREAT EXCL} 0600} fd]} {
209 close $fd
210 set gcc_runtest_parallelize_last 1
211 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 1"
212 incr gcc_runtest_parallelize_counter
213 return 1
215 set gcc_runtest_parallelize_last 0
216 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 0"
217 incr gcc_runtest_parallelize_counter
218 return 0
221 proc gcc_parallel_test_enable { val } {
222 global gcc_runtest_parallelize_enable
223 set gcc_runtest_parallelize_enable $val
226 rename runtest_file_p gcc_parallelize_saved_runtest_file_p
227 proc runtest_file_p { runtests testcase } {
228 if ![gcc_parallelize_saved_runtest_file_p $runtests $testcase] {
229 return 0
231 return [gcc_parallel_test_run_p $testcase]
234 } else {
236 proc gcc_parallel_test_run_p { testcase } {
237 return 1
240 proc gcc_parallel_test_enable { val } {
245 # Like dg-options, but adds to the default options rather than replacing them.
247 proc dg-additional-options { args } {
248 upvar dg-extra-tool-flags extra-tool-flags
250 if { [llength $args] > 3 } {
251 error "[lindex $args 0]: too many arguments"
252 return
255 if { [llength $args] >= 3 } {
256 switch [dg-process-target [lindex $args 2]] {
257 "S" { eval lappend extra-tool-flags [lindex $args 1] }
258 "N" { }
259 "F" { error "[lindex $args 0]: `xfail' not allowed here" }
260 "P" { error "[lindex $args 0]: `xfail' not allowed here" }
262 } else {
263 eval lappend extra-tool-flags [lindex $args 1]
267 # Record additional sources files that must be compiled along with the
268 # main source file.
270 set additional_sources ""
271 set additional_sources_used ""
273 proc dg-additional-sources { args } {
274 global additional_sources
275 set additional_sources [lindex $args 1]
278 # Record additional files -- other than source files -- that must be
279 # present on the system where the compiler runs.
281 set additional_files ""
283 proc dg-additional-files { args } {
284 global additional_files
285 set additional_files [lindex $args 1]
288 # Return an updated version of OPTIONS that mentions any additional
289 # source files registered with dg-additional-sources. SOURCE is the
290 # name of the test case.
292 proc dg-additional-files-options { options source } {
293 global additional_sources
294 global additional_sources_used
295 global additional_files
296 set to_download [list]
297 if { $additional_sources != "" } then {
298 if [is_remote host] {
299 lappend options "additional_flags=$additional_sources"
301 regsub -all "^| " $additional_sources " [file dirname $source]/" additional_sources
302 if ![is_remote host] {
303 lappend options "additional_flags=$additional_sources"
305 set to_download [concat $to_download $additional_sources]
306 set additional_sources_used "$additional_sources"
307 set additional_sources ""
309 if { $additional_files != "" } then {
310 regsub -all "^| " $additional_files " [file dirname $source]/" additional_files
311 set to_download [concat $to_download $additional_files]
312 set additional_files ""
314 if [is_remote host] {
315 foreach file $to_download {
316 remote_download host $file
320 return $options
323 # Return a colon-separate list of directories to search for libraries
324 # for COMPILER, including multilib directories.
326 proc gcc-set-multilib-library-path { compiler } {
327 global rootme
329 # ??? rootme will not be set when testing an installed compiler.
330 # In that case, we should perhaps use some other method to find
331 # libraries.
332 if {![info exists rootme]} {
333 return ""
336 set libpath ":${rootme}"
337 set options [lrange $compiler 1 end]
338 set compiler [lindex $compiler 0]
339 if { [is_remote host] == 0 && [which $compiler] != 0 } {
340 foreach i "[eval exec $compiler $options --print-multi-lib]" {
341 set mldir ""
342 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
343 set mldir [string trimright $mldir "\;@"]
344 if { "$mldir" == "." } {
345 continue
347 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
348 append libpath ":${rootme}/${mldir}"
353 return $libpath
356 # A list of all uses of dg-regexp, each entry of the form:
357 # line-number regexp
358 # This is cleared at the end of each test by gcc-dg.exp's wrapper for dg-test.
359 set freeform_regexps []
361 # Directive for looking for a regexp, without any line numbers or other
362 # prefixes.
364 proc dg-regexp { args } {
365 verbose "dg-regexp: args: $args" 2
367 global freeform_regexps
368 lappend freeform_regexps $args
371 # Hook to be called by prune.exp's prune_gcc_output to
372 # look for the expected dg-regexp expressions, pruning them,
373 # reporting PASS for those that are found, and FAIL for
374 # those that weren't found.
376 # It returns a pruned version of its output.
378 proc handle-dg-regexps { text } {
379 global freeform_regexps
380 global testname_with_flags
382 foreach entry $freeform_regexps {
383 verbose " entry: $entry" 3
385 set linenum [lindex $entry 0]
386 set rexp [lindex $entry 1]
388 # Escape newlines in $rexp so that we can print them in
389 # pass/fail results.
390 set escaped_regex [string map {"\n" "\\n"} $rexp]
391 verbose "escaped_regex: ${escaped_regex}" 4
393 set title "$testname_with_flags dg-regexp $linenum"
395 # Use "regsub" to attempt to prune the pattern from $text
396 if {[regsub -line $rexp $text "" text]} {
397 # Success; the multiline pattern was pruned.
398 pass "$title was found: \"$escaped_regex\""
399 } else {
400 fail "$title not found: \"$escaped_regex\""
404 return $text