c++: Add new test [PR88092]
[gcc.git] / libgomp / testsuite / libgomp.oacc-c++ / c++.exp
1 # This whole file adapted from libgomp.c++/c++.exp.
2
3 load_lib libgomp-dg.exp
4 load_gcc_lib gcc-dg.exp
5 load_gcc_lib torture-options.exp
6
7 proc check_effective_target_c { } {
8 return 0
9 }
10 proc check_effective_target_c++ { } {
11 return 1
12 }
13
14 global shlib_ext
15
16 set shlib_ext [get_shlib_extension]
17 set lang_link_flags "-lstdc++"
18 set lang_test_file_found 0
19 set lang_library_path "../libstdc++-v3/src/.libs"
20 if [info exists lang_include_flags] then {
21 unset lang_include_flags
22 }
23
24 # Initialize dg.
25 dg-init
26 torture-init
27
28 # Turn on OpenACC.
29 lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
30
31 # Switch into C++ mode. Otherwise, the libgomp.oacc-c-c++-common/*.c
32 # files would be compiled as C files.
33 set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
34 set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
35
36 set blddir [lookfor_file [get_multilibs] libgomp]
37
38
39 if { $blddir != "" } {
40 # Look for a static libstdc++ first.
41 if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] {
42 set lang_test_file "${lang_library_path}/libstdc++.a"
43 set lang_test_file_found 1
44 # We may have a shared only build, so look for a shared libstdc++.
45 } elseif [file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] {
46 set lang_test_file "${lang_library_path}/libstdc++.${shlib_ext}"
47 set lang_test_file_found 1
48 } else {
49 puts "No libstdc++ library found, will not execute c++ tests"
50 }
51 } elseif { [info exists GXX_UNDER_TEST] } {
52 set lang_test_file_found 1
53 # Needs to exist for libgomp.exp.
54 set lang_test_file ""
55 } else {
56 puts "GXX_UNDER_TEST not defined, will not execute c++ tests"
57 }
58
59 if { $lang_test_file_found } {
60 # Gather a list of all tests.
61 set tests [lsort [concat \
62 [find $srcdir/$subdir *.C] \
63 [find $srcdir/$subdir/../libgomp.oacc-c-c++-common *.c]]]
64
65 if { $blddir != "" } {
66 set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}"
67 } else {
68 set ld_library_path "$always_ld_library_path"
69 }
70 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
71 set_ld_library_path_env_vars
72
73 set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
74 if { [file exists $flags_file] } {
75 set libstdcxx_includes [exec sh $flags_file --build-includes]
76 } else {
77 set libstdcxx_includes ""
78 }
79
80 # Test with all available offload targets, and with offloading disabled.
81 foreach offload_target [concat [split $offload_targets ","] "disable"] {
82 global openacc_device_type
83 set openacc_device_type [offload_target_to_openacc_device_type $offload_target]
84 set tagopt "-DACC_DEVICE_TYPE_$openacc_device_type=1"
85
86 switch $openacc_device_type {
87 "" {
88 unsupported "$subdir $offload_target offloading"
89 continue
90 }
91 gcn {
92 if { ![check_effective_target_openacc_amdgcn_accel_present] } {
93 # Don't bother; execution testing is going to FAIL.
94 untested "$subdir $offload_target offloading: supported, but hardware not accessible"
95 continue
96 }
97
98 set acc_mem_shared 0
99 }
100 host {
101 set acc_mem_shared 1
102 }
103 nvidia {
104 if { ![check_effective_target_openacc_nvidia_accel_present] } {
105 # Don't bother; execution testing is going to FAIL.
106 untested "$subdir $offload_target offloading: supported, but hardware not accessible"
107 continue
108 }
109
110 # Copy ptx file (TEMPORARY)
111 remote_download host $srcdir/libgomp.oacc-c-c++-common/subr.ptx
112
113 # Where timer.h lives
114 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common"
115
116 set acc_mem_shared 0
117 }
118 default {
119 error "Unknown OpenACC device type: $openacc_device_type (offload target: $offload_target)"
120 }
121 }
122 set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
123
124 # To avoid compilation overhead, and to keep simple '-foffload=[...]'
125 # handling in test cases, by default only build for the offload target
126 # that we're actually going to test.
127 set tagopt "$tagopt -foffload=$offload_target"
128 # Force usage of the corresponding OpenACC device type.
129 setenv ACC_DEVICE_TYPE $openacc_device_type
130
131 # To get better test coverage for device-specific code that is only
132 # ever used in offloading configurations, we'd like more thorough
133 # testing for test cases that deal with offloading, which most of all
134 # OpenACC test cases are. We enable torture testing, but limit it to
135 # -O0 and -O2 only, to avoid testing times exploding too much, under
136 # the assumption that between -O0 and -O[something] there is the
137 # biggest difference in the overall structure of the generated code.
138 switch -glob $offload_target {
139 disable {
140 set-torture-options [list \
141 { -O2 } ]
142 }
143 default {
144 set-torture-options [list \
145 { -O0 } \
146 { -O2 } ]
147 }
148 }
149
150 gcc-dg-runtest $tests "$tagopt" "$libstdcxx_includes"
151 }
152 } else {
153 # Call this once, which placates the subsequent torture-finish.
154 set-torture-options [list \
155 { INVALID } ]
156 }
157
158 # See above.
159 set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST"
160
161 # All done.
162 torture-finish
163 dg-finish