diff mbox series

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

Message ID 20240416020042.509291-6-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 change config while IO is throttled, regression test for:

commit a880ae93e5b5 ("blk-throttle: fix io hung due to configuration updates")

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

Patch

diff --git a/tests/throtl/005 b/tests/throtl/005
new file mode 100755
index 0000000..6caac99
--- /dev/null
+++ b/tests/throtl/005
@@ -0,0 +1,83 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test change config while IO is throttled, regression test for
+# commit a880ae93e5b5 ("blk-throttle: fix io hung due to configuration updates")
+
+. tests/throtl/rc
+
+DESCRIPTION="change config with throttled IO"
+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() {
+	limit=$((512 * 1024))
+	config_throtl wbps=$limit
+
+	{
+		sleep 0.1
+		start_time=$(date +%s.%N)
+
+		dd of=/dev/$devname if=/dev/zero bs=1M count=1 oflag=direct status=none
+
+		# old limit is 512k, issue 1M IO, swith to new limit 215k after 1s
+		# expected wait time is 3s
+		end_time=$(date +%s.%N)
+		elapsed=$(echo "$end_time - $start_time" | bc)
+		printf "%.0f\n" "$elapsed"
+	} &
+
+	pid=$!
+	echo $! > $TEST_DIR/cgroup.procs
+
+	sleep 1
+	limit=$((256 * 1024))
+	config_throtl wbps=$limit
+	wait $pid
+
+	remove_config
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! set_up_test; then
+		return 1;
+	fi
+
+	test_io
+
+	clean_up_test
+	echo "Test complete"
+}
diff --git a/tests/throtl/005.out b/tests/throtl/005.out
new file mode 100644
index 0000000..1d23210
--- /dev/null
+++ b/tests/throtl/005.out
@@ -0,0 +1,3 @@ 
+Running throtl/005
+3
+Test complete