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 tests for user-defined signal handler #215

Merged
merged 4 commits into from
Aug 14, 2017
Merged

Conversation

dhood
Copy link
Member

@dhood dhood commented Aug 9, 2017

connects to ros2/rclcpp#353

This adds two tests.

  1. One checks that a user-defined signal handler is called on interrupt after rclcpp::init has been called (we call it manually in the rclcpp signal handler).
  2. The other checks that the user-defined signal handler is called on interrupt after rclcpp::shutdown has been called, and furthermore that the rclcpp signal handler is not called (notice that the output of that test expects no signal_handler(2) print from rclcpp). The latter is only true with Restore old signal handler after shutdown rclcpp#353
  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dhood dhood self-assigned this Aug 9, 2017
@dhood dhood added in progress Actively being worked on (Kanban column) in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Aug 9, 2017
@dhood
Copy link
Member Author

dhood commented Aug 9, 2017

investigating windows failures and putting this back in progress in the meantime

@dhood dhood added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Aug 9, 2017
@mikaelarguedas
Copy link
Member

Should ticket it connects to be placed in progress as well ?

@dhood
Copy link
Member Author

dhood commented Aug 9, 2017

launch_testing can't send an interrupt to windows, it just terminates the process.

So, this testing method won't work for windows. Quick fix is to disable the test on windows, but then we aren't testing on any platforms where HAS_SIGACTION is not defined.

Here are some options for getting the test coverage for the code path where HAS_SIGACTION isn't defined:

  1. Make the test work for windows (I'd need suggestions on how to accomplish this)
  2. Replace the HAS_SIGACTION logic in rclcpp with a USE_SIGACTION identifier, which is always 0 for platforms that don't have support for sigaction, and optionally 1 for platforms that do.
    1. in some testing instances, build rclcpp with USE_SIGACTION set to 0. which instances though?
  3. Conditionally build support for enabling runtime decision of USE_SIGACTION.
    1. run tests twice for (supported) platforms, once with USE_SIGACTION true and once false.

Though, this code path wasn't tested before either, so it might not be worth the complexity any of these will introduce. I'd appreciate some input from others on this.

launch_testing will terminate the process instead of sending SIGINT, so the tests can't check the response to interrupt
@dhood
Copy link
Member Author

dhood commented Aug 9, 2017

I've skipped the tests for windows so that this PR can move ahead. If appropriate, code coverage for when sigaction isn't used can just be considered as an incremental improvement for a later date.

RMW_IMPLEMENTATION=${rmw_implementation}
)
set_tests_properties(${test_name}${target_suffix}
PROPERTIES DEPENDS "${executable1}${target_suffix}"
Copy link
Member

Choose a reason for hiding this comment

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

The variable executable1 doesn't seem to exist.

@@ -0,0 +1,51 @@
# generated from test_rclcpp/test/test_two_executables.py.in
Copy link
Member

Choose a reason for hiding this comment

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

Copy-n-paste.

std::this_thread::sleep_for(5s);

printf("Exiting.\n");
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this test be done without any output comparison? The signal handler could set a global variable which could be checked in the main function afterwards. I think that would simplify the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just checking the global variable you wouldn't know if the user-defined signal handler has been called "directly" or from within the rclcpp signal handler.
Checking for the presence/absence of the signal_handler(2) output from rclcpp we can infer this without any changes to rclcpp. If we think it's useful in other contexts, we can expose a flag from rclcpp and switch the test to check both variables. Otherwise, for the purpose of this test the console checking can provide that extra info.

if(_ARG_SKIP_TEST)
set(_ARG_SKIP_TEST "SKIP_TEST")
endif()

Copy link
Member

Choose a reason for hiding this comment

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

Since this macro is only used for internal test I don't think this argument parsing is necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

you're right, I thought it was necessary but it was only because I tried to pass ARGN as the last argument to ament_add_nose_test. Removed in 186356c

@dhood dhood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Aug 11, 2017
Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

lgtm

@dhood dhood merged commit 063c001 into master Aug 14, 2017
@dhood dhood deleted the restore_old_signal_handler branch August 14, 2017 21:00
@dhood dhood removed the in review Waiting for review (Kanban column) label Aug 14, 2017
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