a2a5b51d66e3155c279a19c556b18502936e1616
[xfstests-dev.git] / tests / generic / 551
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 551
6 #
7 # Randomly direct AIO write&verify stress test
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # real QA test starts here
32 _supported_fs generic
33 _supported_os Linux
34 _require_scratch
35 _require_aiodio aio-dio-write-verify
36
37 _scratch_mkfs > $seqres.full 2>&1
38 _scratch_mount
39
40 localfile=$SCRATCH_MNT/testfile
41 diosize=`_min_dio_alignment $SCRATCH_DEV`
42
43 # The maximum write size and offset are both 32k diosize. So the maximum
44 # file size will be (32 * 2)k
45 free_size_k=`df -kP $SCRATCH_MNT | grep -v Filesystem | awk '{print $4}'`
46 max_io_size_b=$((32 * 1024))
47 if [ $max_io_size_b -gt $((free_size_k * 1024 / 2 / diosize)) ]; then
48         max_io_size_b=$((free_size_k * 1024 / 2 / diosize))
49 fi
50
51 do_test()
52 {
53         local num_oper
54         local oper_list=""
55         local size
56         local off
57         local truncsize
58
59         # the number of AIO write operation
60         num_oper=$((RANDOM % 64 + 1))
61
62         for ((i=0; i<num_oper; i++)); do
63                 size=$(((RANDOM % max_io_size_b + 1) * diosize))
64                 off=$((RANDOM % max_io_size_b * diosize))
65                 oper_list="$oper_list -a size=$size,off=$off"
66         done
67         truncsize=$(((RANDOM * diosize + RANDOM % diosize) % max_io_size_b))
68
69         $AIO_TEST -t $truncsize $oper_list $localfile
70         if [ $? -ne 0 ];then
71                 echo "$AIO_TEST -t $truncsize $oper_list $localfile"
72                 echo "==========^^ Fail ^^=========="
73         fi
74 }
75
76 testimes=$((LOAD_FACTOR * 100))
77 while [ $testimes -gt 0 ]; do
78         echo > $localfile
79         do_test
80         ((testimes--))
81 done
82
83 echo "Silence is golden"
84
85 # success, all done
86 status=0
87 exit