2022-05-21 23:04:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
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:
|
|
|
|
import test.util_tnc_IRS as irs
|
|
|
|
import test.util_tnc_ISS as iss
|
|
|
|
except ImportError:
|
|
|
|
import util_tnc_IRS as irs
|
|
|
|
import util_tnc_ISS as iss
|
|
|
|
|
2022-05-21 23:04:17 +00:00
|
|
|
|
2022-06-07 00:26:41 +00:00
|
|
|
# These do not update sock.SOCKET_QUEUE:
|
|
|
|
# "CONNECT"
|
2022-05-29 13:27:26 +00:00
|
|
|
# This test is currently a little inconsistent.
|
2022-05-21 23:04:17 +00:00
|
|
|
@pytest.mark.parametrize("command", ["CQ", "PING", "BEACON"])
|
2022-06-12 23:47:53 +00:00
|
|
|
@pytest.mark.flaky(reruns=2)
|
2022-06-12 18:20:49 +00:00
|
|
|
def test_tnc(command, tmp_path):
|
|
|
|
log_handler.setup_logging(filename=tmp_path / "test_tnc", level="INFO")
|
|
|
|
log = structlog.get_logger("test_tnc")
|
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)
|