diff --git a/board/safety.h b/board/safety.h index 82e611f4a5..758223fbfc 100644 --- a/board/safety.h +++ b/board/safety.h @@ -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; } diff --git a/tests/safety/common.py b/tests/safety/common.py index f9b62e8992..701753bfcb 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -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()) diff --git a/tests/safety/test_coverage.sh b/tests/safety/test_coverage.sh index c5168004ae..a1dc1f046f 100755 --- a/tests/safety/test_coverage.sh +++ b/tests/safety/test_coverage.sh @@ -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"