btrfs-progs/tests/misc-tests/024-inspect-internal-rootid/test.sh
Qu Wenruo 8c759d5a06 btrfs-progs: tests: filter output for run_check_stdout
Since run_check_stdout() can insert INSTRUMENT for all btrfs related
programs, which could easily pollute the stdout, any caller of
run_check_stdout() should do proper filter.

The following callers are affected:
- misc/004
  Filter the output of "btrfs ins min-dev-size"

- misc/009
- misc/013
- misc/024
  They are all calling "btrfs ins rootid", so introduce get_subvolid()
  function to grab the subvolid properly.

- misc/031
  Loose the filter for "btrfs qgroup show". No need for "tail -n 1".

So we still have the same coverage, but now these tests won't cause
false alert if we insert INSTRUMENT for all btrfs commands.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:48:42 +02:00

51 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
#
# test commands of inspect-internal rootid
source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
prepare_test_dev
run_check_mkfs_test_dev
run_check_mount_test_dev
run_check $SUDO_HELPER chmod a+rw "$TEST_MNT"
cd "$TEST_MNT"
run_check "$TOP/btrfs" subvolume create sub
run_check "$TOP/btrfs" subvolume create sub/subsub
run_check mkdir dir
run_check touch file1
run_check touch dir/file2
run_check touch sub/file3
id1=$(_get_subvolid .) || { echo $id1; exit 1; }
id2=$(_get_subvolid sub) || { echo $id2; exit 1; }
id3=$(_get_subvolid sub/subsub) || { echo $id3; exit 1; }
id4=$(_get_subvolid dir) || { echo $id4; exit 1; }
id5=$(_get_subvolid file1) || { echo $id5; exit 1; }
id6=$(_get_subvolid dir/file2) || { echo $id6; exit 1; }
id7=$(_get_subvolid sub/file3) || { echo $id7; exit 1; }
if ! ([ "$id1" -ne "$id2" ] && [ "$id1" -ne "$id3" ] && [ "$id2" -ne "$id3" ]); then
_fail "inspect-internal rootid: each subvolume must have different id"
fi
if ! ([ "$id1" -eq "$id4" ] && [ "$id1" -eq "$id5" ] && [ "$id1" -eq "$id6" ]); then
_fail "inspect-internal rootid: rootid mismatch found"
fi
if ! ([ "$id2" -eq "$id7" ]); then
_fail "inspect-internal rootid: rootid mismatch found"
fi
run_mustfail "should fail for non existent file" \
"$TOP/btrfs" inspect-internal rootid no_such_file
run_mustfail "should fail for non-btrfs filesystem" \
"$TOP/btrfs" inspect-internal rootid /dev/null
cd ..
run_check_umount_test_dev