-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathruntime-core.exp
More file actions
168 lines (143 loc) · 5.25 KB
/
Copy pathruntime-core.exp
File metadata and controls
168 lines (143 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Copyright (C) 2023-2026 Free Software Foundation, Inc.
# Copyright (C) 2023-2026 Advanced Micro Devices, Inc. All rights reserved.
# This file is part of GDB.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This test exercises the case where a HIP application generates a fault
# on the GPU (pagefault, abort, or assert (false)) which triggers the
# runtime to generate a core dump. The test will find the host and GPU
# core dumps, create a unified core using coremerge and open it in GDB.
load_lib rocm.exp
require allow_rocm_core_tests
require allow_hipcc_tests
standard_testfile .cpp
if { [build_executable "failed to prepare" ${testfile} ${srcfile} \
{debug hip}] } {
return -1
}
# The "do_test" function is called multiple times, and any may exit early if
# it turns out the current configuration does not allow the creation of core
# dumps. However, if at least one core dump can be produced, all must be.
# Keep track of the number of attempts and their status to enforce this
# property.
set total_count 0
set untested_count 0
set success_count 0
# do_test FAULT CORE_TYPE OUTPUT_TYPE
# Run the test exercising generation of a core dump on fault FAULT
# using a file or a pipe.
#
# FAULT is one of "page", "abort", or "assert", and selects which
# fault the application should generate.
#
# CORE_TYPE is one of "full" or "lightweight".
#
# OUTPUT_TYPE is one of "file" of "pipe".
#
proc do_test { fault core_type output_type } {
incr ::total_count
set use_pipe [expr {$output_type eq "pipe"}]
save_vars { ::env(HSA_ENABLE_LIGHTWEIGHT_COREDUMP) } {
set ::env(HSA_ENABLE_LIGHTWEIGHT_COREDUMP) [expr {$core_type == "lightweight"}]
set coredump [rocm_core_find $::binfile {} $fault $use_pipe]
}
if {$coredump eq ""} {
untested "Could not generate a core file"
incr ::untested_count
return
}
check_sparse $coredump "core is sparse"
set corename "${coredump}-${fault}-${core_type}-${output_type}"
remote_exec build "mv $coredump $corename"
if {$fault == "pagefault"} {
set gpusig "SIGSEGV"
set fault_loc "pagefault_kernel"
} elseif {$fault == "abort"} {
set gpusig "SIGABRT"
set fault_loc "abort"
} elseif {$fault == "assert"} {
set gpusig "SIGABRT"
set fault_loc "__assert_fail"
}
clean_restart
gdb_load $::binfile
gdb_test "core-file $corename" \
[multi_line \
".*" \
"Core was generated by .*" \
"Program terminated with signal SIGABRT.*" \
"Thread $::decimal \\(AMDGPU Wave \[^\r\n\]*\\) stopped because of $gpusig.*"] \
"load corefile"
set faulty_wave 0
set aux_wave 0
gdb_test_multiple "info thread" "identify waves" -lbl {
-re "($::decimal) *AMDGPU Wave \[^\r\n\]*$fault_loc \[^\\n\]*" {
set faulty_wave $expect_out(1,string)
exp_continue
}
-re "($::decimal) *AMDGPU Wave \[^\r\n\]* aux_kernel \[^\\n\]*" {
set aux_wave $expect_out(1,string)
exp_continue
}
-re "$::gdb_prompt $" {
gdb_assert {($faulty_wave != 0) && ($aux_wave != 0)} $gdb_test_name
}
}
# Check that we can access various variables from the scope of the faulty
# thread.
with_test_prefix "faulty_wave" {
gdb_test \
"thread $faulty_wave" \
"Switching to thread $faulty_wave.*" \
"select faulty wave"
# The fault might be reported in a child function. Make sure to unwind
# the frame to the top-level frame.
gdb_test "frame function ${fault}_kernel" ".* ${fault}_kernel \\(.*"
gdb_test "p local" "= 42"
if {$fault == "pagefault"} {
gdb_test "p out == 0" " = true"
}
gdb_test "p some_global" " = 16"
gdb_test "p data" " = \\(int \\*\\) $::hex"
if {$core_type == "lightweight"} {
gdb_test "p data\[12\]" " = <unavailable>"
} else {
gdb_test "p data\[12\]" " = 12"
}
}
# Similarly, make sure we can access data from threads which did not cause
# any error.
with_test_prefix "regular_wave" {
gdb_test "thread $aux_wave" \
"Switching to thread $aux_wave.*" \
"select regular wave"
gdb_test "p local" " = 72"
gdb_test "p some_global" " = 16"
}
gdb_exit
incr ::success_count
}
with_rocm_gpu_lock {
# Check the runtime can configure the core dump generation based
# on env variables.
foreach_with_prefix output_type { file pipe } {
foreach_with_prefix core_type {full lightweight} {
do_test pagefault $core_type $output_type
}
}
# Check that various GPU events can cause a core dump.
# "pagefault" was covered by previous cases already.
foreach_with_prefix fault {abort assert} {
do_test $fault lightweight file
}
}
gdb_assert {$::total_count == ($::untested_count + $::success_count)} "all tests accounted for"
gdb_assert {$::untested_count == 0 || $::success_count == 0} "coredump consistently produced"