Skip to content

Commit 0ca7b32

Browse files
committed
common/rc: Introduce _get_kernel_option()
Move the code for parsing the kernel configuration file from tests/scsi/007 into common/rc. No functionality has been changed. Signed-off-by: Bart Van Assche <[email protected]>
1 parent 261a2b3 commit 0ca7b32

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

common/rc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,33 @@ _have_kernel_config_file() {
198198
return 0
199199
}
200200

201-
# Check if the specified kernel option is defined.
202-
_check_kernel_option() {
203-
local f opt=$1
201+
# Retrieve the value of kernel option $1.
202+
_get_kernel_option() {
203+
local f opt=$1 result
204204

205205
for f in /proc/config.gz /boot/config-$(uname -r); do
206206
[ -e "$f" ] || continue
207-
if zgrep -q "^CONFIG_${opt}=[my]$" "$f"; then
207+
if result=$(zgrep "^CONFIG_${opt}=" "$f"); then
208+
echo "${result#*=}"
208209
return 0
209210
fi
210211
done
211212

212213
return 1
213214
}
214215

216+
# Check if kernel option $1 is defined.
217+
_check_kernel_option() {
218+
local value
219+
220+
case "$(_get_kernel_option "$1")" in
221+
y|m)
222+
return 0;;
223+
esac
224+
225+
return 1
226+
}
227+
215228
# Combine _have_kernel_config_file() and _check_kernel_option().
216229
# Set SKIP_REASONS when _check_kernel_option() returns false.
217230
_have_kernel_option() {

tests/scsi/007

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ 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'
24-
}
25-
2618
test() {
2719
local dev freq delay_s jdelay
2820

@@ -42,7 +34,7 @@ test() {
4234
echo "I/O timeout = $(<"/sys/class/block/$dev/queue/io_timeout")" >>"$FULL"
4335
# Change the scsi_debug delay to 3 seconds.
4436
delay_s=3
45-
freq=$(config_hz)
37+
freq=$(_get_kernel_option HZ)
4638
jdelay=$((delay_s * "${freq}"))
4739
echo "CONFIG_HZ=${freq} jdelay=${jdelay}" >>"$FULL"
4840
echo "$jdelay" > /sys/module/scsi_debug/parameters/delay

0 commit comments

Comments
 (0)