Skip to content

Commit 449c039

Browse files
bvanasscheosandov
authored andcommitted
tests/scsi/007: Add a test that triggers the SCSI error handler
Since none of the existing tests guarantee that the SCSI error handler will be triggered, add a test that guarantees this. Signed-off-by: Bart Van Assche <[email protected]>
1 parent 547997e commit 449c039

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

tests/scsi/007

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-3.0+
3+
# Copyright 2021 Google LLC
4+
#
5+
# Trigger the SCSI error handler.
6+
7+
. tests/scsi/rc
8+
. common/scsi_debug
9+
10+
DESCRIPTION="Trigger the SCSI error handler"
11+
12+
QUICK=1
13+
14+
requires() {
15+
_have_scsi_debug
16+
}
17+
18+
config_hz() {
19+
if [ -e /proc/config.gz ]; then
20+
zcat /proc/config.gz
21+
else
22+
cat "/boot/config-$(uname -r)"
23+
fi | sed -n 's/^CONFIG_HZ=//p'
24+
}
25+
26+
test() {
27+
local dev freq delay_s jdelay
28+
29+
echo "Running ${TEST_NAME}"
30+
31+
if ! _init_scsi_debug; then
32+
return 1
33+
fi
34+
35+
# Enable SCSI error handler logging
36+
echo 63 > /sys/module/scsi_mod/parameters/scsi_logging_level
37+
38+
dev="${SCSI_DEBUG_DEVICES[0]}"
39+
# Change the block layer timeout to max(1 / CONFIG_HZ, 0.001)
40+
# seconds.
41+
echo 1 > "/sys/class/block/$dev/queue/io_timeout"
42+
echo "I/O timeout = $(<"/sys/class/block/$dev/queue/io_timeout")" >>"$FULL"
43+
# Change the scsi_debug delay to 3 seconds.
44+
delay_s=3
45+
freq=$(config_hz)
46+
jdelay=$((delay_s * "${freq}"))
47+
echo "CONFIG_HZ=${freq} jdelay=${jdelay}" >>"$FULL"
48+
echo "$jdelay" > /sys/module/scsi_debug/parameters/delay
49+
if dd if="/dev/$dev" of=/dev/null bs=512 count=1 \
50+
iflag=direct >&/dev/null; then
51+
echo "Reading from scsi_debug succeeded"
52+
else
53+
echo "Reading from scsi_debug failed"
54+
fi
55+
56+
# Disable SCSI error handler logging
57+
echo 0 > /sys/module/scsi_mod/parameters/scsi_logging_level
58+
59+
_exit_scsi_debug
60+
61+
echo "Test complete"
62+
}

tests/scsi/007.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Running scsi/007
2+
Reading from scsi_debug failed
3+
Test complete

0 commit comments

Comments
 (0)