generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 001
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 SGI.  All Rights Reserved.
4 #
5 # FS QA Test No. 001
6 #
7 # Test the xfs_db write of the XFS BMBT entries. For each XFS BMBT field,
8 # write the value 0, each bit and finally the entry beyond the maximum legal
9 # value. Also makes sure a core write and hex input still work.
10 #
11 . ./common/preamble
12 _begin_fstest db auto quick
13
14 _do_bit_test()
15 {
16         field="$1"
17         bits="$2"
18
19         echo "testing $field with $bits bits"
20         _scratch_xfs_db -x -c "inode $FILE_INO" -c "write $field 0"
21         num=1
22         for n in `seq 0 1 $bits`; do
23                 _scratch_xfs_db -x -c "inode $FILE_INO" \
24                           -c "write $field $num"
25                 let num=$num*2
26         done
27         echo
28 }
29
30 # Import common functions.
31 . ./common/filter
32
33 # real QA test starts here
34
35 # Modify as appropriate.
36 _supported_fs xfs
37 _require_scratch_nocheck
38
39 _scratch_mkfs >/dev/null 2>&1
40 _scratch_mount
41
42 # create the test file
43 echo "make a file with data so it has an extent" > $SCRATCH_MNT/file
44
45 # find the inode for the test file
46 FILE_INO=`ls -i $SCRATCH_MNT |awk '{print $1}'`
47
48 _scratch_unmount
49
50 # test bit length constants
51 BMBT_EXNTFLAG_BITLEN=1
52 BMBT_STARTOFF_BITLEN=54
53 BMBT_STARTBLOCK_BITLEN=52
54 BMBT_BLOCKCOUNT_BITLEN=21
55
56 prefix=$(_scratch_get_bmx_prefix $FILE_INO)
57 test -n "$prefix" || _fail "could not find bmx prefix from inode $FILE_INO"
58
59 filter_output() {
60         sed -e "s/${prefix}/u.bmx/g"
61 }
62
63 # test setting the BMBT entries from 0 to past the valid number.
64 _do_bit_test "${prefix}[0].extentflag" $BMBT_EXNTFLAG_BITLEN | filter_output
65 _do_bit_test "${prefix}[0].startoff" $BMBT_STARTOFF_BITLEN | filter_output
66 _do_bit_test "${prefix}[0].startblock" $BMBT_STARTBLOCK_BITLEN | filter_output
67 _do_bit_test "${prefix}[0].blockcount" $BMBT_BLOCKCOUNT_BITLEN | filter_output
68 # test setting the 32 bit generation number
69 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0x5a"
70 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0xa5"
71 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0"
72 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen #5a5a"
73 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen #a5a5"
74 status=0
75 exit