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

Add fault injection macro unit tests #27

Merged
merged 3 commits into from
Aug 26, 2020
Merged

Conversation

brawner
Copy link
Contributor

@brawner brawner commented Jul 29, 2020

Adding fault injection unit tests to rmw_dds_common. This should get coverage to about 99%. I'll post CI results soon.

Signed-off-by: Stephen Brawner brawner@gmail.com

Signed-off-by: Stephen Brawner <brawner@gmail.com>
Signed-off-by: Stephen Brawner <brawner@gmail.com>
@brawner
Copy link
Contributor Author

brawner commented Aug 12, 2020

Builds and tests of the following packages rcutils, rcl_logging_spdlog, rosidl_typesupport_c, rosidl_typesupport_cpp, rcl, rcl_action, rcl_lifecycle, rosidl_runtime_c, rmw_dds_common, rmw

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

@brawner
Copy link
Contributor Author

brawner commented Aug 24, 2020

Testing this PR branch against current ros 2 branches. Testing --packages-select rmw_dds_common

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

@@ -1550,3 +1551,64 @@ TEST(test_graph_cache, bad_arguments)
rcutils_reset_error();
}
}

TEST(test_graph_cache, get_writers_info_by_topic_maybe_fail)
Copy link
Contributor

Choose a reason for hiding this comment

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

@brawner would it make sense to split this test case into three separate ones (i.e. one for each method being fault injected).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done! I think I originally intended for that given the test name.

graph_cache, {
{"participant1", "ns1", "node1"},
{"participant1", "ns1", "node2"},
{"participant1", "ns2", "node1"}});
Copy link
Contributor

Choose a reason for hiding this comment

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

@brawner perhaps not an issue, but should the test fixture be setup outside the fault injection loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, created a test fixture class.

&allocator,
&info);
if (RMW_RET_OK == ret) {
ret = rmw_topic_endpoint_info_array_fini(&info, &allocator);
Copy link
Contributor

Choose a reason for hiding this comment

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

@brawner should this be:

Suggested change
ret = rmw_topic_endpoint_info_array_fini(&info, &allocator);
EXPECT_EQ(RWM_RET_OK, rmw_topic_endpoint_info_array_fini(&info, &allocator));

instead? Also, what if fault injection occurs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it will fail during a fault injection test because there will be at least one hook in there. I added a check on the return of fini just in case it needs be done a second time.

Copy link

@Blast545 Blast545 left a comment

Choose a reason for hiding this comment

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

Minor question

RCUTILS_FAULT_INJECTION_TEST(
{
GraphCache graph_cache;
add_participants(graph_cache, {"participant1"});

Choose a reason for hiding this comment

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

Can this init section be left out of the fault_injection test macro?

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 think so. I created a test fixture class and split this test into three separate TEST_Fs

Signed-off-by: Stephen Brawner <brawner@gmail.com>
@@ -1550,3 +1551,64 @@ TEST(test_graph_cache, bad_arguments)
rcutils_reset_error();
}
}

TEST(test_graph_cache, get_writers_info_by_topic_maybe_fail)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done! I think I originally intended for that given the test name.

RCUTILS_FAULT_INJECTION_TEST(
{
GraphCache graph_cache;
add_participants(graph_cache, {"participant1"});
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 think so. I created a test fixture class and split this test into three separate TEST_Fs

graph_cache, {
{"participant1", "ns1", "node1"},
{"participant1", "ns1", "node2"},
{"participant1", "ns2", "node1"}});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, created a test fixture class.

&allocator,
&info);
if (RMW_RET_OK == ret) {
ret = rmw_topic_endpoint_info_array_fini(&info, &allocator);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it will fail during a fault injection test because there will be at least one hook in there. I added a check on the return of fini just in case it needs be done a second time.

ret = rcutils_string_array_fini(&namespaces);
ret = rcutils_string_array_fini(&enclaves);
// rcutils_string_array_fini is not under test, so disable fault injection test here.
int64_t fault_injection_count = rcutils_fault_injection_get_count();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hidmic This is the only location here that would make sense to disable fault injection testing because rcutils_string_array_fini is out of scope for this test. Do you think it would make sense to submit a PR to rcutils to add in the disable fault injection testing macros?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine as-is for the time being. If it starts showing up more often, we can add a macro.

@brawner
Copy link
Contributor Author

brawner commented Aug 26, 2020

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

@brawner
Copy link
Contributor Author

brawner commented Aug 26, 2020

Trying again after merging ros2/rcutils#283

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

@brawner
Copy link
Contributor Author

brawner commented Aug 26, 2020

rpr build fails because it requires a new release to rcutils for the fault injection macros, but the CI builds all pass so this should be good.

@brawner brawner merged commit 14e666d into master Aug 26, 2020
@delete-merged-branch delete-merged-branch bot deleted the brawner/fault-injection-macros branch August 26, 2020 23:27
@dirk-thomas
Copy link
Member

rpr build fails because it requires a new release to rcutils for the fault injection macros, but the CI builds all pass so this should be good.

Why not first release rcutils and once retriggered CI passes merge?

@brawner
Copy link
Contributor Author

brawner commented Aug 26, 2020

That's reasonable. It will be my first release, so I was just unsure about the whole process. I'll work to figure it out.

ahcorde pushed a commit that referenced this pull request Oct 13, 2020
* Add fault injection macro unit tests

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* target definitions

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* PR Fixup

Signed-off-by: Stephen Brawner <brawner@gmail.com>
ahcorde pushed a commit that referenced this pull request Oct 15, 2020
* Add fault injection macro unit tests

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* target definitions

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* PR Fixup

Signed-off-by: Stephen Brawner <brawner@gmail.com>
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.

4 participants