Skip to content

Commit

Permalink
Added utils test for broken rolling
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Tudela <ajtudela@gmail.com>
  • Loading branch information
ajtudela committed Apr 6, 2024
1 parent f53d373 commit 60108e6
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/repos.repos

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ jobs:
- name: Setup ROS 2
uses: ros-tooling/setup-ros@v0.7
with:
required-ros-distributions: rolling
required-ros-distributions: humble
- name: Install dependencies
uses: ros-tooling/action-ros-ci@v0.3
with:
package-name: scitos2
target-ros2-distro: rolling
vcs-repo-file-url: ./.github/repos.repos # Until nav2 is released in rolling
target-ros2-distro: humble
colcon-defaults: |
{
"build": {
Expand Down
1 change: 1 addition & 0 deletions scitos2_behavior_tree/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog for package scitos2_behavior_tree
* Improve formatting.
* Add generate_scitos2_tree_nodes_xml.
* Add unit testing.
* The utils folder in test is just a copy of nav2_behavior_tree/test/utils because Rolling CI is currently broken. This will be removed once Rolling CI is fixed.

0.3.0 (26-04-2023)
------------------
Expand Down
4 changes: 4 additions & 0 deletions scitos2_behavior_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ install(DIRECTORY include/
DESTINATION include/
)

install(DIRECTORY test/utils/
DESTINATION include/${PROJECT_NAME}/utils/
)

install(FILES scitos2_tree_nodes.xml DESTINATION share/${PROJECT_NAME})
install(FILES ${GENERATED_DIR}/plugins_list.hpp DESTINATION include/${PROJECT_NAME})

Expand Down
2 changes: 0 additions & 2 deletions scitos2_behavior_tree/test/action/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
find_package(nav2_behavior_tree REQUIRED)

# Test for the emergency stop service
ament_add_gtest(test_scitos2_action_emergency_stop_service
test_emergency_stop_service.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "behaviortree_cpp_v3/bt_factory.h"

#include "nav2_behavior_tree/utils/test_service.hpp"
#include "utils/test_service.hpp"
#include "scitos2_behavior_tree/action/emergency_stop_service.hpp"

class EmergencyStopService : public TestService<scitos2_msgs::srv::EmergencyStop>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "behaviortree_cpp_v3/bt_factory.h"

#include "nav2_behavior_tree/utils/test_service.hpp"
#include "utils/test_service.hpp"
#include "scitos2_behavior_tree/action/reset_motor_stop_service.hpp"

class ResetMotorStopService : public TestService<scitos2_msgs::srv::ResetMotorStop>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "scitos2_msgs/msg/bumper_status.hpp"

#include "nav2_behavior_tree/utils/test_behavior_tree_fixture.hpp"
#include "utils/test_behavior_tree_fixture.hpp"
#include "scitos2_behavior_tree/condition/is_bumper_activated_condition.hpp"

class IsBumperActivatedConditionTestFixture : public ::testing::Test
Expand Down
93 changes: 93 additions & 0 deletions scitos2_behavior_tree/test/utils/test_behavior_tree_fixture.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (c) 2018 Intel Corporation
// Copyright (c) 2020 Sarthak Mittal
//
// 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.

#ifndef UTILS__TEST_BEHAVIOR_TREE_FIXTURE_HPP_
#define UTILS__TEST_BEHAVIOR_TREE_FIXTURE_HPP_

#include <gtest/gtest.h>
#include <memory>
#include <set>

#include "behaviortree_cpp_v3/bt_factory.h"
#include "rclcpp/rclcpp.hpp"

#include "test_transform_handler.hpp"
#include "test_dummy_tree_node.hpp"

namespace nav2_behavior_tree
{

class BehaviorTreeTestFixture : public ::testing::Test
{
public:
static void SetUpTestCase()
{
node_ = std::make_shared<rclcpp::Node>("test_behavior_tree_fixture");
transform_handler_ = std::make_shared<nav2_behavior_tree::TransformHandler>(node_);
factory_ = std::make_shared<BT::BehaviorTreeFactory>();

config_ = new BT::NodeConfiguration();

// Create the blackboard that will be shared by all of the nodes in the tree
config_->blackboard = BT::Blackboard::create();
// Put items on the blackboard
config_->blackboard->set(
"node",
node_);
config_->blackboard->set(
"tf_buffer",
transform_handler_->getBuffer());
config_->blackboard->set<std::chrono::milliseconds>(
"server_timeout",
std::chrono::milliseconds(20));
config_->blackboard->set<std::chrono::milliseconds>(
"bt_loop_duration",
std::chrono::milliseconds(10));
config_->blackboard->set("initial_pose_received", false);

transform_handler_->activate();
transform_handler_->waitForTransform();
}

static void TearDownTestCase()
{
transform_handler_->deactivate();
delete config_;
config_ = nullptr;
transform_handler_.reset();
node_.reset();
factory_.reset();
}

protected:
static rclcpp::Node::SharedPtr node_;
static std::shared_ptr<nav2_behavior_tree::TransformHandler> transform_handler_;
static BT::NodeConfiguration * config_;
static std::shared_ptr<BT::BehaviorTreeFactory> factory_;
};

} // namespace nav2_behavior_tree

rclcpp::Node::SharedPtr nav2_behavior_tree::BehaviorTreeTestFixture::node_ = nullptr;

std::shared_ptr<nav2_behavior_tree::TransformHandler>
nav2_behavior_tree::BehaviorTreeTestFixture::transform_handler_ = nullptr;

BT::NodeConfiguration * nav2_behavior_tree::BehaviorTreeTestFixture::config_ = nullptr;

std::shared_ptr<BT::BehaviorTreeFactory>
nav2_behavior_tree::BehaviorTreeTestFixture::factory_ = nullptr;

#endif // UTILS__TEST_BEHAVIOR_TREE_FIXTURE_HPP_
59 changes: 59 additions & 0 deletions scitos2_behavior_tree/test/utils/test_dummy_tree_node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2018 Intel Corporation
// Copyright (c) 2020 Sarthak Mittal
//
// 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.

#ifndef UTILS__TEST_DUMMY_TREE_NODE_HPP_
#define UTILS__TEST_DUMMY_TREE_NODE_HPP_

#include <behaviortree_cpp_v3/basic_types.h>
#include <behaviortree_cpp_v3/action_node.h>

namespace nav2_behavior_tree
{

/**
* @brief A Dummy TreeNode to be used as a child for testing nodes
* Returns the current status on tick without any execution logic
*/
class DummyNode : public BT::ActionNodeBase
{
public:
DummyNode()
: BT::ActionNodeBase("dummy", {})
{
}

void changeStatus(BT::NodeStatus status)
{
setStatus(status);
}

BT::NodeStatus executeTick() override
{
return tick();
}

BT::NodeStatus tick() override
{
return status();
}

void halt() override
{
}
};

} // namespace nav2_behavior_tree

#endif // UTILS__TEST_DUMMY_TREE_NODE_HPP_
60 changes: 60 additions & 0 deletions scitos2_behavior_tree/test/utils/test_service.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2020 Sarthak Mittal
//
// 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.

#ifndef UTILS__TEST_SERVICE_HPP_
#define UTILS__TEST_SERVICE_HPP_

#include <string>
#include <memory>

#include "rclcpp/rclcpp.hpp"

template<class ServiceT>
class TestService : public rclcpp::Node
{
public:
explicit TestService(
std::string service_name,
const rclcpp::NodeOptions & options = rclcpp::NodeOptions())
: Node("test_service", options)
{
using namespace std::placeholders; // NOLINT

server_ = create_service<ServiceT>(
service_name,
std::bind(&TestService::handle_service, this, _1, _2, _3));
}

std::shared_ptr<typename ServiceT::Request> getCurrentRequest() const
{
return current_request_;
}

protected:
virtual void handle_service(
const std::shared_ptr<rmw_request_id_t> request_header,
const std::shared_ptr<typename ServiceT::Request> request,
const std::shared_ptr<typename ServiceT::Response> response)
{
(void)request_header;
(void)response;
current_request_ = request;
}

private:
typename rclcpp::Service<ServiceT>::SharedPtr server_;
std::shared_ptr<typename ServiceT::Request> current_request_;
};

#endif // UTILS__TEST_SERVICE_HPP_
Loading

0 comments on commit 60108e6

Please sign in to comment.