Testsuite: add dg-{begin|end}-multiline-output commands
[gcc.git] / libgomp / testsuite / lib / libgomp.exp
1 # Damn dejagnu for not having proper library search paths for load_lib.
2 # We have to explicitly load everything that gcc-dg.exp wants to load.
3
4 proc load_gcc_lib { filename } {
5 global srcdir loaded_libs
6
7 load_file $srcdir/../../gcc/testsuite/lib/$filename
8 set loaded_libs($filename) ""
9 }
10
11 load_lib dg.exp
12
13 # Required to use gcc-dg.exp - however, the latter should NOT be
14 # loaded until ${tool}_target_compile is defined since it uses that
15 # to determine default LTO options.
16
17 load_gcc_lib multiline.exp
18 load_gcc_lib prune.exp
19 load_gcc_lib target-libpath.exp
20 load_gcc_lib wrapper.exp
21 load_gcc_lib target-supports.exp
22 load_gcc_lib target-utils.exp
23 load_gcc_lib gcc-defs.exp
24 load_gcc_lib timeout.exp
25 load_gcc_lib file-format.exp
26 load_gcc_lib target-supports-dg.exp
27 load_gcc_lib scanasm.exp
28 load_gcc_lib scandump.exp
29 load_gcc_lib scanrtl.exp
30 load_gcc_lib scantree.exp
31 load_gcc_lib scanipa.exp
32 load_gcc_lib timeout-dg.exp
33 load_gcc_lib torture-options.exp
34 load_gcc_lib fortran-modules.exp
35
36 # Try to load a test support file, built during libgomp configuration.
37 load_file libgomp-test-support.exp
38
39 # Populate offload_targets_s (offloading targets separated by a space), and
40 # offload_targets_s_openacc (the same, but with OpenACC names; OpenACC spells
41 # some of them a little differently).
42 set offload_targets_s [split $offload_targets ","]
43 set offload_targets_s_openacc {}
44 foreach offload_target_openacc $offload_targets_s {
45 switch $offload_target_openacc {
46 intelmic {
47 # Skip; will all FAIL because of missing
48 # GOMP_OFFLOAD_CAP_OPENACC_200.
49 continue
50 }
51 nvptx {
52 set offload_target_openacc "nvidia"
53 }
54 }
55 lappend offload_targets_s_openacc "$offload_target_openacc"
56 }
57 lappend offload_targets_s_openacc "host"
58
59 set dg-do-what-default run
60
61 #
62 # GCC_UNDER_TEST is the compiler under test.
63 #
64
65 set libgomp_compile_options ""
66
67 #
68 # libgomp_init
69 #
70
71 if [info exists TOOL_OPTIONS] {
72 set multilibs [get_multilibs $TOOL_OPTIONS]
73 } else {
74 set multilibs [get_multilibs]
75 }
76
77 proc libgomp_init { args } {
78 global srcdir blddir objdir tool_root_dir
79 global libgomp_initialized
80 global tmpdir
81 global blddir
82 global gluefile wrap_flags
83 global ALWAYS_CFLAGS
84 global CFLAGS
85 global TOOL_EXECUTABLE TOOL_OPTIONS
86 global GCC_UNDER_TEST
87 global TESTING_IN_BUILD_TREE
88 global target_triplet
89 global always_ld_library_path
90
91 set blddir [lookfor_file [get_multilibs] libgomp]
92
93 # We set LC_ALL and LANG to C so that we get the same error
94 # messages as expected.
95 setenv LC_ALL C
96 setenv LANG C
97
98 # Many hosts now default to a non-ASCII C locale, however, so
99 # they can set a charset encoding here if they need.
100 if { [ishost "*-*-cygwin*"] } {
101 setenv LC_ALL C.ASCII
102 setenv LANG C.ASCII
103 }
104
105 if ![info exists GCC_UNDER_TEST] then {
106 if [info exists TOOL_EXECUTABLE] {
107 set GCC_UNDER_TEST $TOOL_EXECUTABLE
108 } else {
109 set GCC_UNDER_TEST "[find_gcc]"
110 }
111 }
112
113 if ![info exists tmpdir] {
114 set tmpdir "/tmp"
115 }
116
117 if [info exists gluefile] {
118 unset gluefile
119 }
120
121 if {![info exists CFLAGS]} {
122 set CFLAGS ""
123 }
124
125 # Locate libgcc.a so we don't need to account for different values of
126 # SHLIB_EXT on different platforms
127 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
128 if {$gccdir != ""} {
129 set gccdir [file dirname $gccdir]
130 }
131
132 # Compute what needs to be put into LD_LIBRARY_PATH
133 set always_ld_library_path ".:${blddir}/.libs"
134
135 # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
136 # non-fallback testing for Intel MIC targets
137 global offload_targets
138 if { [string match "*,intelmic,*" ",$offload_targets,"] } {
139 append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
140 append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
141 # libstdc++ is required by liboffloadmic
142 append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
143 }
144
145 global offload_additional_lib_paths
146 if { $offload_additional_lib_paths != "" } {
147 append always_ld_library_path "${offload_additional_lib_paths}"
148 }
149
150 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
151 if {$gccdir != ""} {
152 # Add AIX pthread directory first.
153 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
154 append always_ld_library_path ":${gccdir}/pthread"
155 }
156 append always_ld_library_path ":${gccdir}"
157 set compiler [lindex $GCC_UNDER_TEST 0]
158
159 if { [is_remote host] == 0 && [which $compiler] != 0 } {
160 foreach i "[exec $compiler --print-multi-lib]" {
161 set mldir ""
162 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
163 set mldir [string trimright $mldir "\;@"]
164 if { "$mldir" == "." } {
165 continue
166 }
167 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
168 append always_ld_library_path ":${gccdir}/${mldir}"
169 }
170 }
171 }
172 }
173
174 set ALWAYS_CFLAGS ""
175 if { $blddir != "" } {
176 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
177 # targets that use libgomp.a%s in their specs need a -B option
178 # for uninstalled testing.
179 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
180 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
181 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
182 # The top-level include directory, for gomp-constants.h.
183 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
184 }
185 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
186
187 # For build-tree testing, also consider the CUDA paths used for builing.
188 # For installed testing, we assume all that to be provided in the sysroot.
189 if { $blddir != "" } {
190 global cuda_driver_include
191 global cuda_driver_lib
192 if { $cuda_driver_include != "" } {
193 # Stop gfortran from freaking out:
194 # Warning: Nonexistent include directory "[...]"
195 if {[file exists $cuda_driver_include]} {
196 lappend ALWAYS_CFLAGS "additional_flags=-I$cuda_driver_include"
197 }
198 }
199 if { $cuda_driver_lib != "" } {
200 lappend ALWAYS_CFLAGS "additional_flags=-L$cuda_driver_lib"
201 append always_ld_library_path ":$cuda_driver_lib"
202 }
203 }
204
205 # We use atomic operations in the testcases to validate results.
206 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
207 && [check_effective_target_ia32] } {
208 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
209 }
210
211 if [istarget *-*-darwin*] {
212 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
213 }
214
215 if [istarget sparc*-*-*] {
216 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
217 }
218
219 if [info exists TOOL_OPTIONS] {
220 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
221 }
222
223 # Make sure that lines are not wrapped. That can confuse the
224 # error-message parsing machinery.
225 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
226
227 # Disable caret
228 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
229
230 # Disable color diagnostics
231 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
232
233 # Used for support non-fallback offloading.
234 # Help GCC to find target mkoffload.
235 global offload_additional_options
236 if { $offload_additional_options != "" } {
237 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
238 }
239 }
240
241 #
242 # libgomp_target_compile -- compile a source file
243 #
244
245 proc libgomp_target_compile { source dest type options } {
246 global blddir
247 global libgomp_compile_options
248 global gluefile wrap_flags
249 global ALWAYS_CFLAGS
250 global GCC_UNDER_TEST
251 global lang_test_file
252 global lang_library_path
253 global lang_link_flags
254 global lang_include_flags
255 global lang_source_re
256
257 if { [info exists lang_test_file] } {
258 if { $blddir != "" } {
259 # Some targets use libgfortran.a%s in their specs, so they need
260 # a -B option for uninstalled testing.
261 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
262 lappend options "ldflags=-L${blddir}/${lang_library_path}"
263 }
264 lappend options "ldflags=${lang_link_flags}"
265 if { [info exists lang_include_flags] \
266 && [regexp ${lang_source_re} ${source}] } {
267 lappend options "additional_flags=${lang_include_flags}"
268 }
269 }
270
271 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
272 lappend options "libs=${gluefile}"
273 lappend options "ldflags=${wrap_flags}"
274 }
275
276 lappend options "additional_flags=[libio_include_flags]"
277 lappend options "timeout=[timeout_value]"
278 lappend options "compiler=$GCC_UNDER_TEST"
279
280 set options [concat $libgomp_compile_options $options]
281
282 if [info exists ALWAYS_CFLAGS] {
283 set options [concat "$ALWAYS_CFLAGS" $options]
284 }
285
286 set options [dg-additional-files-options $options $source]
287
288 set result [target_compile $source $dest $type $options]
289
290 return $result
291 }
292
293 proc libgomp_option_help { } {
294 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
295 }
296
297 proc libgomp_option_proc { option } {
298 if [regexp "^--additional_options," $option] {
299 global libgomp_compile_options
300 regsub "--additional_options," $option "" option
301 foreach x [split $option ","] {
302 lappend libgomp_compile_options "additional_flags=$x"
303 }
304 return 1
305 } else {
306 return 0
307 }
308 }
309
310 # Return 1 if offload device is available.
311 proc check_effective_target_offload_device { } {
312 return [check_runtime_nocache offload_device_available_ {
313 #include <omp.h>
314 int main ()
315 {
316 int a;
317 #pragma omp target map(from: a)
318 a = omp_is_initial_device ();
319 return a;
320 }
321 } ]
322 }
323
324 # Return 1 if at least one nvidia board is present.
325
326 proc check_effective_target_openacc_nvidia_accel_present { } {
327 return [check_runtime openacc_nvidia_accel_present {
328 #include <openacc.h>
329 int main () {
330 return !(acc_get_num_devices (acc_device_nvidia) > 0);
331 }
332 } "" ]
333 }
334
335 # Return 1 if at least one nvidia board is present, and the nvidia device type
336 # is selected by default by means of setting the environment variable
337 # ACC_DEVICE_TYPE.
338
339 proc check_effective_target_openacc_nvidia_accel_selected { } {
340 if { ![check_effective_target_openacc_nvidia_accel_present] } {
341 return 0;
342 }
343 global offload_target_openacc
344 if { $offload_target_openacc == "nvidia" } {
345 return 1;
346 }
347 return 0;
348 }
349
350 # Return 1 if the host target is selected for offloaded
351
352 proc check_effective_target_openacc_host_selected { } {
353 global offload_target_openacc
354 if { $offload_target_openacc == "host" } {
355 return 1;
356 }
357 return 0;
358 }