1 # Copyright 2010-2013 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 Ken Werner <ken.werner@de.ibm.com>.
18 # Support library for testing OpenCL GDB features
20 # Compile OpenCL programs using a generic host app.
21 proc gdb_compile_opencl_hostapp {clsource executable options} {
22 global srcdir objdir subdir
23 set src "${srcdir}/lib/cl_util.c ${srcdir}/lib/opencl_hostapp.c"
24 set binfile ${objdir}/${subdir}/${executable}
25 set compile_flags [concat additional_flags=-I${srcdir}/lib/ additional_flags=-DCL_SOURCE=$clsource]
26 set options_opencl [concat {debug} $compile_flags $options [list libs=-lOpenCL]]
27 return [gdb_compile ${src} ${binfile} "executable" ${options_opencl}]
30 # Run a test on the target to check if it supports OpenCL. Return 0 if so, 1 if
32 proc skip_opencl_tests {} {
33 global skip_opencl_tests_saved srcdir objdir subdir gdb_prompt
34 global inferior_exited_re
36 # Use the cached value, if it exists. Cache value per "board" to handle
37 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
38 set me "skip_opencl_tests"
39 set board [target_info name]
40 if [info exists skip_opencl_tests_saved($board)] {
41 verbose "$me: returning saved $skip_opencl_tests_saved($board)" 2
42 return $skip_opencl_tests_saved($board)
45 # Set up, compile, and execute an OpenCL program. Include the current
46 # process ID in the file name of the executable to prevent conflicts with
47 # invocations for multiple testsuites.
48 set clprogram [remote_download target ${srcdir}/lib/opencl_kernel.cl]
49 set executable opencltest[pid].x
51 verbose "$me: compiling OpenCL test app" 2
52 set compile_flags {debug nowarnings quiet}
54 if { [gdb_compile_opencl_hostapp "${clprogram}" "${executable}" "${compile_flags}" ] != "" } {
55 verbose "$me: compiling OpenCL binary failed, returning 1" 2
56 return [set skip_opencl_tests_saved($board) 1]
59 # Compilation succeeded so now run it via gdb.
60 clean_restart "$executable"
63 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
64 verbose -log "\n$me: OpenCL support detected"
65 set skip_opencl_tests_saved($board) 0
67 -re ".*$inferior_exited_re code.*${gdb_prompt} $" {
68 verbose -log "\n$me: OpenCL support not detected"
69 set skip_opencl_tests_saved($board) 1
72 verbose -log "\n$me OpenCL support not detected (default case)"
73 set skip_opencl_tests_saved($board) 1
77 remote_file build delete $executable
79 # Delete the OpenCL program source file.
80 remote_file target delete ${clprogram}
82 verbose "$me: returning $skip_opencl_tests_saved($board)" 2
83 return $skip_opencl_tests_saved($board)