OSDN Git Service

Merge from pch-branch.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gcc-dg.exp
1 #   Copyright (C) 1997, 1999, 2000 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 load_lib dg.exp
18 load_lib file-format.exp
19 load_lib target-supports.exp
20 load_lib scanasm.exp
21 load_lib prune.exp
22
23 if ![info exists TORTURE_OPTIONS] {
24     # It is theoretically beneficial to group all of the O2/O3 options together,
25     # as in many cases the compiler will generate identical executables for
26     # all of them--and the c-torture testsuite will skip testing identical
27     # executables multiple times.
28     # Also note that -finline-functions is explicitly included in one of the
29     # items below, even though -O3 is also specified, because some ports may
30     # choose to disable inlining functions by default, even when optimizing.
31     set TORTURE_OPTIONS [list \
32         { -O0 } \
33         { -O1 } \
34         { -O2 } \
35         { -O3 -fomit-frame-pointer } \
36         { -O3 -fomit-frame-pointer -funroll-loops } \
37         { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
38         { -O3 -g } \
39         { -Os } ]
40 }
41
42
43 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
44 # one for testcases without loops.
45
46 set torture_with_loops $TORTURE_OPTIONS
47 set torture_without_loops ""
48 foreach option $TORTURE_OPTIONS {
49     if ![string match "*loop*" $option] {
50         lappend torture_without_loops $option
51     }
52 }
53
54 # Define gcc callbacks for dg.exp.
55
56 proc gcc-dg-test { prog do_what extra_tool_flags } {
57     # Set up the compiler flags, based on what we're going to do.
58
59     switch $do_what {
60         "preprocess" {
61             set compile_type "preprocess"
62             set output_file "[file rootname [file tail $prog]].i"
63         }
64         "compile" {
65             set compile_type "assembly"
66             set output_file "[file rootname [file tail $prog]].s"
67         }
68         "assemble" {
69             set compile_type "object"
70             set output_file "[file rootname [file tail $prog]].o"
71         }
72         "precompile" {
73             set compile_type "precompiled_header"
74             set output_file "[file tail $prog].pch"
75         }
76         "link" {
77             set compile_type "executable"
78             set output_file "[file rootname [file tail $prog]].exe"
79             # The following line is needed for targets like the i960 where
80             # the default output file is b.out.  Sigh.
81         }
82         "run" {
83             set compile_type "executable"
84             # FIXME: "./" is to cope with "." not being in $PATH.
85             # Should this be handled elsewhere?
86             # YES.
87             set output_file "./[file rootname [file tail $prog]].exe"
88             # This is the only place where we care if an executable was
89             # created or not.  If it was, dg.exp will try to run it.
90             remote_file build delete $output_file;
91         }
92         default {
93             perror "$do_what: not a valid dg-do keyword"
94             return ""
95         }
96     }
97     set options ""
98     if { $extra_tool_flags != "" } {
99         lappend options "additional_flags=$extra_tool_flags"
100     }
101
102     set comp_output [gcc_target_compile "$prog" "$output_file" "$compile_type" $options];
103
104     return [list $comp_output $output_file]
105 }
106
107 proc gcc-dg-prune { system text } {
108     set text [prune_gcc_output $text]
109
110     # If we see "region xxx is full" then the testcase is too big for ram.
111     # This is tricky to deal with in a large testsuite like c-torture so
112     # deal with it here.  Just mark the testcase as unsupported.
113     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
114         # The format here is important.  See dg.exp.
115         return "::unsupported::memory full"
116     }
117
118     return $text
119 }
120
121 # Utility routines.
122
123 #
124 # search_for -- looks for a string match in a file
125 #
126 proc search_for { file pattern } {
127     set fd [open $file r]
128     while { [gets $fd cur_line]>=0 } {
129         if [string match "*$pattern*" $cur_line] then {
130             close $fd
131             return 1
132         }
133     }
134     close $fd
135     return 0
136 }
137
138 # Modified dg-runtest that can cycle through a list of optimization options
139 # as c-torture does.
140 proc gcc-dg-runtest { testcases default-extra-flags } {
141     global runtests
142
143     foreach test $testcases {
144         # If we're only testing specific files and this isn't one of 
145         # them, skip it.
146         if ![runtest_file_p $runtests $test] {
147             continue
148         }
149
150         # Look for a loop within the source code - if we don't find one,
151         # don't pass -funroll[-all]-loops.
152         global torture_with_loops torture_without_loops
153         if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
154             set option_list $torture_with_loops
155         } else {
156             set option_list $torture_without_loops
157         }
158
159         set nshort [file tail [file dirname $test]]/[file tail $test]
160
161         foreach flags $option_list {
162             verbose "Testing $nshort, $flags" 1
163             dg-test $test $flags ${default-extra-flags}
164         }
165     }
166 }