-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathstress-test.sh
More file actions
executable file
·342 lines (299 loc) · 11.2 KB
/
stress-test.sh
File metadata and controls
executable file
·342 lines (299 loc) · 11.2 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/bash
# ##################################################################################################
# The MIT License (MIT)
# Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ##################################################################################################
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
EXAMPLES_DIR="$REPO_ROOT/examples"
# Examples: directory:vbin_prefix:executable
EXAMPLES=(
"00_axilite:axilite:00_axilite"
"01_aximm:aximm:01_aximm"
"02_chain:chain:02_chain"
"04_freq:freq:04_freq"
)
NUM_EXAMPLES=${#EXAMPLES[@]}
# Action names for reporting
ACTION_NAMES=("run_example" "reset" "program" "validate")
NUM_ACTIONS=${#ACTION_NAMES[@]}
# Counters
declare -A ACTION_PASS
declare -A ACTION_FAIL
for name in "${ACTION_NAMES[@]}"; do
ACTION_PASS[$name]=0
ACTION_FAIL[$name]=0
done
ACCURACY_FAIL=0
ITERATIONS_DONE=0
START_TIME=$(date +%s)
# =========================================================================
# Usage
# =========================================================================
usage() {
echo "Usage: $0 <BDF> [--iterations N]"
echo ""
echo " Stress test a V80 board by randomly running examples, resets,"
echo " programming vbins, and memory validation."
echo ""
echo " Arguments:"
echo " BDF Device BDF address (e.g. 0000:e2:00.0)"
echo " --iterations N Number of iterations (default: 100)"
echo ""
echo " Pre-built vbins and executables must exist in examples/*/build/."
exit 1
}
# =========================================================================
# Summary
# =========================================================================
print_summary() {
local end_time
end_time=$(date +%s)
local elapsed=$((end_time - START_TIME))
echo ""
echo "========================================================================"
echo " Stress Test Summary"
echo "========================================================================"
echo " Iterations completed: $ITERATIONS_DONE"
echo " Elapsed time: ${elapsed}s"
echo " Accuracy failures: $ACCURACY_FAIL"
echo "------------------------------------------------------------------------"
printf " %-15s %6s %6s\n" "Action" "Pass" "Fail"
echo "------------------------------------------------------------------------"
for name in "${ACTION_NAMES[@]}"; do
printf " %-15s %6d %6d\n" "$name" "${ACTION_PASS[$name]}" "${ACTION_FAIL[$name]}"
done
echo "========================================================================"
}
# =========================================================================
# Helpers
# =========================================================================
timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}
log() {
echo "[$(timestamp)] $*"
}
# Derive bdf_base from BDF by stripping the PCI function suffix (e.g. 0000:1b:00.0 -> 0000:1b:00)
bdf_to_base() {
echo "${1%.*}"
}
check_device() {
log "v80-smi list -j"
local json
json=$(v80-smi list -j)
echo "$json"
local bdf_base
bdf_base=$(bdf_to_base "$BDF")
local board_status
board_status=$(echo "$json" | jq -r --arg b "$bdf_base" '.boards[] | select(.bdf_base == $b) | .status')
if [[ -z "$board_status" ]]; then
log "ERROR: Board $bdf_base not found in v80-smi list output"
return 1
fi
if [[ "$board_status" != "OK" ]]; then
log "ERROR: Board $bdf_base status is '$board_status' (expected 'OK')"
return 1
fi
log "Board $bdf_base status: OK"
}
random_delay() {
local delay=$((RANDOM % 11))
if [[ $delay -gt 0 ]]; then
log "Sleeping ${delay}s..."
sleep "$delay"
fi
}
pick_random_example() {
local idx=$((RANDOM % NUM_EXAMPLES))
echo "${EXAMPLES[$idx]}"
}
# =========================================================================
# Parse arguments
# =========================================================================
if [[ $# -lt 1 ]]; then
usage
fi
BDF="$1"
shift
ITERATIONS=100
NO_RESET=0
while [[ $# -gt 0 ]]; do
case "$1" in
--iterations)
if [[ $# -lt 2 ]]; then
echo "ERROR: --iterations requires a value"
usage
fi
ITERATIONS="$2"
shift 2
;;
--no-reset)
NO_RESET=1
shift
;;
*)
echo "ERROR: Unknown argument '$1'"
usage
;;
esac
done
if [[ "$NO_RESET" -eq 1 ]]; then
ACTION_NAMES=("run_example" "program" "validate")
NUM_ACTIONS=${#ACTION_NAMES[@]}
fi
# =========================================================================
# Pre-flight checks
# =========================================================================
log "Starting stress test: BDF=$BDF, iterations=$ITERATIONS"
echo ""
log "Checking device visibility..."
if ! check_device; then
echo "ERROR: Device check failed. Is the device present and vrtd running?"
exit 1
fi
echo ""
MISSING=0
for entry in "${EXAMPLES[@]}"; do
IFS=':' read -r dir vbin_prefix executable <<< "$entry"
vbin_file="$EXAMPLES_DIR/$dir/build/${vbin_prefix}_hw.vbin"
exec_file="$EXAMPLES_DIR/$dir/build/$executable"
if [[ ! -f "$vbin_file" ]]; then
echo "ERROR: Missing vbin: $vbin_file"
MISSING=1
fi
if [[ ! -f "$exec_file" ]]; then
echo "ERROR: Missing executable: $exec_file"
MISSING=1
fi
done
if [[ $MISSING -ne 0 ]]; then
echo ""
echo "Pre-built vbins and executables are required. Build them first:"
echo " ./scripts/test-examples.sh hw $BDF"
exit 1
fi
log "All pre-flight checks passed."
echo ""
# =========================================================================
# Signal handler
# =========================================================================
trap 'log "Interrupted."; print_summary; exit 130' INT TERM
# =========================================================================
# Main loop
# =========================================================================
for ((i = 1; i <= ITERATIONS; i++)); do
action_idx=$((RANDOM % NUM_ACTIONS))
action="${ACTION_NAMES[$action_idx]}"
echo ""
echo "========================================================================"
log "Iteration $i/$ITERATIONS — action: $action"
echo "========================================================================"
case "$action" in
run_example)
IFS=':' read -r dir vbin_prefix executable <<< "$(pick_random_example)"
vbin_file="$EXAMPLES_DIR/$dir/build/${vbin_prefix}_hw.vbin"
exec_file="$EXAMPLES_DIR/$dir/build/$executable"
log "Running: $exec_file $BDF $vbin_file"
rc=0
"$exec_file" "$BDF" "$vbin_file" || rc=$?
if [[ $rc -eq 2 ]]; then
log "ACCURACY FAILURE: $action ($dir) at iteration $i (continuing)"
ACCURACY_FAIL=$((ACCURACY_FAIL + 1))
elif [[ $rc -ne 0 ]]; then
log "FAILED: $action ($dir) at iteration $i"
ACTION_FAIL[$action]=$((ACTION_FAIL[$action] + 1))
ITERATIONS_DONE=$i
print_summary
exit 1
fi
ACTION_PASS[$action]=$((ACTION_PASS[$action] + 1))
if ! check_device; then
log "FAILED: device check after $action ($dir) at iteration $i"
ITERATIONS_DONE=$i
print_summary
exit 1
fi
;;
reset)
log "Running: v80-smi reset -d $BDF"
if ! v80-smi reset -d "$BDF"; then
log "FAILED: $action at iteration $i"
ACTION_FAIL[$action]=$((ACTION_FAIL[$action] + 1))
ITERATIONS_DONE=$i
print_summary
exit 1
fi
ACTION_PASS[$action]=$((ACTION_PASS[$action] + 1))
if ! check_device; then
log "FAILED: device check after $action at iteration $i"
ITERATIONS_DONE=$i
print_summary
exit 1
fi
;;
program)
IFS=':' read -r dir vbin_prefix executable <<< "$(pick_random_example)"
vbin_file="$EXAMPLES_DIR/$dir/build/${vbin_prefix}_hw.vbin"
log "Running: v80-smi program -d $BDF $vbin_file"
if ! v80-smi program -d "$BDF" "$vbin_file"; then
log "FAILED: $action ($dir) at iteration $i"
ACTION_FAIL[$action]=$((ACTION_FAIL[$action] + 1))
ITERATIONS_DONE=$i
print_summary
exit 1
fi
ACTION_PASS[$action]=$((ACTION_PASS[$action] + 1))
if ! check_device; then
log "FAILED: device check after $action ($dir) at iteration $i"
ITERATIONS_DONE=$i
print_summary
exit 1
fi
# TODO: Add "v80-smi query -d $BDF -j" here once the query bug is fixed
;;
validate)
threads=$((RANDOM % 64 + 1))
NO_RESET_FLAG=""
if [[ "$NO_RESET" -eq 1 ]]; then NO_RESET_FLAG="--no-reset"; fi
log "Running: v80-smi validate -d $BDF -j $threads $NO_RESET_FLAG"
if ! v80-smi validate -d "$BDF" -j "$threads" $NO_RESET_FLAG; then
log "FAILED: $action (threads=$threads) at iteration $i"
ACTION_FAIL[$action]=$((ACTION_FAIL[$action] + 1))
ITERATIONS_DONE=$i
print_summary
exit 1
fi
ACTION_PASS[$action]=$((ACTION_PASS[$action] + 1))
if ! check_device; then
log "FAILED: device check after $action (threads=$threads) at iteration $i"
ITERATIONS_DONE=$i
print_summary
exit 1
fi
;;
esac
ITERATIONS_DONE=$i
random_delay
done
# =========================================================================
# Final summary
# =========================================================================
log "Stress test completed successfully."
print_summary