Skip to content

Commit d90042e

Browse files
committed
Added testing
Signed-off-by: Alberto Tudela <[email protected]>
1 parent 98dc324 commit d90042e

8 files changed

+735
-2
lines changed

.github/workflows/build.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Simple set of rules for GitHub actions integration with a ROS project
2+
#
3+
4+
name: Build
5+
6+
on:
7+
push:
8+
branches:
9+
- dev
10+
pull_request:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v2
18+
- name: Setup ROS 2
19+
uses: ros-tooling/[email protected]
20+
with:
21+
required-ros-distributions: humble
22+
- name: Install slg_msgs dependencies
23+
run: |
24+
cd ${{steps.action_ros_ci_step.outputs.ros-workspace-directory-name}}
25+
git clone https://github.com/ajtudela/slg_msgs.git
26+
- name: Install dependencies
27+
uses: ros-tooling/[email protected]
28+
with:
29+
package-name: laser_segmentation
30+
target-ros2-distro: humble
31+
colcon-defaults: |
32+
{
33+
"build": {
34+
"mixin": ["coverage-gcc", "coverage-pytest"]
35+
},
36+
"test": {
37+
"mixin": ["coverage-pytest"]
38+
}
39+
}
40+
skip-tests: false
41+
- name: Upload coverage reports to Codecov
42+
uses: codecov/[email protected]
43+
with:
44+
token: ${{ secrets.CODECOV_TOKEN }}
45+
files: ros_ws/lcov/total_coverage.info,ros_ws/coveragepy/.coverage
46+
flags: unittests
47+
name: codecov-umbrella

CHANGELOG.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Changelog for package laser_segmentation
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5-
3.0.0 (XX-03-2024)
5+
3.0.0 (08-03-2024)
66
------------------
77
* Improve formatting.
88
* Improve documentation of source.
@@ -12,6 +12,7 @@ Changelog for package laser_segmentation
1212
* Move parameters to new class: parameterHandler.
1313
* Rename show_visualization to create_segment_viz_points.
1414
* Fix jump distance merge.
15+
* Add unit testing.
1516

1617
2.1.2 (23-06-2023)
1718
------------------

codecov.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fixes:
2+
- "src/laser_segmentation/::"
3+
- "install/::"
4+
5+
ignore:
6+
- "*/**/test/*" # ignore package test directories
7+
- "*/test/**/*" # ignore package test directories
8+
- "**/test_*.*" # ignore files starting with test_
9+
- "**/main*.*" # ignore files starting with main
10+
- "**/*_tests.*" # ignore files ending with _tests
11+
- "*/**/benchmark/*" # ignore package test directories
12+
- "*/benchmark/**/*" # ignore package test directories
13+
- "**/benchmark_*.*" # ignore files starting with test_
14+
- "**/*_benchmark.*" # ignore files ending with _tests

package.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>laser_segmentation</name>
5-
<version>2.1.2</version>
5+
<version>3.0.0</version>
66
<description>Implementation of algorithms for segmentation of laserscans.</description>
77
<maintainer email="[email protected]">Alberto J. Tudela Roldán</maintainer>
88
<maintainer email="[email protected]">Manuel Fernandez-Carmona</maintainer>

test/CMakeLists.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Test for segmentations algorithm
2+
ament_add_gtest(test_segmentations
3+
test_segmentations.cpp
4+
)
5+
ament_target_dependencies(test_segmentations
6+
${dependencies}
7+
)
8+
target_link_libraries(test_segmentations
9+
${library_name}
10+
)
11+
12+
# Test for laser_segmentation
13+
ament_add_gtest(test_laser_segmentation
14+
test_laser_segmentation.cpp
15+
)
16+
ament_target_dependencies(test_laser_segmentation
17+
${dependencies}
18+
)
19+
target_link_libraries(test_laser_segmentation
20+
${library_name}
21+
)
22+
23+
# Test for laser_segmentation integration
24+
ament_add_gtest(test_integration
25+
test_integration.cpp
26+
)
27+
ament_target_dependencies(test_integration
28+
${dependencies}
29+
)
30+
target_link_libraries(test_integration
31+
${library_name}
32+
)

test/test_integration.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2017 Alberto J. Tudela Roldán
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "gtest/gtest.h"
16+
#include "rclcpp/rclcpp.hpp"
17+
#include "laser_segmentation/laser_segmentation.hpp"
18+
19+
TEST(LaserSegmentationTest, integration) {
20+
rclcpp::init(0, nullptr);
21+
// Create the scan publisher node
22+
auto pub_node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("scan_publisher");
23+
pub_node->configure();
24+
// Create a publisher for the scan
25+
auto scan_pub = pub_node->create_publisher<sensor_msgs::msg::LaserScan>("scan", 1);
26+
ASSERT_EQ(scan_pub->get_subscription_count(), 0);
27+
EXPECT_FALSE(scan_pub->is_activated());
28+
// Activate the publisher
29+
pub_node->activate();
30+
EXPECT_TRUE(scan_pub->is_activated());
31+
scan_pub->on_activate();
32+
auto pub_thread = std::thread([&]() {rclcpp::spin(pub_node->get_node_base_interface());});
33+
34+
// Create and configure the laser_segmentation node
35+
auto seg_node = std::make_shared<laserSegmentation>();
36+
// Set some parameters
37+
nav2_util::declare_parameter_if_not_declared(
38+
seg_node, "min_points_segment", rclcpp::ParameterValue(1));
39+
nav2_util::declare_parameter_if_not_declared(
40+
seg_node, "max_points_segment", rclcpp::ParameterValue(3));
41+
seg_node->configure();
42+
seg_node->activate();
43+
44+
// Create a scan message with three points
45+
sensor_msgs::msg::LaserScan scan;
46+
scan.header.frame_id = "laser_frame";
47+
scan.angle_min = -M_PI / 2;
48+
scan.angle_max = M_PI / 2;
49+
scan.angle_increment = M_PI / 180;
50+
scan.time_increment = 0.1;
51+
scan.scan_time = 0.1;
52+
scan.range_min = 0.0;
53+
scan.range_max = 10.0;
54+
scan.ranges.push_back(1.0);
55+
scan.ranges.push_back(1.1);
56+
scan.ranges.push_back(2.0);
57+
scan.ranges.push_back(2.1);
58+
scan.ranges.push_back(3.0);
59+
scan.ranges.push_back(3.2);
60+
scan.ranges.push_back(12.0);
61+
// Publish the message
62+
scan_pub->publish(scan);
63+
64+
// Create the segments subscriber node
65+
auto sub_node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("segment_subscriber");
66+
sub_node->configure();
67+
sub_node->activate();
68+
// Create a subscriber for the segments
69+
auto seg_sub = sub_node->create_subscription<slg_msgs::msg::SegmentArray>(
70+
"segments", 1,
71+
[&](const slg_msgs::msg::SegmentArray msg) {
72+
EXPECT_EQ(msg.segments.size(), 1);
73+
RCLCPP_INFO(sub_node->get_logger(), "Segment received: %ld", msg.segments.size());
74+
});
75+
auto sub_thread = std::thread([&]() {rclcpp::spin(sub_node->get_node_base_interface());});
76+
77+
// Spin the laser_segmentation node
78+
rclcpp::spin_some(seg_node->get_node_base_interface());
79+
80+
// Check the results: now, the scan should have a subscription
81+
// and the segment should have a publisher
82+
EXPECT_EQ(scan_pub->get_subscription_count(), 1);
83+
EXPECT_EQ(seg_sub->get_publisher_count(), 1);
84+
85+
// Deactivate the nodes
86+
seg_node->deactivate();
87+
pub_node->deactivate();
88+
sub_node->deactivate();
89+
rclcpp::shutdown();
90+
// Have to join thread after rclcpp is shut down otherwise test hangs.
91+
sub_thread.join();
92+
pub_thread.join();
93+
}

0 commit comments

Comments
 (0)