-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix lack of test coverage for angle_meas scaling in subaru.h #3084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,15 @@ def gen2_long_additional_tx_msgs(): | |
| def fwd_blacklisted_addr(lkas_msg=SubaruMsg.ES_LKAS): | ||
| return {SUBARU_CAM_BUS: [lkas_msg, SubaruMsg.ES_DashStatus, SubaruMsg.ES_LKAS_State, SubaruMsg.ES_Infotainment]} | ||
|
|
||
| def get_raw16_from_canpacket(msg) -> int: | ||
| # msg is cdata 'CANPacket_t *' | ||
| b4 = int(msg[0].data[4]) | ||
| b5 = int(msg[0].data[5]) | ||
| return b4 | (b5 << 8) | ||
|
|
||
| def to_signed16(x: int) -> int: | ||
| x &= 0xFFFF | ||
| return (x ^ 0x8000) - 0x8000 | ||
|
|
||
| class TestSubaruSafetyBase(common.CarSafetyTest): | ||
| FLAGS = 0 | ||
|
|
@@ -76,6 +85,7 @@ class TestSubaruSafetyBase(common.CarSafetyTest): | |
| DEG_TO_CAN = 100 | ||
|
|
||
| INACTIVE_GAS = 1818 | ||
| ANGLE_MEAS_SCALE = -2.17 | ||
|
|
||
| def setUp(self): | ||
| self.packer = CANPackerSafety("subaru_global_2017_generated") | ||
|
|
@@ -111,6 +121,21 @@ def _pcm_status_msg(self, enable): | |
| values = {"Cruise_Activated": enable} | ||
| return self.packer.make_can_msg_safety("CruiseControl", self.ALT_MAIN_BUS, values) | ||
|
|
||
| def test_angle_meas_scaling(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have a test to make sure
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure if that's the intention of those tests as they don't catch the mutation: Results in the mutation tests failing as before:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see, that steering angle test is only being done for angle-based cars
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright @sshane I updated to use the helper in common.py One note -- I wanted to just add this to all the cars, but not everything has an easily accessible As a workaround, I just added it in test_subaru.py
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the safety test/mode is for angle, it should subclass from that base angle test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The case we're looking at here is for torque-based, I'm hesitant to subclass from that because subarus don't support angle based steering yet.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @sshane , sorry to ping you again :). I refactored the scaling check into a dedicated test ( This should keep these tests a little more DRY, let me know if this is kind of what you were thinking |
||
| for angle in [0, 1, 10, 50, 90, 100, 180, 500]: | ||
| msg = None | ||
| # Fill the 6-sample buffer with nearly identical samples | ||
| for _ in range(6): | ||
| msg = self._angle_meas_msg(angle) | ||
| self._rx(msg) | ||
|
|
||
| raw16 = get_raw16_from_canpacket(msg) | ||
| signed = to_signed16(raw16) | ||
| expected = int(round(self.ANGLE_MEAS_SCALE * signed)) | ||
|
|
||
| self.assertEqual(self.safety.get_angle_meas_min(), expected) | ||
| self.assertEqual(self.safety.get_angle_meas_max(), expected) | ||
|
|
||
|
|
||
| class TestSubaruStockLongitudinalSafetyBase(TestSubaruSafetyBase): | ||
| def _cancel_msg(self, cancel, cruise_throttle=0): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed, but is there to demonstrate that the tests added cover the mutant tests for this line
Feel free to accept this suggestion to undo the change: