[PATCH blktests 2/3] Add I/O scheduler tests for queue depth 1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some block devices, e.g. USB sticks, only support queue depth 1. The
QD=1 code paths do not get tested routinely. Hence add tests for the
QD=1 use case.

Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
 common/rc           |  5 ++++
 tests/block/032     | 62 ++++++++++++++++++++++++++++++++++++++++++++
 tests/block/032.out |  2 ++
 tests/scsi/008      | 63 +++++++++++++++++++++++++++++++++++++++++++++
 tests/scsi/008.out  |  2 ++
 5 files changed, 134 insertions(+)
 create mode 100755 tests/block/032
 create mode 100644 tests/block/032.out
 create mode 100755 tests/scsi/008
 create mode 100644 tests/scsi/008.out

diff --git a/common/rc b/common/rc
index 0528ce808256..2377e223aea7 100644
--- a/common/rc
+++ b/common/rc
@@ -321,6 +321,11 @@ _uptime_s() {
 	awk '{ print int($1) }' /proc/uptime
 }
 
+# System uptime in centiseconds.
+_uptime_cs() {
+	sed 's/\.//;s/ .*//' /proc/uptime
+}
+
 # Arguments: module to unload ($1) and retry count ($2).
 unload_module() {
 	local i m=$1 rc=${2:-1}
diff --git a/tests/block/032 b/tests/block/032
new file mode 100755
index 000000000000..8b4d30282988
--- /dev/null
+++ b/tests/block/032
@@ -0,0 +1,62 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Google LLC
+
+. tests/block/rc
+. common/null_blk
+. common/iosched
+
+DESCRIPTION="test I/O scheduler performance of null_blk with queue_depth 1"
+QUICK=1
+
+requires() {
+	_have_null_blk
+}
+
+# Measure the time required to perform I/O on dev $1 with I/O scheduler $2.
+sched_time() {
+	local dev=$1 sched=$2
+	echo "$sched" > "/sys/block/$dev/queue/scheduler"
+	local start
+	start=$(_uptime_cs)
+	dd if="/dev/$dev" of=/dev/null bs=4K count=$((512 * 1024)) \
+	   iflag=direct status=none &
+	dd of="/dev/$dev" if=/dev/zero bs=4K count=$((512 * 1024)) \
+	   oflag=direct status=none &
+	wait
+	echo $(($(_uptime_cs) - start))
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local params=(
+		hw_queue_depth=1
+		queue_mode=2
+	)
+	_init_null_blk "${params[@]}" || return 1
+
+	local dev=nullb0 fail status
+
+	none_time_cs=$(sched_time "$dev" none)
+	for sched in $(io_schedulers "$dev"); do
+		[ "$sched" = none ] && continue
+		time_cs=$(sched_time "$dev" "$sched")
+		if [ "$time_cs" -lt $(("$none_time_cs" * 110 / 100)) ]; then
+			status=pass
+		else
+			status=fail
+			fail=true
+		fi
+		TEST_RUN[$sched]="$time_cs vs $none_time_cs: $status"
+	done
+
+	_exit_null_blk
+
+	if [ -z "$fail" ]; then
+		echo "Test complete"
+	else
+		echo "Test failed"
+		return 1
+	fi
+}
diff --git a/tests/block/032.out b/tests/block/032.out
new file mode 100644
index 000000000000..3604e9e1e751
--- /dev/null
+++ b/tests/block/032.out
@@ -0,0 +1,2 @@
+Running block/032
+Test complete
diff --git a/tests/scsi/008 b/tests/scsi/008
new file mode 100755
index 000000000000..dec304fd29a2
--- /dev/null
+++ b/tests/scsi/008
@@ -0,0 +1,63 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Google LLC
+
+. tests/scsi/rc
+. common/iosched
+. common/scsi_debug
+
+DESCRIPTION="test I/O scheduler performance of scsi_debug with queue_depth 1"
+QUICK=1
+
+requires() {
+	_have_scsi_debug
+}
+
+# Measure the time required to perform I/O on dev $1 with I/O scheduler $2.
+sched_time() {
+	local dev=$1 sched=$2
+	echo "$sched" > "/sys/block/$dev/queue/scheduler"
+	local start
+	start=$(_uptime_cs)
+	dd if="/dev/$dev" of=/dev/null bs=4K count=$((512 * 1024)) \
+	   iflag=direct status=none &
+	dd of="/dev/$dev" if=/dev/zero bs=4K count=$((512 * 1024)) \
+	   oflag=direct status=none &
+	wait
+	echo $(($(_uptime_cs) - start))
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local params=(
+		delay=0
+		dev_size_mb=2048
+		host_max_queue=1
+	)
+	_init_scsi_debug "${params[@]}" || return 1
+
+	local dev="${SCSI_DEBUG_DEVICES[0]}" fail
+
+	none_time_cs=$(sched_time "$dev" none)
+	for sched in $(io_schedulers "$dev"); do
+		[ "$sched" = none ] && continue
+		time_cs=$(sched_time "$dev" "$sched")
+		if [ "$time_cs" -lt $(("$none_time_cs" * 110 / 100)) ]; then
+			status=pass
+		else
+			status=fail
+			fail=true
+		fi
+		TEST_RUN[$sched]="$time_cs vs $none_time_cs: $status"
+	done
+
+	_exit_scsi_debug
+
+	if [ -z "$fail" ]; then
+		echo "Test complete"
+	else
+		echo "Test failed"
+		return 1
+	fi
+}
diff --git a/tests/scsi/008.out b/tests/scsi/008.out
new file mode 100644
index 000000000000..135bd5ae4b2d
--- /dev/null
+++ b/tests/scsi/008.out
@@ -0,0 +1,2 @@
+Running scsi/008
+Test complete



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux