From 51e0a55d6d5fce5a9edf4178baccd4b2a4e23290 Mon Sep 17 00:00:00 2001 From: Jason Young <46612682+jyoung8607@users.noreply.github.com> Date: Wed, 1 Apr 2020 10:17:51 -0700 Subject: [PATCH] Support code for unsafe mode unit tests (#478) * Support code for unsafe mode tests * Fix pre-existing MISRA warning while I'm here --- board/main.c | 6 +++--- tests/safety/common.py | 7 +++++++ tests/safety/libpandasafety_py.py | 2 ++ tests/safety/test.c | 8 ++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/board/main.c b/board/main.c index dfd61ad8d2c333..d11f003f47bdb8 100644 --- a/board/main.c +++ b/board/main.c @@ -472,9 +472,9 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // **** 0xdf: set unsafe mode case 0xdf: // you can only set this if you are in a non car safety mode - if (current_safety_mode == SAFETY_SILENT || - current_safety_mode == SAFETY_NOOUTPUT || - current_safety_mode == SAFETY_ELM327) { + if ((current_safety_mode == SAFETY_SILENT) || + (current_safety_mode == SAFETY_NOOUTPUT) || + (current_safety_mode == SAFETY_ELM327)) { unsafe_mode = setup->b.wValue.w; } break; diff --git a/tests/safety/common.py b/tests/safety/common.py index e0296d3ac11d54..875bfac76a5f87 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -2,6 +2,13 @@ MAX_WRONG_COUNTERS = 5 +class UNSAFE_MODE: + DEFAULT = 0 + DISABLE_DISENGAGE_ON_GAS = 1 + DISABLE_STOCK_AEB = 2 + ENABLE_WEAK_STEERING_WHILE_NOT_ENGAGED = 4 + RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX = 8 + def make_msg(bus, addr, length=8): to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') if addr >= 0x800: diff --git a/tests/safety/libpandasafety_py.py b/tests/safety/libpandasafety_py.py index 3b552d0f80ed62..295a04848ff7ae 100644 --- a/tests/safety/libpandasafety_py.py +++ b/tests/safety/libpandasafety_py.py @@ -32,6 +32,8 @@ void set_controls_allowed(bool c); bool get_controls_allowed(void); +void set_unsafe_mode(int mode); +int get_unsafe_mode(void); void set_relay_malfunction(bool c); bool get_relay_malfunction(void); void set_gas_interceptor_detected(bool c); diff --git a/tests/safety/test.c b/tests/safety/test.c index 9c7955b2869ce0..393a45b65a84ec 100644 --- a/tests/safety/test.c +++ b/tests/safety/test.c @@ -81,6 +81,10 @@ void set_controls_allowed(bool c){ controls_allowed = c; } +void set_unsafe_mode(int mode){ + unsafe_mode = mode; +} + void set_relay_malfunction(bool c){ relay_malfunction = c; } @@ -93,6 +97,10 @@ bool get_controls_allowed(void){ return controls_allowed; } +int get_unsafe_mode(void){ + return unsafe_mode; +} + bool get_relay_malfunction(void){ return relay_malfunction; }