Repository navigation
Fix findWayPointIndicesForDurationAfterStart method when out of bounds - #3626
Conversation
…s and add unit tests
|
Hey @nbbrooks , this pr is ready for review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3626 +/- ##
==========================================
- Coverage 46.24% 46.03% -0.20%
==========================================
Files 726 726
Lines 59430 59492 +62
Branches 7625 7623 -2
==========================================
- Hits 27477 27381 -96
- Misses 31787 31945 +158
Partials 166 166 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nbbrooks
left a comment
There was a problem hiding this comment.
This is looking good considering the unclear intended behavior from the original function description and the current [old] error handling patterns in the codebase. As I see it, the expected output with edge cases should be:
// If waypoints are empty: before == 0, after == 0, blend == 0 (invalid - empty trajectory)
// If target duration < 0: before == 0, after == 0, blend == 0 (invalid - before trajectory has started)
// If target duration > total duration of waypoints, before == size() - 1, after == size() - 1, blend == 1 (after trajectory has completed)
// If 1 waypoint and target duration == total duration of waypoints, before == 0, after == 0, blend == 1 (at single point trajectory completion)
// Else before == last waypoint index with total duration < target duration, after == before + 1, blend == fraction of target duration between total duration @ before and total duration @ after
// Therefore, if 2 waypoints and target duration == total duration of waypoints, before == 0, after == 1, blend == 1 (at trajectory completion)
Since you are being so thorough, here are the last changes I suggest:
- Change access to use at() as you noted. I would not expect this to be in a real-time loop or have significant impact.
- Consider updating your test names to be more descriptive of the corner case they are checking (my suggestions are
RobotTrajectoryFindWayPointIndicesBetweenWaypoints,RobotTrajectoryFindWayPointIndicesAtLastOfManyWaypoints,RobotTrajectoryFindWayPointIndicesAfterLastWaypoint, andRobotTrajectoryFindWayPointIndicesEmptyWaypoints) - Add two more tests to check the remaining cases:
RobotTrajectoryFindWayPointIndicesBeforeFirstWaypointandRobotTrajectoryFindWayPointIndicesAtLastOfSingleWaypointor something to that effect.
|
Nice! Then I change the unit test to use |
|
Thank you Nathan for the code review! I learned a lot. |
#3626) (#3874) * Fix findWayPointIndicesForDurationAfterStart method when out of bounds and add unit tests * Use .at() to index deque; Add 2 more edge test cases * Revise function comments --------- (cherry picked from commit 4287c80) Co-authored-by: Xingxin HE <[email protected]> Co-authored-by: Nathan Brooks <[email protected]> Co-authored-by: Ezra Brooks <[email protected]>
Description
The fix is to address the bug raised in issue #3612 which causes UB. The change has been
moveit/moveit2:rolling-cimoveit_core/robot_trajectory/test/test_robot_trajectory.cppChecklist
Misc.
Actually, the wording "Create tests, which fail without this PR" is not strictly correct. Without the fix, the unit tests will "pass", but it passes with undefined behavior. Meaning, all the
EXPECT_xxafter the callfindWayPointIndicesForDurationAfterStartwill be omitted and the google test doesn't actually check it. I once plan to use theEXPECT_EXITbut UB doesn't always result in a SIGSEGV.In my perspective, I prefer the
.at()over[index]. See the guideline. But I guess using.at(might cause a little bit performance degrade in real time control of robot? If we use the[index]approach, then the unit test should run with AddressSanitizer or something. Since I am not quite familiar with the CI/CD of moveit2, therefore I defer whether to keep current implementation or change to.at()to @nbbrooks .