blob: 33bd1792e23ed5806da4313520d395eae5282502 [file] [log] [blame]
#!/system/bin/sh
FAIL_CODE=32767
function do_test() {
# parameters: sizeK vfat_arg id
UUT=/tmp/$$.disk
MPT=/tmp/$$
DEV=/dev/block/loop7
step=0
rc=0
while true; do
step=1
echo "Creating disk of size $1..." | tee -a $LOG
dd if=/dev/zero of=$UUT bs=1024 count=$1 >> $LOG
rc=$?
if [ $rc -ne 0 ]; then
echo "Problems with dd" | tee -a $LOG
break
fi
step=2
echo "Setting up loop device $DEV"
losetup $DEV $UUT >> $LOG
rc=$?
if [ $rc -ne 0 ]; then
echo "Problems setting up loop device" | tee -a $LOG
break
fi
step=3
echo "Running mkfs.vfat..." | tee -a $LOG
mkfs.vfat $2 -i $3 $DEV >> $LOG
rc=$?
if [ $rc -ne 0 ]; then
echo "Problems formatting loop device" | tee -a $LOG
break
fi
step=4
mkdir -p $MPT
step=5
# argument "-t vfat" here is necessary, busybox's mount requires it
echo "Mounting device" | tee -a $LOG
mount -t vfat $DEV $MPT | tee -a $LOG
rc=$?
if [ $rc -ne 0 ]; then
echo "Could not mount device" | tee -a $LOG
break
fi
step=6
echo "Getting volume ID" | tee -a $LOG
v1=`/system/bin/vfat-volid --path $MPT -i`
rc=$?
if [ $rc -ne 0 ]; then
echo "Error when getting volume ID" | tee -a $LOG
break
fi
step=7
echo "Got volume IDs $v1 and $3, should be identical" | tee -a $LOG
if [ x$v1 != x$3 ]; then
rc=$FAIL_CODE # indicate fail
fi
break
done
# clean up
[ $step -gt 5 ] && umount $MPT
[ $step -gt 4 ] && rmdir $MPT
[ $step -gt 2 ] && losetup -d $DEV
[ $step -gt 1 ] && rm $UUT
return $rc
}
echo "Starting"
mount -o rw,remount /
mkdir /tmp
LOG=/dev/null
if [ $# -ge 1 ]; then
LOG=$1
fi
for FTYPE in 12 16 32; do
for SIZE in 360 1024 102400; do
for ID in 0x12347900 0x00000000 0xDEADBEEF 0xFFFFFDFD; do
do_test "$SIZE" "-F $FTYPE" "$ID"
rc=$?
if [ $rc -ne 0 ]; then
echo -e "### FAIL code = $rc" | tee -a $LOG
echo -e "[vfat_${FTYPE}_${SIZE}_$ID]: test failed"
else
echo -e "### PASS" | tee -a $LOG
echo -e "[vfat_${FTYPE}_${SIZE}_$ID]: test passed"
fi
echo -e "(FTYPE=$FTYPE, SIZE=$SIZE, ID=$ID)\n" | tee -a $LOG
done
done
done