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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
#!/bin/bash
#
# tst_api_demod_check
#
# Setup input and reference data for one of several versions of this test.
# Find the scripts directory
SCRIPTS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Setup common variables
source $SCRIPTS/run_tests_common.sh
# RUN_DIR - Directory where test will be run
RUN_DIR="${UNITTEST_BASE}/test_run/${FULL_TEST_NAME}"
# Call common setup function to make the directory
setup_common "${RUN_DIR}"
# Change to test directory
cd "${RUN_DIR}"
# way of performing a rough comparison of two output speech files that are not exactly the same
function compare_energy() {
energy_ref=$(python3 -c "import numpy as np; x=np.fromfile(\"ref_demod.raw\",dtype=\"int16\").astype(float); print(10*np.log10(np.dot(x,x)))")
energy_target=$(python3 -c "import numpy as np; x=np.fromfile(\"stm_out.raw\",dtype=\"int16\").astype(float); print(10*np.log10(np.dot(x,x)))")
printf "ref energy: %f target energy: %f\n" $energy_ref $energy_target
python3 -c "import sys; sys.exit(1) if abs($energy_ref-$energy_target) < 1 else sys.exit(0)"
if [[ $? -eq 1 ]]; then echo "energy compare OK";
else echo "energy compare BAD";
let Fails=($Fails + 1)
fi
}
#####################################################################
## Test CHECK actions:
declare -i Fails=0
case "${TEST_OPT}" in
700D_plain_test)
echo "Check reference decode"
p1=$(grep '^BER\.*: 0.000' ref_gen.log | wc -l)
p2=$(grep '^Coded BER: 0.000' ref_gen.log | wc -l)
if [[ $p1 -eq 1 && $p2 -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
#
echo "Check target decode"
p1=$(grep '^BER\.*: 0.000' stderr.log | wc -l)
p2=$(grep '^Coded BER: 0.000' stderr.log | wc -l)
if [[ $p1 -eq 1 && $p2 -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
;;
700D_AWGN_test)
echo "Check reference decode"
uber_ref=$(cat ref_gen.log | sed -n "s/^BER.*: \([0-9..]*\).*Tbits.*/\1/p")
cber_ref=$(cat ref_gen.log | sed -n "s/^Coded BER.*: \([0-9..]*\).*Tbits.*/\1/p")
printf "REF uncoded BER: %f coded BER: %f\n" $uber_ref $cber_ref
# As per notes in tst_api_demod_setup, coded BER is unreliable
# for such a short test, so we'll just sanity check the
# reference uncoded BER here. Bash can't compare floats
# .... so use return code of some python script
python3 -c "import sys; sys.exit(1) if $uber_ref < 0.1 else sys.exit(0)"
if [[ $? -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
echo "Check target decode"
uber_target=$(cat stderr.log | sed -n "s/^BER.*: \([0-9..]*\).*Tbits.*/\1/p")
cber_target=$(cat stderr.log | sed -n "s/^Coded BER.*: \([0-9..]*\).*Tbits.*/\1/p")
printf "TARGET uncoded BER: %f coded BER: %f\n" $uber_target $cber_target
python3 -c "import sys; sys.exit(1) if $uber_target < 0.1 and abs($cber_ref-$cber_target) < 0.01 else sys.exit(0)"
if [[ $? -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
;;
700D_AWGN_codec)
# 1/ The two output files sound OK, and when plotted look very
# similar, but they don't match on a sample-sample basis.
# 2/ Suspect some small state difference, or perhaps random
# number generator diverging, sampling codec2_rand() at the
# end of the x86 and stm32 test programs might show up any
# differences.
# 3/ At this stage - we can't make sample by sample automatic
# tests work. However there is value in running the test
# to ensure no asserts are hit and the code doesn't crash
# (e.g. due to an out of memory issues). A simple energy
# comparison is used on the output speech files, which
# will trap any large errors.
# 4/ We can also manually evaluate the output decoded speech by
# listening to the output speech files.
compare_energy;
# make sure execution time stays within bounds
execution_time=mktmp
cat stdout.log | sed -n "s/.*freedv_rx \([0-9..]*\) msecs/\1/p" > $execution_time
python3 -c "import sys; import numpy as np; x=np.loadtxt(\"$execution_time\"); print(\"execution time max:: %5.2f mean: %5.2f ms\" % (np.max(x), np.mean(x))); sys.exit(1) if np.max(x) < 80.0 else sys.exit(0)"
if [[ $? -eq 1 ]]; then echo "execution time OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
;;
700E_plain_test)
echo "Check reference decode"
p1=$(grep '^BER\.*: 0.000' ref_gen.log | wc -l)
p2=$(grep '^Coded BER: 0.000' ref_gen.log | wc -l)
if [[ $p1 -eq 1 && $p2 -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
#
echo "Check target decode"
p1=$(grep '^BER\.*: 0.000' stderr.log | wc -l)
p2=$(grep '^Coded BER: 0.000' stderr.log | wc -l)
if [[ $p1 -eq 1 && $p2 -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
;;
700E_AWGN_test)
echo "Check reference decode"
uber_ref=$(cat ref_gen.log | sed -n "s/^BER.*: \([0-9..]*\).*Tbits.*/\1/p")
cber_ref=$(cat ref_gen.log | sed -n "s/^Coded BER.*: \([0-9..]*\).*Tbits.*/\1/p")
printf "REF uncoded BER: %f coded BER: %f\n" $uber_ref $cber_ref
# As per notes in tst_api_demod_setup, coded BER is unreliable
# for such a short test, so we'll just sanity check the
# reference uncoded BER here. Bash can't compare floats
# .... so use return code of some python script
python3 -c "import sys; sys.exit(1) if $uber_ref < 0.1 else sys.exit(0)"
if [[ $? -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
echo "Check target decode"
uber_target=$(cat stderr.log | sed -n "s/^BER.*: \([0-9..]*\).*Tbits.*/\1/p")
cber_target=$(cat stderr.log | sed -n "s/^Coded BER.*: \([0-9..]*\).*Tbits.*/\1/p")
printf "TARGET uncoded BER: %f coded BER: %f\n" $uber_target $cber_target
python3 -c "import sys; sys.exit(1) if $uber_target < 0.1 and abs($cber_ref-$cber_target) < 0.01 else sys.exit(0)"
if [[ $? -eq 1 ]]; then echo "OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
;;
700E_AWGN_codec)
# 1/ The two output files sound OK, and when plotted look very
# similar, but they don't match on a sample-sample basis.
# 2/ Suspect some small state difference, or perhaps random
# number generator diverging, sampling codec2_rand() at the
# end of the x86 and stm32 test programs might show up any
# differences.
# 3/ At this stage - we can't make sample by sample automatic
# tests work. However there is value in running the test
# to ensure no asserts are hit and the code doesn't crash
# (e.g. due to an out of memory issues). A simple energy
# comparison is used on the output speech files, which
# will trap any large errors.
# 4/ We can also manually evaluate the output decoded speech by
# listening to the output speech files.
compare_energy;
# make sure execution time stays within bounds
execution_time=mktmp
cat stdout.log | sed -n "s/.*freedv_rx \([0-9..]*\) msecs/\1/p" > $execution_time
python3 -c "import sys; import numpy as np; x=np.loadtxt(\"$execution_time\"); print(\"execution time max:: %5.2f mean: %5.2f ms\" % (np.max(x), np.mean(x))); sys.exit(1) if np.max(x) < 80.0 else sys.exit(0)"
if [[ $? -eq 1 ]]; then echo "execution time OK";
else echo "BAD";
let Fails=($Fails + 1)
fi
;;
1600_plain_codec)
compare_energy;
;;
*)
printf "ERROR: invalid test option. Valid options are:\n 700D_plain_test\n 700D_AWGN_test\n 700D_plain_codec\n 1600_plain_codec\n"
exit 1
esac
if (( $Fails == 0 )); then
echo -e "\nTest PASSED"
else
echo -e "\nTest FAILED!"
fi
exit $Fails
|