#!/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

test() {
	echo "Running ${TEST_NAME}"

	local page_size max_secs
	local io_size_kb block_size
	local iops=256

	page_size=$(getconf PAGE_SIZE)
	max_secs=$((page_size / 512))

	if ! _set_up_throtl max_sectors="${max_secs}"; then
		return 1;
	fi

	io_size_kb=$(($(_throtl_get_max_io_size) * 1024))
	block_size=$((iops * io_size_kb))

	_throtl_set_limits wiops="${iops}"
	_throtl_test_io write "${block_size}" 1
	_throtl_remove_limits

	_throtl_set_limits riops="${iops}"
	_throtl_test_io read "${block_size}" 1
	_throtl_remove_limits

	_clean_up_throtl
	echo "Test complete"
}
