From 7281231f4f4d76243adbc9dde0a20005a9ee29e2 Mon Sep 17 00:00:00 2001 From: Mike Wake Date: Fri, 31 Jan 2025 12:32:18 +1100 Subject: [PATCH] dwb_critics flaky test - lineCost coordinates must be within costmap (#4884) There is no protection/checks in the pathway from lineCost to costmap_2d::getIndex(mx, my) for grid coordinates that exceed the of bounds of the allocated costmap. (presumably for speed) This test was triggering an off by one error attempting to read the the 2500 byte costmap at byte 2503 costmap size 50x50. getIndex(3, 50) = my * size_x_ + mx; = 50 * 50 + 3; = 2503 Signed-off-by: Mike Wake --- .../dwb_critics/test/obstacle_footprint_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nav2_dwb_controller/dwb_critics/test/obstacle_footprint_test.cpp b/nav2_dwb_controller/dwb_critics/test/obstacle_footprint_test.cpp index 5c400c47d5a..4a6a091deff 100644 --- a/nav2_dwb_controller/dwb_critics/test/obstacle_footprint_test.cpp +++ b/nav2_dwb_controller/dwb_critics/test/obstacle_footprint_test.cpp @@ -248,7 +248,9 @@ TEST(ObstacleFootprint, LineCost) costmap_ros->getCostmap()->setCost(4, 3, 100); costmap_ros->getCostmap()->setCost(4, 4, 100); - ASSERT_EQ(critic->lineCost(3, 3, 0, 50), 50); // all 50 + auto max_y_in_grid_coordinates = costmap_ros->getCostmap()->getSizeInCellsY() - 1; + ASSERT_EQ(max_y_in_grid_coordinates, 49); + ASSERT_EQ(critic->lineCost(3, 3, 0, max_y_in_grid_coordinates), 50); // all 50 ASSERT_EQ(critic->lineCost(4, 4, 0, 10), 100); // all 100 ASSERT_EQ(critic->lineCost(0, 50, 3, 3), 100); // pass 50 and 100 }