1 # Copyright 2011-2023 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 # Contributed by Ulrich Weigand <ulrich.weigand@de.ibm.com>.
18 # Tests OpenCL function calling conventions.
22 if { [skip_opencl_tests] } {
23 unsupported "OpenCL support not detected"
27 set testfile "callfuncs"
28 set clprogram [remote_download target ${srcdir}/${subdir}/${testfile}.cl]
30 # Compile the generic OpenCL host app
31 if { [gdb_compile_opencl_hostapp "${clprogram}" "${testfile}" "" ] != "" } {
32 untested "failed to compile"
40 gdb_reinitialize_dir $srcdir/$subdir
41 gdb_load ${objdir}/${subdir}/${testfile}
43 # Set breakpoint at the OpenCL kernel
44 gdb_test "tbreak testkernel" \
46 "Set pending breakpoint" \
47 ".*Function \"testkernel\" not defined.*Make breakpoint pending.*y or \\\[n\\\]. $" \
51 gdb_test "" ".*reakpoint.*1.*testkernel.*" "run"
53 # Continue to the marker
54 gdb_breakpoint [gdb_get_line_number "marker" "${clprogram}"]
55 gdb_continue_to_breakpoint "marker"
57 # Check if the language was switched to opencl
58 gdb_test "show language" "The current source language is \"auto; currently opencl\"\."
60 # Prevent multi-threaded execution during inferior calls
61 gdb_test_no_output "set scheduler-locking on"
63 # Retrieve some information about the OpenCL version and the availability of extensions
64 set opencl_version [get_integer_valueof "opencl_version" 0]
65 set have_cl_khr_fp64 [get_integer_valueof "have_cl_khr_fp64" 0]
66 set have_cl_khr_fp16 [get_integer_valueof "have_cl_khr_fp16" 0]
68 # Check function call / return sequence
69 proc call_test { type var } {
72 gdb_test "print/d call_${type} (${var}, ${var})" " = 2"
73 gdb_test "print/d call_${type}2 (${var}2, ${var}2)" " = \\{2, 4\\}"
74 if { ${opencl_version} >= 110 } {
75 gdb_test "print/d call_${type}3 (${var}3, ${var}3)" " = \\{2, 4, 6\\}"
77 gdb_test "print/d call_${type}4 (${var}4, ${var}4)" " = \\{2, 4, 6, 8\\}"
78 gdb_test "print/d call_${type}8 (${var}8, ${var}8)" " = \\{2, 4, 6, 8, 10, 12, 14, 16\\}"
79 gdb_test "print/d call_${type}16 (${var}16, ${var}16)" " = \\{2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32\\}"
83 call_test "uchar" "uc"
85 call_test "ushort" "us"
89 call_test "ulong" "ul"
90 if { ${have_cl_khr_fp16} } {
94 if { ${have_cl_khr_fp64} } {
95 call_test "double" "d"
98 # Delete the OpenCL program source
99 remote_file target delete ${clprogram}