Skip to contentSkip to conversation

block/044: basic block error injection sanity test

PATCH In review Christoph Hellwig 2 participants 2 messages Jun 30 – Jul 6 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 block/044: basic block error injection sanity test

Test the basic block layer error injection functionality.

---

Changes since v1:
- change license to GPLv2 or later
- incorporate various improvements from Shin'ichiro

 tests/block/044     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 tests/block/044.out |  9 +++++++
 2 files changed, 71 insertions(+)
 create mode 100755 tests/block/044
 create mode 100644 tests/block/044.out
tests/block/044 new file +62 -0
new file mode 100755
index 000000000000..097dd79d3bda
@@ -0,0 +1,62 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2026 Christoph Hellwig.
+#
+# Basic block error injection test.
+
+. tests/block/rc
+. common/scsi_debug
+
+DESCRIPTION="basic block error injection test"
+QUICK=1
+
+requires()
+{
+	_have_kernel_option BLK_ERROR_INJECTION
+	_have_loadable_scsi_debug
+	_have_program xfs_io
+}
+
+# load and remove scsi_debug once to test the static_key bug in the
+# initial commit
+_test_load_unload()
+{
+	if ! _init_scsi_debug dev_size_mb=500; then
+		return 1
+	fi
+	echo "Testing unload without rules"
+	_exit_scsi_debug
+}
+
+_test_rules()
+{
+	if ! _init_scsi_debug dev_size_mb=500; then
+		return 1
+	fi
+
+	local dev=${SCSI_DEBUG_DEVICES[0]}
+	local debugfs_file="/sys/kernel/debug/block/$dev/error_injection"
+
+	echo "Testing valid rules"
+	echo "add,op=WRITE,status=RESOURCE,start=0,nr_sectors=8" > "$debugfs_file"
+	echo "add,op=READ,status=IOERR,start=16,nr_sectors=8" > "$debugfs_file"
+	xfs_io -d -c 'pwrite -q 0 4096' /dev/"$dev"
+	xfs_io -d -c 'pread -q 0 4096' /dev/"$dev"
+	xfs_io -d -c 'pwrite -q 4096 4096' /dev/"$dev"
+	xfs_io -d -c 'pread -q 8192 8192' /dev/"$dev"
+
+	echo "Testing invalid rules"
+	echo "op=READ,status=IOERR" > "$debugfs_file"
+	echo "add,op=READ,status=EIO,start=32" > "$debugfs_file"
+	_exit_scsi_debug
+}
+
+test()
+{
+	echo "Running ${TEST_NAME}"
+
+	_test_load_unload
+	_test_rules
+
+	echo "Test complete"
+}
tests/block/044.out new file +9 -0
new file mode 100644
index 000000000000..92efcddf7c8e
@@ -0,0 +1,9 @@
+Running block/044
+Testing unload without rules
+Testing valid rules
+pwrite: Cannot allocate memory
+pread: Input/output error
+Testing invalid rules
+tests/block/044: line 56: echo: write error: Invalid argument
+tests/block/044: line 57: echo: write error: Invalid argument
+Test complete
Signature · 1 line
2.53.0