1 # Copyright (C) 1992, 1993, 1994, 1996, 1997, 1999, 2000 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 2 of the License, or
6 # (at your option) any later version.
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 this program; if not, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # This file was written by Rob Savoye (rob@cygnus.com)
18 # Currently maintained by Doug Evans (dje@cygnus.com)
20 # This file is loaded by the tool init file (eg: unix.exp). It provides
21 # default definitions for gcc_start, etc. and other supporting cast members.
23 # These globals are used by gcc_start if no compiler arguments are provided.
24 # They are also used by the various testsuites to define the environment:
25 # where to find stdio.h, libc.a, etc.
27 # we want to use libgloss so we can get find_gcc.
32 # GCC_UNDER_TEST is the compiler under test.
36 # default_gcc_version -- extract and print the version number of the compiler
39 proc default_gcc_version { } {
44 # ignore any arguments after the command
45 set compiler [lindex $GCC_UNDER_TEST 0]
47 if ![is_remote host] {
48 set compiler_name [which $compiler];
50 set compiler_name $compiler;
53 # verify that the compiler exists
54 if { $compiler_name != 0 } then {
55 set tmp [remote_exec host "$compiler -v"]
56 set status [lindex $tmp 0];
57 set output [lindex $tmp 1];
58 regexp "version.*$" $output version
59 if { $status == 0 && [info exists version] } then {
60 clone_output "$compiler_name $version\n"
62 clone_output "Couldn't determine version of $compiler_name: $output\n"
65 # compiler does not exist (this should have already been detected)
66 warning "$compiler does not exist"
71 # Call gcc_version. We do it this way so we can override it if needed.
73 proc gcc_version { } {
78 # gcc_init -- called at the start of each .exp script.
80 # There currently isn't much to do, but always using it allows us to
81 # make some enhancements without having to go back and rewrite the scripts.
86 proc gcc_init { args } {
89 global gluefile wrap_flags
90 global gcc_initialized
92 global TOOL_EXECUTABLE
94 if { $gcc_initialized == 1 } { return; }
96 if ![info exists GCC_UNDER_TEST] {
97 if [info exists TOOL_EXECUTABLE] {
98 set GCC_UNDER_TEST $TOOL_EXECUTABLE;
100 set GCC_UNDER_TEST "[find_gcc]"
104 if ![info exists tmpdir] then {
107 if { [target_info needs_status_wrapper]!="" && ![info exists gluefile] } {
108 set gluefile ${tmpdir}/testglue.o;
109 set result [build_wrapper $gluefile];
110 if { $result != "" } {
111 set gluefile [lindex $result 0];
112 set wrap_flags [lindex $result 1];
119 proc gcc_target_compile { source dest type options } {
121 global gluefile wrap_flags;
122 global GCC_UNDER_TEST
125 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
126 lappend options "libs=${gluefile}"
127 lappend options "ldflags=$wrap_flags"
130 if [target_info exists gcc,stack_size] {
131 lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
133 if [target_info exists gcc,no_trampolines] {
134 lappend options "additional_flags=-DNO_TRAMPOLINES"
136 if [target_info exists gcc,no_label_values] {
137 lappend options "additional_flags=-DNO_LABEL_VALUES"
139 if [info exists TOOL_OPTIONS] {
140 lappend options "additional_flags=$TOOL_OPTIONS"
142 if [target_info exists gcc,no_varargs] {
143 lappend options "additional_flags=-DNO_VARARGS"
145 if [target_info exists gcc,timeout] {
146 lappend options "timeout=[target_info gcc,timeout]"
148 lappend options "compiler=$GCC_UNDER_TEST"
149 return [target_compile $source $dest $type $options]
153 # Reports pass/fail for a gcc compilation and returns true/false.
154 proc gcc_check_compile {testcase option objname gcc_output} {
156 set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
158 if [string match "$fatal_signal 6" $gcc_output] then {
159 gcc_fail $testcase "Got Signal 6, $option"
163 if [string match "$fatal_signal 11" $gcc_output] then {
164 gcc_fail $testcase "Got Signal 11, $option"
168 # We shouldn't get these because of -w, but just in case.
169 if [string match "*cc:*warning:*" $gcc_output] then {
170 warning "$testcase: (with warnings) $option"
171 send_log "$gcc_output\n"
172 unresolved "$testcase, $option"
176 set gcc_output [prune_warnings $gcc_output]
178 set unsupported_message [gcc_check_unsupported_p $gcc_output]
179 if { $unsupported_message != "" } {
180 unsupported "$testcase: $unsupported_message"
184 # remove any leftover LF/CR to make sure any output is legit
185 regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
187 # If any message remains, we fail.
188 if ![string match "" $gcc_output] then {
189 gcc_fail $testcase $option
193 # fail if the desired object file doesn't exist.
194 # FIXME: there's no way of checking for existence on a remote host.
195 if {$objname != "" && ![is3way] && ![file exists $objname]} {
196 gcc_fail $testcase $option
200 gcc_pass $testcase $option
207 # gcc_pass -- utility to record a testcase passed
210 proc gcc_pass { testcase cflags } {
211 if { "$cflags" == "" } {
214 pass "$testcase, $cflags"
219 # gcc_fail -- utility to record a testcase failed
222 proc gcc_fail { testcase cflags } {
223 if { "$cflags" == "" } {
226 fail "$testcase, $cflags"
231 # gcc_finish -- called at the end of every .exp script that calls gcc_init
233 # The purpose of this proc is to hide all quirks of the testing environment
234 # from the testsuites. It also exists to undo anything that gcc_init did
235 # (that needs undoing).
238 proc gcc_finish { } {
239 # The testing harness apparently requires this.
242 if [info exists errorInfo] then {
246 # Might as well reset these (keeps our caller from wondering whether
247 # s/he has to or not).
248 global prms_id bug_id
256 if [info exists gluefile] {
257 file_on_build delete $gluefile;
262 # If this is an older version of dejagnu (without runtest_file_p),
263 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
264 # This can be deleted after next dejagnu release.
266 if { [info procs runtest_file_p] == "" } then {
267 proc runtest_file_p { runtests testcase } {
268 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
269 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
279 # Utility used by mike-gcc.exp and c-torture.exp.
280 # Check the compiler(/assembler/linker) output for text indicating that
281 # the testcase should be marked as "unsupported".
283 # When dealing with a large number of tests, it's difficult to weed out the
284 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
285 # of memory). There are various ways to deal with this. Here's one.
286 # Fortunately, all of the cases where this is likely to happen will be using
287 # gld so we can tell what the error text will look like.
289 proc ${tool}_check_unsupported_p { output } {
290 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {