btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[platform/upstream/btrfs-progs.git] / tests / misc-tests / 003-zero-log / test.sh
1 #!/bin/bash
2 # test zero-log
3
4 source "$TEST_TOP/common"
5
6 check_prereq mkfs.btrfs
7 check_prereq btrfs
8 prepare_test_dev
9
10 get_log_root()
11 {
12         local image
13
14         image="$1"
15         $TOP/btrfs inspect-internal dump-super "$image" | \
16                 grep '^log_root\>' | awk '{print $2}'
17 }
18 get_log_root_level() {
19         local image
20
21         image="$1"
22         $TOP/btrfs inspect-internal dump-super "$image" | \
23                 grep '^log_root_level' | awk '{print $2}'
24 }
25
26 test_zero_log()
27 {
28         # FIXME: we need an image with existing log_root
29         run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \
30                 --rootdir $INTERNAL_BIN/Documentation \
31                 $TEST_DEV
32         run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV
33         if [ "$1" = 'standalone' ]; then
34                 run_check $TOP/btrfs rescue zero-log $TEST_DEV
35         else
36                 run_check $TOP/btrfs-zero-log $TEST_DEV
37         fi
38         log_root=$(get_log_root $TEST_DEV)
39         log_root_level=$(get_log_root $TEST_DEV)
40         if [ "$log_root" != 0 ]; then
41                 _fail "FAIL: log_root not reset"
42         fi
43         if [ "$log_root_level" != 0 ]; then
44                 _fail "FAIL: log_root_level not reset"
45         fi
46         run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV
47         run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
48 }
49
50 test_zero_log standalone
51 test_zero_log internal