]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/lib/opencl.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / opencl.exp
1 # Copyright 2010-2013 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.
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}]
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.
32 proc skip_opencl_tests {} {
33 global skip_opencl_tests_saved srcdir objdir subdir gdb_prompt
34 global inferior_exited_re
35
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)
43 }
44
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
50
51 verbose "$me: compiling OpenCL test app" 2
52 set compile_flags {debug nowarnings quiet}
53
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]
57 }
58
59 # Compilation succeeded so now run it via gdb.
60 clean_restart "$executable"
61 gdb_run_cmd
62 gdb_expect 30 {
63 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
64 verbose -log "\n$me: OpenCL support detected"
65 set skip_opencl_tests_saved($board) 0
66 }
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
70 }
71 default {
72 verbose -log "\n$me OpenCL support not detected (default case)"
73 set skip_opencl_tests_saved($board) 1
74 }
75 }
76 gdb_exit
77 remote_file build delete $executable
78
79 # Delete the OpenCL program source file.
80 remote_file target delete ${clprogram}
81
82 verbose "$me: returning $skip_opencl_tests_saved($board)" 2
83 return $skip_opencl_tests_saved($board)
84 }