#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2024 Yu Kuai
#
# Test bps limit work correctly for big IO of blk-throttle, regression test for
# commit 111be8839817 ("block-throttle: avoid double charge")

. tests/throtl/rc

DESCRIPTION="bps limit over IO split"
QUICK=1

set_conditions() {
	_set_throtl_blkdev_type "$@"
}

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

	local page_size
	page_size=$(getconf PAGE_SIZE)

	if ! _set_up_throtl --sector_size "${page_size}"; then
		return 1;
	fi

	local limit=$((1024 * 1024))

	_throtl_set_limits wbps=$limit
	_throtl_test_io write 1M 1
	_throtl_remove_limits

	_throtl_set_limits rbps=$limit
	_throtl_test_io read 1M 1
	_throtl_remove_limits

	_clean_up_throtl
	echo "Test complete"
}
