From ca02c438dcc2c231c82ce544d5906433a3f8e432 Mon Sep 17 00:00:00 2001 From: "jack.song" Date: Thu, 28 Sep 2023 18:16:25 +0800 Subject: [PATCH 1/2] add interface tools test Signed-off-by: jack.song --- .../component_interface_tools/CMakeLists.txt | 15 +++++ common/component_interface_tools/package.xml | 4 +- .../test/test_service_log_checker.cpp | 63 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 common/component_interface_tools/test/test_service_log_checker.cpp diff --git a/common/component_interface_tools/CMakeLists.txt b/common/component_interface_tools/CMakeLists.txt index a5ebc29463bec..0852f78cfed2e 100644 --- a/common/component_interface_tools/CMakeLists.txt +++ b/common/component_interface_tools/CMakeLists.txt @@ -4,4 +4,19 @@ project(component_interface_tools) find_package(autoware_cmake REQUIRED) autoware_package() ament_auto_add_executable(service_log_checker src/service_log_checker.cpp) + +ament_auto_add_library(${PROJECT_NAME} SHARED + src/service_log_checker.cpp +) + +if(BUILD_TESTING) + ament_add_ros_isolated_gtest(test_service_log_checker + test/test_service_log_checker.cpp + ) + + target_link_libraries(test_service_log_checker + component_interface_tools + ) + target_include_directories(test_service_log_checker PRIVATE src) +endif() ament_auto_package(INSTALL_TO_SHARE launch) diff --git a/common/component_interface_tools/package.xml b/common/component_interface_tools/package.xml index ebf0684d0066c..a7a2903d385eb 100644 --- a/common/component_interface_tools/package.xml +++ b/common/component_interface_tools/package.xml @@ -17,10 +17,12 @@ rclcpp tier4_system_msgs yaml_cpp_vendor + service_log_checker ament_lint_auto autoware_lint_common - + ament_cmake_ros + ament_cmake diff --git a/common/component_interface_tools/test/test_service_log_checker.cpp b/common/component_interface_tools/test/test_service_log_checker.cpp new file mode 100644 index 0000000000000..c4ed193a08d2f --- /dev/null +++ b/common/component_interface_tools/test/test_service_log_checker.cpp @@ -0,0 +1,63 @@ +// Copyright 2023 TIER IV, 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 "gtest/gtest.h" +#include "service_log_checker.hpp" +#include +#include +#include + +TEST(service,checker) +{ + { + using ServiceLog = tier4_system_msgs::msg::ServiceLog; + using DiagnosticArray = diagnostic_msgs::msg::DiagnosticArray; + + class PubManager : public rclcpp::Node + { + public: + PubManager() : Node("test_pub_node") + { + pub_odom_ = create_publisher("service_log", 1); + sub_odom_ = create_subscription("/diagnostics", 1, std::bind(&PubManager::on_service_log, this, std::placeholders::_1)); + } + rclcpp::Publisher::SharedPtr pub_odom_; + rclcpp::Subscription::SharedPtr sub_odom_; + bool flag=false; + void on_service_log(const DiagnosticArray::ConstSharedPtr msg) + { + if(msg->status.size()>0) + { + auto diag_array = msg->status[0].message.c_str(); + EXPECT_EQ(diag_array,"ERROR"); + flag=true; + } + } + }; + + auto checker = std::make_shared(); + + auto test_log = std::make_shared(); + ServiceLog log; + log.type=6; + log.name="test"; + log.node="test_node"; + test_log->pub_odom_->publish(log); + + while(!test_log->flag) + { + + } + } +} From 2fb3493e4cd50ec4cb52d07e283287dda1f68345 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 10:20:07 +0000 Subject: [PATCH 2/2] style(pre-commit): autofix --- .../component_interface_tools/CMakeLists.txt | 2 +- common/component_interface_tools/package.xml | 6 +- .../test/test_service_log_checker.cpp | 76 +++++++++---------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/common/component_interface_tools/CMakeLists.txt b/common/component_interface_tools/CMakeLists.txt index 0852f78cfed2e..3301d4b09f892 100644 --- a/common/component_interface_tools/CMakeLists.txt +++ b/common/component_interface_tools/CMakeLists.txt @@ -13,7 +13,7 @@ if(BUILD_TESTING) ament_add_ros_isolated_gtest(test_service_log_checker test/test_service_log_checker.cpp ) - + target_link_libraries(test_service_log_checker component_interface_tools ) diff --git a/common/component_interface_tools/package.xml b/common/component_interface_tools/package.xml index a7a2903d385eb..e1cf1282bd9c5 100644 --- a/common/component_interface_tools/package.xml +++ b/common/component_interface_tools/package.xml @@ -15,14 +15,14 @@ diagnostic_updater fmt rclcpp + service_log_checker tier4_system_msgs yaml_cpp_vendor - service_log_checker + ament_cmake_ros ament_lint_auto autoware_lint_common - ament_cmake_ros - + ament_cmake diff --git a/common/component_interface_tools/test/test_service_log_checker.cpp b/common/component_interface_tools/test/test_service_log_checker.cpp index c4ed193a08d2f..87d13f336419b 100644 --- a/common/component_interface_tools/test/test_service_log_checker.cpp +++ b/common/component_interface_tools/test/test_service_log_checker.cpp @@ -14,50 +14,50 @@ #include "gtest/gtest.h" #include "service_log_checker.hpp" + #include + #include #include -TEST(service,checker) +TEST(service, checker) { - { - using ServiceLog = tier4_system_msgs::msg::ServiceLog; - using DiagnosticArray = diagnostic_msgs::msg::DiagnosticArray; - - class PubManager : public rclcpp::Node - { - public: - PubManager() : Node("test_pub_node") - { - pub_odom_ = create_publisher("service_log", 1); - sub_odom_ = create_subscription("/diagnostics", 1, std::bind(&PubManager::on_service_log, this, std::placeholders::_1)); - } - rclcpp::Publisher::SharedPtr pub_odom_; - rclcpp::Subscription::SharedPtr sub_odom_; - bool flag=false; - void on_service_log(const DiagnosticArray::ConstSharedPtr msg) - { - if(msg->status.size()>0) - { - auto diag_array = msg->status[0].message.c_str(); - EXPECT_EQ(diag_array,"ERROR"); - flag=true; - } - } - }; - - auto checker = std::make_shared(); - - auto test_log = std::make_shared(); - ServiceLog log; - log.type=6; - log.name="test"; - log.node="test_node"; - test_log->pub_odom_->publish(log); - - while(!test_log->flag) - { + { + using ServiceLog = tier4_system_msgs::msg::ServiceLog; + using DiagnosticArray = diagnostic_msgs::msg::DiagnosticArray; + class PubManager : public rclcpp::Node + { + public: + PubManager() : Node("test_pub_node") + { + pub_odom_ = create_publisher("service_log", 1); + sub_odom_ = create_subscription( + "/diagnostics", 1, std::bind(&PubManager::on_service_log, this, std::placeholders::_1)); + } + rclcpp::Publisher::SharedPtr pub_odom_; + rclcpp::Subscription::SharedPtr sub_odom_; + bool flag = false; + void on_service_log(const DiagnosticArray::ConstSharedPtr msg) + { + if (msg->status.size() > 0) { + auto diag_array = msg->status[0].message.c_str(); + EXPECT_EQ(diag_array, "ERROR"); + flag = true; } + } + }; + + auto checker = std::make_shared(); + + auto test_log = std::make_shared(); + ServiceLog log; + log.type = 6; + log.name = "test"; + log.node = "test_node"; + test_log->pub_odom_->publish(log); + + while (!test_log->flag) { } + } }