fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 018
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Eric Sandeen.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/018
6 #
7 # Basic defragmentation sanity tests
8 #
9 . ./common/preamble
10 _begin_fstest auto fsr quick defrag
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/defrag
15
16 # real QA test starts here
17 _supported_fs generic
18
19 # We require scratch so that we'll have free contiguous space
20 _require_scratch
21 _scratch_mkfs >/dev/null 2>&1
22 _scratch_mount
23
24 _require_defrag
25
26 fragfile=$SCRATCH_MNT/fragfile.$$
27
28 rm -f $fragfile
29
30 # Craft some fragmented files, defrag them, check the result.
31 bsize=$(_get_file_block_size $SCRATCH_MNT)
32
33 echo "zero-length file:" | tee -a $seqres.full
34 touch $fragfile
35 _defrag --before 0 --after 0 $fragfile
36
37 echo "Sparse file (no blocks):" | tee -a $seqres.full
38 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
39 _defrag --before 0 --after 0 $fragfile
40
41 echo "Contiguous file:" | tee -a $seqres.full
42 $XFS_IO_PROG -f -c "pwrite -b $((4 * bsize)) 0 $((4 * bsize))" $fragfile \
43                                         > /dev/null
44 _defrag --before 1 --after 1 $fragfile
45
46 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
47 for i in `seq 9 -1 0`; do
48         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
49                                         > /dev/null
50 done
51
52 # Accept fewer fragments than we might expect; we don't have perfect control.
53 _defrag --max_before 10 --min_before 5 --after 1 $fragfile
54
55 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
56 for i in `seq 31 -2 0`; do
57         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
58                                         > /dev/null
59 done
60 _defrag --before 16 --after 16 $fragfile
61
62 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
63 for i in `seq 0 2 31`; do
64         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
65                                         > /dev/null
66 done
67 _defrag --before 16 --after 16 $fragfile
68
69 status=0
70 exit