Skip to content

Commit

Permalink
spacepackets update
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Apr 23, 2024
1 parent 154d806 commit 4a88306
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 98 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Starting from v4.0.0, this project adheres to [Semantic Versioning](http://semve

# [unreleased]

# [v8.0.0rc2] 2024-04-22
# [v8.0.0rc2] 2024-04-23

- Bumped `spacepackets` to release range >=0.24, <0.25.
- Bumped `cfdp-py` to v0.1.1.

## Changed

Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ dependencies = [
"Deprecated~=1.2",
"pyserial~=3.5",
"dle-encoder~=0.2.3",
"spacepackets~=0.23.0",
"cfdp-py~=0.1.0"
"spacepackets>=0.24.0, <0.25",
"cfdp-py~=0.1.1",
# "spacepackets @ git+https://github.com/us-irs/spacepackets-py@main"
]

Expand All @@ -56,7 +56,7 @@ test = [
[tool.setuptools.packages]
find = {}

[tool.ruff]
[tool.ruff.lint]
ignore = ["E501"]
[tool.ruff.extend-per-file-ignores]
[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = ["F401"]
2 changes: 1 addition & 1 deletion release-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The steps shown here are for Ubuntu/MacOS.
with date and new `unreleased`section.
4. Run tests with `pytest .`
5. Run auto-formatter with `black .`
6. Run linter with `ruff .`
6. Run linter with `ruff check .`
7. Wait for CI/CD results. This also runs the tests on different
operating systems

Expand Down
2 changes: 1 addition & 1 deletion tests/com/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_dummy_if(self):
dummy_com_if.initialize()
self.assertTrue(dummy_com_if.initialized)
self.assertFalse(dummy_com_if.data_available())
dummy_com_if.send(PusTelecommand(service=17, subservice=1).pack())
dummy_com_if.send(PusTelecommand(apid=0x02, service=17, subservice=1).pack())
self.assertTrue(dummy_com_if.data_available())
replies = dummy_com_if.receive()
# Full verification set (acceptance, start and completion) and ping reply
Expand Down
2 changes: 1 addition & 1 deletion tests/com/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self) -> None:
self.base_data = bytes([0, 1, 2, 3])
self.ping_cmd = PusTelecommand(service=17, subservice=1, apid=0x22)
self.ping_reply = PusTelemetry(
service=17, subservice=2, apid=0x22, time_provider=None
service=17, subservice=2, apid=0x22, timestamp=bytes()
)
self.tcp_client = TcpSpacePacketsClient(
"tcp",
Expand Down
2 changes: 1 addition & 1 deletion tests/tc/test_srv20.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
self.boolean_param = create_scalar_boolean_parameter(
object_id=self.obj_id, domain_id=1, unique_id=5, parameter=True
)
self.tc = create_load_param_cmd(self.boolean_param)
self.tc = create_load_param_cmd(0x05, self.boolean_param)

def test_basic(self):
# 12 bytes of generic parameter header + 1 byte parameter itself
Expand Down
19 changes: 12 additions & 7 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@


class TcHandlerMock(TcHandlerBase):
def __init__(self):
def __init__(self, apid: int):
super().__init__()
self.apid = apid
self.is_feed_cb_valid = False
self.feed_cb_call_count = 0
self.feed_cb_def_proc_count = 0
Expand Down Expand Up @@ -56,22 +57,23 @@ def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper):
self.send_cb_cmd_path_arg = def_info.cmd_path
if def_info.cmd_path == "/ping":
self.queue_helper.add_pus_tc(
PusTelecommand(service=17, subservice=1)
PusTelecommand(apid=self.apid, service=17, subservice=1)
)
elif def_info.cmd_path == "/event":
self.queue_helper.add_pus_tc(
PusTelecommand(service=17, subservice=1)
PusTelecommand(apid=self.apid, service=17, subservice=1)
)
self.queue_helper.add_pus_tc(
PusTelecommand(service=5, subservice=1)
PusTelecommand(apid=self.apid, service=5, subservice=1)
)


class TestBackend(TestCase):
def setUp(self) -> None:
self.com_if = DummyComIF()
self.tm_listener = MagicMock(specs=CcsdsTmListener)
self.tc_handler = TcHandlerMock()
self.apid = 0x06
self.tc_handler = TcHandlerMock(self.apid)
self.backend = CcsdsTmtcBackend(
tc_mode=TcMode.IDLE,
tm_mode=TmMode.IDLE,
Expand Down Expand Up @@ -130,7 +132,9 @@ def test_basic_ops(self):
self.assertEqual(self.tc_handler.send_cb_call_args.com_if, self.com_if)
cast_wrapper = self.tc_handler.send_cb_call_args.entry
pus_entry = cast_wrapper.to_pus_tc_entry()
self.assertEqual(pus_entry.pus_tc, PusTelecommand(service=17, subservice=1))
self.assertEqual(
pus_entry.pus_tc, PusTelecommand(apid=self.apid, service=17, subservice=1)
)
self.backend.close_com_if()
self.assertFalse(self.com_if.is_open())

Expand Down Expand Up @@ -190,5 +194,6 @@ def _check_tc_req_recvd(self, service: int, subservice: int):
cast_wrapper = self.tc_handler.send_cb_call_args.entry
pus_entry = cast_wrapper.to_pus_tc_entry()
self.assertEqual(
pus_entry.pus_tc, PusTelecommand(service=service, subservice=subservice)
pus_entry.pus_tc,
PusTelecommand(apid=self.apid, service=service, subservice=subservice),
)
4 changes: 3 additions & 1 deletion tests/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# TODO: Use temp files to test loggers?
class TestPrintersLoggers(TestCase):
def setUp(self):
self.apid = 0x07
self.log_path = Path(LOG_DIR)
if not self.log_path.exists():
self.log_path.mkdir()
Expand All @@ -34,8 +35,9 @@ def test_pus_loggers(self):
pus_tc = create_service_17_ping_command()
raw_tmtc_log.log_tc(pus_tc)
pus_tm = Service1Tm(
apid=self.apid,
subservice=Subservice.TM_START_SUCCESS,
time_provider=CdsShortTimestamp.from_now(),
timestamp=CdsShortTimestamp.now().pack(),
verif_params=VerificationParams(
req_id=RequestId(pus_tc.packet_id, pus_tc.packet_seq_control)
),
Expand Down
51 changes: 33 additions & 18 deletions tests/test_pus_verif_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

class TestPusVerifLog(TestCase):
def setUp(self) -> None:
self.apid = 0x02
self.log_file_name = RegularTmtcLogWrapper.get_current_tmtc_file_name()
self.logger = logging.getLogger(__name__)
add_colorlog_console_logger(self.logger)
Expand All @@ -39,11 +40,12 @@ def test_console_log_success_without_colors(self):

def _test_success(self, wrapper: VerificationWrapper):
verificator = wrapper.verificator
tc = PusTelecommand(service=17, subservice=1, seq_count=0)
tc = PusTelecommand(apid=self.apid, service=17, subservice=1, seq_count=0)
verificator.add_tc(tc)
srv_1_tm = create_acceptance_success_tm(
tc, time_provider=CdsShortTimestamp.empty()
apid=self.apid, pus_tc=tc, timestamp=CdsShortTimestamp.empty().pack()
)
empty_stamp = CdsShortTimestamp.empty().pack()

def generic_checks():
self.assertTrue("acc" in cm.output[0])
Expand All @@ -59,7 +61,9 @@ def generic_checks():
f"Request ID {srv_1_tm.tc_req_id.as_u32():#08x}" in cm.output[0]
)
generic_checks()
srv_1_tm = create_start_success_tm(tc, time_provider=CdsShortTimestamp.empty())
srv_1_tm = create_start_success_tm(
apid=self.apid, pus_tc=tc, timestamp=empty_stamp
)
res = verificator.add_tm(srv_1_tm)
with self.assertLogs(self.logger) as cm:
wrapper.log_to_console(srv_1_tm, res)
Expand All @@ -69,7 +73,10 @@ def generic_checks():
)
generic_checks()
srv_1_tm = create_step_success_tm(
tc, StepId.with_byte_size(1, 1), time_provider=CdsShortTimestamp.empty()
apid=self.apid,
pus_tc=tc,
step_id=StepId.with_byte_size(1, 1),
timestamp=empty_stamp,
)
res = verificator.add_tm(srv_1_tm)
with self.assertLogs(self.logger) as cm:
Expand All @@ -80,7 +87,7 @@ def generic_checks():
)
generic_checks()
srv_1_tm = create_completion_success_tm(
tc, time_provider=CdsShortTimestamp.empty()
apid=self.apid, pus_tc=tc, timestamp=empty_stamp
)
res = verificator.add_tm(srv_1_tm)
with self.assertLogs(self.logger) as cm:
Expand All @@ -102,12 +109,13 @@ def test_console_log_acc_failure_without_colors(self):

def _test_acc_failure(self, wrapper: VerificationWrapper):
verificator = wrapper.verificator
tc = PusTelecommand(service=17, subservice=1, seq_count=1)
tc = PusTelecommand(apid=self.apid, service=17, subservice=1, seq_count=1)
verificator.add_tc(tc)
srv_1_tm = create_acceptance_failure_tm(
tc,
apid=self.apid,
pus_tc=tc,
failure_notice=FailureNotice(code=ErrorCode(pfc=8, val=1), data=bytes()),
time_provider=CdsShortTimestamp.empty(),
timestamp=CdsShortTimestamp.empty().pack(),
)
res = verificator.add_tm(srv_1_tm)
# TODO: Use self.assertLogs here instead
Expand All @@ -116,20 +124,22 @@ def _test_acc_failure(self, wrapper: VerificationWrapper):
def test_console_log_start_failure(self):
wrapper = VerificationWrapper(PusVerificator(), self.logger, None)
verificator = wrapper.verificator
tc = PusTelecommand(service=17, subservice=1, seq_count=2)
tc = PusTelecommand(apid=self.apid, service=17, subservice=1, seq_count=2)
verificator.add_tc(tc)
srv_1_tm = create_acceptance_failure_tm(
tc,
apid=self.apid,
pus_tc=tc,
failure_notice=FailureNotice(code=ErrorCode(pfc=8, val=1), data=bytes()),
time_provider=CdsShortTimestamp.empty(),
timestamp=CdsShortTimestamp.empty().pack(),
)
res = verificator.add_tm(srv_1_tm)
# TODO: Use self.assertLogs here instead
wrapper.log_to_console(srv_1_tm, res)
srv_1_tm = create_start_failure_tm(
tc,
apid=self.apid,
pus_tc=tc,
failure_notice=FailureNotice(code=ErrorCode(pfc=8, val=1), data=bytes()),
time_provider=CdsShortTimestamp.empty(),
timestamp=CdsShortTimestamp.empty().pack(),
)
res = verificator.add_tm(srv_1_tm)
# TODO: Use self.assertLogs here instead
Expand All @@ -139,23 +149,28 @@ def test_file_logger(self):
tmtc_logger = RegularTmtcLogWrapper(file_name=self.log_file_name)
wrapper = VerificationWrapper(PusVerificator(), None, tmtc_logger.logger)
verificator = wrapper.verificator
tc = PusTelecommand(service=17, subservice=1, seq_count=0)
tc = PusTelecommand(apid=self.apid, service=17, subservice=1, seq_count=0)
verificator.add_tc(tc)
srv_1_tm = create_acceptance_success_tm(
tc, time_provider=CdsShortTimestamp.empty()
apid=self.apid, pus_tc=tc, timestamp=CdsShortTimestamp.empty().pack()
)
res = verificator.add_tm(srv_1_tm)
wrapper.log_to_file(srv_1_tm, res)
srv_1_tm = create_start_success_tm(tc, time_provider=CdsShortTimestamp.empty())
srv_1_tm = create_start_success_tm(
apid=self.apid, pus_tc=tc, timestamp=CdsShortTimestamp.empty().pack()
)
res = verificator.add_tm(srv_1_tm)
wrapper.log_to_file(srv_1_tm, res)
srv_1_tm = create_step_success_tm(
tc, StepId.with_byte_size(1, 1), time_provider=CdsShortTimestamp.empty()
apid=self.apid,
pus_tc=tc,
step_id=StepId.with_byte_size(1, 1),
timestamp=CdsShortTimestamp.empty().pack(),
)
res = verificator.add_tm(srv_1_tm)
wrapper.log_to_file(srv_1_tm, res)
srv_1_tm = create_completion_success_tm(
tc, time_provider=CdsShortTimestamp.empty()
apid=self.apid, pus_tc=tc, timestamp=CdsShortTimestamp.empty().pack()
)
res = verificator.add_tm(srv_1_tm)
wrapper.log_to_file(srv_1_tm, res)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class TestTcQueue(TestCase):
def setUp(self) -> None:
self.apid = 0x11
self.queue_wrapper = QueueWrapper(
info=TreeCommandingProcedure.empty(), queue=deque()
)
Expand All @@ -33,7 +34,7 @@ def setUp(self) -> None:
default_pus_apid=None,
pus_verificator=None,
)
self.pus_cmd = PusTelecommand(service=17, subservice=1)
self.pus_cmd = PusTelecommand(apid=self.apid, service=17, subservice=1)

def test_wait_entry(self):
self.queue_helper.add_wait(timedelta(seconds=2))
Expand Down Expand Up @@ -71,7 +72,7 @@ def test_faulty_cast(self):
cast_wrapper.to_wait_entry()

def test_multi_entry(self):
pus_cmd = PusTelecommand(service=17, subservice=1)
pus_cmd = PusTelecommand(apid=self.apid, service=17, subservice=1)
self.queue_helper.add_pus_tc(pus_cmd)
self.assertEqual(len(self.queue_wrapper.queue), 1)
self.queue_helper.add_log_cmd("Test String")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_seq_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class TestSendReceive(TestCase):
def setUp(self) -> None:
self.apid = 0x22
self.queue_wrapper = QueueWrapper.empty()
self.queue_helper = DefaultPusQueueHelper(
self.queue_wrapper,
Expand Down Expand Up @@ -110,7 +111,7 @@ def test_with_wait_entry(self):
def test_interpacket_delay(self):
delay_ms = 20
inter_packet_delay = timedelta(milliseconds=delay_ms)
ping_cmd = PusTelecommand(service=17, subservice=1)
ping_cmd = PusTelecommand(apid=self.apid, service=17, subservice=1)
self.queue_helper.add_pus_tc(ping_cmd)
self.queue_helper.add_packet_delay_ms(delay_ms)
self.queue_helper.add_ccsds_tc(ping_cmd.to_space_packet())
Expand Down
18 changes: 15 additions & 3 deletions tests/test_tm_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def handle_tm(self, packet: bytes, user_args: any):


class TestTmHandler(TestCase):
def setUp(self) -> None:
self.apid = 0x33

def test_basic(self):
tm_handler = ApidHandler(0x01)
com_if = MagicMock(specs=ComInterface)
Expand All @@ -39,10 +42,16 @@ def test_basic(self):
self.assertEqual(handled_packets, 0)
self.assertTrue(ccsds_handler.has_apid(0x01))
tm0_raw = PusTelemetry(
service=1, subservice=12, apid=0x01, time_provider=CdsShortTimestamp.empty()
service=1,
subservice=12,
apid=0x01,
timestamp=CdsShortTimestamp.empty().pack(),
).pack()
tm1_raw = PusTelemetry(
service=5, subservice=1, apid=0x01, time_provider=CdsShortTimestamp.empty()
service=5,
subservice=1,
apid=0x01,
timestamp=CdsShortTimestamp.empty().pack(),
).pack()
com_if.receive.return_value = [tm0_raw]
handled_packets = tm_listener.operation(com_if)
Expand All @@ -58,7 +67,10 @@ def test_basic(self):
self.assertEqual(tm_handler.packet_queue.pop(), tm0_raw)
self.assertEqual(tm_handler.packet_queue.pop(), tm1_raw)
unknown_apid = PusTelemetry(
service=1, subservice=12, apid=0x02, time_provider=CdsShortTimestamp.empty()
service=1,
subservice=12,
apid=0x02,
timestamp=CdsShortTimestamp.empty().pack(),
).pack()
com_if.receive.return_value = [unknown_apid]
handled_packets = tm_listener.operation(com_if)
Expand Down
8 changes: 5 additions & 3 deletions tests/tm/test_srv1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import struct
from unittest import TestCase

from spacepackets.ecss import RequestId, PusTelecommand, PacketFieldU8
from spacepackets.ecss import RequestId, PusTc, PacketFieldU8
from spacepackets.ecss.pus_1_verification import (
Service1Tm,
Subservice,
Expand All @@ -13,7 +13,8 @@

class TestVerif1TmWrapper(TestCase):
def setUp(self) -> None:
self.ping_tc = PusTelecommand(service=17, subservice=1)
self.apid = 0x01
self.ping_tc = PusTc(apid=self.apid, service=17, subservice=1)
pass

def test_basic(self):
Expand All @@ -25,8 +26,9 @@ def test_basic(self):
code=PacketFieldU8(1), data=context_param_1 + context_param_2
)
service_1_tm = Service1Tm(
apid=self.apid,
subservice=Subservice.TM_START_FAILURE,
time_provider=None,
timestamp=bytes(),
verif_params=VerificationParams(
step_id=None,
req_id=RequestId.from_pus_tc(self.ping_tc),
Expand Down
Loading

0 comments on commit 4a88306

Please sign in to comment.