Skip to content

Commit

Permalink
Improve tests (#456)
Browse files Browse the repository at this point in the history
* much more thorough Honda-Bosch tests and better test inheritance. Also fix counter test bug

* Fixed other counters too

* remove unnecessary function
  • Loading branch information
rbiasini authored Feb 29, 2020
1 parent fb02390 commit 11ef24b
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 145 deletions.
6 changes: 3 additions & 3 deletions tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def make_msg(bus, addr, length=8):

return to_send

def test_relay_malfunction(test, addr):
# input is a test class and the address that, if seen on bus 0, triggers
def test_relay_malfunction(test, addr, bus=0):
# input is a test class and the address that, if seen on specified bus, triggers
# the relay_malfunction protection logic: both tx_hook and fwd_hook are
# expected to return failure
test.assertFalse(test.safety.get_relay_malfunction())
test.safety.safety_rx_hook(make_msg(0, addr, 8))
test.safety.safety_rx_hook(make_msg(bus, addr, 8))
test.assertTrue(test.safety.get_relay_malfunction())
for a in range(1, 0x800):
for b in range(0, 3):
Expand Down
1 change: 0 additions & 1 deletion tests/safety/libpandasafety_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
int get_honda_gas_prev(void);
void set_honda_fwd_brake(bool);
void set_honda_alt_brake_msg(bool);
void set_honda_hw(int);
int get_honda_hw(void);
void init_tests_cadillac(void);
Expand Down
4 changes: 0 additions & 4 deletions tests/safety/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ void set_honda_alt_brake_msg(bool c){
honda_alt_brake_msg = c;
}

void set_honda_hw(int c){
honda_hw = c;
}

int get_honda_hw(void) {
return honda_hw;
}
Expand Down
17 changes: 9 additions & 8 deletions tests/safety/test_chrysler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ def chrysler_checksum(msg, len_msg):
return ~checksum & 0xFF

class TestChryslerSafety(unittest.TestCase):
cnt_torque_meas = 0
cnt_gas = 0
cnt_cruise = 0
cnt_brake = 0

@classmethod
def setUp(cls):
cls.safety = libpandasafety_py.libpandasafety
cls.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0)
cls.safety.init_tests_chrysler()
cls.cnt_torque_meas = 0
cls.cnt_gas = 0
cls.cnt_cruise = 0
cls.cnt_brake = 0

def _button_msg(self, buttons):
to_send = make_msg(0, 571)
Expand All @@ -62,7 +63,7 @@ def _cruise_msg(self, active):
to_send[0].RDLR = 0x380000 if active else 0
to_send[0].RDHR |= (self.cnt_cruise % 16) << 20
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
self.cnt_cruise += 1
self.__class__.cnt_cruise += 1
return to_send

def _speed_msg(self, speed):
Expand All @@ -76,15 +77,15 @@ def _gas_msg(self, gas):
to_send = make_msg(0, 308)
to_send[0].RDHR = (gas & 0x7F) << 8
to_send[0].RDHR |= (self.cnt_gas % 16) << 20
self.cnt_gas += 1
self.__class__.cnt_gas += 1
return to_send

def _brake_msg(self, brake):
to_send = make_msg(0, 320)
to_send[0].RDLR = 5 if brake else 0
to_send[0].RDHR |= (self.cnt_brake % 16) << 20
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
self.cnt_brake += 1
self.__class__.cnt_brake += 1
return to_send

def _set_prev_torque(self, t):
Expand All @@ -97,7 +98,7 @@ def _torque_meas_msg(self, torque):
to_send[0].RDHR = ((torque + 1024) >> 8) + (((torque + 1024) & 0xff) << 8)
to_send[0].RDHR |= (self.cnt_torque_meas % 16) << 20
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
self.cnt_torque_meas += 1
self.__class__.cnt_torque_meas += 1
return to_send

def _torque_msg(self, torque):
Expand Down
Loading

0 comments on commit 11ef24b

Please sign in to comment.