xref: /linux/tools/testing/selftests/ublk/test_generic_06.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
8_prep_test "fault_inject" "fast cleanup when all I/Os of one hctx are in server"
9
10# configure ublk server to sleep 2s before completing each I/O
11dev_id=$(_add_ublk_dev -t fault_inject -q 2 -d 1 --delay_us 2000000)
12_check_add_dev $TID $?
13
14STARTTIME=${SECONDS}
15
16dd if=/dev/urandom of=/dev/ublkb${dev_id} oflag=direct bs=4k count=1 status=none > /dev/null 2>&1 &
17dd_pid=$!
18
19__ublk_kill_daemon ${dev_id} "DEAD" >/dev/null
20
21wait $dd_pid
22dd_exitcode=$?
23
24ENDTIME=${SECONDS}
25ELAPSED=$(($ENDTIME - $STARTTIME))
26
27# assert that dd sees an error and exits quickly after ublk server is
28# killed. previously this relied on seeing an I/O timeout and so would
29# take ~30s
30if [ $dd_exitcode -eq 0 ]; then
31        echo "dd unexpectedly exited successfully!"
32        ERR_CODE=255
33fi
34if [ $ELAPSED -ge 5 ]; then
35        echo "dd took $ELAPSED seconds to exit (>= 5s tolerance)!"
36        ERR_CODE=255
37fi
38
39_cleanup_test "fault_inject"
40_show_result $TID $ERR_CODE
41