-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for user-defined signal handler (#215)
* Add tests for user-defined signal handler * Skip signal handler tests on Windows launch_testing will terminate the process instead of sending SIGINT, so the tests can't check the response to interrupt * Fixup * Remove argument parsing
- Loading branch information
Showing
8 changed files
with
193 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# generated from test_rclcpp/test/test_executable_output.py.in | ||
# generated code does not contain a copyright notice | ||
|
||
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@() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
8 changes: 8 additions & 0 deletions
8
test_rclcpp/test/test_signal_handler_after_shutdown__expected_output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
6 changes: 6 additions & 0 deletions
6
test_rclcpp/test/test_signal_handler_after_shutdown__trigger_shutdown.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |
9 changes: 9 additions & 0 deletions
9
test_rclcpp/test/test_signal_handler_before_shutdown__expected_output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
3 changes: 3 additions & 0 deletions
3
test_rclcpp/test/test_signal_handler_before_shutdown__trigger_shutdown.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |