Skip to content

Commit

Permalink
safety tests a bit more simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Nov 15, 2019
1 parent 2027765 commit e74ed93
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 33 deletions.
6 changes: 6 additions & 0 deletions tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ def test_relay_malfunction(test, addr):
for b in range(0, 3):
test.assertFalse(test.safety.safety_tx_hook(make_msg(b, a, 8)))
test.assertEqual(-1, test.safety.safety_fwd_hook(b, make_msg(b, a, 8)))

def test_manually_enable_controls_allowed(test):
test.safety.set_controls_allowed(1)
test.assertTrue(test.safety.get_controls_allowed())
test.safety.set_controls_allowed(0)
test.assertFalse(test.safety.get_controls_allowed())
6 changes: 2 additions & 4 deletions tests/safety/test_cadillac.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import make_msg
from panda.tests.safety.common import make_msg, test_manually_enable_controls_allowed


MAX_RATE_UP = 2
Expand Down Expand Up @@ -61,9 +61,7 @@ def test_default_controls_not_allowed(self):
self.assertFalse(self.safety.get_controls_allowed())

def test_manually_enable_controls_allowed(self):
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(0)
test_manually_enable_controls_allowed(self)

def test_enable_control_allowed_from_cruise(self):
to_push = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
Expand Down
7 changes: 2 additions & 5 deletions tests/safety/test_chrysler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import test_relay_malfunction, make_msg
from panda.tests.safety.common import test_relay_malfunction, make_msg, test_manually_enable_controls_allowed

MAX_RATE_UP = 3
MAX_RATE_DOWN = 3
Expand Down Expand Up @@ -78,10 +78,7 @@ def test_steer_safety_check(self):
self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t)))

def test_manually_enable_controls_allowed(self):
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(0)
self.assertFalse(self.safety.get_controls_allowed())
test_manually_enable_controls_allowed(self)

def test_enable_control_allowed_from_cruise(self):
to_push = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
Expand Down
7 changes: 2 additions & 5 deletions tests/safety/test_gm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import test_relay_malfunction, make_msg
from panda.tests.safety.common import test_relay_malfunction, make_msg, test_manually_enable_controls_allowed

MAX_RATE_UP = 7
MAX_RATE_DOWN = 17
Expand Down Expand Up @@ -195,10 +195,7 @@ def test_steer_safety_check(self):
self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t)))

def test_manually_enable_controls_allowed(self):
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(0)
self.assertFalse(self.safety.get_controls_allowed())
test_manually_enable_controls_allowed(self)

def test_non_realtime_limit_up(self):
self.safety.set_gm_torque_driver(0, 0)
Expand Down
5 changes: 4 additions & 1 deletion tests/safety/test_honda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import test_relay_malfunction, make_msg
from panda.tests.safety.common import test_relay_malfunction, make_msg, test_manually_enable_controls_allowed

MAX_BRAKE = 255

Expand Down Expand Up @@ -85,6 +85,9 @@ def test_relay_malfunction(self):
def test_default_controls_not_allowed(self):
self.assertFalse(self.safety.get_controls_allowed())

def test_manually_enable_controls_allowed(self):
test_manually_enable_controls_allowed(self)

def test_resume_button(self):
RESUME_BTN = 4
self.safety.set_controls_allowed(0)
Expand Down
7 changes: 2 additions & 5 deletions tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import test_relay_malfunction, make_msg
from panda.tests.safety.common import test_relay_malfunction, make_msg, test_manually_enable_controls_allowed

MAX_RATE_UP = 3
MAX_RATE_DOWN = 7
Expand Down Expand Up @@ -73,10 +73,7 @@ def test_steer_safety_check(self):
self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t)))

def test_manually_enable_controls_allowed(self):
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(0)
self.assertFalse(self.safety.get_controls_allowed())
test_manually_enable_controls_allowed(self)

def test_enable_control_allowed_from_cruise(self):
to_push = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
Expand Down
7 changes: 2 additions & 5 deletions tests/safety/test_subaru.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import test_relay_malfunction, make_msg
from panda.tests.safety.common import test_relay_malfunction, make_msg, test_manually_enable_controls_allowed

MAX_RATE_UP = 50
MAX_RATE_DOWN = 70
Expand Down Expand Up @@ -88,10 +88,7 @@ def test_steer_safety_check(self):
self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t)))

def test_manually_enable_controls_allowed(self):
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(0)
self.assertFalse(self.safety.get_controls_allowed())
test_manually_enable_controls_allowed(self)

def test_non_realtime_limit_up(self):
self.safety.set_subaru_torque_driver(0, 0)
Expand Down
5 changes: 2 additions & 3 deletions tests/safety/test_toyota.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import test_relay_malfunction, make_msg
from panda.tests.safety.common import test_relay_malfunction, make_msg, test_manually_enable_controls_allowed

MAX_RATE_UP = 10
MAX_RATE_DOWN = 25
Expand Down Expand Up @@ -98,8 +98,7 @@ def test_default_controls_not_allowed(self):
self.assertFalse(self.safety.get_controls_allowed())

def test_manually_enable_controls_allowed(self):
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.get_controls_allowed())
test_manually_enable_controls_allowed(self)

def test_enable_control_allowed_from_cruise(self):
self.safety.safety_rx_hook(self._pcm_cruise_msg(False))
Expand Down
7 changes: 2 additions & 5 deletions tests/safety/test_volkswagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from panda import Panda
from panda.tests.safety import libpandasafety_py
from panda.tests.safety.common import test_relay_malfunction, make_msg
from panda.tests.safety.common import test_relay_malfunction, make_msg, test_manually_enable_controls_allowed

MAX_RATE_UP = 4
MAX_RATE_DOWN = 10
Expand Down Expand Up @@ -127,10 +127,7 @@ def test_steer_safety_check(self):
self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t)))

def test_manually_enable_controls_allowed(self):
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.get_controls_allowed())
self.safety.set_controls_allowed(0)
self.assertFalse(self.safety.get_controls_allowed())
test_manually_enable_controls_allowed(self)

def test_spam_cancel_safety_check(self):
BIT_CANCEL = 13
Expand Down

0 comments on commit e74ed93

Please sign in to comment.