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"))
|
2018-02-08 17:34:40 +00:00
|
|
|
if [ -z "$TOP" ]; then
|
|
|
|
TOP=$(readlink -f "$SCRIPT_DIR/../")
|
|
|
|
if [ -f "$TOP/configure.ac" ]; then
|
|
|
|
# inside git
|
2020-04-03 02:10:41 +00:00
|
|
|
TEST_TOP="$TOP/tests"
|
2018-02-08 17:34:40 +00:00
|
|
|
INTERNAL_BIN="$TOP"
|
|
|
|
else
|
|
|
|
# external, defaults to system binaries
|
|
|
|
TOP=$(dirname `which btrfs`)
|
|
|
|
TEST_TOP="$SCRIPT_DIR"
|
|
|
|
INTERNAL_BIN="$TEST_TOP"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# assume external, TOP set from commandline
|
|
|
|
TEST_TOP="$SCRIPT_DIR"
|
|
|
|
INTERNAL_BIN="$TEST_TOP"
|
|
|
|
fi
|
|
|
|
if ! [ -x "$TOP/btrfs" ]; then
|
|
|
|
echo "ERROR: cannot execute btrfs from TOP=$TOP"
|
|
|
|
exit 1
|
2018-02-08 06:34:19 +00:00
|
|
|
fi
|
2014-12-25 01:32:11 +00:00
|
|
|
TEST_DEV=${TEST_DEV:-}
|
2018-02-08 06:34:19 +00:00
|
|
|
RESULTS="$TEST_TOP/fsck-tests-results.txt"
|
|
|
|
IMAGE="$TEST_TOP/test.img"
|
2014-12-25 01:32:11 +00:00
|
|
|
|
2018-02-08 06:34:19 +00:00
|
|
|
source "$TEST_TOP/common"
|
2014-12-25 01:32:11 +00:00
|
|
|
|
2018-02-08 06:34:19 +00:00
|
|
|
export INTERNAL_BIN
|
|
|
|
export TEST_TOP
|
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
|
2017-07-10 21:29:08 +00:00
|
|
|
check_prereq btrfstune
|
2016-11-10 17:57:38 +00:00
|
|
|
check_kernel_support
|
2013-09-09 20:41:58 +00:00
|
|
|
|
2023-06-21 14:44:30 +00:00
|
|
|
test_found=0
|
|
|
|
|
2015-07-10 22:31:02 +00:00
|
|
|
run_one_test() {
|
2023-06-21 14:44:30 +00:00
|
|
|
local testdir
|
2015-07-10 22:31:02 +00:00
|
|
|
local testname
|
|
|
|
|
2023-06-21 14:44:30 +00:00
|
|
|
testdir="$1"
|
|
|
|
testname=$(basename "$testdir")
|
|
|
|
if ! [ -z "$TEST_FROM" ]; then
|
|
|
|
if [ "$test_found" == 0 ]; then
|
|
|
|
case "$testname" in
|
|
|
|
$TEST_FROM) test_found=1;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
if [ "$test_found" == 0 ]; then
|
|
|
|
printf " [TEST/fsck] %-32s (SKIPPED)\n" "$testname"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
2015-11-30 17:13:01 +00:00
|
|
|
echo " [TEST/fsck] $(basename $testname)"
|
2023-06-21 14:44:30 +00:00
|
|
|
cd "$testdir"
|
2018-05-08 17:04:41 +00:00
|
|
|
echo "=== START TEST $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
|
2023-06-21 14:44:30 +00:00
|
|
|
_fail "test failed for case $testname"
|
2015-07-10 22:31:02 +00:00
|
|
|
fi
|
2022-01-13 16:24:52 +00:00
|
|
|
# These tests have overridden check_image() and their images may
|
2021-08-18 06:44:19 +00:00
|
|
|
# have intentional unaligned metadata to trigger subpage
|
|
|
|
# warnings (like fsck/018), skip the check for their subpage
|
|
|
|
# warnings.
|
|
|
|
#
|
|
|
|
# We care about subpage related warnings for write operations
|
|
|
|
# (mkfs/convert/repair), not those read-only checks on crafted
|
|
|
|
# images.
|
2015-07-10 22:31:02 +00:00
|
|
|
else
|
|
|
|
# Type 1
|
2016-11-18 18:21:02 +00:00
|
|
|
check_all_images
|
2015-07-10 22:31:02 +00:00
|
|
|
fi
|
2018-02-08 06:34:19 +00:00
|
|
|
cd "$TEST_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
|
|
|
|
|
2018-02-08 06:34:19 +00:00
|
|
|
for i in $(find "$TEST_TOP/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
|