xfs: force file creation to the data device for certain layout tests
[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 _require_scratch
34 _require_aiodio aio-dio-write-verify
35
36 _scratch_mkfs > $seqres.full 2>&1
37 _scratch_mount
38
39 localfile=$SCRATCH_MNT/testfile
40 diosize=`_min_dio_alignment $SCRATCH_DEV`
41
42 # The maximum write size and offset are both 32k diosize. So the maximum
43 # file size will be (32 * 2)k
44 free_size_k=`df -kP $SCRATCH_MNT | grep -v Filesystem | awk '{print $4}'`
45 max_io_size_b=$((32 * 1024))
46 if [ $max_io_size_b -gt $((free_size_k * 1024 / 2 / diosize)) ]; then
47         max_io_size_b=$((free_size_k * 1024 / 2 / diosize))
48 fi
49
50 do_test()
51 {
52         local num_oper
53         local oper_list=""
54         local size
55         local off
56         local truncsize
57         local total_size=0
58         local avail_mem=`_available_memory_bytes`
59
60         # the number of AIO write operation
61         num_oper=$((RANDOM % 64 + 1))
62
63         for ((i=0; i<num_oper; i++)); do
64                 size=$(((RANDOM % max_io_size_b + 1) * diosize))
65                 total_size=$((total_size + size*2))
66                 if [[ $total_size -ge $avail_mem ]]; then
67                         break
68                 fi
69                 off=$((RANDOM % max_io_size_b * diosize))
70                 oper_list="$oper_list -a size=$size,off=$off"
71         done
72         truncsize=$(((RANDOM * diosize + RANDOM % diosize) % max_io_size_b))
73
74         $AIO_TEST -t $truncsize $oper_list $localfile
75         if [ $? -ne 0 ];then
76                 echo "$AIO_TEST -t $truncsize $oper_list $localfile"
77                 echo "==========^^ Fail ^^=========="
78         fi
79 }
80
81 testimes=$((LOAD_FACTOR * 100))
82 while [ $testimes -gt 0 ]; do
83         echo > $localfile
84         do_test
85         ((testimes--))
86 done
87
88 echo "Silence is golden"
89
90 # success, all done
91 status=0
92 exit