|
13 | 13 | from pathlib import Path |
14 | 14 | import shutil |
15 | 15 | import json |
| 16 | +import tempfile |
16 | 17 |
|
17 | 18 | from fprime_gds.common.models.serialize.time_type import TimeType |
18 | 19 |
|
|
21 | 22 | from fprime_gds.common.history.test import TestHistory |
22 | 23 | from fprime_gds.common.logger.test_logger import TestLogger |
23 | 24 | from fprime_gds.common.testing_fw import predicates |
| 25 | +from fprime_gds.common.tools.seqgen import SeqGenException, generateSequence |
24 | 26 | from fprime_gds.common.utils.event_severity import EventSeverity |
25 | 27 |
|
26 | 28 |
|
@@ -1158,11 +1160,53 @@ def uplink_file(self, file_path, destination=None): |
1158 | 1160 |
|
1159 | 1161 | Args: |
1160 | 1162 | file_path: the path to the file to upload |
| 1163 | + destination: the destination path for the uploaded file |
1161 | 1164 | """ |
1162 | 1165 | uplink_file = Path(self.pipeline.up_store) / Path(file_path).name |
1163 | 1166 | shutil.copy2(file_path, uplink_file) |
1164 | 1167 | self.pipeline.files.uplinker.enqueue(str(uplink_file), destination) |
1165 | 1168 |
|
| 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 | + |
1166 | 1210 | ###################################################################################### |
1167 | 1211 | # History Searches |
1168 | 1212 | ###################################################################################### |
|
0 commit comments