Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Dec 9, 2024
1 parent e4fca0c commit 55fdf2b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/libpanda/safety_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ bool get_pcm_main_cruise_available(void){
return m_mads_state.acc_main.available;
}

bool get_acc_main_on_non_pcm(void){
return m_mads_state.acc_main_on_non_pcm;
}

//int get_temp_debug(void){
// return temp_debug;
//}
Expand Down
2 changes: 2 additions & 0 deletions tests/libpanda/safety_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def setup_safety_helpers(ffi):
int get_temp_debug(void);
bool get_mads_acc_main_prev(void);
bool get_pcm_main_cruise_available(void);
bool get_acc_main_on_non_pcm(void);
""")

class PandaSafety(Protocol):
Expand Down Expand Up @@ -147,6 +148,7 @@ def set_lkas_button_press(self, lkas_button_press: int) -> None: ...
def get_enable_mads(self) -> bool: ...
def get_disengage_lat_on_brake(self) -> bool: ...
def get_pcm_main_cruise_available(self) -> bool: ...
def get_acc_main_on_non_pcm(self) -> bool: ...
#def set_main_button_engaged(self, engaged: bool) -> None: ...
#def get_main_button_engaged(self) -> bool: ...
#def set_lkas_button_engaged(self, engaged: bool) -> None: ...
Expand Down
72 changes: 72 additions & 0 deletions tests/safety/mads_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,75 @@ def test_enable_lateral_control_with_main_cruise_button_and_disable_with_lfa(sel
self.assertFalse(self.safety.get_controls_allowed_lat())
finally:
self._mads_states_cleanup()

def test_acc_main_non_pcm_toggle_behavior(self):
"""Test that non-PCM ACC main properly toggles states"""
try:
self._mads_states_cleanup()
self.safety.set_enable_mads(True, False)

# Initial state should be False
self.assertFalse(self.safety.get_acc_main_on_non_pcm())
self.assertFalse(self.safety.get_controls_requested_lat())

# First button press should toggle to True
self._rx(self._main_cruise_button_msg(True))
self._rx(self._main_cruise_button_msg(False))
self.assertTrue(self.safety.get_acc_main_on_non_pcm())
self.assertTrue(self.safety.get_controls_requested_lat())

# Second press should toggle to False
self._rx(self._main_cruise_button_msg(True))
self._rx(self._main_cruise_button_msg(False))
self.assertFalse(self.safety.get_acc_main_on_non_pcm())
self.assertFalse(self.safety.get_controls_requested_lat())
finally:
self._mads_states_cleanup()

def test_acc_main_non_pcm_multiple_toggles(self):
"""Test multiple consecutive toggles of non-PCM ACC main"""
try:
self._mads_states_cleanup()
self.safety.set_enable_mads(True, False)

expected_state = False
# Test several toggle cycles
for _ in range(5):
self.assertEqual(self.safety.get_acc_main_on_non_pcm(), expected_state)
self.assertEqual(self.safety.get_controls_requested_lat(), expected_state)

self._rx(self._main_cruise_button_msg(True))
self._rx(self._main_cruise_button_msg(False))
expected_state = not expected_state
finally:
self._mads_states_cleanup()

def test_acc_main_non_pcm_controls_sync(self):
"""Test that controls_requested_lat stays in sync with acc_main_non_pcm"""
try:
self._mads_states_cleanup()
self.safety.set_enable_mads(True, False)

# Test initial state
self.assertFalse(self.safety.get_acc_main_on_non_pcm())
self.assertFalse(self.safety.get_controls_requested_lat())

# Toggle and verify both states
for _ in range(3):
# Toggle on
self._rx(self._main_cruise_button_msg(True))
self._rx(self._main_cruise_button_msg(False))
self.assertTrue(self.safety.get_acc_main_on_non_pcm())
self.assertTrue(self.safety.get_controls_requested_lat())

# Toggle off
self._rx(self._main_cruise_button_msg(True))
self._rx(self._main_cruise_button_msg(False))
self.assertFalse(self.safety.get_acc_main_on_non_pcm())
self.assertFalse(self.safety.get_controls_requested_lat())

# Verify controls exit was called
self.assertEqual(self.safety.get_current_disengage_reason(),
self.safety.get_disengage_reason_button())
finally:
self._mads_states_cleanup()

0 comments on commit 55fdf2b

Please sign in to comment.