#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2017 Jens Axboe
#
# Test if a block driver with BLK_MQ_F_BLOCKING set works correctly.
#
# Regression test for commit bf4907c05e61 ("blk-mq: fix schedule-under-preempt
# or blocking drivers")

. tests/block/rc
. common/null_blk

DESCRIPTION="run null-blk in blocking mode"
TIMED=1
CAN_BE_ZONED=1

requires() {
	_have_null_blk && _have_module_param null_blk blocking && _have_fio
}

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

	_divide_timeout 2
	FIO_PERF_FIELDS=("read iops")

	if ! _configure_null_blk nullb1 submit_queues=2 blocking=1 power=1; then
		return 1
	fi

	# run sync test
	_fio_perf --bs=4k --ioengine=sync --rw=randread --norandommap --name=sync \
		--filename=/dev/nullb1 --size=5g --direct=1

	# run async test
	_fio_perf --bs=4k --ioengine=libaio --iodepth=8 --numjobs="$(nproc)" \
		--rw=randread --norandommap --name=async \
		--filename=/dev/nullb1 --size=5g --direct=1

	_exit_null_blk

	echo "Test complete"
}
