Skip to content

Commit

Permalink
safety: full coverage (#1750)
Browse files Browse the repository at this point in the history
* stash

* if x > xy.x[0], then subsequent x < xy.x[i+1] enforces it is monotonic, or uses last y

* rm

* test safety tick

* coverage: include safety.h

* car-only test

* MAX

* op

* add safety_config_valid
  • Loading branch information
sshane authored Dec 9, 2023
1 parent fbef311 commit cf108cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 1 addition & 3 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,7 @@ float interpolate(struct lookup_t xy, float x) {
float dx = xy.x[i+1] - x0;
float dy = xy.y[i+1] - y0;
// dx should not be zero as xy.x is supposed to be monotonic
if (dx <= 0.) {
dx = 0.0001;
}
dx = MAX(dx, 0.0001);
ret = (dy * (x - x0) / dx) + y0;
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 @@ -1046,3 +1046,10 @@ def test_vehicle_moving(self):
# past threshold
self._rx(self._vehicle_moving_msg(self.STANDSTILL_THRESHOLD + 1))
self.assertTrue(self.safety.get_vehicle_moving())

def test_safety_tick(self):
self.safety.set_timer(int(2e6))
self.safety.set_controls_allowed(True)
self.safety.safety_tick_current_safety_config()
self.assertFalse(self.safety.get_controls_allowed())
self.assertFalse(self.safety.safety_config_valid())
2 changes: 1 addition & 1 deletion tests/safety/test_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

# test coverage
GCOV_OUTPUT=$(gcov -n ../libpanda/panda.c)
INCOMPLETE_COVERAGE=$(echo "$GCOV_OUTPUT" | paste -s -d' \n' | grep "File.*safety/safety_.*.h" | grep -v "100.00%" || true)
INCOMPLETE_COVERAGE=$(echo "$GCOV_OUTPUT" | paste -s -d' \n' | grep -E "File.*(safety\/safety_.*)|(safety)\.h" | grep -v "100.00%" || true)
if [ -n "$INCOMPLETE_COVERAGE" ]; then
echo "FAILED: Some files have less than 100% coverage:"
echo "$INCOMPLETE_COVERAGE"
Expand Down

0 comments on commit cf108cd

Please sign in to comment.