Skip to content

Commit 11ef24b

Browse files
authored
Improve tests (#456)
* much more thorough Honda-Bosch tests and better test inheritance. Also fix counter test bug * Fixed other counters too * remove unnecessary function
1 parent fb02390 commit 11ef24b

8 files changed

+151
-145
lines changed

tests/safety/common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def make_msg(bus, addr, length=8):
1313

1414
return to_send
1515

16-
def test_relay_malfunction(test, addr):
17-
# input is a test class and the address that, if seen on bus 0, triggers
16+
def test_relay_malfunction(test, addr, bus=0):
17+
# input is a test class and the address that, if seen on specified bus, triggers
1818
# the relay_malfunction protection logic: both tx_hook and fwd_hook are
1919
# expected to return failure
2020
test.assertFalse(test.safety.get_relay_malfunction())
21-
test.safety.safety_rx_hook(make_msg(0, addr, 8))
21+
test.safety.safety_rx_hook(make_msg(bus, addr, 8))
2222
test.assertTrue(test.safety.get_relay_malfunction())
2323
for a in range(1, 0x800):
2424
for b in range(0, 3):

tests/safety/libpandasafety_py.py

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
int get_honda_gas_prev(void);
6161
void set_honda_fwd_brake(bool);
6262
void set_honda_alt_brake_msg(bool);
63-
void set_honda_hw(int);
6463
int get_honda_hw(void);
6564
6665
void init_tests_cadillac(void);

tests/safety/test.c

-4
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ void set_honda_alt_brake_msg(bool c){
259259
honda_alt_brake_msg = c;
260260
}
261261

262-
void set_honda_hw(int c){
263-
honda_hw = c;
264-
}
265-
266262
int get_honda_hw(void) {
267263
return honda_hw;
268264
}

tests/safety/test_chrysler.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ def chrysler_checksum(msg, len_msg):
4242
return ~checksum & 0xFF
4343

4444
class TestChryslerSafety(unittest.TestCase):
45+
cnt_torque_meas = 0
46+
cnt_gas = 0
47+
cnt_cruise = 0
48+
cnt_brake = 0
49+
4550
@classmethod
4651
def setUp(cls):
4752
cls.safety = libpandasafety_py.libpandasafety
4853
cls.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0)
4954
cls.safety.init_tests_chrysler()
50-
cls.cnt_torque_meas = 0
51-
cls.cnt_gas = 0
52-
cls.cnt_cruise = 0
53-
cls.cnt_brake = 0
5455

5556
def _button_msg(self, buttons):
5657
to_send = make_msg(0, 571)
@@ -62,7 +63,7 @@ def _cruise_msg(self, active):
6263
to_send[0].RDLR = 0x380000 if active else 0
6364
to_send[0].RDHR |= (self.cnt_cruise % 16) << 20
6465
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
65-
self.cnt_cruise += 1
66+
self.__class__.cnt_cruise += 1
6667
return to_send
6768

6869
def _speed_msg(self, speed):
@@ -76,15 +77,15 @@ def _gas_msg(self, gas):
7677
to_send = make_msg(0, 308)
7778
to_send[0].RDHR = (gas & 0x7F) << 8
7879
to_send[0].RDHR |= (self.cnt_gas % 16) << 20
79-
self.cnt_gas += 1
80+
self.__class__.cnt_gas += 1
8081
return to_send
8182

8283
def _brake_msg(self, brake):
8384
to_send = make_msg(0, 320)
8485
to_send[0].RDLR = 5 if brake else 0
8586
to_send[0].RDHR |= (self.cnt_brake % 16) << 20
8687
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
87-
self.cnt_brake += 1
88+
self.__class__.cnt_brake += 1
8889
return to_send
8990

9091
def _set_prev_torque(self, t):
@@ -97,7 +98,7 @@ def _torque_meas_msg(self, torque):
9798
to_send[0].RDHR = ((torque + 1024) >> 8) + (((torque + 1024) & 0xff) << 8)
9899
to_send[0].RDHR |= (self.cnt_torque_meas % 16) << 20
99100
to_send[0].RDHR |= chrysler_checksum(to_send[0], 8) << 24
100-
self.cnt_torque_meas += 1
101+
self.__class__.cnt_torque_meas += 1
101102
return to_send
102103

103104
def _torque_msg(self, torque):

0 commit comments

Comments
 (0)