2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / lib / libgomp.exp
blobea3da2cb38356d8de90460f38a4d81829a52737e
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 scanipa.exp
33 load_gcc_lib timeout-dg.exp
34 load_gcc_lib torture-options.exp
35 load_gcc_lib fortran-modules.exp
37 # Try to load a test support file, built during libgomp configuration.
38 load_file libgomp-test-support.exp
40 # Populate offload_targets_s (offloading targets separated by a space), and
41 # offload_targets_s_openacc (the same, but with OpenACC names; OpenACC spells
42 # some of them a little differently).
43 set offload_targets_s [split $offload_targets ","]
44 set offload_targets_s_openacc {}
45 foreach offload_target_openacc $offload_targets_s {
46 # Translate to OpenACC names, or skip if not yet supported.
47 switch $offload_target_openacc {
48 intelmic {
49 continue
51 nvptx {
52 set offload_target_openacc "nvidia"
54 hsa {
55 continue
58 lappend offload_targets_s_openacc "$offload_target_openacc"
60 lappend offload_targets_s_openacc "host"
62 set dg-do-what-default run
65 # GCC_UNDER_TEST is the compiler under test.
68 set libgomp_compile_options ""
71 # libgomp_init
74 if [info exists TOOL_OPTIONS] {
75 set multilibs [get_multilibs $TOOL_OPTIONS]
76 } else {
77 set multilibs [get_multilibs]
80 proc libgomp_init { args } {
81 global srcdir blddir objdir tool_root_dir
82 global libgomp_initialized
83 global tmpdir
84 global blddir
85 global gluefile wrap_flags
86 global ALWAYS_CFLAGS
87 global CFLAGS
88 global TOOL_EXECUTABLE TOOL_OPTIONS
89 global GCC_UNDER_TEST
90 global TESTING_IN_BUILD_TREE
91 global target_triplet
92 global always_ld_library_path
94 set blddir [lookfor_file [get_multilibs] libgomp]
96 # We set LC_ALL and LANG to C so that we get the same error
97 # messages as expected.
98 setenv LC_ALL C
99 setenv LANG C
101 # Many hosts now default to a non-ASCII C locale, however, so
102 # they can set a charset encoding here if they need.
103 if { [ishost "*-*-cygwin*"] } {
104 setenv LC_ALL C.ASCII
105 setenv LANG C.ASCII
108 if ![info exists GCC_UNDER_TEST] then {
109 if [info exists TOOL_EXECUTABLE] {
110 set GCC_UNDER_TEST $TOOL_EXECUTABLE
111 } else {
112 set GCC_UNDER_TEST "[find_gcc]"
116 if ![info exists tmpdir] {
117 set tmpdir "/tmp"
120 if [info exists gluefile] {
121 unset gluefile
124 if {![info exists CFLAGS]} {
125 set CFLAGS ""
128 # Locate libgcc.a so we don't need to account for different values of
129 # SHLIB_EXT on different platforms
130 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
131 if {$gccdir != ""} {
132 set gccdir [file dirname $gccdir]
135 # Compute what needs to be put into LD_LIBRARY_PATH
136 set always_ld_library_path ".:${blddir}/.libs"
138 # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
139 # non-fallback testing for Intel MIC targets
140 global offload_targets
141 if { [string match "*,intelmic,*" ",$offload_targets,"] } {
142 append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
143 append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
144 # libstdc++ is required by liboffloadmic
145 append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
146 # libgcc_s is required by libstdc++
147 append always_ld_library_path ":${blddir}/../libgcc"
150 global offload_additional_lib_paths
151 if { $offload_additional_lib_paths != "" } {
152 append always_ld_library_path "${offload_additional_lib_paths}"
155 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
156 if {$gccdir != ""} {
157 # Add AIX pthread directory first.
158 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
159 append always_ld_library_path ":${gccdir}/pthread"
161 append always_ld_library_path ":${gccdir}"
162 set compiler [lindex $GCC_UNDER_TEST 0]
164 if { [is_remote host] == 0 && [which $compiler] != 0 } {
165 foreach i "[exec $compiler --print-multi-lib]" {
166 set mldir ""
167 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
168 set mldir [string trimright $mldir "\;@"]
169 if { "$mldir" == "." } {
170 continue
172 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
173 append always_ld_library_path ":${gccdir}/${mldir}"
179 set ALWAYS_CFLAGS ""
180 if { $blddir != "" } {
181 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
182 # targets that use libgomp.a%s in their specs need a -B option
183 # for uninstalled testing.
184 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
185 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
186 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
187 # The top-level include directory, for gomp-constants.h.
188 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
190 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
192 # For build-tree testing, also consider the library paths used for builing.
193 # For installed testing, we assume all that to be provided in the sysroot.
194 if { $blddir != "" } {
195 global cuda_driver_include
196 global cuda_driver_lib
197 if { $cuda_driver_include != "" } {
198 # Stop gfortran from freaking out:
199 # Warning: Nonexistent include directory "[...]"
200 if {[file exists $cuda_driver_include]} {
201 lappend ALWAYS_CFLAGS "additional_flags=-I$cuda_driver_include"
204 if { $cuda_driver_lib != "" } {
205 lappend ALWAYS_CFLAGS "additional_flags=-L$cuda_driver_lib"
206 append always_ld_library_path ":$cuda_driver_lib"
208 global hsa_runtime_lib
209 if { $hsa_runtime_lib != "" } {
210 append always_ld_library_path ":$hsa_runtime_lib"
214 # We use atomic operations in the testcases to validate results.
215 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
216 && [check_effective_target_ia32] } {
217 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
220 if [istarget *-*-darwin*] {
221 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
224 if [istarget sparc*-*-*] {
225 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
228 if [info exists TOOL_OPTIONS] {
229 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
232 # Make sure that lines are not wrapped. That can confuse the
233 # error-message parsing machinery.
234 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
236 # Disable caret
237 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
239 # Disable HSA warnings by default.
240 lappend ALWAYS_CFLAGS "additional_flags=-Wno-hsa"
242 # Disable color diagnostics
243 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
245 # Used for support non-fallback offloading.
246 # Help GCC to find target mkoffload.
247 global offload_additional_options
248 if { $offload_additional_options != "" } {
249 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
254 # libgomp_target_compile -- compile a source file
257 proc libgomp_target_compile { source dest type options } {
258 global blddir
259 global libgomp_compile_options
260 global gluefile wrap_flags
261 global ALWAYS_CFLAGS
262 global GCC_UNDER_TEST
263 global lang_test_file
264 global lang_library_path
265 global lang_link_flags
266 global lang_include_flags
267 global lang_source_re
269 if { [info exists lang_test_file] } {
270 if { $blddir != "" } {
271 # Some targets use libgfortran.a%s in their specs, so they need
272 # a -B option for uninstalled testing.
273 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
274 lappend options "ldflags=-L${blddir}/${lang_library_path}"
276 lappend options "ldflags=${lang_link_flags}"
277 if { [info exists lang_include_flags] \
278 && [regexp ${lang_source_re} ${source}] } {
279 lappend options "additional_flags=${lang_include_flags}"
283 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
284 lappend options "libs=${gluefile}"
285 lappend options "ldflags=${wrap_flags}"
288 lappend options "additional_flags=[libio_include_flags]"
289 lappend options "timeout=[timeout_value]"
290 lappend options "compiler=$GCC_UNDER_TEST"
292 set options [concat $libgomp_compile_options $options]
294 if [info exists ALWAYS_CFLAGS] {
295 set options [concat "$ALWAYS_CFLAGS" $options]
298 set options [dg-additional-files-options $options $source]
300 set result [target_compile $source $dest $type $options]
302 return $result
305 proc libgomp_option_help { } {
306 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
309 proc libgomp_option_proc { option } {
310 if [regexp "^--additional_options," $option] {
311 global libgomp_compile_options
312 regsub "--additional_options," $option "" option
313 foreach x [split $option ","] {
314 lappend libgomp_compile_options "additional_flags=$x"
316 return 1
317 } else {
318 return 0
322 # Return 1 if offload device is available.
323 proc check_effective_target_offload_device { } {
324 return [check_runtime_nocache offload_device_available_ {
325 #include <omp.h>
326 int main ()
328 int a;
329 #pragma omp target map(from: a)
330 a = omp_is_initial_device ();
331 return a;
336 # Return 1 if offload device is available and it has non-shared address space.
337 proc check_effective_target_offload_device_nonshared_as { } {
338 return [check_runtime_nocache offload_device_nonshared_as {
339 int main ()
341 int a = 8;
342 #pragma omp target map(to: a)
343 a++;
344 return a != 8;
349 # Return 1 if offload device is available and it has shared address space.
350 proc check_effective_target_offload_device_shared_as { } {
351 return [check_runtime_nocache offload_device_shared_as {
352 int main ()
354 int x = 10;
355 #pragma omp target map(to: x)
356 x++;
357 return x == 10;
362 # Return 1 if configured for nvptx offloading.
364 proc check_effective_target_openacc_nvidia_accel_configured { } {
365 global offload_targets
366 if { ![string match "*,nvptx,*" ",$offload_targets,"] } {
367 return 0
369 # PR libgomp/65099: Currently, we only support offloading in 64-bit
370 # configurations.
371 return [is-effective-target lp64]
374 # Return 1 if at least one nvidia board is present.
376 proc check_effective_target_openacc_nvidia_accel_present { } {
377 return [check_runtime openacc_nvidia_accel_present {
378 #include <openacc.h>
379 int main () {
380 return !(acc_get_num_devices (acc_device_nvidia) > 0);
382 } "" ]
385 # Return 1 if at least one nvidia board is present, and the nvidia device type
386 # is selected by default by means of setting the environment variable
387 # ACC_DEVICE_TYPE.
389 proc check_effective_target_openacc_nvidia_accel_selected { } {
390 if { ![check_effective_target_openacc_nvidia_accel_present] } {
391 return 0;
393 global offload_target_openacc
394 if { $offload_target_openacc == "nvidia" } {
395 return 1;
397 return 0;
400 # Return 1 if the host target is selected for offloaded
402 proc check_effective_target_openacc_host_selected { } {
403 global offload_target_openacc
404 if { $offload_target_openacc == "host" } {
405 return 1;
407 return 0;
410 # Return 1 if the selected OMP device is actually a HSA device
412 proc check_effective_target_hsa_offloading_selected_nocache {} {
413 global tool
415 set src {
416 int main () {
417 int v = 1;
418 #pragma omp target map(from:v)
419 v = 0;
420 return v;
424 set result [check_compile hsa_offloading_src executable $src]
425 set lines [lindex $result 0]
426 set exe [lindex $result 1]
428 set ok 0
429 if { [string match "" $lines] } {
430 # No error messages, let us switch on HSA debugging output and run it
431 set prev_HSA_DEBUG [getenv HSA_DEBUG]
432 setenv HSA_DEBUG "1"
433 set result [remote_load target "./$exe"]
434 if { [string match "" $prev_HSA_DEBUG] } {
435 unsetenv HSA_DEBUG
436 } else {
437 setenv HSA_DEBUG $prev_HSA_DEBUG
439 set status [lindex $result 0]
440 if { $status != "pass" } {
441 remote_file build delete $exe
442 verbose "HSA availability test failed"
443 return 0
445 set output [lindex $result 1]
446 if { [string match "*HSA debug: Going to dispatch kernel*" $output] } {
447 verbose "HSA availability detected"
448 set ok 1
451 remote_file build delete $exe
452 return $ok
455 # Return 1 if the selected OMP device is actually a HSA device and
456 # cache the result
458 proc check_effective_target_hsa_offloading_selected {} {
459 return [check_cached_effective_target hsa_offloading_selected {
460 check_effective_target_hsa_offloading_selected_nocache