OSDN Git Service

401651c2b79de8afd6e55b1079a91c2297cf2f2b
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gfortran-dg.exp
1 #   Copyright (C) 2004, 2005, 2006, 2007, 2008 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 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.
12
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/>.
16
17 load_lib gcc-dg.exp
18
19 # Define gfortran callbacks for dg.exp.
20
21 proc gfortran-dg-test { prog do_what extra_tool_flags } {
22     set result \
23         [gcc-dg-test-1 gfortran_target_compile $prog $do_what $extra_tool_flags]
24     
25     set comp_output [lindex $result 0]
26     set output_file [lindex $result 1]
27
28     # gfortran error messages look like this:
29     #     [name]:[locus]:
30     #
31     #        some code
32     #              1
33     #     Error: Some error at (1)
34     # or
35     #     [name]:[locus]:
36     #
37     #       some code
38     #              1
39     #     [name]:[locus2]:
40     #
41     #       some other code
42     #         2
43     #     Error: Some error at (1) and (2)
44     # or
45     #     [name]:[locus]:
46     #
47     #       some code and some more code
48     #              1       2
49     #     Error: Some error at (1) and (2)
50     #
51     # Where [locus] is either [line] or [line].[columns] .
52     #
53     # We collapse these to look like:
54     #  [name]:[line]: Error: Some error at (1) and (2)
55     # or
56     #  [name]:[line]: Error: Some error at (1) and (2)
57     #  [name]:[line2]: Error: Some error at (1) and (2)
58     # We proceed in two steps: first we deal with the form with two
59     # different locus lines, then with the form with only one locus line.
60     #
61     # Note that these regexps only make sense in the combinations used below.
62     # Note also that is imperative that we first deal with the form with
63     # two loci.
64     set locus_regexp "(\[^\n\]*):(\[0-9\]*)\[^\n\]*:\n\n\[^\n\]*\n\[^\n\]*\n"
65     set diag_regexp "(\[^\n\]*)\n"
66
67     set two_loci "$locus_regexp$locus_regexp$diag_regexp"
68     set single_locus "$locus_regexp$diag_regexp"
69     regsub -all $two_loci $comp_output "\\1:\\2: \\5\n\\3:\\4: \\5\n" comp_output
70     regsub -all $single_locus $comp_output "\\1:\\2: \\3\n" comp_output
71
72     return [list $comp_output $output_file]
73 }
74
75 proc gfortran-dg-prune { system text } {
76     return [gcc-dg-prune $system $text]
77 }
78
79 # Utility routines.
80
81 # Modified dg-runtest that can cycle through a list of optimization options
82 # as c-torture does.
83 proc gfortran-dg-runtest { testcases default-extra-flags } {
84     global runtests
85     global TORTURE_OPTIONS
86
87     foreach test $testcases {
88         # If we're only testing specific files and this isn't one of
89         # them, skip it.
90         if ![runtest_file_p $runtests $test] {
91             continue
92         }
93
94         # look if this is dg-do-run test, in which case
95         # we cycle through the option list, otherwise we don't
96         if [expr [search_for $test "dg-do run"]] {
97             set option_list $TORTURE_OPTIONS
98         } else {
99             set option_list [list { -O } ]
100         }
101
102         set nshort [file tail [file dirname $test]]/[file tail $test]
103
104         foreach flags $option_list {
105             verbose "Testing $nshort, $flags" 1
106             dg-test $test $flags ${default-extra-flags}
107         }
108     }
109 }
110
111 proc gfortran-dg-debug-runtest { target_compile trivial opt_opts testcases } {
112     global srcdir subdir DEBUG_TORTURE_OPTIONS
113
114     if ![info exists DEBUG_TORTURE_OPTIONS] {
115        set DEBUG_TORTURE_OPTIONS ""
116        set type_list [list "-gstabs" "-gstabs+" "-gxcoff" "-gxcoff+" "-gcoff" "-gdwarf-2" ]
117        foreach type $type_list {
118            set comp_output [$target_compile \
119                    "$srcdir/$subdir/$trivial" "trivial.S" assembly \
120                    "additional_flags=$type"]
121            if { [string match "exit status *" $comp_output] } {
122                continue
123            }
124            if { [string match \
125                        "* target system does not support the * debug format*" \
126                        $comp_output]
127            } {
128                continue
129            }
130            foreach level {1 "" 3} {
131                lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
132                foreach opt $opt_opts {
133                    lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}" \
134                       "$opt" ]
135                }
136            }
137        }
138     }
139
140     verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
141
142     global runtests
143
144     foreach test $testcases {
145        # If we're only testing specific files and this isn't one of 
146        # them, skip it.
147        if ![runtest_file_p $runtests $test] {
148            continue
149        }
150
151        set nshort [file tail [file dirname $test]]/[file tail $test]
152
153        foreach flags $DEBUG_TORTURE_OPTIONS {
154            set doit 1
155            # gcc-specific checking removed here
156
157            if { $doit } {
158                verbose -log "Testing $nshort, $flags" 1
159                dg-test $test $flags ""
160            }
161        }
162     }
163 }