1# This whole file adapted from libgomp.c/c.exp.
2
3if [info exists lang_library_path] then {
4    unset lang_library_path
5    unset lang_link_flags
6}
7if [info exists lang_test_file] then {
8    unset lang_test_file
9}
10if [info exists lang_include_flags] then {
11    unset lang_include_flags
12}
13
14load_lib libgomp-dg.exp
15load_gcc_lib gcc-dg.exp
16load_gcc_lib torture-options.exp
17
18proc check_effective_target_c { } {
19    return 1
20}
21proc check_effective_target_c++ { } {
22    return 0
23}
24
25# Initialize dg.
26dg-init
27torture-init
28
29# Turn on OpenACC.
30lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
31
32# Gather a list of all tests.
33set tests [lsort [concat \
34		      [find $srcdir/$subdir *.c] \
35		      [find $srcdir/$subdir/../libgomp.oacc-c-c++-common *.c]]]
36
37set ld_library_path $always_ld_library_path
38append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
39set_ld_library_path_env_vars
40
41# Test with all available offload targets, and with offloading disabled.
42set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
43foreach offload_target [concat [split $offload_targets ","] "disable"] {
44    set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
45    global openacc_device_type
46    set openacc_device_type [offload_target_to_openacc_device_type $offload_target]
47    set tagopt "-DACC_DEVICE_TYPE_$openacc_device_type=1"
48
49    switch $openacc_device_type {
50	"" {
51	    unsupported "$subdir $offload_target offloading"
52	    continue
53	}
54	host {
55	    set acc_mem_shared 1
56	}
57	nvidia {
58	    if { ![check_effective_target_openacc_nvidia_accel_present] } {
59		# Don't bother; execution testing is going to FAIL.
60		untested "$subdir $offload_target offloading: supported, but hardware not accessible"
61		continue
62	    }
63
64	    # Copy ptx file (TEMPORARY)
65	    remote_download host $srcdir/libgomp.oacc-c-c++-common/subr.ptx
66
67	    # Where timer.h lives
68	    lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common"
69
70	    set acc_mem_shared 0
71	}
72	radeon {
73	    if { ![check_effective_target_openacc_radeon_accel_present] } {
74		# Don't bother; execution testing is going to FAIL.
75		untested "$subdir $offload_target offloading: supported, but hardware not accessible"
76		continue
77	    }
78
79	    set acc_mem_shared 0
80	}
81	default {
82	    error "Unknown OpenACC device type: $openacc_device_type (offload target: $offload_target)"
83	}
84    }
85    set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
86
87    # To avoid compilation overhead, and to keep simple '-foffload=[...]'
88    # handling in test cases, by default only build for the offload target
89    # that we're actually going to test.
90    set tagopt "$tagopt -foffload=$offload_target"
91    # Force usage of the corresponding OpenACC device type.
92    setenv ACC_DEVICE_TYPE $openacc_device_type
93
94    # To get better test coverage for device-specific code that is only
95    # ever used in offloading configurations, we'd like more thorough
96    # testing for test cases that deal with offloading, which most of all
97    # OpenACC test cases are.  We enable torture testing, but limit it to
98    # -O0 and -O2 only, to avoid testing times exploding too much, under
99    # the assumption that between -O0 and -O[something] there is the
100    # biggest difference in the overall structure of the generated code.
101    switch -glob $offload_target {
102	disable {
103	    set-torture-options [list \
104				     { -O2 } ]
105	}
106	default {
107	    set-torture-options [list \
108				     { -O0 } \
109				     { -O2 } ]
110	}
111    }
112
113    gcc-dg-runtest $tests "$tagopt" ""
114}
115
116# All done.
117torture-finish
118dg-finish
119