Skip to content

Commit a830c09

Browse files
committed
Add debug prints to back2back_test to analyze race condition
Might fail if pytest does not print stdout
1 parent 3ae0879 commit a830c09

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test/back2back_test.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,31 @@ def _check_received_message(
7676
if not sent_msg.is_remote_frame:
7777
self.assertSequenceEqual(recv_msg.data, sent_msg.data)
7878

79-
def _send_and_receive(self, msg: can.Message) -> None:
79+
def _send_and_receive(self, msg: can.Message, bus_clear_timeout: float = 0) -> None:
8080
# Send with bus 1, receive with bus 2
81+
print(f"Send on Bus 1: {msg}")
8182
self.bus1.send(msg)
83+
8284
recv_msg = self.bus2.recv(self.TIMEOUT)
85+
print(f"Received on Bus 2: {recv_msg}")
8386
self._check_received_message(recv_msg, msg)
87+
8488
# Some buses may receive their own messages. Remove it from the queue
85-
self.bus1.recv(0)
89+
cleared_msg = self.bus1.recv(bus_clear_timeout)
90+
print(f"Bus 1 msg cleared: {cleared_msg}")
8691

8792
# Send with bus 2, receive with bus 1
8893
# Add 1 to arbitration ID to make it a different message
8994
msg.arbitration_id += 1
95+
print(f"Send on Bus 2: {msg}")
9096
self.bus2.send(msg)
97+
9198
# Some buses may receive their own messages. Remove it from the queue
92-
self.bus2.recv(0)
99+
cleared_msg = self.bus2.recv(bus_clear_timeout)
100+
print(f"Bus 2 msg cleared: {cleared_msg}")
101+
93102
recv_msg = self.bus1.recv(self.TIMEOUT)
103+
print(f"Received on Bus 1: {recv_msg}")
94104
self._check_received_message(recv_msg, msg)
95105

96106
def test_no_message(self):
@@ -142,6 +152,10 @@ def test_dlc_less_than_eight(self):
142152
msg = can.Message(is_extended_id=False, arbitration_id=0x300, data=[4, 5, 6])
143153
self._send_and_receive(msg)
144154

155+
def test_dlc_less_than_eight_with_clear_timeout(self):
156+
msg = can.Message(is_extended_id=False, arbitration_id=0x300, data=[4, 5, 6])
157+
self._send_and_receive(msg, bus_clear_timeout=0.3)
158+
145159
@unittest.skip(
146160
"TODO: how shall this be treated if sending messages locally? should be done uniformly"
147161
)

0 commit comments

Comments
 (0)