-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fsck.sh
executable file
·75 lines (64 loc) · 1.5 KB
/
test_fsck.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
TESTCASE_DIR=$1
IMAGE_FILE=exfat.img
FSCK_PROG=../build/sbin/fsck.exfat
FSCK_OPTS=-y
PASS_COUNT=0
function cleanup {
echo ""
echo "Passed ${PASS_COUNT} of ${TEST_COUNT}"
exit
}
if [ $# -eq 0 ]; then
TESTCASE_DIRS=`find -mindepth 1 -maxdepth 1 -type d`
TEST_COUNT=`find -mindepth 1 -maxdepth 1 -type d | wc -l`
else
TESTCASE_DIRS=$@
TEST_COUNT=$#
fi
for TESTCASE_DIR in $TESTCASE_DIRS
do
if [ ! -e ${TESTCASE_DIR}/${IMAGE_FILE}.tar.xz ]; then
TEST_COUNT=$((TEST_COUNT - 1))
continue
fi
echo "Running $TESTCASE_DIR"
echo "-----------------------------------"
# Set up image file as loop device
tar -C . -xf $TESTCASE_DIR/$IMAGE_FILE.tar.xz
losetup -f $IMAGE_FILE
DEV_FILE=`losetup -j $IMAGE_FILE | awk '{print $1}' | sed 's/://g'`
# Run fsck for repair
$FSCK_PROG $FSCK_OPTS $DEV_FILE
if [ "$?" -ne "1" ]; then
echo ""
echo "Failed to repair $TESTCASE_DIR"
losetup -d $DEV_FILE
cleanup
fi
echo ""
# Run fsck again
$FSCK_PROG -n $DEV_FILE
if [ "$?" -ne "0" ]; then
echo ""
echo "Failed, corrupted $TESTCASE_DIR"
losetup -d $DEV_FILE
cleanup
fi
if [ -e "$TESTCASE_DIR/exfat.img.expected.xz" ]; then
EXPECTED_FILE=$IMAGE_FILE.expected
unxz -cfk "$TESTCASE_DIR/$EXPECTED_FILE.xz" > $EXPECTED_FILE
diff <(xxd $IMAGE_FILE) <(xxd $EXPECTED_FILE)
if [ "$?" -ne "0" ]; then
echo ""
echo "Failed $TESTCASE_DIR"
losetup -d $DEV_FILE
cleanup
fi
fi
echo ""
echo "Passed $TESTCASE_DIR"
PASS_COUNT=$((PASS_COUNT + 1))
losetup -d $DEV_FILE
done
cleanup