btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[platform/upstream/btrfs-progs.git] / tests / fsck-tests / 025-file-extents / test.sh
1 #!/bin/bash
2 # Confirm btrfs check can check file extents without causing false alert
3
4 source "$TEST_TOP/common"
5
6 check_prereq btrfs
7 check_prereq mkfs.btrfs
8 check_prereq btrfstune
9 check_global_prereq dd
10 check_global_prereq fallocate
11 check_global_prereq truncate
12
13 setup_root_helper
14 prepare_test_dev 128M
15
16 # Do some write into a large prealloc range
17 # Lowmem mode can report missing csum due to wrong csum range
18 test_paritical_write_into_prealloc()
19 {
20         run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
21         run_check_mount_test_dev
22
23         run_check $SUDO_HELPER fallocate -l 128K "$TEST_MNT/file"
24         sync
25         run_check $SUDO_HELPER dd conv=notrunc if=/dev/zero of="$TEST_MNT/file" bs=1K count=64
26         run_check_umount_test_dev
27         run_check "$TOP/btrfs" check "$TEST_DEV"
28 }
29
30 # Inline compressed file extent
31 # Lowmem mode can cause silent error without any error message
32 # due to too restrict check on inline extent size
33 test_compressed_inline_extent()
34 {
35         run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
36         run_check_mount_test_dev -o compress=lzo,max_inline=2048
37
38         run_check $SUDO_HELPER dd conv=notrunc if=/dev/null of="$TEST_MNT/file" bs=1K count=1
39         run_check_umount_test_dev
40         run_check "$TOP/btrfs" check "$TEST_DEV"
41 }
42
43 # File extent hole with NO_HOLES incompat feature set.
44 # Lowmem mode will cause a false alert as it doesn't allow any file hole
45 # extents, while we can set NO_HOLES at anytime we want, it's definitely a
46 # false alert
47 test_hole_extent_with_no_holes_flag()
48 {
49         run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
50         run_check_mount_test_dev
51
52         run_check $SUDO_HELPER truncate -s 16K "$TEST_MNT/tmp"
53         run_check_umount_test_dev
54         run_check $SUDO_HELPER "$TOP/btrfstune" -n "$TEST_DEV"
55         run_check "$TOP/btrfs" check "$TEST_DEV"
56 }
57
58 test_paritical_write_into_prealloc
59 test_compressed_inline_extent
60 test_hole_extent_with_no_holes_flag