btrfs-progs: tests: add shell quotes to misc test scripts
[platform/upstream/btrfs-progs.git] / tests / misc-tests / 024-inspect-internal-rootid / test.sh
1 #!/bin/bash
2 #
3 # test commands of inspect-internal rootid
4
5 source "$TEST_TOP/common"
6
7 check_prereq mkfs.btrfs
8 check_prereq btrfs
9
10 prepare_test_dev
11
12 run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV"
13 run_check_mount_test_dev
14 run_check $SUDO_HELPER chmod a+rw "$TEST_MNT"
15 cd "$TEST_MNT"
16
17 run_check "$TOP/btrfs" subvolume create sub
18 run_check "$TOP/btrfs" subvolume create sub/subsub
19 run_check mkdir dir
20 run_check touch file1
21 run_check touch dir/file2
22 run_check touch sub/file3
23
24 id1=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid .) \
25         || { echo $id1; exit 1; }
26 id2=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub) \
27         || { echo $id2; exit 1; }
28 id3=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub/subsub) \
29         || { echo $id3; exit 1; }
30 id4=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid dir) \
31         || { echo $id4; exit 1; }
32 id5=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid file1) \
33         || { echo $id5; exit 1; }
34 id6=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid dir/file2) \
35         || { echo $id6; exit 1; }
36 id7=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub/file3) \
37         || { echo $id7; exit 1; }
38
39 if ! ([ "$id1" -ne "$id2" ] && [ "$id1" -ne "$id3" ] && [ "$id2" -ne "$id3" ]); then
40         _fail "inspect-internal rootid: each subvolume must have different id"
41 fi
42
43 if ! ([ "$id1" -eq "$id4" ] && [ "$id1" -eq "$id5" ] && [ "$id1" -eq "$id6" ]); then
44         _fail "inspect-internal rootid: rootid mismatch found"
45 fi
46
47 if ! ([ "$id2" -eq "$id7" ]); then
48         _fail "inspect-internal rootid: rootid mismatch found"
49 fi
50
51 run_mustfail "should fail for non existent file" \
52         "$TOP/btrfs" inspect-internal rootid no_such_file
53 run_mustfail "should fail for non-btrfs filesystem" \
54         "$TOP/btrfs" inspect-internal rootid /dev/null
55
56 cd ..
57 run_check_umount_test_dev