_fail()
{
- echo "$*" | tee -a $RESULT
+ echo "$*" | tee -a $RESULTS
exit 1
}
run_check()
{
- echo "############### $@" >> $RESULT 2>&1
- "$@" >> $RESULT 2>&1 || _fail "failed: $@"
+ echo "############### $@" >> $RESULTS 2>&1
+ "$@" >> $RESULTS 2>&1 || _fail "failed: $@"
}
check_prereq()
{
- if ! [ -f $top/$1 ]; then
+ if ! [ -f $TOP/$1 ]; then
_fail "Failed prerequisities: $1";
fi
}
check_image()
{
image=$1
- echo "testing image $(basename $image)" >> $RESULT
- $top/btrfs check $image >> $RESULT 2>&1
+ echo "testing image $(basename $image)" >> $RESULTS
+ $TOP/btrfs check $image >> $RESULTS 2>&1
[ $? -eq 0 ] && _fail "btrfs check should have detected corruption"
- run_check $top/btrfs check --repair $image
- run_check $top/btrfs check $image
+ run_check $TOP/btrfs check --repair $image
+ run_check $TOP/btrfs check $image
}
check_all_images()
dir=$1
for i in $(find $dir -iname '*.img')
do
- echo "extracting image $(basename $i)" >> $RESULT
- $top/btrfs-image -r $i $i.restored || \
+ echo "extracting image $(basename $i)" >> $RESULTS
+ $TOP/btrfs-image -r $i $i.restored || \
_fail "failed to extract image $i"
check_image $i.restored
# It's GPL, same as everything else in this tree.
#
-unset top
+unset TOP
unset LANG
LANG=C
-script_dir=$(dirname $(realpath $0))
-top=$(realpath $script_dir/../)
+SCRIPT_DIR=$(dirname $(realpath $0))
+TOP=$(realpath $SCRIPT_DIR/../)
TEST_DEV=${TEST_DEV:-}
-TEST_MNT=${TEST_MNT:-$top/tests/mnt}
-RESULT="$top/tests/fsck-tests-results.txt"
+TEST_MNT=${TEST_MNT:-$TOP/tests/mnt}
+RESULTS="$TOP/tests/fsck-tests-results.txt"
-source $top/tests/common
+source $TOP/tests/common
-# Allow child test to use $top and $RESULT
-export top
-export RESULT
+# Allow child test to use $TOP and $RESULTS
+export TOP
+export RESULTS
# For custom script needs to verfiy recovery
export TEST_MNT
export LANG
-rm -f $RESULT
+rm -f $RESULTS
mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT"
# test rely on corrupting blocks tool
# This is for case btrfs-image can't dump or case needs extra
# check/verify
-for i in $(find $top/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort)
+for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort)
do
echo " [TEST] $(basename $i)"
cd $i
# Type 1
check_all_images `pwd`
fi
- cd $top
+ cd $TOP
done
#!/bin/bash
-source $top/tests/common
+source $TOP/tests/common
-echo "extracting image default_case.tar.xz" >> $RESULT
+echo "extracting image default_case.tar.xz" >> $RESULTS
tar xJf default_case.tar.xz || \
_fail "failed to extract default_case.tar.xz"
check_image test.img
-echo "extracting image skinny_case.tar.xz" >> $RESULT
+echo "extracting image skinny_case.tar.xz" >> $RESULTS
tar xJf skinny_case.tar.xz || \
_fail "failed to extract skinny_case.tar.xz"
check_image test.img
#!/bin/bash
-source $top/tests/common
+source $TOP/tests/common
# Check file list for leaf corruption, no regular/preallocated
# file extent case.
generate_leaf_corrupt_no_data_ext()
{
dest=$1
- echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULT
+ echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULTS
tar xJf ./no_data_extent.tar.xz || \
_fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image"
btrfs-image -r test.img.btrfs-image $dest || \
#!/bin/bash
-source $top/tests/common
+source $TOP/tests/common
if [ -z $TEST_DEV ]; then
echo " [NOTRUN] extent tree rebuild, need TEST_DEV variant"
test_extent_tree_rebuild()
{
echo " [TEST] extent tree rebuild"
- $top/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs"
+ $TOP/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs"
run_check mount $TEST_DEV $TEST_MNT
cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1
for i in `seq 1 100`;do
- $top/btrfs sub snapshot $TEST_MNT \
+ $TOP/btrfs sub snapshot $TEST_MNT \
$TEST_MNT/snapaaaaaaa_$i >& /dev/null
done
run_check umount $TEST_DEV
# get extent root bytenr
- extent_root_bytenr=`$top/btrfs-debug-tree -r $TEST_DEV | \
+ extent_root_bytenr=`$TOP/btrfs-debug-tree -r $TEST_DEV | \
grep extent | awk '{print $7}'`
if [ -z $extent_root_bytenr ];then
_fail "fail to get extent root bytenr"
fi
# corrupt extent root node block
- run_check $top/btrfs-corrupt-block -l $extent_root_bytenr \
+ run_check $TOP/btrfs-corrupt-block -l $extent_root_bytenr \
-b 4096 $TEST_DEV
- $top/btrfs check $TEST_DEV >& /dev/null && \
+ $TOP/btrfs check $TEST_DEV >& /dev/null && \
_fail "btrfs check should detect failure"
- run_check $top/btrfs check --init-extent-tree $TEST_DEV
- run_check $top/btrfs check $TEST_DEV
+ run_check $TOP/btrfs check --init-extent-tree $TEST_DEV
+ run_check $TOP/btrfs check $TEST_DEV
}
test_extent_tree_rebuild