File: self-test

package info (click to toggle)
minimodem 0.24-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, stretch, trixie
  • size: 856 kB
  • ctags: 231
  • sloc: ansic: 2,962; sh: 1,537; makefile: 45
file content (88 lines) | stat: -rwxr-xr-x 1,461 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash

MINIMODEM="${MINIMODEM-./minimodem}"
[ -f "$MINIMODEM" ] || {
    MINIMODEM="../src/minimodem"
    [ -f "$MINIMODEM" ] || {
	echo "E: cannot find minimodem in ./ or ../src/" 1>&2
	exit 1
    }
}

test_perfect=0
[ "$1" = "-P" ] && {
    test_perfect=1
    shift
}

[ $# -ge 2 ] || {
    echo "usage: self-test [-P] textfile minimodem_tx_args [ -- minimodem_rx_args ]" 1>&2
    exit 1
}
textfile="$1"
shift

minimodem_tx_args="$1"
shift
while [ $# -gt 0 ]
do
    [ "$1" = "--" ] && {
	shift
	break
    }
    minimodem_tx_args="$minimodem_tx_args $1"
    shift
done
if [ $# -gt 0 ]
then
    minimodem_rx_args="$*"
else
    minimodem_rx_args="$minimodem_tx_args"
fi


TMPF="/tmp/minimodem-test-$$"
trap "rm -f $TMPF.*" 0

set -e
#echo
#echo "$MINIMODEM --tx ... $minimodem_tx_args"
#echo "$MINIMODEM --rx ... $minimodem_rx_args"

$MINIMODEM --tx --file $TMPF.wav $minimodem_tx_args < "$textfile"

# cp $TMPF.wav /tmp/x.wav

$MINIMODEM --rx --file $TMPF.wav $minimodem_rx_args \
	> $TMPF.out 2> $TMPF.err || {
    cat $TMPF.err
    exit 1
}

cmp "$textfile" $TMPF.out

{
    read xlitcarrier
    read xlitblankline
    read xlithashes xlitnocarrier stats
    stats="${stats% ###}"
} < $TMPF.err


result="OK     "
exitcode=0

[ $test_perfect -eq 1 ] && {
    match="confidence=inf .* (rate perfect)"
    if grep -q "$match" $TMPF.err
    then
	result="PERFECT"
    else
	result="IMPERFECT"
	exitcode=1
    fi
}

echo -e "$result $stats"

exit $exitcode