Skip to content

Commit d3faac8

Browse files
authored
Add uplink_sequence to Integration API (#281)
1 parent a25acb7 commit d3faac8

File tree

1 file changed

+44
-0
lines changed
  • src/fprime_gds/common/testing_fw

1 file changed

+44
-0
lines changed

src/fprime_gds/common/testing_fw/api.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import Path
1414
import shutil
1515
import json
16+
import tempfile
1617

1718
from fprime_gds.common.models.serialize.time_type import TimeType
1819

@@ -21,6 +22,7 @@
2122
from fprime_gds.common.history.test import TestHistory
2223
from fprime_gds.common.logger.test_logger import TestLogger
2324
from fprime_gds.common.testing_fw import predicates
25+
from fprime_gds.common.tools.seqgen import SeqGenException, generateSequence
2426
from fprime_gds.common.utils.event_severity import EventSeverity
2527

2628

@@ -1158,11 +1160,53 @@ def uplink_file(self, file_path, destination=None):
11581160
11591161
Args:
11601162
file_path: the path to the file to upload
1163+
destination: the destination path for the uploaded file
11611164
"""
11621165
uplink_file = Path(self.pipeline.up_store) / Path(file_path).name
11631166
shutil.copy2(file_path, uplink_file)
11641167
self.pipeline.files.uplinker.enqueue(str(uplink_file), destination)
11651168

1169+
def uplink_sequence_and_await_completion(self, sequence_path, destination=None, timeout=10):
1170+
"""
1171+
This function will upload a sequence and wait for its completion, awaiting for the
1172+
FileReceived event.
1173+
1174+
Args:
1175+
sequence_path: the path to the sequence to upload
1176+
destination: the destination path for the uploaded sequence
1177+
timeout: the maximum time to wait for the event
1178+
"""
1179+
self.uplink_sequence(sequence_path, destination)
1180+
self.await_event("FileReceived", timeout=timeout)
1181+
1182+
def uplink_sequence(self, sequence_path, destination=None):
1183+
"""
1184+
This function will upload a sequence to the specified location.
1185+
1186+
Note: this will simply put the sequence file on the outgoing queue. No guarantee
1187+
is made on when the sequence will be delivered. To wait for the completion of
1188+
the sequence uplink, use uplink_sequence_and_await_completion()
1189+
1190+
Args:
1191+
sequence_path: the path to the sequence to upload
1192+
destination: the destination path for the uploaded sequence
1193+
"""
1194+
with tempfile.TemporaryDirectory() as tempdir:
1195+
temp_bin_path = (Path(tempdir) / Path(sequence_path).name).with_suffix(".bin")
1196+
try:
1197+
generateSequence(
1198+
sequence_path, temp_bin_path, self.dictionaries.dictionary_path, 0xFFFF, cont=True
1199+
)
1200+
except OSError as ose:
1201+
msg = f"Failed to generate sequence binary from {sequence_path}: {ose}"
1202+
self.__log(msg, TestLogger.RED)
1203+
raise
1204+
except SeqGenException as exc:
1205+
msg = f"Failed to generate sequence binary from {sequence_path}: {exc}"
1206+
self.__log(msg, TestLogger.RED)
1207+
raise
1208+
self.uplink_file(temp_bin_path, destination)
1209+
11661210
######################################################################################
11671211
# History Searches
11681212
######################################################################################

0 commit comments

Comments
 (0)