From 55fdf2b758700330c0cd2d2a3f413455f4b6b9bb Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 9 Dec 2024 00:08:44 -0500 Subject: [PATCH] more --- tests/libpanda/safety_helpers.h | 4 ++ tests/libpanda/safety_helpers.py | 2 + tests/safety/mads_common.py | 72 ++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/tests/libpanda/safety_helpers.h b/tests/libpanda/safety_helpers.h index e9adeb1b86..a491ce7413 100644 --- a/tests/libpanda/safety_helpers.h +++ b/tests/libpanda/safety_helpers.h @@ -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; //} diff --git a/tests/libpanda/safety_helpers.py b/tests/libpanda/safety_helpers.py index 1c6c88999d..8f7c7dacde 100644 --- a/tests/libpanda/safety_helpers.py +++ b/tests/libpanda/safety_helpers.py @@ -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): @@ -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: ... diff --git a/tests/safety/mads_common.py b/tests/safety/mads_common.py index 0ef0806a97..c5b5cefa48 100644 --- a/tests/safety/mads_common.py +++ b/tests/safety/mads_common.py @@ -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()