aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/lib/libgomp.exp
blob: 107a3c2ac9de16f5d5d19c056682b815f47c1b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# Damn dejagnu for not having proper library search paths for load_lib.
# We have to explicitly load everything that gcc-dg.exp wants to load.

proc load_gcc_lib { filename } {
    global srcdir loaded_libs

    load_file $srcdir/../../gcc/testsuite/lib/$filename
    set loaded_libs($filename) ""
}

load_lib dg.exp

# Required to use gcc-dg.exp - however, the latter should NOT be
# loaded until ${tool}_target_compile is defined since it uses that
# to determine default LTO options.

load_gcc_lib multiline.exp
load_gcc_lib prune.exp
load_gcc_lib target-libpath.exp
load_gcc_lib wrapper.exp
load_gcc_lib target-supports.exp
load_gcc_lib target-utils.exp
load_gcc_lib gcc-defs.exp
load_gcc_lib timeout.exp
load_gcc_lib file-format.exp
load_gcc_lib target-supports-dg.exp
load_gcc_lib scanasm.exp
load_gcc_lib scandump.exp
load_gcc_lib scanlang.exp
load_gcc_lib scanrtl.exp
load_gcc_lib scansarif.exp
load_gcc_lib scantree.exp
load_gcc_lib scanltranstree.exp
load_gcc_lib scanoffload.exp
load_gcc_lib scanoffloadtree.exp
load_gcc_lib scanoffloadrtl.exp
load_gcc_lib scanipa.exp
load_gcc_lib scanwpaipa.exp
load_gcc_lib timeout-dg.exp
load_gcc_lib torture-options.exp
load_gcc_lib fortran-modules.exp

# Try to load a test support file, built during libgomp configuration.
load_file libgomp-test-support.exp

set dg-do-what-default run

#
# GCC_UNDER_TEST is the compiler under test.
#

set libgomp_compile_options ""

#
# libgomp_init
#

if [info exists TOOL_OPTIONS] {
    set multilibs [get_multilibs $TOOL_OPTIONS]
} else {
    set multilibs [get_multilibs]
}

proc libgomp_init { args } {
    global srcdir blddir objdir tool_root_dir
    global libgomp_initialized
    global tmpdir
    global blddir
    global gluefile wrap_flags
    global ALWAYS_CFLAGS
    global CFLAGS
    global TOOL_EXECUTABLE TOOL_OPTIONS
    global GCC_UNDER_TEST
    global TESTING_IN_BUILD_TREE
    global target_triplet
    global always_ld_library_path

    set blddir [lookfor_file [get_multilibs] libgomp]

    # We set LC_ALL and LANG to C so that we get the same error
    # messages as expected.
    setenv LC_ALL C
    setenv LANG C

    # Many hosts now default to a non-ASCII C locale, however, so
    # they can set a charset encoding here if they need.
    if { [ishost "*-*-cygwin*"] } {
      setenv LC_ALL C.ASCII
      setenv LANG C.ASCII
    }

    if ![info exists GCC_UNDER_TEST] then {
	if [info exists TOOL_EXECUTABLE] {
	    set GCC_UNDER_TEST $TOOL_EXECUTABLE
	} else {
	    set GCC_UNDER_TEST "[find_gcc]"
	}
    }

    if ![info exists tmpdir] {
	set tmpdir "/tmp"
    }

    if [info exists gluefile] {
	unset gluefile
    }

    if {![info exists CFLAGS]} {
	set CFLAGS ""
    }

    # Locate libgcc.a so we don't need to account for different values of
    # SHLIB_EXT on different platforms
    set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
    if {$gccdir != ""} {
        set gccdir [file dirname $gccdir]
    }

    # Compute what needs to be put into LD_LIBRARY_PATH
    set always_ld_library_path ".:${blddir}/.libs"

    # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
    # Intel MIC offloading testing.
    global offload_plugins
    if { [string match "*,intelmic,*" ",$offload_plugins,"] } {
	append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
	append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
	# libstdc++ is required by liboffloadmic
	append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
	# libgcc_s is required by libstdc++
	append always_ld_library_path ":${blddir}/../libgcc"
    }

    global offload_additional_lib_paths
    if { $offload_additional_lib_paths != "" } {
	append always_ld_library_path "${offload_additional_lib_paths}"
    }

    # Compute what needs to be added to the existing LD_LIBRARY_PATH.
    if {$gccdir != ""} {
	# Add AIX pthread directory first.
	if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
	    append always_ld_library_path ":${gccdir}/pthread"
	}
	append always_ld_library_path ":${gccdir}"
	set compiler [lindex $GCC_UNDER_TEST 0]

	if { [is_remote host] == 0 && [which $compiler] != 0 } {
	  foreach i "[exec $compiler --print-multi-lib]" {
	    set mldir ""
	    regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
	    set mldir [string trimright $mldir "\;@"]
	    if { "$mldir" == "." } {
	      continue
	    }
	    if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
	      append always_ld_library_path ":${gccdir}/${mldir}"
	    }
	  }
	}
    }

    set ALWAYS_CFLAGS ""
    if { $blddir != "" } {
        lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
        # targets that use libgomp.a%s in their specs need a -B option
        # for uninstalled testing.
        lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
        lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
        lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
    }
    # The top-level include directory, for gomp-constants.h.
    lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
    lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."

    # For build-tree testing, also consider the library paths used for builing.
    # For installed testing, we assume all that to be provided in the sysroot.
    if { $blddir != "" } {
	# The `-fopenacc' and `-fopenmp' options imply `-pthread', and
	# that implies `-latomic' on some hosts, so wire in libatomic
	# build directories.
	if [ishost "riscv*-*-linux*"] {
	    set shlib_ext [get_shlib_extension]
	    set atomic_library_path "${blddir}/../libatomic/.libs"
	    if { [file exists "${atomic_library_path}/libatomic.a"]
		 || [file exists \
		     "${atomic_library_path}/libatomic.${shlib_ext}"] } {
		lappend ALWAYS_CFLAGS \
		    "additional_flags=-L${atomic_library_path}"
		append always_ld_library_path ":${atomic_library_path}"
	    }
	}
    }

    # We use atomic operations in the testcases to validate results.
    if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
	 && [check_effective_target_ia32]
	 && ![check_effective_target_cas_char] } {
	lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
    }

    if [istarget *-*-darwin*] {
	lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
    }

    if [istarget sparc*-*-*] {
	lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
    }

    if [info exists TOOL_OPTIONS] {
	lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
    }

    # Make sure that lines are not wrapped.  That can confuse the
    # error-message parsing machinery.
    lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"

    # Disable caret
    lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"

    # Disable color diagnostics
    lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"

    # Help GCC to find offload compilers' 'mkoffload'.
    global offload_additional_options
    if { $offload_additional_options != "" } {
	lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
    }

    # Tell warning from error diagnostics.  This fits for C, C++, and Fortran.
    global gcc_warning_prefix
    set gcc_warning_prefix "\[Ww\]arning:"
    global gcc_error_prefix
    set gcc_error_prefix "(\[Ff\]atal )?\[Ee\]rror:"
}

#
# libgomp_target_compile -- compile a source file
#

proc libgomp_target_compile { source dest type options } {
    global blddir
    global libgomp_compile_options
    global gluefile wrap_flags
    global ALWAYS_CFLAGS
    global GCC_UNDER_TEST
    global lang_test_file
    global lang_library_path
    global lang_link_flags
    global lang_include_flags
    global lang_source_re

    if { [info exists lang_test_file] } {
        if { $blddir != "" } {
            # Some targets use libgfortran.a%s in their specs, so they need
            # a -B option for uninstalled testing.
            lappend options "additional_flags=-B${blddir}/${lang_library_path}"
            lappend options "ldflags=-L${blddir}/${lang_library_path}"
        }
        lappend options "ldflags=${lang_link_flags}"
	if { [info exists lang_include_flags] \
	     && [regexp ${lang_source_re} ${source}] } {
	    lappend options "additional_flags=${lang_include_flags}"
	}
    }

    if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
	lappend options "libs=${gluefile}"
	lappend options "ldflags=${wrap_flags}"
    }

    lappend options "additional_flags=[libio_include_flags]"
    lappend options "timeout=[timeout_value]"
    lappend options "compiler=$GCC_UNDER_TEST"

    set options [concat $libgomp_compile_options $options]

    if [info exists ALWAYS_CFLAGS] {
	set options [concat "$ALWAYS_CFLAGS" $options]
    }

    set options [dg-additional-files-options $options $source]

    set result [target_compile $source $dest $type $options]

    return $result
}

proc libgomp_option_help { } {
    send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
}

proc libgomp_option_proc { option } {
    if [regexp "^--additional_options," $option] {
	global libgomp_compile_options
	regsub "--additional_options," $option "" option
	foreach x [split $option ","] {
	    lappend libgomp_compile_options "additional_flags=$x"
	}
	return 1
    } else {
	return 0
    }
}

# Translate offload target to OpenACC device type.  Return the empty string if
# not supported, and 'host' for offload target 'disable'.
proc offload_target_to_openacc_device_type { offload_target } {
    switch -glob $offload_target {
	amdgcn* {
	    return "radeon"
	}
	disable {
	    return "host"
	}
	*-intelmic* {
	    return ""
	}
	nvptx* {
	    return "nvidia"
	}
	default {
	    error "Unknown offload target: $offload_target"
	}
    }
}

# Return 1 if compiling for the specified offload target
# Takes -foffload=... into account by checking OFFLOAD_TARGET_NAMES=
# in the -v compiler output.
proc libgomp_check_effective_target_offload_target { target_name } {
    # Consider all actual options, including the flags passed to
    # 'gcc-dg-runtest', or 'gfortran-dg-runtest' (see the 'libgomp.*/*.exp'
    # files; in particular, '-foffload', 'libgomp.oacc-*/*.exp'), which don't
    # get passed on to 'check_effective_target_*' functions.  (Not caching the
    # result due to that.)
    set options [list "additional_flags=[concat "-v" [current_compiler_flags]]"]
    # Instead of inspecting command-line options, look what the compiler driver
    # decides.  This is somewhat modelled after
    # 'gcc/testsuite/lib/target-supports.exp:check_configured_with'.
    set gcc_output [libgomp_target_compile "" "" "none" $options]
    if [regexp "(?n)^OFFLOAD_TARGET_NAMES=(.*)" $gcc_output dummy gcc_offload_targets] {
	verbose "compiling for offload targets: $gcc_offload_targets"
	return [string match "*:$target_name*:*" ":$gcc_offload_targets:"]
    }

    verbose "not compiling for $target_name offload target"
    return 0
}

# Return 1 if compiling for any offload target.
proc check_effective_target_offload_target_any { } {
    return [libgomp_check_effective_target_offload_target ""]
}

# Return 1 if compiling for offload target nvptx.
proc check_effective_target_offload_target_nvptx { } {
    return [libgomp_check_effective_target_offload_target "nvptx"]
}

# Return 1 if compiling for offload target amdgcn
proc check_effective_target_offload_target_amdgcn { } {
    return [libgomp_check_effective_target_offload_target "amdgcn"]
}

# Return 1 if offload device is available.
proc check_effective_target_offload_device { } {
    return [check_runtime_nocache offload_device_available_ {
      #include <omp.h>
      int main ()
	{
	  int a;
	  #pragma omp target map(from: a)
	    a = omp_is_initial_device ();
	  return a;
	}
    } ]
}

# Return 1 if offload device is available and it has non-shared address space.
proc check_effective_target_offload_device_nonshared_as { } {
    return [check_runtime_nocache offload_device_nonshared_as {
      int main ()
	{
	  int a = 8;
	  #pragma omp target map(to: a)
	    a++;
	  return a != 8;
	}
    } ]
}
  
# Return 1 if offload device is available and it has shared address space.
proc check_effective_target_offload_device_shared_as { } {
    return [check_runtime_nocache offload_device_shared_as {
      int main ()
	{
	  int x = 10;
	  #pragma omp target map(to: x)
	    x++;
	  return x == 10;
	}
    } ]
}

# Return 1 if using nvptx offload device.
proc check_effective_target_offload_device_nvptx { } {
    return [check_runtime_nocache offload_device_nvptx {
      #include <omp.h>
      #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
      int main ()
	{
	  return !on_device_arch_nvptx ();
	}
    } ]
}

# Return 1 if at least one Nvidia GPU is accessible.

proc check_effective_target_openacc_nvidia_accel_present { } {
    return [check_runtime openacc_nvidia_accel_present {
	#include <openacc.h>
	int main () {
	return !(acc_get_num_devices (acc_device_nvidia) > 0);
	}
    } "" ]
}

# Return 1 if at least one Nvidia GPU is accessible, and the OpenACC 'nvidia'
# device type is selected.

proc check_effective_target_openacc_nvidia_accel_selected { } {
    if { ![check_effective_target_openacc_nvidia_accel_present] } {
	return 0;
    }
    global openacc_device_type
    return [string match "nvidia" $openacc_device_type]
}

# Return 1 if using Intel MIC offload device.
proc check_effective_target_offload_device_intel_mic { } {
    return [check_runtime_nocache offload_device_intel_mic {
      #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
      int main ()
	{
	  return !on_device_arch_intel_mic ();
	}
    } ]
}

# Return 1 if any Intel MIC offload device is available.
proc check_effective_target_offload_device_any_intel_mic { } {
    return [check_runtime_nocache offload_device_any_intel_mic {
      #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
      int main ()
	{
	  return !any_device_arch_intel_mic ();
	}
    } ]
}

# Return 1 if the OpenACC 'host' device type is selected.

proc check_effective_target_openacc_host_selected { } {
    global openacc_device_type
    return [string match "host" $openacc_device_type]
}

# Return 1 if at least one AMD GPU is accessible.

proc check_effective_target_openacc_radeon_accel_present { } {
    return [check_runtime openacc_radeon_accel_present {
	#include <openacc.h>
	int main () {
	return !(acc_get_num_devices (acc_device_radeon) > 0);
	}
    } "" ]
}

# Return 1 if at least one AMD GPU is accessible, and the OpenACC 'radeon'
# device type is selected.

proc check_effective_target_openacc_radeon_accel_selected { } {
    if { ![check_effective_target_openacc_radeon_accel_present] } {
	return 0;
    }
    global openacc_device_type
    return [string match "radeon" $openacc_device_type]
}

# Return 1 if cuda.h and -lcuda are available.

proc check_effective_target_openacc_cuda { } {
    return [check_no_compiler_messages openacc_cuda executable {
#include <cuda.h>
int main() {
    CUdevice dev;
    CUresult r = cuDeviceGet (&dev, 0);
    if (r != CUDA_SUCCESS)
	return 1;
    return 0;
} } "-lcuda" ]
}

# Return 1 if cublas_v2.h and -lcublas are available.

proc check_effective_target_openacc_cublas { } {
    return [check_no_compiler_messages openacc_cublas executable {
#include <cuda.h>
#include <cublas_v2.h>
int main() {
    cublasStatus_t s;
    cublasHandle_t h;
    CUdevice dev;
    CUresult r = cuDeviceGet (&dev, 0);
    if (r != CUDA_SUCCESS)
	return 1;
    s = cublasCreate (&h);
    if (s != CUBLAS_STATUS_SUCCESS)
	return 1;
    return 0;
} } "-lcuda -lcublas" ]
}

# Return 1 if cuda_runtime_api.h and -lcudart are available.

proc check_effective_target_openacc_cudart { } {
    return [check_no_compiler_messages openacc_cudart executable {
#include <cuda.h>
#include <cuda_runtime_api.h>
int main() {
    cudaError_t e;
    int devn;
    CUdevice dev;
    CUresult r = cuDeviceGet (&dev, 0);
    if (r != CUDA_SUCCESS)
	return 1;
    e = cudaGetDevice (&devn);
    if (e != cudaSuccess)
	return 1;
    return 0;
} } "-lcuda -lcudart" ]
}