| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
MINIMODEM="${MINIMODEM-./minimodem}" |
| 4 |
[ -f "$MINIMODEM" ] || { |
| 5 |
MINIMODEM="../src/minimodem" |
| 6 |
[ -f "$MINIMODEM" ] || { |
| 7 |
echo "E: cannot find minimodem in ./ or ../src/" 1>&2 |
| 8 |
exit 1 |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
test_perfect=0 |
| 13 |
[ "$1" = "-P" ] && { |
| 14 |
test_perfect=1 |
| 15 |
shift |
| 16 |
} |
| 17 |
|
| 18 |
[ $# -ge 2 ] || { |
| 19 |
echo "usage: self-test [-P] textfile minimodem_tx_args [ -- minimodem_rx_args ]" 1>&2 |
| 20 |
exit 1 |
| 21 |
} |
| 22 |
textfile="$1" |
| 23 |
shift |
| 24 |
|
| 25 |
minimodem_tx_args="$1" |
| 26 |
shift |
| 27 |
while [ $# -gt 0 ] |
| 28 |
do |
| 29 |
[ "$1" = "--" ] && { |
| 30 |
shift |
| 31 |
break |
| 32 |
} |
| 33 |
minimodem_tx_args="$minimodem_tx_args $1" |
| 34 |
shift |
| 35 |
done |
| 36 |
if [ $# -gt 0 ] |
| 37 |
then |
| 38 |
minimodem_rx_args="$*" |
| 39 |
else |
| 40 |
minimodem_rx_args="$minimodem_tx_args" |
| 41 |
fi |
| 42 |
|
| 43 |
|
| 44 |
TMPF="/tmp/minimodem-test-$$" |
| 45 |
trap "rm -f $TMPF.*" 0 |
| 46 |
|
| 47 |
set -e |
| 48 |
#echo |
| 49 |
#echo "$MINIMODEM --tx ... $minimodem_tx_args" |
| 50 |
#echo "$MINIMODEM --rx ... $minimodem_rx_args" |
| 51 |
|
| 52 |
$MINIMODEM --tx --file $TMPF.wav $minimodem_tx_args < "$textfile" |
| 53 |
|
| 54 |
# cp $TMPF.wav /tmp/x.wav |
| 55 |
|
| 56 |
$MINIMODEM --rx --file $TMPF.wav $minimodem_rx_args \ |
| 57 |
> $TMPF.out 2> $TMPF.err || { |
| 58 |
cat $TMPF.err |
| 59 |
exit 1 |
| 60 |
} |
| 61 |
|
| 62 |
cmp "$textfile" $TMPF.out |
| 63 |
|
| 64 |
{ |
| 65 |
read xlitcarrier |
| 66 |
read xlitblankline |
| 67 |
read xlithashes xlitnocarrier stats |
| 68 |
stats="${stats% ###}" |
| 69 |
} < $TMPF.err |
| 70 |
|
| 71 |
|
| 72 |
result="OK " |
| 73 |
exitcode=0 |
| 74 |
|
| 75 |
[ $test_perfect -eq 1 ] && { |
| 76 |
match="confidence=inf .* (rate perfect)" |
| 77 |
if grep -q "$match" $TMPF.err |
| 78 |
then |
| 79 |
result="PERFECT" |
| 80 |
else |
| 81 |
result="IMPERFECT" |
| 82 |
exitcode=1 |
| 83 |
fi |
| 84 |
} |
| 85 |
|
| 86 |
echo -e "$result $stats" |
| 87 |
|
| 88 |
exit $exitcode |