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
18# Initialize dg.
19dg-init
20torture-init
21
22# Turn on OpenACC.
23lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
24
25# Gather a list of all tests.
26set tests [lsort [concat \
27		      [find $srcdir/$subdir *.c] \
28		      [find $srcdir/$subdir/../libgomp.oacc-c-c++-common *.c]]]
29
30set ld_library_path $always_ld_library_path
31append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
32set_ld_library_path_env_vars
33
34# Test OpenACC with available accelerators.
35set SAVE_ALWAYS_CFLAGS "$ALWAYS_CFLAGS"
36foreach offload_target_openacc $offload_targets_s_openacc {
37    set ALWAYS_CFLAGS "$SAVE_ALWAYS_CFLAGS"
38    set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
39
40    switch $offload_target_openacc {
41	host {
42	    set acc_mem_shared 1
43	}
44	nvidia {
45	    if { ![check_effective_target_openacc_nvidia_accel_present] } {
46		# Don't bother; execution testing is going to FAIL.
47		untested "$subdir $offload_target_openacc offloading"
48		continue
49	    }
50
51	    # Copy ptx file (TEMPORARY)
52	    remote_download host $srcdir/libgomp.oacc-c-c++-common/subr.ptx
53
54	    # Where timer.h lives
55	    lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common"
56
57	    set acc_mem_shared 0
58	}
59	default {
60	    set acc_mem_shared 0
61	}
62    }
63    set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
64
65    setenv ACC_DEVICE_TYPE $offload_target_openacc
66
67    # To get better test coverage for device-specific code that is only
68    # ever used in offloading configurations, we'd like more thorough
69    # testing for test cases that deal with offloading, which most of all
70    # OpenACC test cases are.  We enable torture testing, but limit it to
71    # -O0 and -O2 only, to avoid testing times exploding too much, under
72    # the assumption that between -O0 and -O[something] there is the
73    # biggest difference in the overall structure of the generated code.
74    switch $offload_target_openacc {
75	host {
76	    set-torture-options [list \
77				     { -O2 } ]
78	}
79	default {
80	    set-torture-options [list \
81				     { -O0 } \
82				     { -O2 } ]
83	}
84    }
85
86    gcc-dg-runtest $tests "$tagopt" ""
87}
88
89# All done.
90torture-finish
91dg-finish
92