1# This whole file adapted from libgomp.c++/c++.exp.
2
3load_lib libgomp-dg.exp
4load_gcc_lib gcc-dg.exp
5load_gcc_lib torture-options.exp
6
7proc check_effective_target_c { } {
8    return 0
9}
10proc check_effective_target_c++ { } {
11    return 1
12}
13
14global shlib_ext
15
16set shlib_ext [get_shlib_extension]
17set lang_link_flags "-lstdc++"
18set lang_test_file_found 0
19set lang_library_path "../libstdc++-v3/src/.libs"
20if [info exists lang_include_flags] then {
21    unset lang_include_flags
22}
23
24# Initialize dg.
25dg-init
26torture-init
27
28# Turn on OpenACC.
29lappend 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.
33set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
34set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
35
36set blddir [lookfor_file [get_multilibs] libgomp]
37
38
39if { $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
59if { $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 OpenACC with available accelerators.
81    foreach offload_target_openacc $offload_targets_s_openacc {
82	set tagopt "-DACC_DEVICE_TYPE_$offload_target_openacc=1"
83
84	switch $offload_target_openacc {
85	    host {
86		set acc_mem_shared 1
87	    }
88	    nvidia {
89		if { ![check_effective_target_openacc_nvidia_accel_present] } {
90		    # Don't bother; execution testing is going to FAIL.
91		    untested "$subdir $offload_target_openacc offloading"
92		    continue
93		}
94
95		# Copy ptx file (TEMPORARY)
96		remote_download host $srcdir/libgomp.oacc-c-c++-common/subr.ptx
97
98		# Where timer.h lives
99		lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/libgomp.oacc-c-c++-common"
100
101		set acc_mem_shared 0
102	    }
103	    default {
104		set acc_mem_shared 0
105	    }
106	}
107	set tagopt "$tagopt -DACC_MEM_SHARED=$acc_mem_shared"
108
109	setenv ACC_DEVICE_TYPE $offload_target_openacc
110
111	# To get better test coverage for device-specific code that is only
112	# ever used in offloading configurations, we'd like more thorough
113	# testing for test cases that deal with offloading, which most of all
114	# OpenACC test cases are.  We enable torture testing, but limit it to
115	# -O0 and -O2 only, to avoid testing times exploding too much, under
116	# the assumption that between -O0 and -O[something] there is the
117	# biggest difference in the overall structure of the generated code.
118	switch $offload_target_openacc {
119	    host {
120		set-torture-options [list \
121					 { -O2 } ]
122	    }
123	    default {
124		set-torture-options [list \
125					 { -O0 } \
126					 { -O2 } ]
127	    }
128	}
129
130	gcc-dg-runtest $tests "$tagopt" "$libstdcxx_includes"
131    }
132} else {
133    # Call this once, which placates the subsequent torture-finish.
134    set-torture-options [list \
135			     { INVALID } ]
136}
137
138# See above.
139set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST"
140
141# All done.
142torture-finish
143dg-finish
144