Skip to content

Commit 6fb43d4

Browse files
adding wait recovery integration test (#1685)
* adding recovery wait test * adding copy rights * fixing gaurds
1 parent b2c1661 commit 6fb43d4

11 files changed

+513
-4
lines changed

‎nav2_system_tests/CMakeLists.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ if(BUILD_TESTING)
5757
add_subdirectory(src/system)
5858
add_subdirectory(src/updown)
5959
add_subdirectory(src/waypoint_follower)
60-
add_subdirectory(src/recoveries)
60+
add_subdirectory(src/recoveries/spin)
61+
add_subdirectory(src/recoveries/wait)
6162
install(DIRECTORY maps DESTINATION share/${PROJECT_NAME})
6263

6364
endif()

‎nav2_system_tests/src/recoveries/spin_recovery_tester.hpp‎ renamed to ‎nav2_system_tests/src/recoveries/spin/spin_recovery_tester.hpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License. Reserved.
1515

16-
#ifndef RECOVERIES__SPIN_RECOVERY_TESTER_HPP_
17-
#define RECOVERIES__SPIN_RECOVERY_TESTER_HPP_
16+
#ifndef RECOVERIES__SPIN__SPIN_RECOVERY_TESTER_HPP_
17+
#define RECOVERIES__SPIN__SPIN_RECOVERY_TESTER_HPP_
1818

1919
#include <gtest/gtest.h>
2020
#include <memory>
@@ -86,4 +86,4 @@ class SpinRecoveryTester
8686

8787
} // namespace nav2_system_tests
8888

89-
#endif // RECOVERIES__SPIN_RECOVERY_TESTER_HPP_
89+
#endif // RECOVERIES__SPIN__SPIN_RECOVERY_TESTER_HPP_

‎nav2_system_tests/src/recoveries/test_spin_recovery_node.cpp‎ renamed to ‎nav2_system_tests/src/recoveries/spin/test_spin_recovery_node.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Copyright (c) 2020 Samsung Research
12
// Copyright (c) 2020 Sarthak Mittal
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
set(test_wait_recovery_exec test_wait_recovery_node)
2+
3+
ament_add_gtest_executable(${test_wait_recovery_exec}
4+
test_wait_recovery_node.cpp
5+
wait_recovery_tester.cpp
6+
)
7+
8+
ament_target_dependencies(${test_wait_recovery_exec}
9+
${dependencies}
10+
)
11+
12+
ament_add_test(test_wait_recovery
13+
GENERATE_RESULT_FOR_RETURN_CODE_ZERO
14+
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_wait_recovery_launch.py"
15+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
16+
TIMEOUT 100
17+
ENV
18+
TEST_MAP=${PROJECT_SOURCE_DIR}/maps/map_circular.yaml
19+
TEST_EXECUTABLE=$<TARGET_FILE:${test_wait_recovery_exec}>
20+
TEST_WORLD=${PROJECT_SOURCE_DIR}/worlds/turtlebot3_ros2_demo.world
21+
GAZEBO_MODEL_PATH=${PROJECT_SOURCE_DIR}/models
22+
BT_NAVIGATOR_XML=navigate_w_replanning_and_recovery.xml
23+
)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#! /usr/bin/env python3
2+
# Copyright (c) 2019 Samsung Research America
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import os
17+
import sys
18+
19+
from ament_index_python.packages import get_package_share_directory
20+
21+
from launch import LaunchDescription
22+
from launch import LaunchService
23+
from launch.actions import ExecuteProcess, IncludeLaunchDescription, SetEnvironmentVariable
24+
from launch.launch_description_sources import PythonLaunchDescriptionSource
25+
from launch_ros.actions import Node
26+
from launch_testing.legacy import LaunchTestService
27+
28+
from nav2_common.launch import RewrittenYaml
29+
30+
31+
def generate_launch_description():
32+
map_yaml_file = os.getenv('TEST_MAP')
33+
world = os.getenv('TEST_WORLD')
34+
35+
bt_navigator_xml = os.path.join(get_package_share_directory('nav2_bt_navigator'),
36+
'behavior_trees',
37+
os.getenv('BT_NAVIGATOR_XML'))
38+
39+
bringup_dir = get_package_share_directory('nav2_bringup')
40+
params_file = os.path.join(bringup_dir, 'params/nav2_params.yaml')
41+
42+
# Replace the `use_astar` setting on the params file
43+
configured_params = RewrittenYaml(
44+
source_file=params_file,
45+
root_key='',
46+
param_rewrites='',
47+
convert_types=True)
48+
49+
return LaunchDescription([
50+
SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
51+
52+
# Launch gazebo server for simulation
53+
ExecuteProcess(
54+
cmd=['gzserver', '-s', 'libgazebo_ros_init.so',
55+
'--minimal_comms', world],
56+
output='screen'),
57+
58+
# TODO(orduno) Launch the robot state publisher instead
59+
# using a local copy of TB3 urdf file
60+
Node(
61+
package='tf2_ros',
62+
node_executable='static_transform_publisher',
63+
output='screen',
64+
arguments=['0', '0', '0', '0', '0', '0', 'base_footprint', 'base_link']),
65+
66+
Node(
67+
package='tf2_ros',
68+
node_executable='static_transform_publisher',
69+
output='screen',
70+
arguments=['0', '0', '0', '0', '0', '0', 'base_link', 'base_scan']),
71+
72+
IncludeLaunchDescription(
73+
PythonLaunchDescriptionSource(
74+
os.path.join(bringup_dir, 'launch', 'bringup_launch.py')),
75+
launch_arguments={
76+
'map': map_yaml_file,
77+
'use_sim_time': 'True',
78+
'params_file': configured_params,
79+
'bt_xml_file': bt_navigator_xml,
80+
'autostart': 'True'}.items()),
81+
])
82+
83+
84+
def main(argv=sys.argv[1:]):
85+
ld = generate_launch_description()
86+
87+
testExecutable = os.getenv('TEST_EXECUTABLE')
88+
89+
test1_action = ExecuteProcess(
90+
cmd=[testExecutable],
91+
name='test_wait_recovery_node',
92+
output='screen')
93+
94+
lts = LaunchTestService()
95+
lts.add_test_action(ld, test1_action)
96+
ls = LaunchService(argv=argv)
97+
ls.include_launch_description(ld)
98+
return lts.run(ls)
99+
100+
101+
if __name__ == '__main__':
102+
sys.exit(main())
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) 2020 Samsung Research
2+
// Copyright (c) 2020 Sarthak Mittal
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License. Reserved.
15+
16+
#include <gtest/gtest.h>
17+
#include <cmath>
18+
#include <tuple>
19+
20+
#include "rclcpp/rclcpp.hpp"
21+
22+
#include "wait_recovery_tester.hpp"
23+
24+
using namespace std::chrono_literals;
25+
26+
using nav2_system_tests::WaitRecoveryTester;
27+
28+
class WaitRecoveryTestFixture
29+
: public ::testing::TestWithParam<std::tuple<float, float>>
30+
{
31+
public:
32+
static void SetUpTestCase()
33+
{
34+
wait_recovery_tester = new WaitRecoveryTester();
35+
if (!wait_recovery_tester->isActive()) {
36+
wait_recovery_tester->activate();
37+
}
38+
}
39+
40+
static void TearDownTestCase()
41+
{
42+
delete wait_recovery_tester;
43+
wait_recovery_tester = nullptr;
44+
}
45+
46+
protected:
47+
static WaitRecoveryTester * wait_recovery_tester;
48+
};
49+
50+
WaitRecoveryTester * WaitRecoveryTestFixture::wait_recovery_tester = nullptr;
51+
52+
TEST_P(WaitRecoveryTestFixture, testSWaitRecovery)
53+
{
54+
float wait_time = std::get<0>(GetParam());
55+
56+
bool success = false;
57+
int num_tries = 3;
58+
for (int i = 0; i != num_tries; i++) {
59+
success = success || wait_recovery_tester->recoveryTest(wait_time);
60+
if (success) {
61+
break;
62+
}
63+
}
64+
65+
EXPECT_EQ(true, success);
66+
}
67+
68+
INSTANTIATE_TEST_CASE_P(
69+
WaitRecoveryTests,
70+
WaitRecoveryTestFixture,
71+
::testing::Values(
72+
std::make_tuple(1.0, 0.0),
73+
std::make_tuple(2.0, 0.0),
74+
std::make_tuple(5.0, 0.0)), );
75+
76+
int main(int argc, char ** argv)
77+
{
78+
::testing::InitGoogleTest(&argc, argv);
79+
80+
// initialize ROS
81+
rclcpp::init(argc, argv);
82+
83+
bool all_successful = RUN_ALL_TESTS();
84+
85+
// shutdown ROS
86+
rclcpp::shutdown();
87+
88+
return all_successful;
89+
}

0 commit comments

Comments
 (0)