]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/lib/opencl.exp
gdb:
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / opencl.exp
CommitLineData
f4b8a18d
KW
1# Copyright 2010 Free Software Foundation, Inc.
2#
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.
7#
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.
12#
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/>.
15#
16# Contributed by Ken Werner <ken.werner@de.ibm.com>.
17#
18# Support library for testing OpenCL GDB features
19
20# Compile OpenCL programs using a generic host app.
21proc 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}]
28}
29
30# Run a test on the target to check if it supports OpenCL. Return 0 if so, 1 if
31# it does not.
32proc skip_opencl_tests {} {
33 global skip_opencl_tests_saved srcdir objdir subdir gdb_prompt
34
35 # Use the cached value, if it exists. Cache value per "board" to handle
36 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
37 set me "skip_opencl_tests"
38 set board [target_info name]
39 if [info exists skip_opencl_tests_saved($board)] {
40 verbose "$me: returning saved $skip_opencl_tests_saved($board)" 2
41 return $skip_opencl_tests_saved($board)
42 }
43
44 # Set up, compile, and execute an OpenCL program. Include the current
45 # process ID in the file name of the executable to prevent conflicts with
46 # invocations for multiple testsuites.
47 set clprogram [remote_download target ${srcdir}/lib/opencl_kernel.cl]
48 set executable opencltest[pid].x
49
50 verbose "$me: compiling OpenCL test app" 2
51 set compile_flags {debug nowarnings quiet}
52
53 if { [gdb_compile_opencl_hostapp "${clprogram}" "${executable}" "" ] != "" } {
54 verbose "$me: compiling OpenCL binary failed, returning 1" 2
55 return [set skip_opencl_tests_saved($board) 1]
56 }
57
58 # Compilation succeeded so now run it via gdb.
59 clean_restart "$executable"
60 gdb_run_cmd
61 gdb_expect 30 {
62 -re ".*Program exited normally.*${gdb_prompt} $" {
63 verbose -log "\n$me: OpenCL support detected"
64 set skip_opencl_tests_saved($board) 0
65 }
66 -re ".*Program exited with code.*${gdb_prompt} $" {
67 verbose -log "\n$me: OpenCL support not detected"
68 set skip_opencl_tests_saved($board) 1
69 }
70 default {
71 verbose -log "\n$me OpenCL support not detected (default case)"
72 set skip_opencl_tests_saved($board) 1
73 }
74 }
75 gdb_exit
76 remote_file build delete $executable
77
78 # Delete the OpenCL program source file.
79 remote_file target delete ${clprogram}
80
81 verbose "$me: returning $skip_opencl_tests_saved($board)" 2
82 return $skip_opencl_tests_saved($board)
83}