OSDN Git Service

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