Skip to content

Commit

Permalink
Support code for unsafe mode unit tests (#478)
Browse files Browse the repository at this point in the history
* Support code for unsafe mode tests

* Fix pre-existing MISRA warning while I'm here
  • Loading branch information
jyoung8607 authored Apr 1, 2020
1 parent 5325b62 commit 51e0a55
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tests/safety/libpandasafety_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/safety/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 51e0a55

Please sign in to comment.