]> www.infradead.org Git - users/hch/blktests.git/commitdiff
tests/scsi/007: Add a test that triggers the SCSI error handler
authorBart Van Assche <bvanassche@acm.org>
Mon, 4 Oct 2021 17:35:44 +0000 (10:35 -0700)
committerOmar Sandoval <osandov@osandov.com>
Mon, 22 Nov 2021 19:13:19 +0000 (11:13 -0800)
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 <bvanassche@acm.org>
tests/scsi/007 [new file with mode: 0755]
tests/scsi/007.out [new file with mode: 0644]

diff --git a/tests/scsi/007 b/tests/scsi/007
new file mode 100755 (executable)
index 0000000..002bf4a
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright 2021 Google LLC
+#
+# Trigger the SCSI error handler.
+
+. tests/scsi/rc
+. common/scsi_debug
+
+DESCRIPTION="Trigger the SCSI error handler"
+
+QUICK=1
+
+requires() {
+       _have_scsi_debug
+}
+
+config_hz() {
+       if [ -e /proc/config.gz ]; then
+               zcat /proc/config.gz
+       else
+               cat "/boot/config-$(uname -r)"
+       fi | sed -n 's/^CONFIG_HZ=//p'
+}
+
+test() {
+       local dev freq delay_s jdelay
+
+       echo "Running ${TEST_NAME}"
+
+       if ! _init_scsi_debug; then
+               return 1
+       fi
+
+       # Enable SCSI error handler logging
+       echo 63 > /sys/module/scsi_mod/parameters/scsi_logging_level
+
+       dev="${SCSI_DEBUG_DEVICES[0]}"
+       # Change the block layer timeout to max(1 / CONFIG_HZ, 0.001)
+       # seconds.
+       echo 1 > "/sys/class/block/$dev/queue/io_timeout"
+       echo "I/O timeout = $(<"/sys/class/block/$dev/queue/io_timeout")" >>"$FULL"
+        # Change the scsi_debug delay to 3 seconds.
+       delay_s=3
+        freq=$(config_hz)
+        jdelay=$((delay_s * "${freq}"))
+        echo "CONFIG_HZ=${freq} jdelay=${jdelay}" >>"$FULL"
+       echo "$jdelay" > /sys/module/scsi_debug/parameters/delay
+       if dd if="/dev/$dev" of=/dev/null bs=512 count=1 \
+             iflag=direct >&/dev/null; then
+               echo "Reading from scsi_debug succeeded"
+       else
+               echo "Reading from scsi_debug failed"
+       fi
+
+       # Disable SCSI error handler logging
+       echo 0 > /sys/module/scsi_mod/parameters/scsi_logging_level
+
+       _exit_scsi_debug
+
+       echo "Test complete"
+}
diff --git a/tests/scsi/007.out b/tests/scsi/007.out
new file mode 100644 (file)
index 0000000..716676a
--- /dev/null
@@ -0,0 +1,3 @@
+Running scsi/007
+Reading from scsi_debug failed
+Test complete