And now, for something entirely different...
Doing a simple wrap test on a serial port should be a no-brainer in bash, but I could not find all the pieces in one place, so I assembled the pieces into a short bash script. This is not very stressful and, I am sure, could be improved, but it gets the basic job done: send a string, verify it wrapped and was received correctly, rinse and repeat.
Tip: View page source to get a better formatted copy.
#!/bin/bash
#
# Serial wrap test
#
PORT=$1
LOOPS=0
TIMEOUTS=0
MISCOMPARES=0
# Receive the wrapped string
# \param $1 - port device
# \param $2 - length of string that we should receive
#
# It works without knowing the length, but knowing the length
# helps re-synchronize.
#
function receive {
unset recv
read -n $2 recv < $1
echo ${recv} > $3
}
stty -F ${PORT} sane speed 115200 > /dev/null
while [ true ] ; do
send=`date +"%c %N"`
receive ${PORT} ${#send} $$.tmp &
sleep 0.1 # Block ourselves to let the receive run
echo ${send} > ${PORT}
sleep 0.5 # let the send complete
if [ -f $$.tmp ] ; then
recv=`cat $$.tmp`
rm $$.tmp
if [ "${send}" != "${recv}" ] ; then
echo -e "\n${send} != ${recv}"
let "MISCOMPARES += 1"
fi
else
let "TIMEOUTS += 1"
echo -e "\nTimeout"
fi
let "LOOPS += 1"
echo -ne "Loops ${LOOPS} Timeouts ${TIMEOUTS} Miscompares ${MISCOMPARES}\r"
done