@@ -15,18 +15,45 @@ requires() {
1515 _have_module scsi_debug
1616}
1717
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'
18+ start_tracing () {
19+ if [ -e /sys/kernel/tracing/tracing_on ]; then
20+ (
21+ set -e
22+ cd /sys/kernel/tracing
23+ echo 1024 > buffer_size_kb
24+ echo function > current_tracer
25+ echo 0 > tracing_on
26+ echo > trace
27+ {
28+ echo scsi_error_handler
29+ echo " scsi_eh_*"
30+ echo scsi_timeout
31+ echo scsi_try_host_reset
32+ } > set_ftrace_filter
33+ echo 0 > events/enable
34+ echo 1 > tracing_on
35+ )
36+ fi
2437}
2538
26- test () {
27- local dev freq delay_s jdelay
39+ stop_tracing () {
40+ if [ -e /sys/kernel/tracing/tracing_on ]; then
41+ (
42+ set -e
43+ cd /sys/kernel/tracing
44+ cat trace >> " ${FULL} "
45+ if ! grep -qw scsi_timeout trace; then
46+ echo " Unexpected: scsi_timeout() has not been called"
47+ fi
48+ echo 0 > tracing_on
49+ )
50+ fi
51+ }
2852
29- echo " Running ${TEST_NAME} "
53+ run_test () {
54+ set -e
55+
56+ local dev freq delay_s jdelay
3057
3158 if ! _init_scsi_debug; then
3259 return 1
@@ -42,21 +69,43 @@ test() {
4269 echo " I/O timeout = $( < " /sys/class/block/$dev /queue/io_timeout" ) " >> " $FULL "
4370 # Change the scsi_debug delay to 3 seconds.
4471 delay_s=3
45- freq=$( config_hz )
72+ freq=$( _get_kernel_option HZ )
4673 jdelay=$(( delay_s * "${freq} "))
4774 echo " CONFIG_HZ=${freq} jdelay=${jdelay} " >> " $FULL "
4875 echo " $jdelay " > /sys/module/scsi_debug/parameters/delay
76+
77+ start_tracing
78+
79+ set +e
80+
4981 if dd if=" /dev/$dev " of=/dev/null bs=512 count=1 \
5082 iflag=direct >& /dev/null; then
5183 echo " Reading from scsi_debug succeeded"
5284 else
5385 echo " Reading from scsi_debug failed"
5486 fi
5587
88+ stop_tracing
89+
5690 # Disable SCSI error handler logging
5791 echo 0 > /sys/module/scsi_mod/parameters/scsi_logging_level
92+ }
93+
94+ test () {
95+ echo " Running ${TEST_NAME} "
96+
97+ (
98+ run_test
99+ )
100+ # shellcheck disable=SC2181
101+ (( $? != 0 )) && fail=true
58102
59103 _exit_scsi_debug
60104
61- echo " Test complete"
105+ if [ -z " $fail " ]; then
106+ echo " Test complete"
107+ else
108+ echo " Test failed"
109+ return 1
110+ fi
62111}
0 commit comments