Skip to content

Commit 687dfde

Browse files
robert-hhdpgeorge
authored andcommitted
tests/multi_extmod: Make small adaptions of CAN tests 04, 05, 07 and 08.
- multi_extmod/machine_can_04_tx_order.py: Skip for Alif, since the Alif port has an opaque send queue which provides no information of the slot number of a message in the TX queue. - multi_extmod/machine_can_05_tx_prio_cancel.py: Skip for Alif, since the Alif port has an opaque send queue which does not allow specific cancels and provides no information of the slot number of a message in the TX queue. - tests/multi_extmod/machine_can_07_error_states.py: Swap the order of resetting the baud rate and restart(). If restart() happens before resetting the baud rate, then the REC counter increases fast and the bus state switched to PASSIVE before the baud rate can be fixed. - tests/multi_extmod/machine_can_07_error_states.py: Add a delay after sending the message "PAYLOAD" avoiding a collision with the test broadcast messages. - multi_extmod/machine_can_08_init_mode.py: Cater for error frames not being reported in SILENT mode. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent f612fd5 commit 687dfde

5 files changed

Lines changed: 36 additions & 8 deletions

tests/multi_extmod/machine_can_04_tx_order.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
import micropython
77

8+
# The Alif port has an opaque send queue. The Alif CAN controller
9+
# provides no information about the slot number where the message
10+
# is stored, and it does not allow to cancel specific messages.
11+
# This test needs the slot number, which is not available.
12+
13+
if "alif" in sys.platform:
14+
print("SKIP")
15+
raise SystemExit
16+
817
micropython.alloc_emergency_exception_buf(256)
918
seed(0)
1019

tests/multi_extmod/machine_can_05_tx_prio_cancel.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
import time
33
import sys
44

5+
# The Alif port has an opaque send queue. The Alif CAN controller
6+
# provides no information about the slot number where the message
7+
# is stored, and it does not allow to cancel specific messages.
8+
# This test needs both the slot number, and uses cancel_send() for
9+
# dedicated messages, which both is not available.
10+
11+
if "alif" in sys.platform:
12+
print("SKIP")
13+
raise SystemExit
14+
515
# Check that cancelling a low priority outgoing message and replacing it with a
616
# high priority message causes it to be transmitted successfully onto a busy bus
717

tests/multi_extmod/machine_can_07_error_states.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def instance1():
108108

109109
# Send a single message to the receiver, to verify it's working
110110
can.send(_ID, b"PAYLOAD")
111+
time.sleep_ms(50) # irq_sender should fire during this window
112+
111113
active_counters = can.get_counters()
112114
# print(active_counters) # DEBUG
113115

@@ -189,15 +191,19 @@ def instance1():
189191
# with this test setup, as Bus Off requires more than just "normal" frame
190192
# transmit errors.
191193

192-
# restarting the controller may cause it to leave its error state, or not, depending
193-
# on the implementation - but it shouldn't cause any recovery issues. Also cancels all pending TX
194-
# (note: have to do this before 'fix baud' or we create a race condition for pending tx)
195-
can.restart()
196-
197-
# tell the receiver to go back to a valid baud rate
194+
# tell the receiver to go back to a valid baud rate, causing the pending tx
195+
# to be sent.
198196
multitest.broadcast("fix baud")
199197
multitest.wait("fixed baud")
200198

199+
# Restarting the controller may cause it to leave its error state, or not, depending
200+
# on the implementation - but it shouldn't cause any recovery issues. Also cancels all pending TX.
201+
# If restart() clears the TEC and REC error counters, resetting the error state to ACTIVE,
202+
# and if that is done while instance0 is still trying to send at the wrong baud rate,
203+
# the error state rushes up again pretty fast. Therefore the baud rate is fixed before
204+
# calling restart().
205+
can.restart()
206+
201207
idx_more = can.send(_ID, b"MOREMORE")
202208
time.sleep_ms(50) # irq_sender should fire during this window
203209
print("queued moremore", idx_more is not None)

tests/multi_extmod/machine_can_07_error_states.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ one over thresh True
3333
no new warning True
3434
counted passive True
3535
irq sent True
36+
irq sent True
3637
queued moremore True
3738
done

tests/multi_extmod/machine_can_08_init_mode.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ def instance0():
6868
multitest.wait("silent done")
6969
# we should have received the message from instance1 many times, as instance0 won't have ACKed it
7070
# create a dummy "OK" for MIMXRT, since it on receives ACKed messages in SILENT mode.
71-
if "mimxrt" in sys.platform:
71+
if ("mimxrt" in sys.platform) or ("alif" in sys.platform):
7272
print("silent_rx_count True")
7373
else:
7474
print("silent_rx_count", silent_rx_count > 5)
75-
can.cancel_send(idx)
75+
# Cancel the sent message only if it was accpeted for sending.
76+
if idx is not None:
77+
can.cancel_send(idx)
7678

7779
reinit_with_mode(can.MODE_SILENT_LOOPBACK)
7880
print("Silent Loopback", "MODE_SILENT_LOOPBACK" in str(can))

0 commit comments

Comments
 (0)