Skip to content

Commit

Permalink
Safety Test Refactor: Volkswagen MQB (#493)
Browse files Browse the repository at this point in the history
* pull test_volkswagen_mqb.py from safety-test-refactor

* prev_brake is now a standard test

* abstract cruise enable/disable tests

* unused

* move

* hack to get around unittest reporting skipped tests
  • Loading branch information
adeebshihadeh authored Apr 14, 2020
1 parent f07a6ee commit 6c442b4
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 225 deletions.
28 changes: 27 additions & 1 deletion tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def _speed_msg(self, speed):
def _gas_msg(self, speed):
pass

@abc.abstractmethod
def _pcm_status_msg(self, enable):
pass

# ***** standard tests for all safety modes *****

def test_relay_malfunction(self):
Expand Down Expand Up @@ -119,9 +123,12 @@ def test_manually_enable_controls_allowed(self):
self.assertTrue(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(0)
self.assertFalse(self.safety.get_controls_allowed())

def test_prev_gas(self):
self.assertFalse(self.safety.get_gas_pressed_prev())
for pressed in [True, False]:
self._rx(self._gas_msg(not pressed))
self.assertEqual(not pressed, self.safety.get_gas_pressed_prev())
self._rx(self._gas_msg(pressed))
self.assertEqual(pressed, self.safety.get_gas_pressed_prev())

Expand All @@ -146,6 +153,25 @@ def test_unsafe_mode_no_disengage_on_gas(self):
self._rx(self._gas_msg(1))
self.assertTrue(self.safety.get_controls_allowed())

def test_prev_brake(self):
self.assertFalse(self.safety.get_brake_pressed_prev())
for pressed in [True, False]:
self._rx(self._brake_msg(not pressed))
self.assertEqual(not pressed, self.safety.get_brake_pressed_prev())
self._rx(self._brake_msg(pressed))
self.assertEqual(pressed, self.safety.get_brake_pressed_prev())

def test_enable_control_allowed_from_cruise(self):
self._rx(self._pcm_status_msg(False))
self.assertFalse(self.safety.get_controls_allowed())
self._rx(self._pcm_status_msg(True))
self.assertTrue(self.safety.get_controls_allowed())

def test_disable_control_allowed_from_cruise(self):
self.safety.set_controls_allowed(1)
self._rx(self._pcm_status_msg(False))
self.assertFalse(self.safety.get_controls_allowed())

def test_allow_brake_at_zero_speed(self):
# Brake was already pressed
self._rx(self._speed_msg(0))
Expand Down
21 changes: 5 additions & 16 deletions tests/safety/test_toyota.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import CANPackerPanda, PandaSafetyTest, \
interceptor_msg, UNSAFE_MODE
import panda.tests.safety.common as common
from panda.tests.safety.common import CANPackerPanda, interceptor_msg, UNSAFE_MODE

MAX_RATE_UP = 10
MAX_RATE_DOWN = 25
Expand All @@ -22,7 +22,7 @@
MAX_TORQUE_ERROR = 350
INTERCEPTOR_THRESHOLD = 475

class TestToyotaSafety(PandaSafetyTest):
class TestToyotaSafety(common.PandaSafetyTest):

TX_MSGS = [[0x283, 0], [0x2E6, 0], [0x2E7, 0], [0x33E, 0], [0x344, 0], [0x365, 0], [0x366, 0], [0x4CB, 0], # DSU bus 0
[0x128, 1], [0x141, 1], [0x160, 1], [0x161, 1], [0x470, 1], # DSU bus 1
Expand Down Expand Up @@ -71,22 +71,11 @@ def _gas_msg(self, pressed):
values = {"GAS_RELEASED": not pressed, "CRUISE_ACTIVE": cruise_active}
return self.packer.make_can_msg_panda("PCM_CRUISE", 0, values)

def _pcm_cruise_msg(self, cruise_on):
def _pcm_status_msg(self, cruise_on):
values = {"CRUISE_ACTIVE": cruise_on}
values["CHECKSUM"] = 1
return self.packer.make_can_msg_panda("PCM_CRUISE", 0, values)

def test_enable_control_allowed_from_cruise(self):
self._rx(self._pcm_cruise_msg(False))
self.assertFalse(self.safety.get_controls_allowed())
self._rx(self._pcm_cruise_msg(True))
self.assertTrue(self.safety.get_controls_allowed())

def test_disable_control_allowed_from_cruise(self):
self.safety.set_controls_allowed(1)
self._rx(self._pcm_cruise_msg(False))
self.assertFalse(self.safety.get_controls_allowed())

def test_prev_gas_interceptor(self):
self._rx(interceptor_msg(0x0, 0x201))
self.assertFalse(self.safety.get_gas_interceptor_prev())
Expand Down Expand Up @@ -237,7 +226,7 @@ def test_rx_hook(self):
if msg == "trq":
to_push = self._torque_meas_msg(0)
if msg == "pcm":
to_push = self._pcm_cruise_msg(1)
to_push = self._pcm_status_msg(True)
self.assertTrue(self._rx(to_push))
to_push[0].RDHR = 0
self.assertFalse(self._rx(to_push))
Expand Down
Loading

0 comments on commit 6c442b4

Please sign in to comment.