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 OpenACC with available accelerators.
42set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
43foreach offload_target_openacc $offload_targets_s_openacc {
44    set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
45    set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
46
47    switch $offload_target_openacc {
48	host {
49	    set acc_mem_shared 1
50	}
51	nvidia {
52	    if { ![check_effective_target_openacc_nvidia_accel_present] } {
53		# Don't bother; execution testing is going to FAIL.
54		untested "$subdir $offload_target_openacc offloading"
55		continue
56	    }
57
58	    # Copy ptx file (TEMPORARY)
59	    remote_download host $srcdir/libgomp.oacc-c-c++-common/subr.ptx
60
61	    # Where timer.h lives
62	    lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common"
63
64	    set acc_mem_shared 0
65	}
66	default {
67	    set acc_mem_shared 0
68	}
69    }
70    set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
71
72    setenv ACC_DEVICE_TYPE $offload_target_openacc
73
74    # To get better test coverage for device-specific code that is only
75    # ever used in offloading configurations, we'd like more thorough
76    # testing for test cases that deal with offloading, which most of all
77    # OpenACC test cases are.  We enable torture testing, but limit it to
78    # -O0 and -O2 only, to avoid testing times exploding too much, under
79    # the assumption that between -O0 and -O[something] there is the
80    # biggest difference in the overall structure of the generated code.
81    switch $offload_target_openacc {
82	host {
83	    set-torture-options [list \
84				     { -O2 } ]
85	}
86	default {
87	    set-torture-options [list \
88				     { -O0 } \
89				     { -O2 } ]
90	}
91    }
92
93    gcc-dg-runtest $tests "$tagopt" ""
94}
95
96# All done.
97torture-finish
98dg-finish
99