Skip to content
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

Feature/unit tests/simple sensor simulator #27

Open
wants to merge 178 commits into
base: feature/simple_sensor_simulator_unit_tests_part3
Choose a base branch
from

Conversation

robomic
Copy link

@robomic robomic commented Jun 20, 2024

Description

Abstract

This PR contains unit tests for multiple classes, all of them are a part of simple_sensor_simulator package.

  1. SensorSimulation
  2. ScenarioSimulator
  3. OccupancyGridBuilder

Details

List of tests included in this PR:

  1. ScenarioSimulator.initialize_defaultPort
  2. ScenarioSimulator.initialize_customPort
  3. ScenarioSimulatorTest.updateFrame_correct
  4. ScenarioSimulatorTest.updateFrame_noInitialize
  5. ScenarioSimulatorTest.spawnVehicleEntity_firstEgo
  6. ScenarioSimulatorTest.spawnVehicleEntity_npc
  7. ScenarioSimulatorTest.spawnPedestrianEntity
  8. ScenarioSimulatorTest.spawnMiscObjectEntity
  9. ScenarioSimulatorTest.despawnEntity_vehicle
  10. ScenarioSimulatorTest.despawnEntity_pedestrian
  11. ScenarioSimulatorTest.despawnEntity_miscObject
  12. ScenarioSimulatorTest.despawnEntity_invalidName
  13. ScenarioSimulatorTest.attachDetectionSensor
  14. ScenarioSimulatorTest.attachLidarSensor
  15. ScenarioSimulatorTest.attachOccupancyGridSensor
  16. SensorSimulationTest.attachLidarSensor_wrongArchitecture
  17. SensorSimulationTest.attachLidarSensor_correctConfiguration
  18. SensorSimulationTest.attachDetectionSensor_wrongArchitecture
  19. SensorSimulationTest.attachDetectionSensor_correctConfiguration
  20. SensorSimulationTest.attachOccupancyGridSensor_wrongArchitecture
  21. SensorSimulationTest.attachOccupancyGridSensor_correctConfiguration
  22. OccupancyGridBuilder.add_overLimit
  23. OccupancyGridBuilder.add_primitiveInside
  24. OccupancyGridBuilder.add_primitiveProtruding
  25. OccupancyGridBuilder.add_primitiveInCenter
  26. OccupancyGridBuilder.reset

References

Jira ticket: internal link

Destructive Changes

There are no destructive changes.

yamacir-kit and others added 30 commits May 29, 2023 16:16
Signed-off-by: yamacir-kit <[email protected]>
…ion_action/qos_depth

fix(action): fix fault injection action - qos
@robomic robomic requested a review from SzymonParapura June 20, 2024 12:18
{
auto request = simulation_api_schema::InitializeRequest();
request.set_lanelet2_map_path(
ament_index_cpp::get_package_share_directory("traffic_simulator") + "/map/lanelet2_map.osm");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid dependency on the traffic_simulator package, consider adding the map file lanelet2_map.osm to the simple_sensor_simulator package. This way, the tests won't break if there are changes in the traffic_simulator package.

#include <simple_sensor_simulator/sensor_simulation/occupancy_grid/grid_traversal.hpp>
#include <simple_sensor_simulator/sensor_simulation/occupancy_grid/occupancy_grid_builder.hpp>

auto printGrid(const simple_sensor_simulator::OccupancyGridBuilder & builder) -> void

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this function is not currently being used. Perhaps it was helpful during the creation of tests, but if it's no longer needed, we might consider removing it.

{
const auto & grid = builder.get();
for (size_t i = static_cast<size_t>(0); i < builder.height; ++i) {
for (size_t j = static_cast<size_t>(0); j < builder.width; ++j) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, using 0 directly is completely safe in this specific case. When you have a literal that is zero, it is safe to omit the static_cast, which can improve readability.

However, in the tests below, the use of static_cast is appropriate because it clearly describes the intent and ensures safe type conversion.

1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
// clang-format on

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving results_expected to the beginning of the test could enhance clarity. Similarly, you might consider applying this approach (Arrange-Act-Assert pattern) to the tests below as well.

return request;
}

class ScenarioSimulatorTest : public testing::Test

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, it is a good practice to separate implementation from headers. But if it passed the review at Tier4, then it's okay

auto makeAttachLidarSensorRequest() -> simulation_api_schema::AttachLidarSensorRequest
{
auto request = simulation_api_schema::AttachLidarSensorRequest();
auto configuration = traffic_simulator::helper::constructLidarConfiguration(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the functions makeAttachDetectionSensorRequest and makeAttachLidarSensorRequest are using helper functions from the traffic_simulator package to construct configurations. This dependency could cause tests in the scenario_simulator to fail if there are changes in the traffic_simulator package, rather than changes in the simulation_api_schema.pb.h.

Given that only two helper functions are involved, it seems reasonable to duplicate these functions within the simple_sensor_simulator package. This would ensure that the tests fail solely due to changes in the simulation_api_schema.pb.h without being affected by modifications in the traffic_simulator package.

Copy link

@SzymonParapura SzymonParapura Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can solve this similarly to how we handle makeAttachOccupancyGridSensorRequest by defining the configuration directly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to add new directory where we can put a file with definition of constructLidarConfiguration and other useful functions. Take a look here PR

EXPECT_TRUE(client.call(makeUpdateFrameRequest()).result().success());

rclcpp::shutdown();
server.join();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider moving these lines to destructor or TearDown(). And try to apply this to tests below

hakuturu583 and others added 24 commits June 24, 2024 11:19
Signed-off-by: Masaya Kataoka <[email protected]>
Signed-off-by: Masaya Kataoka <[email protected]>
Signed-off-by: Masaya Kataoka <[email protected]>
…ct_entity

Feature/unit tests/misc object entity
Optimize entity frame computation.
fix: Automated branch deletion is not working properly
@robomic robomic changed the base branch from feature/simple_sensor_simulator_unit_test to feature/simple_sensor_simulator_unit_tests_part3 June 28, 2024 11:55
@robomic
Copy link
Author

robomic commented Jun 28, 2024

This PR contains newest changes from tier4/master and is built on this branch.

Copy link

@SzymonParapura SzymonParapura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

We need to wait with this branch because it is based on a branch that hasn't been merged yet. To avoid submitting the same code for review twice, we should merge my branch first, and then yours. That's what I think would be the best approach.

rclcpp::shutdown();
server.join();
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might consider adding a header guard also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants