1 # Copyright (C) 2019-2020 Free Software Foundation, Inc.
2 # Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
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/>.
18 set testfile "bit_extract_compile"
19 set srcfile ${srcdir}/${subdir}/${testfile}.cpp
20 set objfile [standard_output_file ${testfile}.o]
21 set binfile [standard_output_file ${testfile}]
24 set wave_id {(0,0,0)/2}
25 set rocm_threadno {1.3}
28 # Check if skip hip tests
29 if [skip_hipcc_tests] {
30 verbose "Skipping hip test: ${testfile}."
34 # Compile the hip program
35 if {[prepare_for_testing "failed to prepare ${testfile}" $testfile $srcfile {debug hip}]} {
41 # Load the hip program
42 if {[gdb_load ${binfile}] == -1} {
43 verbose "failed to load program ${testfile}."
47 # Run to main and break
49 fail "can't run to main and break in program ${testfile}."
54 #break <device_function_name>
55 #break bit_extract_kernel
56 # Set breakpoing in device code
57 gdb_breakpoint "bit_extract_kernel" "allow-pending"
59 # Do continue to check the breakpoint is created at device
60 gdb_test "c" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
62 clean_restart ${binfile}
66 #tbreak <device_function_name>
67 #tbreak bit_extract_kernel
68 gdb_breakpoint "bit_extract_kernel" "allow-pending" "temporary"
69 gdb_test "run" {.+hit\sTemporary\sbreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
70 #controlling the timeout of the test as continue on device thread taking around 20-30s
72 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
74 clean_restart ${binfile}
77 #break <file>:<lineNO>
78 #e.g. break bit_extract_compile:35
79 gdb_test "break $srcfile:$breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
80 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
82 clean_restart ${binfile}
87 gdb_test "break $breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
88 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
90 clean_restart ${binfile}
92 #Code to fetch threadno and corresponding wave_id
93 #Set breakpoing in device code
94 gdb_breakpoint "bit_extract_kernel" "allow-pending"
95 gdb_test "run" {.+hit\sBreakpoint\s\d+.+\sbit_extract_kernel\s\(.*\)\sat.*}
96 send_gdb "info threads\n"
97 gdb_expect -re "\\s+(\\d+)\\s+ROCm Thread\\s+(\\d+\.\\d+)\\s+(\\(\\d+,\\d+,\\d+\\)/\\d+).*$gdb_prompt $" {
98 set threadid "$expect_out(1,string)"
99 set rocm_threadno "$expect_out(2,string)"
100 set wave_id "$expect_out(3,string)"
103 verbose $rocm_threadno
106 regsub -all {[]*+.|()^$\[\\]} $wave_id {\\&} wave_id_re
109 clean_restart ${binfile}
113 #break <file>:<lineNO> <device thread condition>
114 #e.g. break bit_extract_compile:35 if $_thread==<threadno>
115 gdb_test "break $srcfile:$breakpoint_loc if \$_thread==$threadid" "Breakpoint .* at .*${testfile}.*"
116 gdb_test "run" ".+Thread.+$threadid.+hit.+Breakpoint.+${testfile}.cpp:$breakpoint_loc.*"
117 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
120 clean_restart ${binfile}
122 #break <file>:<lineNO> <device thread condition>
123 #e.g. break bit_extract_compile:35 if $_streq($_wave_id,(0,0,1)/2)
124 gdb_test "break $srcfile:$breakpoint_loc if \$_streq(\$_wave_id,\"$wave_id\")" "Breakpoint .* at .*${testfile}.*"
125 gdb_test "run" ".+$wave_id_re.+Thread.+hit.+Breakpoint.+${testfile}.cpp:$breakpoint_loc.*"
126 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
130 clean_restart ${binfile}
133 #enable\disable the breakpoint in device thread
134 #break <device_function_name>
135 #break bit_extract_kernel
136 #run //to hit the breakpoint in device thread
137 #disable <breakpoint no>
138 #continue //to exit inferior normally
139 #run //to check that test running without hitting any breakpoint as it disabled
140 #enable <breakpoint no>
141 ##run //to hit the breakpoint in device thread after enabling the breakpoint
143 # Set breakpoing in device code
144 gdb_breakpoint "bit_extract_kernel" "allow-pending"
146 # Do continue to check the breakpoint is created at device
147 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
149 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
150 gdb_test "run" {.+Inferior\s[\d].+\sexited\snormally.+}
152 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
154 clean_restart ${binfile}
157 #clear the breakpoint in device thread
158 #break <file>:<lineNO>
159 #e.g. break bit_extract_compile:35
160 gdb_test "break $srcfile:$breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
161 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
162 gdb_test "continue" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
163 gdb_test "clear $breakpoint_loc"
164 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}