Avoid ERROR in libgomp.oacc-c++/c++.exp in non-C++ configurations
[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 global shlib_ext
8
9 set shlib_ext [get_shlib_extension]
10 set lang_link_flags "-lstdc++"
11 set lang_test_file_found 0
12 set lang_library_path "../libstdc++-v3/src/.libs"
13 if [info exists lang_include_flags] then {
14 unset lang_include_flags
15 }
16
17 # Initialize dg.
18 dg-init
19 torture-init
20
21 # Turn on OpenACC.
22 lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
23
24 # Switch into C++ mode. Otherwise, the libgomp.oacc-c-c++-common/*.c
25 # files would be compiled as C files.
26 set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
27 set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
28
29 set blddir [lookfor_file [get_multilibs] libgomp]
30
31
32 if { $blddir != "" } {
33 # Look for a static libstdc++ first.
34 if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] {
35 set lang_test_file "${lang_library_path}/libstdc++.a"
36 set lang_test_file_found 1
37 # We may have a shared only build, so look for a shared libstdc++.
38 } elseif [file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] {
39 set lang_test_file "${lang_library_path}/libstdc++.${shlib_ext}"
40 set lang_test_file_found 1
41 } else {
42 puts "No libstdc++ library found, will not execute c++ tests"
43 }
44 } elseif { [info exists GXX_UNDER_TEST] } {
45 set lang_test_file_found 1
46 # Needs to exist for libgomp.exp.
47 set lang_test_file ""
48 } else {
49 puts "GXX_UNDER_TEST not defined, will not execute c++ tests"
50 }
51
52 if { $lang_test_file_found } {
53 # Gather a list of all tests.
54 set tests [lsort [concat \
55 [find $srcdir/$subdir *.C] \
56 [find $srcdir/$subdir/../libgomp.oacc-c-c++-common *.c]]]
57
58 if { $blddir != "" } {
59 set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}"
60 } else {
61 set ld_library_path "$always_ld_library_path"
62 }
63 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
64 set_ld_library_path_env_vars
65
66 set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
67 if { [file exists $flags_file] } {
68 set libstdcxx_includes [exec sh $flags_file --build-includes]
69 } else {
70 set libstdcxx_includes ""
71 }
72
73 # Test OpenACC with available accelerators.
74 foreach offload_target_openacc $offload_targets_s_openacc {
75 set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
76
77 switch $offload_target_openacc {
78 host {
79 set acc_mem_shared 1
80 }
81 nvidia {
82 if { ![check_effective_target_openacc_nvidia_accel_present] } {
83 # Don't bother; execution testing is going to FAIL.
84 untested "$subdir $offload_target_openacc offloading"
85 continue
86 }
87
88 # Copy ptx file (TEMPORARY)
89 remote_download host $srcdir/libgomp.oacc-c-c++-common/subr.ptx
90
91 # Where timer.h lives
92 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common"
93
94 set acc_mem_shared 0
95 }
96 default {
97 set acc_mem_shared 0
98 }
99 }
100 set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
101
102 setenv ACC_DEVICE_TYPE $offload_target_openacc
103
104 # To get better test coverage for device-specific code that is only
105 # ever used in offloading configurations, we'd like more thorough
106 # testing for test cases that deal with offloading, which most of all
107 # OpenACC test cases are. We enable torture testing, but limit it to
108 # -O0 and -O2 only, to avoid testing times exploding too much, under
109 # the assumption that between -O0 and -O[something] there is the
110 # biggest difference in the overall structure of the generated code.
111 switch $offload_target_openacc {
112 host {
113 set-torture-options [list \
114 { -O2 } ]
115 }
116 default {
117 set-torture-options [list \
118 { -O0 } \
119 { -O2 } ]
120 }
121 }
122
123 gcc-dg-runtest $tests "$tagopt" "$libstdcxx_includes"
124 }
125 } else {
126 # Call this once, which placates the subsequent torture-finish.
127 set-torture-options [list \
128 { INVALID } ]
129 }
130
131 # See above.
132 set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST"
133
134 # All done.
135 torture-finish
136 dg-finish