xref: /linux/tools/testing/selftests/ublk/test_generic_02.sh (revision 6f7e6393d1ce636bb7ec77a7fe7b77458fddf701)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5
6ERR_CODE=0
7
8if ! _have_program bpftrace; then
9	exit "$UBLK_SKIP_CODE"
10fi
11
12if ! _have_program fio; then
13	exit "$UBLK_SKIP_CODE"
14fi
15
16_prep_test "null" "ublk dispatch won't reorder IO for MQ"
17
18dev_id=$(_add_ublk_dev -t null -q 2)
19_check_add_dev $TID $?
20
21dev_t=$(_get_disk_dev_t "$dev_id")
22bpftrace trace/seq_io.bt "$dev_t" "W" 1 > "$UBLK_TMP" 2>&1 &
23btrace_pid=$!
24
25# Wait for bpftrace probes to be attached (BEGIN block prints BPFTRACE_READY)
26for _ in $(seq 100); do
27	grep -q "BPFTRACE_READY" "$UBLK_TMP" 2>/dev/null && break
28	sleep 0.1
29done
30
31if ! kill -0 "$btrace_pid" 2>/dev/null; then
32	_cleanup_test "null"
33	exit "$UBLK_SKIP_CODE"
34fi
35
36# run fio over this ublk disk (pinned to CPU 0)
37taskset -c 0 fio --name=write_seq \
38    --filename=/dev/ublkb"${dev_id}" \
39    --ioengine=libaio --iodepth=16 \
40    --rw=write \
41    --size=512M \
42    --direct=1 \
43    --bs=4k > /dev/null 2>&1
44ERR_CODE=$?
45kill "$btrace_pid"
46wait
47
48# Check for out-of-order completions detected by bpftrace
49if grep -q "^out_of_order:" "$UBLK_TMP"; then
50	echo "I/O reordering detected:"
51	grep "^out_of_order:" "$UBLK_TMP"
52	ERR_CODE=255
53fi
54_cleanup_test "null"
55_show_result $TID $ERR_CODE
56