btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[platform/upstream/btrfs-progs.git] / tests / misc-tests / 001-btrfstune-features / test.sh
1 #!/bin/bash
2 # test btrfstune options that enable filesystem features
3
4 source "$TEST_TOP/common"
5
6 check_prereq mkfs.btrfs
7 check_prereq btrfstune
8 check_prereq btrfs
9
10 setup_root_helper
11 prepare_test_dev
12
13 # test whether fsck can rebuild a corrupted extent tree
14 # parameters:
15 # - option for mkfs.btrfs -O, empty for defaults
16 # - option for btrfstune
17 # - string representing the feature in dump-super output
18 test_feature()
19 {
20         local mkfsfeatures
21         local tuneopt
22         local sbflag
23
24         mkfsfeatures=${1:+-O ^$1}
25         tuneopt="$2"
26         sbflag="$3"
27
28         run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $mkfsfeatures $TEST_DEV
29         if run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | \
30                         grep -q "$sbflag"; then
31                 _fail "FAIL: feature $sbflag must not be set on the base image"
32         fi
33         run_check $TOP/btrfstune $tuneopt $TEST_DEV
34         if ! run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | \
35                         grep -q "$sbflag"; then
36                 _fail "FAIL: feature $sbflag not set"
37         fi
38         run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
39 }
40
41 test_feature extref -r EXTENDED_IREF
42 test_feature skinny-metadata -x SKINNY_METADATA
43 test_feature no-holes -n NO_HOLES
44 test_feature '' '-S 1' SEEDING