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

Bump graph API test coverage. #132

Merged
merged 4 commits into from
Sep 24, 2020
Merged

Bump graph API test coverage. #132

merged 4 commits into from
Sep 24, 2020

Conversation

hidmic
Copy link
Contributor

@hidmic hidmic commented Sep 18, 2020

This pull request adds tests for each graph query API when used with bad arguments.

Test all query APIs with bad arguments.

Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic
Copy link
Contributor Author

hidmic commented Sep 18, 2020

I considered de-duplication, but despite commonalities, APIs have enough small differences to end up with an obfuscated function-parameterized test.

Copy link
Contributor

@brawner brawner left a comment

Choose a reason for hiding this comment

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

I agree about reducing duplication. It's probably not warranted for these unit tests


rmw_context_t context{rmw_get_zero_initialized_context()};
rmw_node_t * node{nullptr};
const char * const node_name = "my_test_node";
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it makes sense to have these string literals as member variables. Maybe make them constants defined at the top of the file? They can also be constexpr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do like keeping variables in fixture scope. I can make them static constexpr, but then I need explicit scope resolution. That's why I went with member variables for otherwise constant string literals.


TEST_F(
CLASSNAME(TestGraphAPI, RMW_IMPLEMENTATION),
get_node_names_with_enclaves_with_bad_arguments) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is a bit long and can be difficult to follow what each chunk is doing. Could you either add comments to just make it more explicit, or create several different tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable. Went with comments in 4435c51.

rmw_reset_error();
EXPECT_EQ(RMW_RET_OK, rmw_names_and_types_check_zero(&topic_names_and_types));

ASSERT_EQ(RMW_RET_OK, rmw_names_and_types_init(&topic_names_and_types, 1u, &allocator)) <<
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment describing why this is a bad argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 4435c51.

rmw_reset_error();
EXPECT_EQ(RMW_RET_OK, rmw_names_and_types_check_zero(&topic_names_and_types));

ASSERT_EQ(RMW_RET_OK, rmw_names_and_types_init(&topic_names_and_types, 1u, &allocator)) <<
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 4435c51.

rcutils_allocator_t invalid_allocator = rcutils_get_zero_initialized_allocator();
EXPECT_EQ(
RMW_RET_INVALID_ARGUMENT, rmw_get_subscriber_names_and_types_by_node(
node, &invalid_allocator, other_node_name, other_node_namespace, no_demangle, nullptr));
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the last argument need to be a nullptr for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! Fixed in 4435c51.

node, &allocator, other_node_name, other_node_namespace, no_demangle, nullptr));
rmw_reset_error();

ASSERT_EQ(RMW_RET_OK, rmw_names_and_types_init(&topic_names_and_types, 1u, &allocator)) <<
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment describing bad argument here and other similar instances

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 4435c51.

rcutils_allocator_t invalid_allocator = rcutils_get_zero_initialized_allocator();
EXPECT_EQ(
RMW_RET_INVALID_ARGUMENT, rmw_get_publisher_names_and_types_by_node(
node, &invalid_allocator, other_node_name, other_node_namespace, no_demangle, nullptr));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same q about last argument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, see 4435c51..

@@ -0,0 +1,808 @@
// Copyright 2020 Open Source Robotics Foundation, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning on adding versions of these tests that check the good cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally yes, but likely not with this PR. Rationale here is to cover basic error handling cases as described in ros2/rmw#272 only, which are the ones definitely not covered by tests in upper layers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfectly reasonable, just wanted to check.

@hidmic
Copy link
Contributor Author

hidmic commented Sep 18, 2020

Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic hidmic requested a review from brawner September 21, 2020 18:27
Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic
Copy link
Contributor Author

hidmic commented Sep 21, 2020

CI up to test_rmw_implementation:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@@ -0,0 +1,808 @@
// Copyright 2020 Open Source Robotics Foundation, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perfectly reasonable, just wanted to check.

Copy link
Contributor

@Lobotuerk Lobotuerk left a comment

Choose a reason for hiding this comment

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

LGTM after brawner comments

@hidmic
Copy link
Contributor Author

hidmic commented Sep 22, 2020

CI up to test_rmw_implementation, rcl, and rclcpp:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@hidmic
Copy link
Contributor Author

hidmic commented Sep 24, 2020

@ros-pull-request-builder retest this please

@hidmic
Copy link
Contributor Author

hidmic commented Sep 24, 2020

All CI's green! Merging.

@hidmic hidmic merged commit 64f1fd9 into master Sep 24, 2020
@delete-merged-branch delete-merged-branch bot deleted the hidmic/rmw-graph-api-tests branch September 24, 2020 13:34
ahcorde pushed a commit that referenced this pull request Oct 9, 2020
Test all ROS graph query APIs with bad arguments.

Signed-off-by: Michel Hidalgo <[email protected]>
ahcorde pushed a commit that referenced this pull request Oct 21, 2020
Test all ROS graph query APIs with bad arguments.

Signed-off-by: Michel Hidalgo <[email protected]>
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.

3 participants