Skip to content

Commit 58b16e5

Browse files
committed
Add max-size ping-pong link test
1 parent cd2dae3 commit 58b16e5

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

test/two-board/long_test.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
MAX_TC_FRAME_SIZE = 248
1212
MAX_TC_FRAME_PAYLOAD_SIZE = 241
1313
LONG_FRAME_COUNT = 64
14+
PING_PONG_EXCHANGE_COUNT = 32
15+
PING_PONG_EXCHANGE_MAX_SECONDS = 60.0
1416

1517

1618
def _assert_no_warnings(fprime_test_api):
@@ -40,9 +42,7 @@ def test_link_one_to_two_64_max_tc_frames(
4042
received = b""
4143

4244
for frame in frames:
43-
assert len(frame) == MAX_TC_FRAME_SIZE
44-
assert data_port_one.write(frame) == len(frame)
45-
data_port_one.flush()
45+
data_port_one.write(frame)
4646
received += data_port_two.read_all()
4747
# A 252-byte LoRa packet has about 902ms time-on-air according to
4848
# Semtech calculator at SF8/125 kHz/CR 4/5
@@ -69,11 +69,9 @@ def test_link_two_to_one_64_max_tc_frames(
6969
received = b""
7070

7171
for frame in frames:
72-
assert len(frame) == MAX_TC_FRAME_SIZE
73-
assert data_port_two.write(frame) == len(frame)
74-
# See comment in one-to-two test
75-
data_port_two.flush()
72+
data_port_two.write(frame)
7673
received += data_port_one.read_all()
74+
# See comment in one-to-two test
7775
time.sleep(1.0)
7876

7977
received += data_port_one.read(len(sent) - len(received))
@@ -84,3 +82,36 @@ def test_link_two_to_one_64_max_tc_frames(
8482
)
8583
finally:
8684
_assert_no_warnings(fprime_test_api)
85+
86+
87+
def test_ping_pong_one_two(fprime_test_api, data_port_one, data_port_two):
88+
try:
89+
exchanges = [
90+
(
91+
_tc_frame(bytes([packet_number]) * MAX_TC_FRAME_PAYLOAD_SIZE),
92+
_tc_frame(
93+
bytes([packet_number + PING_PONG_EXCHANGE_COUNT])
94+
* MAX_TC_FRAME_PAYLOAD_SIZE
95+
),
96+
)
97+
for packet_number in range(PING_PONG_EXCHANGE_COUNT)
98+
]
99+
received = []
100+
101+
start = time.monotonic()
102+
for outbound, reply in exchanges:
103+
data_port_one.write(outbound)
104+
received.append(data_port_two.read(len(outbound)))
105+
106+
data_port_two.write(reply)
107+
received.append(data_port_one.read(len(reply)))
108+
elapsed = time.monotonic() - start
109+
110+
assert received == [packet for exchange in exchanges for packet in exchange]
111+
assert elapsed < PING_PONG_EXCHANGE_MAX_SECONDS, (
112+
f"Expected {PING_PONG_EXCHANGE_COUNT * 2} max-size packets to "
113+
f"exchange in less than {PING_PONG_EXCHANGE_MAX_SECONDS:.1f}s, "
114+
f"took {elapsed:.1f}s"
115+
)
116+
finally:
117+
_assert_no_warnings(fprime_test_api)

test/two-board/main_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def test_link_one_to_two_one_packet(fprime_test_api, data_port_one, data_port_tw
3434
try:
3535
sent = _tc_frame(b"one-packet")
3636
data_port_one.write(sent)
37-
data_port_one.flush()
3837

3938
received = data_port_two.read(len(sent))
4039
assert received == sent, "Timed out waiting for data from board two"
@@ -131,7 +130,6 @@ def test_link_survives_valid_freq_change(fprime_test_api, data_port_one, data_po
131130
timeout=2,
132131
)
133132
data_port_one.write(sent)
134-
data_port_one.flush()
135133

136134
received = data_port_two.read(len(sent))
137135
assert received == sent, (
@@ -163,7 +161,6 @@ def test_link_breaks_after_mismatched_freq(
163161
timeout=2,
164162
)
165163
data_port_one.write(sent)
166-
data_port_one.flush()
167164

168165
received = data_port_two.read(len(sent))
169166
assert received != sent, (

0 commit comments

Comments
 (0)