Skip to content

Commit

Permalink
update test and readme
Browse files Browse the repository at this point in the history
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
  • Loading branch information
isamu-takagi committed Mar 6, 2025
1 parent 5827423 commit 9d3e172
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
4 changes: 3 additions & 1 deletion autoware_utils_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ ament_auto_add_library(${PROJECT_NAME} SHARED

if(BUILD_TESTING)
file(GLOB_RECURSE test_files test/*.cpp)
ament_auto_add_gtest(test_${PROJECT_NAME} ${test_files})
ament_add_ros_isolated_gtest(test_${PROJECT_NAME} ${test_files})
ament_target_dependencies(test_${PROJECT_NAME} std_msgs)
target_link_libraries(test_${PROJECT_NAME} ${PROJECT_NAME})
endif()

ament_auto_package()
16 changes: 12 additions & 4 deletions autoware_utils_testing/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# autoware_utils_testing

## Notice

**This package is under construction. All interfaces currently provided are unstable.**

## Overview

The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications.
This package provides essential utilities for visualization.
It is extensively used in the Autoware project to handle common tasks such as creating markers for RViz.
This package provides essential utilities for testing.
It is extensively used in the Autoware project to handle common tasks such as handling executor and mock node.

## Design
## Usage Example

- **`marker_helper.hpp`**: Helper functions for creating and manipulating visualization markers.
- See [test/main.cpp](./test/main.cpp)
- `gtest/ros_env.hpp`
- See [test/cases/mock_node.cpp](./test/cases/mock_node.cpp)
- `mock_node.hpp`
- `spin_thread.hpp`
2 changes: 2 additions & 0 deletions autoware_utils_testing/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
<depend>gtest_vendor</depend>
<depend>rclcpp</depend>

<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>
<test_depend>std_msgs</test_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
56 changes: 56 additions & 0 deletions autoware_utils_testing/test/cases/mock_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2025 The Autoware Contributors
//
// 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 <autoware_utils_testing/mock_node.hpp>
#include <autoware_utils_testing/spin_thread.hpp>
#include <rclcpp/rclcpp.hpp>

#include <std_msgs/msg/int32.hpp>
#include <std_msgs/msg/string.hpp>

#include <gtest/gtest.h>

#include <memory>
#include <thread>

TEST(TestDebugPublisher, Main)
{
const auto mock = std::make_shared<autoware_utils_testing::MockNode>("mock_node");
const auto node = std::make_shared<rclcpp::Node>("test_node");

auto pub1 = node->create_publisher<std_msgs::msg::Int32>("/test/foo", rclcpp::QoS(1));
auto pub2 = node->create_publisher<std_msgs::msg::String>("/test/bar", rclcpp::QoS(1));
auto sub1 = mock->sub<std_msgs::msg::Int32>("/test/foo", rclcpp::QoS(1));
auto sub2 = mock->sub<std_msgs::msg::String>("/test/bar", rclcpp::QoS(1));

autoware_utils_testing::SpinThread thread;
thread.add_node(mock);
thread.add_node(node);
thread.start();
pub1->publish(std_msgs::build<std_msgs::msg::Int32>().data(123));
pub2->publish(std_msgs::build<std_msgs::msg::String>().data("hello"));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
pub1->publish(std_msgs::build<std_msgs::msg::Int32>().data(456));
pub2->publish(std_msgs::build<std_msgs::msg::String>().data("world"));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
thread.stop();

EXPECT_EQ(sub1->data.size(), 2);
EXPECT_EQ(sub1->data[0].data, 123);
EXPECT_EQ(sub1->data[1].data, 456);

EXPECT_EQ(sub2->data.size(), 2);
EXPECT_EQ(sub2->data[0].data, "hello");
EXPECT_EQ(sub2->data[1].data, "world");
}
3 changes: 2 additions & 1 deletion autoware_utils_testing/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>
#include <autoware_utils_testing/gtest/ros_env.hpp>

int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
testing::AddGlobalTestEnvironment(autoware_utils_testing::gtest::ros_env(argc, argv));
return RUN_ALL_TESTS();
}

0 comments on commit 9d3e172

Please sign in to comment.