]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gfortran-dg.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / gfortran-dg.exp
1 # Copyright (C) 2004-2015 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 load_lib torture-options.exp
19
20 # Define gfortran callbacks for dg.exp.
21
22 proc gfortran-dg-test { prog do_what extra_tool_flags } {
23 set result \
24 [gcc-dg-test-1 gfortran_target_compile $prog $do_what $extra_tool_flags]
25
26 set comp_output [lindex $result 0]
27 set output_file [lindex $result 1]
28
29 # gfortran error messages look like this:
30 # [name]:[locus]:
31 #
32 # some code
33 # 1
34 # Error: Some error at (1)
35 # or
36 # [name]:[locus]:
37 #
38 # some code
39 # 1
40 # [name]:[locus2]:
41 #
42 # some other code
43 # 2
44 # Error: Some error at (1) and (2)
45 # or
46 # [name]:[locus]:
47 #
48 # some code and some more code
49 # 1 2
50 # Error: Some error at (1) and (2)
51 #
52 # or
53 # [name]:[locus]: Error: Some error
54 #
55 # Where [locus] is either [line] or [line].[column] or
56 # [line].[column]-[column] .
57 #
58 # We collapse these to look like:
59 # [name]:[line]:[column]: Error: Some error at (1) and (2)
60 # or
61 # [name]:[line]:[column]: Error: Some error at (1) and (2)
62 # [name]:[line2]:[column]: Error: Some error at (1) and (2)
63 #
64 # Note that these regexps only make sense in the combinations used below.
65 # Note also that is imperative that we first deal with the form with
66 # two loci.
67 set locus_regexp "(\[^\n\]+:\[0-9\]+)\[\.:\](\[0-9\]+)(-\[0-9\]+)?:\n\n\[^\n\]+\n\[^\n\]+\n"
68 set diag_regexp "(\[^\n\]+)\n"
69
70 # We proceed in steps:
71
72 # 1. We add first a column number if none exists.
73 # (Some Fortran diagnostics have the locus after Warning|Error)
74 set colnum_regexp "(^|\n)(Warning: |Error: )?(\[^:\n\]+:\[0-9\]+):(\[ \n\])"
75 regsub -all $colnum_regexp $comp_output "\\1\\3:0:\\4\\2" comp_output
76 verbose "comput_output0:\n$comp_output"
77
78 # 2. We deal with the form with two different locus lines,
79 set two_loci "(^|\n)$locus_regexp$locus_regexp$diag_regexp"
80 regsub -all $two_loci $comp_output "\\1\\2:\\3: \\8\n\\5\:\\6: \\8\n" comp_output
81 verbose "comput_output1:\n$comp_output"
82
83 # 3. then with the form with only one locus line.
84 set single_locus "(^|\n)$locus_regexp$diag_regexp"
85 regsub -all $single_locus $comp_output "\\1\\2:\\3: \\5\n" comp_output
86 verbose "comput_output2:\n$comp_output"
87
88 # 4. Add a line number if none exists
89 regsub -all "(^|\n)(Warning: |Error: )" $comp_output "\\1:0:0: \\2" comp_output
90 verbose "comput_output3:\n$comp_output"
91 return [list $comp_output $output_file]
92 }
93
94 proc gfortran-dg-prune { system text } {
95 return [gcc-dg-prune $system $text]
96 }
97
98 # Utility routines.
99
100 # Modified dg-runtest that can cycle through a list of optimization options
101 # as c-torture does.
102 proc gfortran-dg-runtest { testcases flags default-extra-flags } {
103 global runtests
104 global DG_TORTURE_OPTIONS torture_with_loops
105
106 torture-init
107 set-torture-options $DG_TORTURE_OPTIONS
108
109 foreach test $testcases {
110 # If we're only testing specific files and this isn't one of
111 # them, skip it.
112 if ![runtest_file_p $runtests $test] {
113 continue
114 }
115
116 # look if this is dg-do-run test, in which case
117 # we cycle through the option list, otherwise we don't
118 if [expr [search_for $test "dg-do run"]] {
119 set option_list $torture_with_loops
120 } else {
121 set option_list [list { -O } ]
122 }
123
124 set nshort [file tail [file dirname $test]]/[file tail $test]
125 list-module-names $test
126
127 foreach flags_t $option_list {
128 verbose "Testing $nshort, $flags $flags_t" 1
129 dg-test $test "$flags $flags_t" ${default-extra-flags}
130 cleanup-modules ""
131 }
132 }
133
134 torture-finish
135 }
136
137 proc gfortran-dg-debug-runtest { target_compile trivial opt_opts testcases } {
138 global srcdir subdir DEBUG_TORTURE_OPTIONS
139
140 if ![info exists DEBUG_TORTURE_OPTIONS] {
141 set DEBUG_TORTURE_OPTIONS ""
142 set type_list [list "-gstabs" "-gstabs+" "-gxcoff" "-gxcoff+" "-gcoff" "-gdwarf-2" ]
143 foreach type $type_list {
144 set comp_output [$target_compile \
145 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
146 "additional_flags=$type"]
147 if { [string match "exit status *" $comp_output] } {
148 continue
149 }
150 if { [string match \
151 "* target system does not support the * debug format*" \
152 $comp_output]
153 } {
154 continue
155 }
156 remove-build-file "trivial.S"
157 foreach level {1 "" 3} {
158 if { ($type == "-gdwarf-2") && ($level != "") } {
159 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
160 foreach opt $opt_opts {
161 lappend DEBUG_TORTURE_OPTIONS \
162 [list "${type}" "-g${level}" "$opt" ]
163 }
164 } else {
165 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
166 foreach opt $opt_opts {
167 lappend DEBUG_TORTURE_OPTIONS \
168 [list "${type}${level}" "$opt" ]
169 }
170 }
171 }
172 }
173 }
174
175 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
176
177 global runtests
178
179 foreach test $testcases {
180 # If we're only testing specific files and this isn't one of
181 # them, skip it.
182 if ![runtest_file_p $runtests $test] {
183 continue
184 }
185
186 set nshort [file tail [file dirname $test]]/[file tail $test]
187 list-module-names $test
188
189 foreach flags $DEBUG_TORTURE_OPTIONS {
190 set doit 1
191 # gcc-specific checking removed here
192
193 if { $doit } {
194 verbose -log "Testing $nshort, $flags" 1
195 dg-test $test $flags ""
196 cleanup-modules ""
197 }
198 }
199 }
200 }