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 convert edge cases #2135

Merged

Conversation

Dennis40816
Copy link
Contributor

@Dennis40816 Dennis40816 commented Dec 15, 2023

Pre-Review Checklist for the PR Author

  1. Add a second reviewer for complex new features or larger refactorings
  2. Code follows the coding style of CONTRIBUTING.md
  3. Tests follow the best practice for testing
  4. Changelog updated in the unreleased section including API breaking changes
  5. Branch follows the naming format (iox-123-this-is-a-branch)
  6. Commits messages are according to this guideline
  7. Update the PR title
    • Follow the same conventions as for commit messages
    • Link to the relevant issue
  8. Relevant issues are linked
  9. Add sensible notes for the reviewer
  10. All checks have passed (except task-list-completed)
  11. All touched (C/C++) source code files from iceoryx_hoofs are added to ./clang-tidy-diff-scans.txt
  12. Assign PR to reviewer

Notes for Reviewer

I'm not sure the values of new IOX_2055_WORKAROUNDs are proper or not. Please check them.

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Code according to our coding style and naming conventions
  • Unit tests have been written for new behavior
  • Public API changes are documented via doxygen
  • Copyright owner are updated in the changed files
  • All touched (C/C++) source code files from iceoryx_hoofs have been added to ./clang-tidy-diff-scans.txt
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

References

Copy link

codecov bot commented Dec 15, 2023

Codecov Report

Attention: 63 lines in your changes are missing coverage. Please review.

Comparison is base (154b5a5) 80.22% compared to head (e02d08b) 80.12%.
Report is 3 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2135      +/-   ##
==========================================
- Coverage   80.22%   80.12%   -0.11%     
==========================================
  Files         418      418              
  Lines       16172    16218      +46     
  Branches     2255     2251       -4     
==========================================
+ Hits        12974    12994      +20     
- Misses       2399     2420      +21     
- Partials      799      804       +5     
Flag Coverage Δ
unittests 79.91% <76.49%> (-0.11%) ⬇️
unittests_timing 15.21% <0.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
iceoryx_hoofs/cli/include/iox/cli/arguments.inl 58.82% <100.00%> (ø)
...x_hoofs/utility/include/iox/std_string_support.hpp 100.00% <100.00%> (ø)
...eoryx_posh/internal/runtime/ipc_interface_base.hpp 100.00% <ø> (ø)
...yx_posh/internal/runtime/ipc_runtime_interface.hpp 100.00% <ø> (ø)
iceoryx_posh/source/popo/client_options.cpp 100.00% <100.00%> (ø)
iceoryx_posh/source/popo/server_options.cpp 100.00% <100.00%> (ø)
iceoryx_posh/source/popo/subscriber_options.cpp 93.75% <100.00%> (+0.41%) ⬆️
iceoryx_posh/source/roudi/process_manager.cpp 64.61% <100.00%> (-0.09%) ⬇️
iceoryx_posh/source/roudi/roudi.cpp 66.28% <100.00%> (+0.65%) ⬆️
...ceoryx_posh/source/roudi/roudi_cmd_line_parser.cpp 100.00% <100.00%> (ø)
... and 7 more

... and 4 files with indirect coverage changes

@elBoberido
Copy link
Member

Thanks for the PR. I'll have a closer look tomorrow at the changes but I'm quite happy that the out parameters are soon a thing of the past :)

Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

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

I did not yet fully review the tests and convert.inl. Just had a remark regarding the newly introduced alwaysSuccess. Will finish the review tomorrow.

I think we (and always when I say we I actually mean you :) ) also need to add tests for the corner cases this PR fixes. If you think it will blow the PR up too much, it could also be done in a follow up PR.

iceoryx_dust/cli/include/iox/cli/arguments.inl Outdated Show resolved Hide resolved
iceoryx_dust/utility/include/iox/detail/serialization.inl Outdated Show resolved Hide resolved
iceoryx_examples/iceperf/main_follower.cpp Outdated Show resolved Hide resolved
iceoryx_posh/source/roudi/roudi.cpp Outdated Show resolved Hide resolved
iceoryx_dust/utility/include/iox/detail/serialization.inl Outdated Show resolved Hide resolved
iceoryx_posh/source/runtime/ipc_interface_base.cpp Outdated Show resolved Hide resolved
iceoryx_posh/source/runtime/ipc_runtime_interface.cpp Outdated Show resolved Hide resolved
iceoryx_posh/source/roudi/port_manager.cpp Outdated Show resolved Hide resolved
iceoryx_posh/source/runtime/posh_runtime_impl.cpp Outdated Show resolved Hide resolved
tools/introspection/source/introspection_app.cpp Outdated Show resolved Hide resolved
Rename `fromString` to `from_string`. Note that the name of test cases
are not included.

Signed-off-by: Dennis Liu <[email protected]>
Remove dest for numeric conversion. Now, the part of `for_string` will
return iox::optional.

Also, we introduce `validate_return_value` and `check_edge_case` to
simplify the code of checking. The former can be used to return an
iox::optional object while the latter is used in the former to check
whether any conversion failure happened.

Signed-off-by: Dennis Liu <[email protected]>
The from_string API has been updated. It now returns an
iox::optional of the specified target value type, and the
dest parameter has been removed.

Subsequently, functions that utilize from_string have been
restructured to accommodate the new calling format. Some of
these functions now require default values for the value_or
method, but I am uncertain whether these default values are
appropriate.

A new function named forceOkReturnValue has been introduced
(the name may be subject to change later). This function
addresses a specific issue encountered with uint64_t cases.
Previously, we used failureReturnValue(ULLONG_MAX), which
incorrectly flagged the valid conversion case of
"18446744073709551615" as a failure. With
forceOkReturnValue, the condition call.has_error() should
consistently return false for this scenario. The accuracy of
the conversion result is now assessed within the
check_edge_case function.

As a note, areas marked with @todo iox-eclipse-iceoryx#2055 still require
modifications, most of which pertain to documentation. These
will be addressed in the upcoming commit.

Signed-off-by: Dennis Liu <[email protected]>
In iceoryx_posh/source/runtime/posh_runtime_impl.cpp,
convert::from_string are used to convert the segment id and
offset. However, the conversion failure might occur.

Therefore, an new error type:
`SEGMENT_ID_OR_OFFSET_CONVERSION_FAILURE` are introduced to
be utilized as an error return value, reminding user a conversion
failure happened in posh runtime.

Signed-off-by: Dennis Liu <[email protected]>
@Dennis40816 Dennis40816 force-pushed the iox-2055-fix-convert-edge-cases branch from 1c377a8 to 809dddc Compare December 19, 2023 08:26
Copy link
Member

@elBoberido elBoberido 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. Mostly nitpicks and a few new tests for the edge cases needs to be written :)

iceoryx_posh/source/runtime/ipc_interface_base.cpp Outdated Show resolved Hide resolved
iceoryx_posh/source/runtime/ipc_interface_base.cpp Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.hpp Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.hpp Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.hpp Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/test/moduletests/test_utility_convert.cpp Outdated Show resolved Hide resolved
Change the template args of specialization of `from_string`
from length fixed type to basic type.

Signed-off-by: Dennis Liu <[email protected]>
Function named `convert_id_and_offset` was created.

Signed-off-by: Dennis Liu <[email protected]>
Now, `is_valid_errno` will also print the string that cause
failure.

Signed-off-by: Dennis Liu <[email protected]>
@Dennis40816
Copy link
Contributor Author

It seems that there are some errors occurring during the execution of all_test. I will take a closer look at it tomorrow.

@elBoberido
Copy link
Member

elBoberido commented Dec 20, 2023

It seems that there are some errors occurring during the execution of all_test. I will take a closer look at it tomorrow.

I think you forgot long and unsigned long

- Add long and unsigned long specialization for from_string.
- Remove deprecated `is_iox_string` and `GetCapacity`.
- Move the specialization of std::string to
  `iox/std_string_support.hpp`.
- Replace `enable_if_t` by `if constexpr` branch.

Signed-off-by: Dennis Liu <[email protected]>
- Add a todo in `is_valid_errno`.
- Clean `errno` before leaving from `evaluate return value`.

Signed-off-by: Dennis Liu <[email protected]>
Modify the target function of the `IOX_POSIX_CALL`
invocation, and for those that might encounter an edge case
error due to the invocation of `failureReturnValue`, replace
it with `alwaysSuccess`. Specifically, this applies to
unsigned/signed types: `long long`, `long`, and `int` (for
32-bit systems). Please note that we assume `int` is always
4 bytes, and `long long` is definitively 8 bytes.

Signed-off-by: Dennis Liu <[email protected]>
@Dennis40816
Copy link
Contributor Author

If there are no other issues with the aforementioned modifications, I think we can start adding some edge cases for testing purposes.

@elBoberido
Copy link
Member

If there are no other issues with the aforementioned modifications, I think we can start adding some edge cases for testing purposes.

I did not yet look at the code but I don't expect any issues. Feel free to start whenever it pleases you :)

Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

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

Sorry, I gave you bad advice with suppressErrorMessagesForErrnos. With ignoreErrnos the alwaysSuccess method can be removed.

Except that there are just a few minor things like not having to explicitely cache the errno because it is already done in the result of the posix call.

iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.hpp Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_posh/source/runtime/ipc_interface_base.cpp Outdated Show resolved Hide resolved
iceoryx_posh/source/runtime/ipc_interface_base.cpp Outdated Show resolved Hide resolved
Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

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

I think now is everything covered. The check for signaling NAN can be removed. Sorry for that :)

iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
iceoryx_hoofs/utility/include/iox/detail/convert.inl Outdated Show resolved Hide resolved
Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

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

Except for some additional tests to check for the edge cases this looks now great.

From my point of view the new tests could also be added in a new PR if you think this one is already overloaded. I leave it to you.

@Dennis40816
Copy link
Contributor Author

Thank you for your review. I would like to create a new PR. Our conversation on this PR has already been quite lengthy, and I believe there will be more to discuss when testing edge cases. Therefore, I think we should start a new PR focused on conducting tests for edge cases :)

@elBoberido
Copy link
Member

Merging this PR. All the old tests pass and additional tests for corner cases will be added in a separate PR

@elBoberido elBoberido merged commit fe3ef2e into eclipse-iceoryx:master Jan 2, 2024
23 of 24 checks passed
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.

'convert' is broken for edge cases
2 participants