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