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