• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2
3TESTCASE_DIR=$1
4NEED_LOOPDEV=$2
5IMAGE_FILE=exfat.img
6FSCK_PROG=fsck.exfat
7FSCK_PROG_2=fsck.exfat
8FSCK_OPTS="-y -s"
9PASS_COUNT=0
10
11cleanup() {
12	echo ""
13	echo "Passed ${PASS_COUNT} of ${TEST_COUNT}"
14	if [ ${PASS_COUNT} -ne ${TEST_COUNT} ]; then
15		exit 1
16	else
17		exit 0
18	fi
19}
20
21if [ $# -eq 0 ]; then
22	TESTCASE_DIRS=$(find . -mindepth 1 -maxdepth 1 -type d)
23	TEST_COUNT=$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)
24else
25	TESTCASE_DIRS=$@
26	TEST_COUNT=$#
27fi
28
29for TESTCASE_DIR in $TESTCASE_DIRS; do
30	if [ ! -e "${TESTCASE_DIR}/${IMAGE_FILE}.tar.xz" ]; then
31		TEST_COUNT=$((TEST_COUNT - 1))
32		continue
33	fi
34
35	echo "Running ${TESTCASE_DIR}"
36	echo "-----------------------------------"
37
38	# Set up image file as loop device
39	tar -C . -xf "${TESTCASE_DIR}/${IMAGE_FILE}.tar.xz"
40	if [ "$NEED_LOOPDEV" ]; then
41		DEV_FILE=$(losetup -f "${IMAGE_FILE}" --show)
42	else
43		DEV_FILE=$IMAGE_FILE
44	fi
45
46	# Run fsck for repair
47	$FSCK_PROG $FSCK_OPTS "$DEV_FILE"
48	if [ $? -ne 1 ] && [ $? -ne 0 ]; then
49		echo ""
50		echo "Failed to repair ${TESTCASE_DIR}"
51		if [ "$NEED_LOOPDEV" ]; then
52			losetup -d "${DEV_FILE}"
53		fi
54		cleanup
55	fi
56
57	echo ""
58	# Run fsck again
59	$FSCK_PROG_2 "$DEV_FILE"
60	if [ $? -ne 0 ]; then
61		echo ""
62		echo "Failed, corrupted ${TESTCASE_DIR}"
63		if [ "$NEED_LOOPDEV" ]; then
64			losetup -d "${DEV_FILE}"
65		fi
66		cleanup
67	fi
68
69	echo ""
70	echo "Passed ${TESTCASE_DIR}"
71	PASS_COUNT=$((PASS_COUNT + 1))
72
73	if [ "$NEED_LOOPDEV" ]; then
74		losetup -d "${DEV_FILE}"
75	fi
76done
77cleanup
78