2022-05-21 23:04:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-06-19 13:55:50 +00:00
|
|
|
"""
|
|
|
|
Test connect frame commands over a high quality simulated audio channel.
|
|
|
|
|
|
|
|
Near end-to-end test for sending / receiving connection control frames through the
|
2023-10-22 08:00:37 +00:00
|
|
|
Modem and modem and back through on the other station. Data injection initiates from the
|
|
|
|
queue used by the daemon process into and out of the Modem.
|
2022-06-19 13:55:50 +00:00
|
|
|
|
|
|
|
Can be invoked from CMake, pytest, coverage or directly.
|
|
|
|
|
2023-10-22 08:00:37 +00:00
|
|
|
Uses util_modem_I[RS]S.py in separate process to perform the data transfer.
|
2022-06-19 14:04:46 +00:00
|
|
|
|
|
|
|
@author: DJ2LS, N2KIQ
|
2022-06-19 13:55:50 +00:00
|
|
|
"""
|
2022-05-21 23:04:17 +00:00
|
|
|
|
|
|
|
import multiprocessing
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2022-06-12 18:20:49 +00:00
|
|
|
import log_handler
|
2022-06-03 20:01:50 +00:00
|
|
|
import pytest
|
2022-06-12 18:20:49 +00:00
|
|
|
import structlog
|
2022-05-21 23:04:17 +00:00
|
|
|
|
2022-06-09 22:23:18 +00:00
|
|
|
try:
|
2023-10-22 08:00:37 +00:00
|
|
|
import test.util_modem_IRS as irs
|
|
|
|
import test.util_modem_ISS as iss
|
2022-06-09 22:23:18 +00:00
|
|
|
except ImportError:
|
2023-10-22 08:00:37 +00:00
|
|
|
import util_modem_IRS as irs
|
|
|
|
import util_modem_ISS as iss
|
2022-06-09 22:23:18 +00:00
|
|
|
|
2022-05-21 23:04:17 +00:00
|
|
|
|
2022-05-29 13:27:26 +00:00
|
|
|
# This test is currently a little inconsistent.
|
2022-06-15 23:24:47 +00:00
|
|
|
@pytest.mark.parametrize("command", ["CONNECT"])
|
2022-06-12 23:47:53 +00:00
|
|
|
@pytest.mark.flaky(reruns=2)
|
2023-10-22 08:00:37 +00:00
|
|
|
def test_modem(command, tmp_path):
|
|
|
|
log_handler.setup_logging(filename=tmp_path / "test_modem", level="INFO")
|
|
|
|
log = structlog.get_logger("test_modem")
|
2022-05-21 23:04:17 +00:00
|
|
|
|
2022-06-12 18:20:49 +00:00
|
|
|
iss_proc = multiprocessing.Process(target=iss.t_arq_iss, args=[command, tmp_path])
|
|
|
|
irs_proc = multiprocessing.Process(target=irs.t_arq_irs, args=[command, tmp_path])
|
|
|
|
log.debug("Starting threads.")
|
2022-05-29 13:27:26 +00:00
|
|
|
iss_proc.start()
|
|
|
|
irs_proc.start()
|
2022-05-21 23:04:17 +00:00
|
|
|
|
2022-05-29 13:27:26 +00:00
|
|
|
time.sleep(12)
|
2022-05-21 23:04:17 +00:00
|
|
|
|
2022-06-12 18:20:49 +00:00
|
|
|
log.debug("Terminating threads.")
|
2022-05-29 13:27:26 +00:00
|
|
|
irs_proc.terminate()
|
|
|
|
iss_proc.terminate()
|
|
|
|
irs_proc.join()
|
|
|
|
iss_proc.join()
|
2022-05-21 23:04:17 +00:00
|
|
|
|
|
|
|
for idx in range(2):
|
|
|
|
try:
|
2022-06-12 18:20:49 +00:00
|
|
|
os.unlink(tmp_path / f"hfchannel{idx+1}")
|
2022-05-21 23:04:17 +00:00
|
|
|
except FileNotFoundError as fnfe:
|
2022-06-12 18:20:49 +00:00
|
|
|
log.debug(f"Unlinking pipe: {fnfe}")
|
2022-05-21 23:04:17 +00:00
|
|
|
|
2022-06-10 20:54:20 +00:00
|
|
|
assert iss_proc.exitcode in [0, -15], f"Transmit side failed test. {iss_proc}"
|
|
|
|
assert irs_proc.exitcode in [0, -15], f"Receive side failed test. {irs_proc}"
|
2022-05-21 23:04:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# Run pytest with the current script as the filename.
|
|
|
|
ecode = pytest.main(["-s", "-v", sys.argv[0]])
|
|
|
|
if ecode == 0:
|
|
|
|
print("errors: 0")
|
|
|
|
else:
|
|
|
|
print(ecode)
|