pandad: add jungle spam mode to test (#32636)
Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
parent
7b09285817
commit
a46f1c6eba
|
@ -10,6 +10,7 @@ from openpilot.system.hardware import HARDWARE
|
|||
from openpilot.selfdrive.test.helpers import phone_only, with_processes
|
||||
from openpilot.selfdrive.pandad.tests.test_pandad_loopback import setup_pandad, send_random_can_messages
|
||||
|
||||
JUNGLE_SPAM = "JUNGLE_SPAM" in os.environ
|
||||
|
||||
@pytest.mark.tici
|
||||
class TestBoarddSpi:
|
||||
|
@ -18,9 +19,9 @@ class TestBoarddSpi:
|
|||
if HARDWARE.get_device_type() == 'tici':
|
||||
pytest.skip("only for spi pandas")
|
||||
os.environ['STARTED'] = '1'
|
||||
os.environ['BOARDD_LOOPBACK'] = '1'
|
||||
#os.environ['SPI_ERR_PROB'] = '-1'
|
||||
os.environ['SPI_ERR_PROB'] = '0.001'
|
||||
if not JUNGLE_SPAM:
|
||||
os.environ['BOARDD_LOOPBACK'] = '1'
|
||||
|
||||
@phone_only
|
||||
@with_processes(['pandad'])
|
||||
|
@ -39,12 +40,13 @@ class TestBoarddSpi:
|
|||
|
||||
st = time.monotonic()
|
||||
ts = {s: list() for s in socks.keys()}
|
||||
for _ in range(20):
|
||||
for _ in range(int(os.getenv("TEST_TIME", "20"))):
|
||||
# send some CAN messages
|
||||
sent = send_random_can_messages(sendcan, random.randrange(2, 20))
|
||||
for k, v in sent.items():
|
||||
sent_msgs[k].extend(list(v))
|
||||
total_sent_count += len(v)
|
||||
if not JUNGLE_SPAM:
|
||||
sent = send_random_can_messages(sendcan, random.randrange(2, 20))
|
||||
for k, v in sent.items():
|
||||
sent_msgs[k].extend(list(v))
|
||||
total_sent_count += len(v)
|
||||
|
||||
for service, sock in socks.items():
|
||||
for m in messaging.drain_sock(sock):
|
||||
|
@ -54,6 +56,15 @@ class TestBoarddSpi:
|
|||
assert m.valid or (service == "can")
|
||||
if service == "can":
|
||||
for msg in m.can:
|
||||
if JUNGLE_SPAM:
|
||||
# PandaJungle.set_generated_can(True)
|
||||
i = msg.address - 0x200
|
||||
assert msg.address >= 0x200
|
||||
assert msg.src == (i%3)
|
||||
assert msg.dat == b"\xff"*(i%8)
|
||||
total_recv_count += 1
|
||||
continue
|
||||
|
||||
if msg.src > 4:
|
||||
continue
|
||||
key = (msg.address, msg.dat)
|
||||
|
@ -91,5 +102,5 @@ class TestBoarddSpi:
|
|||
assert len(dts) >= ((et-0.5)*SERVICE_LIST[service].frequency*0.8)
|
||||
|
||||
with subtests.test(msg="CAN traffic"):
|
||||
print(f"Sent {total_sent_count} CAN messages, got {total_recv_count} back. {total_recv_count/total_sent_count:.2%} received")
|
||||
print(f"Sent {total_sent_count} CAN messages, got {total_recv_count} back. {total_recv_count/(total_sent_count+1e-4):.2%} received")
|
||||
assert total_recv_count > 20
|
||||
|
|
Loading…
Reference in New Issue