From ef4e0e2aab30f45c793ef904b6e82428e40b2bea Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 28 Aug 2014 18:04:05 +0300 Subject: [PATCH] test receiver error --- amodem/recv.py | 3 +++ tests/test_full.py | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/amodem/recv.py b/amodem/recv.py index ca185b6..ea4c530 100644 --- a/amodem/recv.py +++ b/amodem/recv.py @@ -256,10 +256,12 @@ def main(args): size = 0 signal, amplitude = detect(signal, config.Fc) bits = receive(signal, modem.freqs, gain=1.0/amplitude) + success = False try: for chunk in decode(bits): args.output.write(chunk) size = size + len(chunk) + success = True except Exception: log.exception('Decoding failed') @@ -279,6 +281,7 @@ def main(args): '$F_c = {} Hz$'.format(freq)) pylab.show() + return success def constellation(y, symbols, title): diff --git a/tests/test_full.py b/tests/test_full.py index c65599f..f4d13a7 100644 --- a/tests/test_full.py +++ b/tests/test_full.py @@ -19,7 +19,7 @@ class Args(object): self.__dict__.update(kwargs) -def run(size, chan=None, df=0): +def run(size, chan=None, df=0, success=True): tx_data = os.urandom(size) tx_audio = BytesIO() send.main(Args(silence_start=1, silence_stop=1, @@ -38,16 +38,23 @@ def run(size, chan=None, df=0): rx_audio = BytesIO(data) rx_data = BytesIO() - recv.main(Args(skip=0, input=rx_audio, output=rx_data)) + result = recv.main(Args(skip=0, input=rx_audio, output=rx_data)) rx_data = rx_data.getvalue() - assert rx_data == tx_data + assert result == success + if success: + assert rx_data == tx_data def test_small(): run(1024, chan=lambda x: x) +def test_error(): + skip = 1 * send.config.Fs # remove trailing silence + run(1024, chan=lambda x: x[:-skip], success=False) + + def test_frequency_error(): for ppm in [0.1, 1, 10]: for sign in [+1, -1]: @@ -78,4 +85,3 @@ def test_medium_noise(): def test_large(): run(54321, chan=lambda x: x) -