]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/testsuite/lib/libgomp.exp
libgomp testsuite: Only use 'blddir' if set
[thirdparty/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 scanlang.exp
30 load_gcc_lib scanrtl.exp
31 load_gcc_lib scansarif.exp
32 load_gcc_lib scantree.exp
33 load_gcc_lib scanltranstree.exp
34 load_gcc_lib scanoffload.exp
35 load_gcc_lib scanoffloadipa.exp
36 load_gcc_lib scanoffloadtree.exp
37 load_gcc_lib scanoffloadrtl.exp
38 load_gcc_lib scanipa.exp
39 load_gcc_lib scanwpaipa.exp
40 load_gcc_lib timeout-dg.exp
41 load_gcc_lib torture-options.exp
42 load_gcc_lib fortran-modules.exp
43
44 # Try to load a test support file, built during libgomp configuration.
45 load_file libgomp-test-support.exp
46
47 set dg-do-what-default run
48
49 #
50 # GCC_UNDER_TEST is the compiler under test.
51 #
52
53 set libgomp_compile_options ""
54
55 #
56 # libgomp_init
57 #
58
59 if [info exists TOOL_OPTIONS] {
60 set multilibs [get_multilibs $TOOL_OPTIONS]
61 } else {
62 set multilibs [get_multilibs]
63 }
64
65 proc libgomp_init { args } {
66 global srcdir blddir objdir tool_root_dir
67 global libgomp_initialized
68 global tmpdir
69 global gluefile wrap_flags
70 global ALWAYS_CFLAGS
71 global CFLAGS
72 global TOOL_EXECUTABLE TOOL_OPTIONS
73 global GCC_UNDER_TEST
74 global TESTING_IN_BUILD_TREE
75 global target_triplet
76 global always_ld_library_path
77
78 set blddir [lookfor_file [get_multilibs] libgomp]
79
80 # We set LC_ALL and LANG to C so that we get the same error
81 # messages as expected.
82 setenv LC_ALL C
83 setenv LANG C
84
85 # Many hosts now default to a non-ASCII C locale, however, so
86 # they can set a charset encoding here if they need.
87 if { [ishost "*-*-cygwin*"] } {
88 setenv LC_ALL C.ASCII
89 setenv LANG C.ASCII
90 }
91
92 if ![info exists GCC_UNDER_TEST] then {
93 if [info exists TOOL_EXECUTABLE] {
94 set GCC_UNDER_TEST $TOOL_EXECUTABLE
95 } else {
96 set GCC_UNDER_TEST "[find_gcc]"
97 }
98 }
99
100 if ![info exists tmpdir] {
101 set tmpdir "/tmp"
102 }
103
104 if [info exists gluefile] {
105 unset gluefile
106 }
107
108 if {![info exists CFLAGS]} {
109 set CFLAGS ""
110 }
111
112 # Locate libgcc.a so we don't need to account for different values of
113 # SHLIB_EXT on different platforms
114 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
115 if {$gccdir != ""} {
116 set gccdir [file dirname $gccdir]
117 }
118
119 # Compute what needs to be put into LD_LIBRARY_PATH
120 set always_ld_library_path "."
121
122 global offload_additional_lib_paths
123 if { $offload_additional_lib_paths != "" } {
124 append always_ld_library_path "${offload_additional_lib_paths}"
125 }
126
127 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
128 if {$gccdir != ""} {
129 # Add AIX pthread directory first.
130 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
131 append always_ld_library_path ":${gccdir}/pthread"
132 }
133 append always_ld_library_path ":${gccdir}"
134 set compiler [lindex $GCC_UNDER_TEST 0]
135
136 if { [is_remote host] == 0 && [which $compiler] != 0 } {
137 foreach i "[exec $compiler --print-multi-lib]" {
138 set mldir ""
139 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
140 set mldir [string trimright $mldir "\;@"]
141 if { "$mldir" == "." } {
142 continue
143 }
144 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
145 append always_ld_library_path ":${gccdir}/${mldir}"
146 }
147 }
148 }
149 }
150
151 set ALWAYS_CFLAGS ""
152 if { $blddir != "" } {
153 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
154 # targets that use libgomp.a%s in their specs need a -B option
155 # for uninstalled testing.
156 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
157 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
158 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
159
160 append always_ld_library_path ":${blddir}/.libs"
161 }
162 # The top-level include directory, for gomp-constants.h.
163 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
164 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
165
166 # For build-tree testing, also consider the library paths used for builing.
167 # For installed testing, we assume all that to be provided in the sysroot.
168 if { $blddir != "" } {
169 # The `-fopenacc' and `-fopenmp' options imply `-pthread', and
170 # that implies `-latomic' on some hosts, so wire in libatomic
171 # build directories.
172 if [ishost "riscv*-*-linux*"] {
173 set shlib_ext [get_shlib_extension]
174 set atomic_library_path "${blddir}/../libatomic/.libs"
175 if { [file exists "${atomic_library_path}/libatomic.a"]
176 || [file exists \
177 "${atomic_library_path}/libatomic.${shlib_ext}"] } {
178 lappend ALWAYS_CFLAGS \
179 "additional_flags=-L${atomic_library_path}"
180 append always_ld_library_path ":${atomic_library_path}"
181 }
182 }
183 }
184
185 # We use atomic operations in the testcases to validate results.
186 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
187 && [check_effective_target_ia32]
188 && ![check_effective_target_cas_char] } {
189 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
190 }
191
192 if [istarget *-*-darwin*] {
193 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
194 }
195
196 if [istarget sparc*-*-*] {
197 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
198 }
199
200 if [info exists TOOL_OPTIONS] {
201 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
202 }
203
204 # Make sure that lines are not wrapped. That can confuse the
205 # error-message parsing machinery.
206 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
207
208 # Disable caret
209 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
210
211 # Disable color diagnostics
212 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
213
214 # Help GCC to find offload compilers' 'mkoffload'.
215 global offload_additional_options
216 if { $offload_additional_options != "" } {
217 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
218 }
219
220 # Tell warning from error diagnostics. This fits for C, C++, and Fortran.
221 global gcc_warning_prefix
222 set gcc_warning_prefix "\[Ww\]arning:"
223 global gcc_error_prefix
224 set gcc_error_prefix "(\[Ff\]atal )?\[Ee\]rror:"
225 }
226
227 #
228 # libgomp_target_compile -- compile a source file
229 #
230
231 proc libgomp_target_compile { source dest type options } {
232 global blddir
233 global libgomp_compile_options
234 global gluefile wrap_flags
235 global ALWAYS_CFLAGS
236 global GCC_UNDER_TEST
237 global lang_test_file
238 global lang_library_path
239 global lang_link_flags
240 global lang_include_flags
241 global lang_source_re
242
243 if { [info exists lang_test_file] } {
244 if { $blddir != "" } {
245 # Some targets use libgfortran.a%s in their specs, so they need
246 # a -B option for uninstalled testing.
247 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
248 lappend options "ldflags=-L${blddir}/${lang_library_path}"
249 }
250 lappend options "ldflags=${lang_link_flags}"
251 if { [info exists lang_include_flags] \
252 && [regexp ${lang_source_re} ${source}] } {
253 lappend options "additional_flags=${lang_include_flags}"
254 }
255 }
256
257 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
258 lappend options "libs=${gluefile}"
259 lappend options "ldflags=${wrap_flags}"
260 }
261
262 lappend options "additional_flags=[libio_include_flags]"
263 lappend options "timeout=[timeout_value]"
264 lappend options "compiler=$GCC_UNDER_TEST"
265
266 set options [concat $libgomp_compile_options $options]
267
268 if [info exists ALWAYS_CFLAGS] {
269 set options [concat "$ALWAYS_CFLAGS" $options]
270 }
271
272 set options [dg-additional-files-options $options $source]
273
274 set result [target_compile $source $dest $type $options]
275
276 return $result
277 }
278
279 proc libgomp_option_help { } {
280 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
281 }
282
283 proc libgomp_option_proc { option } {
284 if [regexp "^--additional_options," $option] {
285 global libgomp_compile_options
286 regsub "--additional_options," $option "" option
287 foreach x [split $option ","] {
288 lappend libgomp_compile_options "additional_flags=$x"
289 }
290 return 1
291 } else {
292 return 0
293 }
294 }
295
296 # Translate offload target to OpenACC device type. Return the empty string if
297 # not supported, and 'host' for offload target 'disable'.
298 proc offload_target_to_openacc_device_type { offload_target } {
299 switch -glob $offload_target {
300 amdgcn* {
301 return "radeon"
302 }
303 disable {
304 return "host"
305 }
306 nvptx* {
307 return "nvidia"
308 }
309 default {
310 error "Unknown offload target: $offload_target"
311 }
312 }
313 }
314
315 # Return 1 if compiling for the specified offload target
316 # Takes -foffload=... into account by checking OFFLOAD_TARGET_NAMES=
317 # in the -v compiler output.
318 proc libgomp_check_effective_target_offload_target { target_name } {
319 # Consider all actual options, including the flags passed to
320 # 'gcc-dg-runtest', or 'gfortran-dg-runtest' (see the 'libgomp.*/*.exp'
321 # files; in particular, '-foffload', 'libgomp.oacc-*/*.exp'), which don't
322 # get passed on to 'check_effective_target_*' functions. (Not caching the
323 # result due to that.)
324 set options [list "additional_flags=[concat "-v" [current_compiler_flags]]"]
325 # Instead of inspecting command-line options, look what the compiler driver
326 # decides. This is somewhat modelled after
327 # 'gcc/testsuite/lib/target-supports.exp:check_configured_with'.
328 set gcc_output [libgomp_target_compile "" "" "none" $options]
329 if [regexp "(?n)^OFFLOAD_TARGET_NAMES=(.*)" $gcc_output dummy gcc_offload_targets] {
330 verbose "compiling for offload targets: $gcc_offload_targets"
331 return [string match "*:$target_name*:*" ":$gcc_offload_targets:"]
332 }
333
334 verbose "not compiling for $target_name offload target"
335 return 0
336 }
337
338 # Return 1 if compiling for any offload target.
339 proc check_effective_target_offload_target_any { } {
340 return [libgomp_check_effective_target_offload_target ""]
341 }
342
343 # Return 1 if compiling for offload target nvptx.
344 proc check_effective_target_offload_target_nvptx { } {
345 return [libgomp_check_effective_target_offload_target "nvptx"]
346 }
347
348 # Return 1 if compiling for offload target amdgcn
349 proc check_effective_target_offload_target_amdgcn { } {
350 return [libgomp_check_effective_target_offload_target "amdgcn"]
351 }
352
353 # Return 1 if offload device is available.
354 proc check_effective_target_offload_device { } {
355 return [check_runtime_nocache offload_device_available_ {
356 #include <omp.h>
357 int main ()
358 {
359 int a;
360 #pragma omp target map(from: a)
361 a = omp_is_initial_device ();
362 return a;
363 }
364 } ]
365 }
366
367 # Return 1 if offload device is available and it has non-shared address space.
368 proc check_effective_target_offload_device_nonshared_as { } {
369 return [check_runtime_nocache offload_device_nonshared_as {
370 int main ()
371 {
372 int a = 8;
373 #pragma omp target map(to: a)
374 a++;
375 return a != 8;
376 }
377 } ]
378 }
379
380 # Return 1 if offload device is available and it has shared address space.
381 proc check_effective_target_offload_device_shared_as { } {
382 return [check_runtime_nocache offload_device_shared_as {
383 int main ()
384 {
385 int x = 10;
386 #pragma omp target map(to: x)
387 x++;
388 return x == 10;
389 }
390 } ]
391 }
392
393 # Return 1 if using nvptx offload device.
394 proc check_effective_target_offload_device_nvptx { } {
395 return [check_runtime_nocache offload_device_nvptx {
396 #include <omp.h>
397 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
398 int main ()
399 {
400 return !on_device_arch_nvptx ();
401 }
402 } ]
403 }
404
405 # Return 1 if using a GCN offload device.
406 proc check_effective_target_offload_device_gcn { } {
407 return [check_runtime_nocache offload_device_gcn {
408 #include <omp.h>
409 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
410 int main ()
411 {
412 return !on_device_arch_gcn ();
413 }
414 } ]
415 }
416
417 # Return 1 if at least one Nvidia GPU is accessible.
418
419 proc check_effective_target_openacc_nvidia_accel_present { } {
420 return [check_runtime openacc_nvidia_accel_present {
421 #include <openacc.h>
422 int main () {
423 return !(acc_get_num_devices (acc_device_nvidia) > 0);
424 }
425 } "" ]
426 }
427
428 # Return 1 if at least one Nvidia GPU is accessible, and the OpenACC 'nvidia'
429 # device type is selected.
430
431 proc check_effective_target_openacc_nvidia_accel_selected { } {
432 if { ![check_effective_target_openacc_nvidia_accel_present] } {
433 return 0;
434 }
435 global openacc_device_type
436 return [string match "nvidia" $openacc_device_type]
437 }
438
439 # Return 1 if the OpenACC 'host' device type is selected.
440
441 proc check_effective_target_openacc_host_selected { } {
442 global openacc_device_type
443 return [string match "host" $openacc_device_type]
444 }
445
446 # Return 1 if at least one AMD GPU is accessible.
447
448 proc check_effective_target_openacc_radeon_accel_present { } {
449 return [check_runtime openacc_radeon_accel_present {
450 #include <openacc.h>
451 int main () {
452 return !(acc_get_num_devices (acc_device_radeon) > 0);
453 }
454 } "" ]
455 }
456
457 # Return 1 if at least one AMD GPU is accessible, and the OpenACC 'radeon'
458 # device type is selected.
459
460 proc check_effective_target_openacc_radeon_accel_selected { } {
461 if { ![check_effective_target_openacc_radeon_accel_present] } {
462 return 0;
463 }
464 global openacc_device_type
465 return [string match "radeon" $openacc_device_type]
466 }
467
468 # Return 1 if cuda.h and -lcuda are available.
469
470 proc check_effective_target_openacc_cuda { } {
471 return [check_no_compiler_messages openacc_cuda executable {
472 #include <cuda.h>
473 int main() {
474 CUdevice dev;
475 CUresult r = cuDeviceGet (&dev, 0);
476 if (r != CUDA_SUCCESS)
477 return 1;
478 return 0;
479 } } "-lcuda" ]
480 }
481
482 # Return 1 if cublas_v2.h and -lcublas are available.
483
484 proc check_effective_target_openacc_cublas { } {
485 return [check_no_compiler_messages openacc_cublas executable {
486 #include <cuda.h>
487 #include <cublas_v2.h>
488 int main() {
489 cublasStatus_t s;
490 cublasHandle_t h;
491 CUdevice dev;
492 CUresult r = cuDeviceGet (&dev, 0);
493 if (r != CUDA_SUCCESS)
494 return 1;
495 s = cublasCreate (&h);
496 if (s != CUBLAS_STATUS_SUCCESS)
497 return 1;
498 return 0;
499 } } "-lcuda -lcublas" ]
500 }
501
502 # Return 1 if cuda_runtime_api.h and -lcudart are available.
503
504 proc check_effective_target_openacc_cudart { } {
505 return [check_no_compiler_messages openacc_cudart executable {
506 #include <cuda.h>
507 #include <cuda_runtime_api.h>
508 int main() {
509 cudaError_t e;
510 int devn;
511 CUdevice dev;
512 CUresult r = cuDeviceGet (&dev, 0);
513 if (r != CUDA_SUCCESS)
514 return 1;
515 e = cudaGetDevice (&devn);
516 if (e != cudaSuccess)
517 return 1;
518 return 0;
519 } } "-lcuda -lcudart" ]
520 }