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

fix(mrm_handler): fix bugprone-branch-clone #9729

Closed
wants to merge 5 commits into from

Conversation

kobayu858
Copy link
Contributor

Description

This is a fix based on clang-tidy bugprone-branch-clone error.

/home/emb4/autoware/autoware/src/universe/autoware.universe/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp:118:30: error: repeated branch in conditional chain [bugprone-branch-clone,-warnings-as-errors]
  if (is_emergency_holding_) {
                             ^
/home/emb4/autoware/autoware/src/universe/autoware.universe/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp:121:4: note: end of the original
  } else if (isEmergency() && param_.turning_hazard_on.emergency) {
   ^
/home/emb4/autoware/autoware/src/universe/autoware.universe/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp:121:67: note: clone 1 starts here
  } else if (isEmergency() && param_.turning_hazard_on.emergency) {
                                                                  ^
/home/emb4/autoware/autoware/src/universe/autoware.universe/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp:188:72: error: repeated branch in conditional chain [bugprone-branch-clone,-warnings-as-errors]
    if (!requestMrmBehavior(mrm_state_.behavior, RequestType::CANCEL)) {
                                                                       ^
/home/emb4/autoware/autoware/src/universe/autoware.universe/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp:190:6: note: end of the original
    } else if (requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) {
     ^
/home/emb4/autoware/autoware/src/universe/autoware.universe/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp:192:12: note: clone 1 starts here
    } else {
           ^

Related links

Parent Issue:

  • Link

How was this PR tested?

Notes for reviewers

None.

Interface changes

None.

Effects on system behavior

None.

Signed-off-by: kobayu858 <[email protected]>
@github-actions github-actions bot added the component:system System design and integration. (auto-assigned) label Dec 23, 2024
Copy link

github-actions bot commented Dec 23, 2024

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@kobayu858 kobayu858 added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Dec 23, 2024
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 29.74%. Comparing base (e5243e4) to head (7b59903).
Report is 165 commits behind head on main.

Files with missing lines Patch % Lines
...m/mrm_handler/src/mrm_handler/mrm_handler_core.cpp 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9729      +/-   ##
==========================================
- Coverage   29.74%   29.74%   -0.01%     
==========================================
  Files        1443     1443              
  Lines      108681   108688       +7     
  Branches    42663    42663              
==========================================
- Hits        32330    32328       -2     
- Misses      73172    73181       +9     
  Partials     3179     3179              
Flag Coverage Δ *Carryforward flag
differential 0.00% <0.00%> (?)
total 29.74% <ø> (+<0.01%) ⬆️ Carriedforward from f06639e

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

} else if (isEmergency() && param_.turning_hazard_on.emergency) {
// turn hazard on if vehicle is in emergency state and
// turning hazard on if emergency flag is true
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

@mkuri @TetsuKawa
The original implementation looks wierd: Is the following correct?

if (param_.turning_hazard_on.emergency) {
  if (is_emergency_holding_ || isEmergency()) {
    msg.command = HazardLightsCommand::ENABLE;
  } else {
    msg.command = HazardLightsCommand::NO_COMMAND;
  }
} else {
  msg.command = HazardLightsCommand::NO_COMMAND;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@mkuri
I think that kambe san’ s code is better.
Is there a problem?

Copy link
Contributor

@veqcc veqcc Jan 6, 2025

Choose a reason for hiding this comment

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

In additiion to that, isEmergerncy() is implemented as follows:
https://github.com/autowarefoundation/autoware.universe/blob/d86c46a35882e75051a0abcba55853da78c1d21f/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp#L540C1-L544C2

bool MrmHandler::isEmergency() const
{
  return !operation_mode_availability_->autonomous || is_emergency_holding_ ||
         is_operation_mode_availability_timeout;
}

So, if (is_emergency_holding_ || isEmergency()) is still redundant and just if (isEmergency()) seems enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

@veqcc
I agree. I think the following is fine too.

if (param_.turning_hazard_on.emergency) {
  if (isEmergency()) {
    msg.command = HazardLightsCommand::ENABLE;
  } else {
    msg.command = HazardLightsCommand::NO_COMMAND;
  }
} else {
  msg.command = HazardLightsCommand::NO_COMMAND;
}

Signed-off-by: kobayu858 <[email protected]>
Signed-off-by: kobayu858 <[email protected]>
Signed-off-by: kobayu858 <[email protected]>
Signed-off-by: kobayu858 <[email protected]>
@github-actions github-actions bot added component:planning Route planning, decision-making, and navigation. (auto-assigned) and removed component:planning Route planning, decision-making, and navigation. (auto-assigned) labels Dec 26, 2024
@veqcc veqcc closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:system System design and integration. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants