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