diff mbox series

[blktests,2/5] tests/throtl: add a new test 002

Message ID 20240416020042.509291-3-yukuai1@huaweicloud.com (mailing list archive)
State New
Headers show
Series add new tests for blk-throttle | expand

Commit Message

Yu Kuai April 16, 2024, 2 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

Test iops limit over IO split, regression tests for:

commit 9f5ede3c01f9 ("block: throttle split bio in case of iops limit")

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/002     | 81 ++++++++++++++++++++++++++++++++++++++++++++
 tests/throtl/002.out |  4 +++
 2 files changed, 85 insertions(+)
 create mode 100755 tests/throtl/002
 create mode 100644 tests/throtl/002.out
diff mbox series

Patch

diff --git a/tests/throtl/002 b/tests/throtl/002
new file mode 100755
index 0000000..e0df4b8
--- /dev/null
+++ b/tests/throtl/002
@@ -0,0 +1,81 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test iops limit work correctly for big IO of blk-throttle, regression test
+# for commit 9f5ede3c01f9 ("block: throttle split bio in case of iops limit")
+
+. tests/throtl/rc
+
+DESCRIPTION="iops limit over IO split"
+QUICK=1
+
+CG=/sys/fs/cgroup
+TEST_DIR=$CG/blktests_throtl
+devname=nullb0
+dev=""
+
+set_up_test() {
+	if ! _init_null_blk max_sectors=8; then
+		return 1;
+	fi
+
+	dev=$(cat /sys/block/$devname/dev)
+	echo +io > $CG/cgroup.subtree_control
+	mkdir $TEST_DIR
+
+	return 0;
+}
+
+clean_up_test() {
+	rmdir $TEST_DIR
+	echo -io > $CG/cgroup.subtree_control
+	_exit_null_blk
+}
+
+config_throtl() {
+	echo "$dev $*" > $TEST_DIR/io.max
+}
+
+remove_config() {
+	echo "$dev rbps=max wbps=max riops=max wiops=max" > $TEST_DIR/io.max
+}
+
+test_io() {
+	config_throtl "$1"
+
+	{
+		sleep 0.1
+		start_time=$(date +%s.%N)
+
+		if [ "$2" == "read" ]; then
+			dd if=/dev/$devname of=/dev/null bs=1M count=1 iflag=direct status=none
+		elif [ "$2" == "write" ]; then
+			dd of=/dev/$devname if=/dev/zero bs=1M count=1 oflag=direct status=none
+		fi
+
+		end_time=$(date +%s.%N)
+		elapsed=$(echo "$end_time - $start_time" | bc)
+		printf "%.0f\n" "$elapsed"
+	} &
+
+	pid=$!
+	echo $! > $TEST_DIR/cgroup.procs
+	wait $pid
+
+	remove_config
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! set_up_test; then
+		return 1;
+	fi
+
+	test_io wiops=256 write
+	test_io riops=256 read
+
+	clean_up_test
+	echo "Test complete"
+}
diff --git a/tests/throtl/002.out b/tests/throtl/002.out
new file mode 100644
index 0000000..7e1ae85
--- /dev/null
+++ b/tests/throtl/002.out
@@ -0,0 +1,4 @@ 
+Running throtl/002
+1
+1
+Test complete