Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/awf-latest' into refactor/contro…
Browse files Browse the repository at this point in the history
…l_launch_xml
  • Loading branch information
mitukou1109 committed Jun 25, 2024
2 parents 19b9523 + 462f624 commit 5276c02
Show file tree
Hide file tree
Showing 126 changed files with 3,148 additions and 1,613 deletions.
9 changes: 3 additions & 6 deletions .cppcheck_suppressions
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
*:*/test/*

arrayIndexThenCheck
checkersReport
constParameterPointer
constParameterReference
constStatement
constVariable
constVariableReference
containerOutOfBounds
// cspell: ignore cstyle
cstyleCast
duplicateAssignExpression
duplicateBranch
duplicateBreak
duplicateExpression
funcArgNamesDifferent
functionConst
functionStatic
Expand All @@ -25,18 +22,18 @@ noExplicitConstructor
noValidConfiguration
passedByValue
preprocessorErrorDirective
redundantContinue
redundantInitialization
returnByReference
shadowArgument
shadowFunction
shadowVariable
syntaxError
// cspell: ignore uninit
uninitMemberVar
unknownMacro
unmatchedSuppression
unreadVariable
unusedFunction
unusedScopedObject
unusedStructMember
unusedVariable
useInitializationList
Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/clang-tidy-differential.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/autowarefoundation/autoware:latest-prebuilt-cuda
steps:
- name: Set PR fetch depth
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"

- name: Checkout PR branch and all PR commits
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
fetch-depth: 0

- name: Show disk space before the tasks
run: df -h
Expand All @@ -41,19 +37,17 @@ jobs:

- name: Get modified files
id: get-modified-files
uses: tj-actions/changed-files@v42
with:
files: |
**/*.cpp
**/*.hpp
run: |
echo "changed_files=$(git diff --name-only "origin/${{ github.base_ref }}"...HEAD | grep -E '\.(cpp|hpp)$' || true)" >> $GITHUB_OUTPUT
shell: bash

- name: Run clang-tidy
if: ${{ steps.get-modified-files.outputs.all_changed_files != '' }}
if: ${{ steps.get-modified-files.outputs.changed_files != '' }}
uses: autowarefoundation/autoware-github-actions/clang-tidy@v1
with:
rosdistro: humble
target-packages: ${{ steps.get-modified-packages.outputs.modified-packages }}
target-files: ${{ steps.get-modified-files.outputs.all_changed_files }}
target-files: ${{ steps.get-modified-files.outputs.changed_files }}
clang-tidy-config-url: https://raw.githubusercontent.com/autowarefoundation/autoware/main/.clang-tidy
build-depends-repos: build_depends.repos

Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/cppcheck-daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
# cppcheck from apt does not yet support --check-level args, and thus install from snap
- name: Install Cppcheck from snap
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake git libpcre3-dev
# cppcheck from apt does not yet support --check-level args, and thus install from source
- name: Install Cppcheck from source
run: |
mkdir /tmp/cppcheck
git clone https://github.com/danmar/cppcheck.git /tmp/cppcheck
cd /tmp/cppcheck
git checkout 2.14.1
mkdir build
cd build
cmake ..
make -j $(nproc)
sudo make install
sudo snap install cppcheck
- name: Run Cppcheck on all files
continue-on-error: true
id: cppcheck
run: |
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --xml . 2> cppcheck-report.xml
cppcheck --enable=all --inconclusive --check-level=exhaustive --suppress=*:*/test/* --error-exitcode=1 --xml . 2> cppcheck-report.xml
shell: bash

- name: Count errors by error ID and severity
Expand Down
34 changes: 18 additions & 16 deletions .github/workflows/cppcheck-differential.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,35 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set PR fetch depth
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"

- name: Checkout PR branch and all PR commits
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }}

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake git libpcre3-dev
sudo apt-get install -y git
# cppcheck from apt does not yet support --check-level args, and thus install from source
- name: Install Cppcheck from source
# cppcheck from apt does not yet support --check-level args, and thus install from snap
- name: Install Cppcheck from snap
run: |
mkdir /tmp/cppcheck
git clone https://github.com/danmar/cppcheck.git /tmp/cppcheck
cd /tmp/cppcheck
git checkout 2.14.1
mkdir build
cd build
cmake ..
make -j $(nproc)
sudo make install
sudo snap install cppcheck
- name: Fetch the base branch with enough history for a common merge-base commit
run: git fetch origin ${{ github.base_ref }}
shell: bash

- name: Get changed files
id: changed-files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --name-only FETCH_HEAD ${{ github.sha }} > changed_files.txt
git diff --name-only "origin/${{ github.base_ref }}"...HEAD > changed_files.txt
cat changed_files.txt
shell: bash

- name: Run Cppcheck on changed files
continue-on-error: true
Expand Down
9 changes: 4 additions & 5 deletions common/autoware_test_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ target_link_libraries(mock_data_parser
)

if(BUILD_TESTING)
ament_add_ros_isolated_gtest(test_mock_data_parser
test/test_mock_data_parser.cpp)

target_link_libraries(test_mock_data_parser
mock_data_parser)
ament_auto_add_gtest(test_autoware_test_utils
test/test_mock_data_parser.cpp
test/test_autoware_test_manager.cpp
)
endif()

ament_auto_package(INSTALL_TO_SHARE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <geometry_msgs/msg/pose_stamped.hpp>
#include <nav_msgs/msg/occupancy_grid.hpp>
#include <nav_msgs/msg/odometry.hpp>
#include <rosgraph_msgs/msg/clock.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <std_msgs/msg/bool.hpp>
#include <tf2_msgs/msg/tf_message.hpp>
Expand All @@ -48,6 +49,7 @@
#include <limits>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

namespace autoware::test_utils
Expand Down Expand Up @@ -512,6 +514,81 @@ void publishToTargetNode(
autoware::test_utils::spinSomeNodes(test_node, target_node, repeat_count);
}

/**
* @brief Manages publishing and subscribing to ROS topics for testing Autoware.
*
* The AutowareTestManager class provides utility functions to facilitate
* the publishing of messages to specified topics and the setting up of
* subscribers to listen for messages on specified topics. This class
* simplifies the setup of test environments in Autoware.
*/
class AutowareTestManager
{
public:
AutowareTestManager()
{
test_node_ = std::make_shared<rclcpp::Node>("autoware_test_manager_node");
pub_clock_ = test_node_->create_publisher<rosgraph_msgs::msg::Clock>("/clock", 1);
}

template <typename MessageType>
void test_pub_msg(
rclcpp::Node::SharedPtr target_node, const std::string & topic_name, MessageType & msg)
{
if (publishers_.find(topic_name) == publishers_.end()) {
auto publisher = test_node_->create_publisher<MessageType>(topic_name, 10);
publishers_[topic_name] = std::static_pointer_cast<rclcpp::PublisherBase>(publisher);
}

auto publisher =
std::dynamic_pointer_cast<rclcpp::Publisher<MessageType>>(publishers_[topic_name]);

autoware::test_utils::publishToTargetNode(test_node_, target_node, topic_name, publisher, msg);
RCLCPP_INFO(test_node_->get_logger(), "Published message on topic '%s'", topic_name.c_str());
}

template <typename MessageType>
void set_subscriber(
const std::string & topic_name,
std::function<void(const typename MessageType::ConstSharedPtr)> callback)
{
if (subscribers_.find(topic_name) == subscribers_.end()) {
std::shared_ptr<rclcpp::Subscription<MessageType>> subscriber;
autoware::test_utils::createSubscription<MessageType>(
test_node_, topic_name, callback, subscriber);
subscribers_[topic_name] = std::static_pointer_cast<rclcpp::SubscriptionBase>(subscriber);
} else {
RCLCPP_WARN(test_node_->get_logger(), "Subscriber %s already set.", topic_name.c_str());
}
}

/**
* @brief Publishes a ROS Clock message with the specified time.
*
* This function publishes a ROS Clock message with the specified time.
* Be careful when using this function, as it can affect the behavior of
* the system under test. Consider using ament_add_ros_isolated_gtest to
* isolate the system under test from the ROS clock.
*
* @param time The time to publish.
*/
void jump_clock(const rclcpp::Time & time)
{
rosgraph_msgs::msg::Clock clock;
clock.clock = time;
pub_clock_->publish(clock);
}

protected:
// Publisher
std::unordered_map<std::string, std::shared_ptr<rclcpp::PublisherBase>> publishers_;
std::unordered_map<std::string, std::shared_ptr<rclcpp::SubscriptionBase>> subscribers_;
rclcpp::Publisher<rosgraph_msgs::msg::Clock>::SharedPtr pub_clock_;

// Node
rclcpp::Node::SharedPtr test_node_;
}; // class AutowareTestManager

} // namespace autoware::test_utils

#endif // AUTOWARE_TEST_UTILS__AUTOWARE_TEST_UTILS_HPP_
30 changes: 25 additions & 5 deletions common/autoware_test_utils/src/autoware_test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <rclcpp/logging.hpp>
#include <rclcpp/node.hpp>

#include <lanelet2_core/geometry/LineString.h>

#include <utility>

namespace autoware::test_utils
Expand Down Expand Up @@ -54,14 +56,32 @@ lanelet::LaneletMapPtr loadMap(const std::string & lanelet2_filename)
lanelet::ErrorMessages errors{};
lanelet::projection::MGRSProjector projector{};
lanelet::LaneletMapPtr map = lanelet::load(lanelet2_filename, projector, &errors);
if (errors.empty()) {
return map;
if (!errors.empty()) {
for (const auto & error : errors) {
RCLCPP_ERROR_STREAM(rclcpp::get_logger("map_loader"), error);
}
return nullptr;
}

for (const auto & error : errors) {
RCLCPP_ERROR_STREAM(rclcpp::get_logger("map_loader"), error);
for (lanelet::Point3d point : map->pointLayer) {
if (point.hasAttribute("local_x")) {
point.x() = point.attribute("local_x").asDouble().value();
}
if (point.hasAttribute("local_y")) {
point.y() = point.attribute("local_y").asDouble().value();
}
}
return nullptr;

// realign lanelet borders using updated points
for (lanelet::Lanelet lanelet : map->laneletLayer) {
auto left = lanelet.leftBound();
auto right = lanelet.rightBound();
std::tie(left, right) = lanelet::geometry::align(left, right);
lanelet.setLeftBound(left);
lanelet.setRightBound(right);
}

return map;
}

LaneletMapBin convertToMapBinMsg(
Expand Down
Loading

0 comments on commit 5276c02

Please sign in to comment.