2013-09-09 20:41:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# loop through all of our bad images and make sure fsck repairs them properly
|
|
|
|
|
2014-12-25 01:32:11 +00:00
|
|
|
LANG=C
|
2016-11-11 09:12:05 +00:00
|
|
|
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
|
|
|
|
TOP=$(readlink -f "$SCRIPT_DIR/../")
|
2014-12-25 01:32:11 +00:00
|
|
|
TEST_DEV=${TEST_DEV:-}
|
2015-04-03 07:01:12 +00:00
|
|
|
RESULTS="$TOP/tests/fsck-tests-results.txt"
|
2016-06-03 14:01:51 +00:00
|
|
|
IMAGE="$TOP/tests/test.img"
|
2014-12-25 01:32:11 +00:00
|
|
|
|
2016-11-11 09:12:05 +00:00
|
|
|
source "$TOP/tests/common"
|
2014-12-25 01:32:11 +00:00
|
|
|
|
2015-04-03 07:01:12 +00:00
|
|
|
export TOP
|
|
|
|
export RESULTS
|
2014-12-25 01:32:11 +00:00
|
|
|
export LANG
|
2016-06-03 14:01:51 +00:00
|
|
|
export IMAGE
|
|
|
|
export TEST_DEV
|
2014-12-12 14:49:26 +00:00
|
|
|
|
2016-11-11 09:12:05 +00:00
|
|
|
rm -f "$RESULTS"
|
2014-05-29 10:01:44 +00:00
|
|
|
|
|
|
|
# test rely on corrupting blocks tool
|
2014-12-12 14:49:26 +00:00
|
|
|
check_prereq btrfs-corrupt-block
|
|
|
|
check_prereq btrfs-image
|
|
|
|
check_prereq btrfs
|
2016-11-10 17:57:38 +00:00
|
|
|
check_kernel_support
|
2013-09-09 20:41:58 +00:00
|
|
|
|
2015-07-10 22:31:02 +00:00
|
|
|
run_one_test() {
|
|
|
|
local testname
|
|
|
|
|
|
|
|
testname="$1"
|
2015-11-30 17:13:01 +00:00
|
|
|
echo " [TEST/fsck] $(basename $testname)"
|
2016-11-11 09:12:05 +00:00
|
|
|
cd "$testname"
|
|
|
|
echo "=== Entering $testname" >> "$RESULTS"
|
2015-07-10 22:31:02 +00:00
|
|
|
if [ -x test.sh ]; then
|
|
|
|
# Type 2
|
|
|
|
./test.sh
|
|
|
|
if [ $? -ne 0 ]; then
|
2016-11-18 14:18:02 +00:00
|
|
|
if [[ $TEST_LOG =~ dump ]]; then
|
|
|
|
cat "$RESULTS"
|
|
|
|
fi
|
2015-07-10 22:31:02 +00:00
|
|
|
_fail "test failed for case $(basename $testname)"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Type 1
|
2016-11-18 18:21:02 +00:00
|
|
|
check_all_images
|
2015-07-10 22:31:02 +00:00
|
|
|
fi
|
2016-11-11 09:12:05 +00:00
|
|
|
cd "$TOP"
|
2015-07-10 22:31:02 +00:00
|
|
|
}
|
|
|
|
|
2014-12-25 01:32:11 +00:00
|
|
|
# Each dir contains one type of error for btrfsck test.
|
|
|
|
# Each dir must be one of the following 2 types:
|
|
|
|
# 1) Only btrfs-image dump
|
|
|
|
# Only contains one or several btrfs-image dumps (.img)
|
|
|
|
# Each image will be tested by generic test routine
|
|
|
|
# (btrfsck --repair and btrfsck).
|
|
|
|
# This is for case that btree-healthy images.
|
|
|
|
# 2) Custom test script
|
|
|
|
# This dir contains test.sh which will do custom image
|
|
|
|
# generation/check/verification.
|
|
|
|
# This is for case btrfs-image can't dump or case needs extra
|
|
|
|
# check/verify
|
|
|
|
|
2016-11-11 09:12:05 +00:00
|
|
|
for i in $(find "$TOP/tests/fsck-tests" -maxdepth 1 -mindepth 1 -type d \
|
2015-07-10 22:38:07 +00:00
|
|
|
${TEST:+-name "$TEST"} | sort)
|
2013-09-09 20:41:58 +00:00
|
|
|
do
|
2015-07-10 22:31:02 +00:00
|
|
|
run_one_test "$i"
|
2013-09-09 20:41:58 +00:00
|
|
|
done
|