misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 324
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/324
6 #
7 # Sanity check for defrag utility.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 PIDS=""
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         rm -f $tmp.*
21 }
22
23 # get standard environment, filters and checks
24 . ./common/rc
25 . ./common/filter
26 . ./common/defrag
27
28 # real QA test starts here
29 _require_scratch
30 _require_defrag
31 _require_xfs_io_command "falloc"
32
33 rm -f $seqres.full
34
35 _workout()
36 {
37         nr=$1
38         echo "Defragment file with $nr * 2 fragments"
39         # Create sparse file
40         for ((i=0;i<nr;i++))
41         do
42                 $XFS_IO_PROG -f -c "falloc $((409600*i)) 4k"  \
43                         $SCRATCH_MNT/test.$nr >> $seqres.full 2>&1
44         done
45         # Fill holes for half of range , as result file will contain nr*1.5 fragments
46         $XFS_IO_PROG -c "falloc 0 $((204800*nr))"  \
47             $SCRATCH_MNT/test.$nr | _filter_xfs_io
48         # Data wrilte will convert extetns to inialized ones
49         for ((i=0;i<nr;i++))
50         do
51                 patt=`printf "0x%x" $i`
52                 $XFS_IO_PROG -c "pwrite -S $patt $((i*123400)) 1234" \
53                         $SCRATCH_MNT/test.$nr | _filter_xfs_io
54         done
55         _defrag --min_before $nr --max_before $((nr*4)) \
56                 --min_after 1 $SCRATCH_MNT/test.$nr
57 }
58
59
60 # Actual testing starting from here
61 _scratch_mkfs  >> $seqres.full 2>&1
62 _scratch_mount
63 _workout 10
64 _workout 250
65 _workout 1000
66 status=0