Safety Test: ensure TX msgs for other cars are blocked (#521)

This commit is contained in:
Adeeb Shihadeh 2020-06-21 23:25:54 -07:00 committed by GitHub
parent 31f8a0d862
commit 0d97b6d4eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import os
import abc
import struct
import unittest
import importlib
import numpy as np
from typing import Optional, List, Dict
from opendbc.can.packer import CANPacker # pylint: disable=import-error
@ -411,3 +413,28 @@ class PandaSafetyTest(PandaSafetyTestBase):
# past threshold
self.safety.safety_rx_hook(self._speed_msg(self.STANDSTILL_THRESHOLD + 1))
self.assertTrue(self.safety.get_vehicle_moving())
def test_tx_hook_on_wrong_safety_mode(self):
files = os.listdir(os.path.dirname(os.path.realpath(__file__)))
test_files = [f for f in files if f.startswith("test_") and f.endswith(".py")]
current_test = self.__class__.__name__
all_tx = []
for tf in test_files:
test = importlib.import_module("panda.tests.safety."+tf[:-3])
for attr in dir(test):
if attr.startswith("Test") and attr != current_test:
tx = getattr(getattr(test, attr), "TX_MSGS")
if tx is not None:
all_tx.append(tx)
# make sure we got all the msgs
self.assertTrue(len(all_tx) >= len(test_files)-1)
for tx_msgs in all_tx:
for addr, bus in tx_msgs:
msg = make_msg(addr, bus)
self.safety.set_controls_allowed(1)
self.assertFalse(self._tx(msg))

View File

@ -24,7 +24,7 @@ class TestGmSafety(common.PandaSafetyTest):
TX_MSGS = [[384, 0], [1033, 0], [1034, 0], [715, 0], [880, 0], # pt bus
[161, 1], [774, 1], [776, 1], [784, 1], # obs bus
[789, 2], # ch bus
[0x104c006c, 3], [0x10400060]] # gmlan
[0x104c006c, 3], [0x10400060, 3]] # gmlan
STANDSTILL_THRESHOLD = 0
RELAY_MALFUNCTION_ADDR = 384
RELAY_MALFUNCTION_BUS = 0