Safety Tests: Create common gas brake safety test (#1537)

* create common gas brake safety test

* remove unrelated subaru reference

* also test below min_value

* better name and hardcoded

* use same as acceleration limits

* revert gm

* remove callable

* added common brake test and moved generic test to base safety class

* remove duplicate test

* wip

* wip

* rename longitudinalaccelsafety

* revert limits correct test

* fix controls allowed test

* move gm over to long gas brake test

* assert that limits are reasonable

* fix typing

* fix linter again

* fix linter again

* fix linter again

* like to make it clear

* typo

* fix from merge

* clearer names

* dont need thesemore

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>
This commit is contained in:
Justin Newberry 2023-08-12 14:03:40 -07:00 committed by GitHub
parent f29c753ba4
commit 7dbdf6ba2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 0 deletions

View File

@ -204,6 +204,39 @@ class LongitudinalAccelSafetyTest(PandaSafetyTestBase, abc.ABC):
self.assertEqual(should_tx, self._tx(self._accel_msg(accel)))
class LongitudinalGasBrakeSafetyTest(PandaSafetyTestBase, abc.ABC):
MIN_BRAKE: int = 0
MAX_BRAKE: Optional[int] = None
MAX_POSSIBLE_BRAKE: Optional[int] = None
MIN_GAS: int = 0
MAX_GAS: Optional[int] = None
INACTIVE_GAS = 0
MAX_POSSIBLE_GAS: Optional[int] = None
def test_gas_brake_limits_correct(self):
self.assertIsNotNone(self.MAX_POSSIBLE_BRAKE)
self.assertIsNotNone(self.MAX_POSSIBLE_GAS)
self.assertGreater(self.MAX_BRAKE, self.MIN_BRAKE)
self.assertGreater(self.MAX_GAS, self.MIN_GAS)
@abc.abstractmethod
def _send_gas_msg(self, gas: int):
pass
@abc.abstractmethod
def _send_brake_msg(self, brake: int):
pass
def test_brake_safety_check(self):
self._generic_limit_safety_check(self._send_brake_msg, self.MIN_BRAKE, self.MAX_BRAKE, 0, self.MAX_POSSIBLE_BRAKE, 1)
def test_gas_safety_check(self):
self._generic_limit_safety_check(self._send_gas_msg, self.MIN_GAS, self.MAX_GAS, 0, self.MAX_POSSIBLE_GAS, 1, self.INACTIVE_GAS)
class TorqueSteeringSafetyTestBase(PandaSafetyTestBase, abc.ABC):
MAX_RATE_UP = 0