Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / libgomp / testsuite / lib / libgomp.exp
blobc41b3e6dc18f662208f76333c68b47987a37b1ee
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.
4 proc load_gcc_lib { filename } {
5 global srcdir loaded_libs
7 load_file $srcdir/../../gcc/testsuite/lib/$filename
8 set loaded_libs($filename) ""
11 load_lib dg.exp
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.
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 scantree.exp
32 load_gcc_lib scanltranstree.exp
33 load_gcc_lib scanoffloadtree.exp
34 load_gcc_lib scanipa.exp
35 load_gcc_lib scanwpaipa.exp
36 load_gcc_lib timeout-dg.exp
37 load_gcc_lib torture-options.exp
38 load_gcc_lib fortran-modules.exp
40 # Try to load a test support file, built during libgomp configuration.
41 load_file libgomp-test-support.exp
43 # Populate offload_targets_s (offloading targets separated by a space), and
44 # offload_targets_s_openacc (the same, but with OpenACC names; OpenACC spells
45 # some of them a little differently).
46 set offload_targets_s [split $offload_targets ","]
47 set offload_targets_s_openacc {}
48 foreach offload_target_openacc $offload_targets_s {
49 # Translate to OpenACC names, or skip if not yet supported.
50 switch $offload_target_openacc {
51 intelmic {
52 continue
54 nvptx {
55 set offload_target_openacc "nvidia"
57 hsa {
58 continue
61 lappend offload_targets_s_openacc "$offload_target_openacc"
63 lappend offload_targets_s_openacc "host"
65 set dg-do-what-default run
68 # GCC_UNDER_TEST is the compiler under test.
71 set libgomp_compile_options ""
74 # libgomp_init
77 if [info exists TOOL_OPTIONS] {
78 set multilibs [get_multilibs $TOOL_OPTIONS]
79 } else {
80 set multilibs [get_multilibs]
83 proc libgomp_init { args } {
84 global srcdir blddir objdir tool_root_dir
85 global libgomp_initialized
86 global tmpdir
87 global blddir
88 global gluefile wrap_flags
89 global ALWAYS_CFLAGS
90 global CFLAGS
91 global TOOL_EXECUTABLE TOOL_OPTIONS
92 global GCC_UNDER_TEST
93 global TESTING_IN_BUILD_TREE
94 global target_triplet
95 global always_ld_library_path
97 set blddir [lookfor_file [get_multilibs] libgomp]
99 # We set LC_ALL and LANG to C so that we get the same error
100 # messages as expected.
101 setenv LC_ALL C
102 setenv LANG C
104 # Many hosts now default to a non-ASCII C locale, however, so
105 # they can set a charset encoding here if they need.
106 if { [ishost "*-*-cygwin*"] } {
107 setenv LC_ALL C.ASCII
108 setenv LANG C.ASCII
111 if ![info exists GCC_UNDER_TEST] then {
112 if [info exists TOOL_EXECUTABLE] {
113 set GCC_UNDER_TEST $TOOL_EXECUTABLE
114 } else {
115 set GCC_UNDER_TEST "[find_gcc]"
119 if ![info exists tmpdir] {
120 set tmpdir "/tmp"
123 if [info exists gluefile] {
124 unset gluefile
127 if {![info exists CFLAGS]} {
128 set CFLAGS ""
131 # Locate libgcc.a so we don't need to account for different values of
132 # SHLIB_EXT on different platforms
133 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
134 if {$gccdir != ""} {
135 set gccdir [file dirname $gccdir]
138 # Compute what needs to be put into LD_LIBRARY_PATH
139 set always_ld_library_path ".:${blddir}/.libs"
141 # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
142 # non-fallback testing for Intel MIC targets
143 global offload_targets
144 if { [string match "*,intelmic,*" ",$offload_targets,"] } {
145 append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
146 append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
147 # libstdc++ is required by liboffloadmic
148 append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
149 # libgcc_s is required by libstdc++
150 append always_ld_library_path ":${blddir}/../libgcc"
153 global offload_additional_lib_paths
154 if { $offload_additional_lib_paths != "" } {
155 append always_ld_library_path "${offload_additional_lib_paths}"
158 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
159 if {$gccdir != ""} {
160 # Add AIX pthread directory first.
161 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
162 append always_ld_library_path ":${gccdir}/pthread"
164 append always_ld_library_path ":${gccdir}"
165 set compiler [lindex $GCC_UNDER_TEST 0]
167 if { [is_remote host] == 0 && [which $compiler] != 0 } {
168 foreach i "[exec $compiler --print-multi-lib]" {
169 set mldir ""
170 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
171 set mldir [string trimright $mldir "\;@"]
172 if { "$mldir" == "." } {
173 continue
175 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
176 append always_ld_library_path ":${gccdir}/${mldir}"
182 set ALWAYS_CFLAGS ""
183 if { $blddir != "" } {
184 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
185 # targets that use libgomp.a%s in their specs need a -B option
186 # for uninstalled testing.
187 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
188 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
189 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
191 # The top-level include directory, for gomp-constants.h.
192 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
193 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
195 # For build-tree testing, also consider the library paths used for builing.
196 # For installed testing, we assume all that to be provided in the sysroot.
197 if { $blddir != "" } {
198 global cuda_driver_include
199 global cuda_driver_lib
200 if { $cuda_driver_include != "" } {
201 # Stop gfortran from freaking out:
202 # Warning: Nonexistent include directory "[...]"
203 if {[file exists $cuda_driver_include]} {
204 lappend ALWAYS_CFLAGS "additional_flags=-I$cuda_driver_include"
207 if { $cuda_driver_lib != "" } {
208 lappend ALWAYS_CFLAGS "additional_flags=-L$cuda_driver_lib"
209 append always_ld_library_path ":$cuda_driver_lib"
211 global hsa_runtime_lib
212 if { $hsa_runtime_lib != "" } {
213 append always_ld_library_path ":$hsa_runtime_lib"
217 # We use atomic operations in the testcases to validate results.
218 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
219 && [check_effective_target_ia32] } {
220 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
223 if [istarget *-*-darwin*] {
224 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
227 if [istarget sparc*-*-*] {
228 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
231 if [info exists TOOL_OPTIONS] {
232 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
235 # Make sure that lines are not wrapped. That can confuse the
236 # error-message parsing machinery.
237 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
239 # Disable caret
240 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
242 # Disable HSA warnings by default.
243 lappend ALWAYS_CFLAGS "additional_flags=-Wno-hsa"
245 # Disable color diagnostics
246 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
248 # Used for support non-fallback offloading.
249 # Help GCC to find target mkoffload.
250 global offload_additional_options
251 if { $offload_additional_options != "" } {
252 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
257 # libgomp_target_compile -- compile a source file
260 proc libgomp_target_compile { source dest type options } {
261 global blddir
262 global libgomp_compile_options
263 global gluefile wrap_flags
264 global ALWAYS_CFLAGS
265 global GCC_UNDER_TEST
266 global lang_test_file
267 global lang_library_path
268 global lang_link_flags
269 global lang_include_flags
270 global lang_source_re
272 if { [info exists lang_test_file] } {
273 if { $blddir != "" } {
274 # Some targets use libgfortran.a%s in their specs, so they need
275 # a -B option for uninstalled testing.
276 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
277 lappend options "ldflags=-L${blddir}/${lang_library_path}"
279 lappend options "ldflags=${lang_link_flags}"
280 if { [info exists lang_include_flags] \
281 && [regexp ${lang_source_re} ${source}] } {
282 lappend options "additional_flags=${lang_include_flags}"
286 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
287 lappend options "libs=${gluefile}"
288 lappend options "ldflags=${wrap_flags}"
291 lappend options "additional_flags=[libio_include_flags]"
292 lappend options "timeout=[timeout_value]"
293 lappend options "compiler=$GCC_UNDER_TEST"
295 set options [concat $libgomp_compile_options $options]
297 if [info exists ALWAYS_CFLAGS] {
298 set options [concat "$ALWAYS_CFLAGS" $options]
301 set options [dg-additional-files-options $options $source]
303 set result [target_compile $source $dest $type $options]
305 return $result
308 proc libgomp_option_help { } {
309 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
312 proc libgomp_option_proc { option } {
313 if [regexp "^--additional_options," $option] {
314 global libgomp_compile_options
315 regsub "--additional_options," $option "" option
316 foreach x [split $option ","] {
317 lappend libgomp_compile_options "additional_flags=$x"
319 return 1
320 } else {
321 return 0
325 # Return 1 if offload device is available.
326 proc check_effective_target_offload_device { } {
327 return [check_runtime_nocache offload_device_available_ {
328 #include <omp.h>
329 int main ()
331 int a;
332 #pragma omp target map(from: a)
333 a = omp_is_initial_device ();
334 return a;
339 # Return 1 if offload device is available and it has non-shared address space.
340 proc check_effective_target_offload_device_nonshared_as { } {
341 return [check_runtime_nocache offload_device_nonshared_as {
342 int main ()
344 int a = 8;
345 #pragma omp target map(to: a)
346 a++;
347 return a != 8;
352 # Return 1 if offload device is available and it has shared address space.
353 proc check_effective_target_offload_device_shared_as { } {
354 return [check_runtime_nocache offload_device_shared_as {
355 int main ()
357 int x = 10;
358 #pragma omp target map(to: x)
359 x++;
360 return x == 10;
365 # Return 1 if configured for nvptx offloading.
367 proc check_effective_target_openacc_nvidia_accel_configured { } {
368 global offload_targets
369 if { ![string match "*,nvptx,*" ",$offload_targets,"] } {
370 return 0
372 # PR libgomp/65099: Currently, we only support offloading in 64-bit
373 # configurations.
374 return [is-effective-target lp64]
377 # Return 1 if at least one nvidia board is present.
379 proc check_effective_target_openacc_nvidia_accel_present { } {
380 return [check_runtime openacc_nvidia_accel_present {
381 #include <openacc.h>
382 int main () {
383 return !(acc_get_num_devices (acc_device_nvidia) > 0);
385 } "" ]
388 # Return 1 if at least one nvidia board is present, and the nvidia device type
389 # is selected by default by means of setting the environment variable
390 # ACC_DEVICE_TYPE.
392 proc check_effective_target_openacc_nvidia_accel_selected { } {
393 if { ![check_effective_target_openacc_nvidia_accel_present] } {
394 return 0;
396 global offload_target_openacc
397 if { $offload_target_openacc == "nvidia" } {
398 return 1;
400 return 0;
403 # Return 1 if the host target is selected for offloaded
405 proc check_effective_target_openacc_host_selected { } {
406 global offload_target_openacc
407 if { $offload_target_openacc == "host" } {
408 return 1;
410 return 0;
413 # Return 1 if the selected OMP device is actually a HSA device
415 proc check_effective_target_hsa_offloading_selected_nocache {} {
416 global tool
418 set src {
419 int main () {
420 int v = 1;
421 #pragma omp target map(from:v)
422 v = 0;
423 return v;
427 set result [check_compile hsa_offloading_src executable $src]
428 set lines [lindex $result 0]
429 set exe [lindex $result 1]
431 set ok 0
432 if { [string match "" $lines] } {
433 # No error messages, let us switch on HSA debugging output and run it
434 set prev_HSA_DEBUG [getenv HSA_DEBUG]
435 setenv HSA_DEBUG "1"
436 set result [remote_load target "./$exe"]
437 if { [string match "" $prev_HSA_DEBUG] } {
438 unsetenv HSA_DEBUG
439 } else {
440 setenv HSA_DEBUG $prev_HSA_DEBUG
442 set status [lindex $result 0]
443 if { $status != "pass" } {
444 remote_file build delete $exe
445 verbose "HSA availability test failed"
446 return 0
448 set output [lindex $result 1]
449 if { [string match "*HSA debug: Going to dispatch kernel*" $output] } {
450 verbose "HSA availability detected"
451 set ok 1
454 remote_file build delete $exe
455 return $ok
458 # Return 1 if the selected OMP device is actually a HSA device and
459 # cache the result
461 proc check_effective_target_hsa_offloading_selected {} {
462 return [check_cached_effective_target hsa_offloading_selected {
463 check_effective_target_hsa_offloading_selected_nocache