-
Notifications
You must be signed in to change notification settings - Fork 52
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# generated from test_rclcpp/test/test_two_executables.py.in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy-n-paste. |
||
|
||
from launch import LaunchDescriptor | ||
from launch.exit_handler import primary_exit_handler | ||
from launch.launcher import DefaultLauncher | ||
from launch.output_handler import ConsoleOutput | ||
|
||
from launch_testing import create_handler | ||
|
||
|
||
def @TEST_NAME@(): | ||
ld = LaunchDescriptor() | ||
|
||
output_handlers = [ConsoleOutput()] | ||
|
||
shutdown_trigger_handler = create_handler( | ||
'@TEST_EXECUTABLE_NAME@', | ||
ld, | ||
'@TEST_EXECUTABLE_TRIGGER_SHUTDOWN_OUTPUT@', | ||
exit_on_match=True, | ||
filtered_rmw_implementation='@rmw_implementation@', | ||
) | ||
output_handlers.append(shutdown_trigger_handler) | ||
|
||
output_check_handler = create_handler( | ||
'@TEST_EXECUTABLE_NAME@', | ||
ld, | ||
'@TEST_EXECUTABLE_EXPECTED_OUTPUT@', | ||
exit_on_match=False, | ||
filtered_rmw_implementation='@rmw_implementation@', | ||
) | ||
output_handlers.append(output_check_handler) | ||
|
||
ld.add_process( | ||
cmd=['@TEST_EXECUTABLE@'], | ||
name='@TEST_EXECUTABLE_NAME@', | ||
exit_handler=primary_exit_handler, | ||
output_handlers=output_handlers, | ||
) | ||
|
||
launcher = DefaultLauncher() | ||
launcher.add_launch_descriptor(ld) | ||
rc = launcher.launch() | ||
|
||
assert rc == 0, "The launch file failed with exit code '" + str(rc) + "'. " | ||
|
||
output_check_handler.check() | ||
|
||
|
||
if __name__ == '__main__': | ||
@TEST_NAME@() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2017 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <iostream> | ||
#include <memory> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
|
||
using namespace std::chrono_literals; | ||
|
||
void sigintHandler(int sig) | ||
{ | ||
(void)sig; | ||
printf("Custom sigint handler called.\n"); | ||
} | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
// This exectuable is used in combination with a script that interrupts it at different times. | ||
// Its purpose is to test that a user-defined signal handler gets called even when the rclcpp | ||
// signal handler is/has been in use. | ||
setvbuf(stdout, NULL, _IONBF, BUFSIZ); | ||
|
||
// Override default sigint handler | ||
signal(SIGINT, sigintHandler); | ||
printf("Registered custom signal handler.\n"); | ||
|
||
rclcpp::init(argc, argv); | ||
printf("Called rclcpp::init.\n"); | ||
|
||
printf("Waiting to give an opportunity for interrupt...\n"); | ||
std::this_thread::sleep_for(5s); | ||
|
||
printf("Calling rclcpp::shutdown...\n"); | ||
rclcpp::shutdown(); | ||
printf("Called rclcpp::shutdown.\n"); | ||
|
||
printf("Waiting to give an opportunity for interrupt...\n"); | ||
std::this_thread::sleep_for(5s); | ||
|
||
printf("Exiting.\n"); | ||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Registered custom signal handler. | ||
Called rclcpp::init. | ||
Waiting to give an opportunity for interrupt... | ||
Calling rclcpp::shutdown... | ||
Called rclcpp::shutdown. | ||
Waiting to give an opportunity for interrupt... | ||
Custom sigint handler called. | ||
Exiting. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Registered custom signal handler. | ||
Called rclcpp::init. | ||
Waiting to give an opportunity for interrupt... | ||
Calling rclcpp::shutdown... | ||
Called rclcpp::shutdown. | ||
Waiting to give an opportunity for interrupt... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Registered custom signal handler. | ||
Called rclcpp::init. | ||
Waiting to give an opportunity for interrupt... | ||
signal_handler(2) | ||
Custom sigint handler called. | ||
Calling rclcpp::shutdown... | ||
Called rclcpp::shutdown. | ||
Waiting to give an opportunity for interrupt... | ||
Exiting. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Registered custom signal handler. | ||
Called rclcpp::init. | ||
Waiting to give an opportunity for interrupt... |
There was a problem hiding this comment.
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.