blob: 8032bd37bd0a2efa116ac7c55aafeebac3f36977 [file] [log] [blame]
#!/bin/sh
set -e
. $(dirname $0)/Config.sh
. $(dirname $0)/utils.sh
error=
cleanup()
{
umount /mnt || echo but no matter
}
usbstick()
{
file=/mnt/diag_test_file
want=4289204007
umount /mnt || echo but no matter
run fdisk -l /dev/sdb
run mount -t vfat /dev/sdb1 /mnt
run rm -f $file
echo "This file must have these exact letters, please do not modify" > $file
sync
run umount /mnt
run mount -t vfat /dev/sdb1 /mnt
cksum=$(cksum $file)
sum=${cksum%% *}
if [ "$sum" != $want ]; then
error="cksum mismatch, wanted $want, got '$sum'"
return 1
fi
run rm -f $file
run umount /mnt
return 0
}
usb3disk()
{
# do a read test from the disk, expect at least 40 MB/sec
d=/dev/sdb
if [ ! -e $d ]; then
error="/dev/sdb not found, is USB disk connected?"
return 1
fi
# this runs dd and prints xfer rate several times as the 1st dd runs
f=/tmp/dd1
dd if=$d bs=65536 count=10000 2>$f |
for n in `seq 1 10`; do dd bs=65536 count=1000 of=/dev/null; done
# eg: 65536000 bytes transferred in 1.522 secs (43059132 bytes/sec)
dd1=$(tail -n 1 /tmp/dd1)
dd1=${dd1%% bytes/sec*}
dd1=${dd1##* secs (}
if [ "$dd1" -lt $usb_min_bps ]; then
error="wanted $usb_min_bps b/s or more, got $dd1 b/s"
return 1
fi
result="$dd1 bytes/sec"
return 0
}
case "$1" in
diag | quick)
if usb3disk; then
echo PASS $result
else
echo FAIL "$error"
fi
;;
*)
echo "Usage: $0 {diag|quick}"
exit 1
esac