#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2018 Ming Lei <ming.lei@redhat.com>
#
# Test blk-mq request allocation when hardware tags are limited. Regression
# test for commit e6fc46498784 ("blk-mq: avoid starving tag allocation after
# allocating process migrates").

. tests/block/rc
. common/null_blk

DESCRIPTION="run null-blk on different schedulers with only one hardware tag"
QUICK=1

requires() {
	_have_null_blk && _have_fio
}

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

	if ! _init_null_blk queue_mode=2 irqmode=2 completion_nsec=2000000 \
	     submit_queues=4 hw_queue_depth=1; then
		return 1
	fi

	local scheds
	# shellcheck disable=SC2207
	scheds=($(sed 's/[][]//g' /sys/block/nullb0/queue/scheduler))

	for sched in "${scheds[@]}"; do
		echo "Testing $sched" >> "$FULL"
		echo "$sched" > /sys/block/nullb0/queue/scheduler
		_fio_perf --bs=4k --ioengine=libaio --iodepth=1024 \
			--numjobs="$(nproc)" --rw=randread --name=async \
			--filename=/dev/nullb0 --size=1g --direct=1 \
			--runtime=10
	done

	_exit_null_blk

	echo "Test complete"
}
