Skip to content

Commit 7b3dc6d

Browse files
authored
Merge pull request #354 from ros-drivers/291-add-renode-test
291 update integration test, prepare CI to run renode
2 parents ca78cd2 + 6b126bd commit 7b3dc6d

File tree

8 files changed

+155
-465
lines changed

8 files changed

+155
-465
lines changed

.github/workflows/build_test.yml

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ name: Build and Test
33
on:
44
push:
55
branches:
6-
- 'ros2'
6+
- 'main'
77
pull_request:
88
branches:
9-
- 'ros2/*'
10-
- 'ros2'
9+
- 'main/*'
10+
- 'main'
1111
workflow_dispatch:
1212

13+
env:
14+
ROS_WORKSPACE_PATH: workspace/src
15+
1316
jobs:
1417
get_ros_distros:
1518
runs-on: ubuntu-latest
@@ -26,7 +29,7 @@ jobs:
2629
- name: Generate actions matrix
2730
id: set-matrix
2831
run: |
29-
ACTIVE_ROS_DISTROS=(noetic)
32+
ACTIVE_ROS_DISTROS=()
3033
DOCKER_DISTRO_MATRIX=()
3134
RAW_DOCKER_JSON=$(curl -s "https://hub.docker.com/v2/repositories/rostooling/setup-ros-docker/tags?page_size=1000")
3235
while read distro; do
@@ -73,44 +76,49 @@ jobs:
7376
container:
7477
image: rostooling/setup-ros-docker:${{ matrix.docker_image }}
7578
steps:
79+
- name: Install dependencies
80+
run: |
81+
sudo apt-get update
82+
sudo apt-get -y install policykit-1 libgtk2.0-common screen uml-utilities libc6-dev libicu-dev gcc python3 python3-pip
83+
mkdir renode_portable
84+
wget https://builds.renode.io/renode-latest.linux-portable.tar.gz
85+
tar xf renode-latest.linux-portable.tar.gz -C renode_portable --strip-components=1
7686
- name: Setup Directories
77-
run: mkdir -p ros_ws/src
87+
run: mkdir -p $ROS_WORKSPACE_PATH
7888
- name: checkout
7989
uses: actions/checkout@v4
8090
with:
81-
path: ros_ws/src
82-
- name: Build and Test ROS 1
83-
uses: ros-tooling/action-ros-ci@master
84-
if: ${{ contains('["melodic", "noetic"]', matrix.ros_distro) }}
85-
continue-on-error: true
86-
with:
87-
package-name: usb_cam
88-
target-ros1-distro: ${{ matrix.ros_distro }}
89-
vcs-repo-file-url: ""
90-
- name: Build and Test ROS 2
91-
id: build_and_test_step
92-
uses: ros-tooling/action-ros-ci@master
93-
if: ${{ contains('["melodic", "noetic"]', matrix.ros_distro) == false }}
94-
with:
95-
package-name: usb_cam
96-
target-ros2-distro: ${{ matrix.ros_distro }}
97-
vcs-repo-file-url: ""
98-
colcon-defaults: |
99-
{
100-
"build": {
101-
"mixin": ["coverage-gcc"]
102-
}
103-
}
104-
# If possible, pin the repository in the workflow to a specific commit to avoid
105-
# changes in colcon-mixin-repository from breaking your tests.
106-
colcon-mixin-repository: https://raw.githubusercontent.com/colcon/colcon-mixin-repository/1ddb69bedfd1f04c2f000e95452f7c24a4d6176b/index.yaml
107-
- uses: actions/upload-artifact@v1
91+
path: $ROS_WORKSPACE_PATH/usb_cam
92+
- name: build
93+
shell: bash
94+
run: |
95+
source /opt/ros/${{ matrix.ros_distro }}/setup.bash
96+
cd $ROS_WORKSPACE_PATH
97+
colcon build --packages-select usb_cam
98+
- name: unit tests
99+
shell: bash
100+
run: |
101+
source /opt/ros/${{ matrix.ros_distro }}/setup.bash
102+
cd $ROS_WORKSPACE_PATH
103+
colcon test --packages-select usb_cam
104+
# Compile again, this time enabling integration tests
105+
- name: Build integration tests
106+
shell: bash
107+
run: |
108+
source /opt/ros/${{ matrix.ros_distro }}/setup.bash
109+
cd $ROS_WORKSPACE_PATH
110+
colcon build --packages-select usb_cam --cmake-args -DSANITIZE=1 -DINTEGRATION_TESTS=1
111+
- name: Run integration tests
112+
shell: bash
113+
run: |
114+
renode_portable/renode --disable-gui --version
115+
- uses: actions/upload-artifact@v4
108116
with:
109117
name: colcon-logs-${{ matrix.ros_distro }}
110118
path: ${{ steps.build_and_test_step.outputs.ros-workspace-directory-name }}/log
111119
if: always()
112120
continue-on-error: true
113-
- uses: actions/upload-artifact@v1
121+
- uses: actions/upload-artifact@v4
114122
with:
115123
name: lcov-logs-${{ matrix.ros_distro }}
116124
path: ${{ steps.build_and_test_step.outputs.ros-workspace-directory-name }}/lcov

CMakeLists.txt

Lines changed: 56 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,11 @@ if(NOT CMAKE_CXX_STANDARD)
77
endif()
88

99
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10-
if($ENV{ROS_VERSION} EQUAL 2)
11-
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
12-
endif()
10+
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
1311
endif()
1412

15-
# Remove once ROS 1 Noetic is deprecated
16-
if($ENV{ROS_VERSION} EQUAL 1)
17-
find_package(catkin REQUIRED COMPONENTS
18-
cv_bridge
19-
roscpp
20-
std_msgs
21-
std_srvs
22-
sensor_msgs
23-
camera_info_manager
24-
image_transport)
25-
else()
26-
find_package(ament_cmake_auto REQUIRED)
27-
ament_auto_find_build_dependencies()
28-
endif()
13+
find_package(ament_cmake_auto REQUIRED)
14+
ament_auto_find_build_dependencies()
2915

3016
find_package(OpenCV REQUIRED)
3117

@@ -63,103 +49,65 @@ target_link_libraries(${PROJECT_NAME}
6349
${swscale_LIBRARIES}
6450
${OpenCV_LIBRARIES})
6551

66-
# Remove once ROS 1 Noetic is deprecated
67-
if($ENV{ROS_VERSION} EQUAL 1)
68-
catkin_package(
69-
INCLUDE_DIRS include
70-
LIBRARIES ${PROJECT_NAME}
71-
)
72-
73-
add_executable(${PROJECT_NAME}_node src/ros1/usb_cam_node.cpp)
74-
target_link_libraries(${PROJECT_NAME}_node
75-
${PROJECT_NAME}
76-
${catkin_LIBRARIES}
77-
)
78-
target_include_directories(${PROJECT_NAME}_node PUBLIC
79-
${catkin_INCLUDE_DIRS})
80-
else()
81-
ament_export_libraries(${PROJECT_NAME})
82-
83-
## Declare a ROS 2 composible node as a library
84-
ament_auto_add_library(${PROJECT_NAME}_node SHARED
85-
src/ros2/usb_cam_node.cpp
86-
)
87-
88-
target_link_libraries(${PROJECT_NAME}_node
89-
${PROJECT_NAME})
52+
ament_export_libraries(${PROJECT_NAME})
9053

91-
## Use node to generate an executable
92-
rclcpp_components_register_node(${PROJECT_NAME}_node
93-
PLUGIN "usb_cam::UsbCamNode"
94-
EXECUTABLE ${PROJECT_NAME}_node_exe
95-
)
96-
if(SANITIZE)
97-
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address -fsanitize=leak)
98-
target_link_libraries(${PROJECT_NAME} -fsanitize=address -fsanitize=leak)
99-
target_compile_options(${PROJECT_NAME}_node PUBLIC -fsanitize=address -fsanitize=leak)
100-
target_link_libraries(${PROJECT_NAME}_node -fsanitize=address -fsanitize=leak)
101-
target_link_libraries(${PROJECT_NAME}_node_exe -fsanitize=address -fsanitize=leak)
102-
endif()
103-
endif()
54+
## Declare a ROS 2 composible node as a library
55+
ament_auto_add_library(${PROJECT_NAME}_node SHARED
56+
src/usb_cam_node.cpp
57+
)
10458

105-
if(BUILD_TESTING)
106-
if($ENV{ROS_VERSION} EQUAL 2)
107-
find_package(ament_lint_auto REQUIRED)
108-
ament_lint_auto_find_test_dependencies()
59+
target_link_libraries(${PROJECT_NAME}_node
60+
${PROJECT_NAME})
10961

110-
find_package(ament_cmake_gtest)
62+
## Use node to generate an executable
63+
rclcpp_components_register_node(${PROJECT_NAME}_node
64+
PLUGIN "usb_cam::UsbCamNode"
65+
EXECUTABLE ${PROJECT_NAME}_node_exe
66+
)
11167

112-
# Unit tests
113-
ament_add_gtest(test_usb_cam_utils
114-
test/test_usb_cam_utils.cpp)
115-
target_link_libraries(test_usb_cam_utils
116-
${PROJECT_NAME})
117-
ament_add_gtest(test_pixel_formats
118-
test/test_pixel_formats.cpp)
119-
target_link_libraries(test_pixel_formats
68+
if(SANITIZE)
69+
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address -fsanitize=leak)
70+
target_link_libraries(${PROJECT_NAME} -fsanitize=address -fsanitize=leak)
71+
target_compile_options(${PROJECT_NAME}_node PUBLIC -fsanitize=address -fsanitize=leak)
72+
target_link_libraries(${PROJECT_NAME}_node -fsanitize=address -fsanitize=leak)
73+
target_link_libraries(${PROJECT_NAME}_node_exe -fsanitize=address -fsanitize=leak)
74+
endif()
75+
76+
if(BUILD_TESTING)
77+
find_package(ament_lint_auto REQUIRED)
78+
ament_lint_auto_find_test_dependencies()
79+
find_package(ament_cmake_gtest)
80+
# Unit tests
81+
ament_add_gtest(test_usb_cam_utils
82+
test/test_usb_cam_utils.cpp)
83+
target_link_libraries(test_usb_cam_utils
84+
${PROJECT_NAME})
85+
ament_add_gtest(test_pixel_formats
86+
test/test_pixel_formats.cpp)
87+
target_link_libraries(test_pixel_formats
88+
${PROJECT_NAME})
89+
if(INTEGRATION_TESTS)
90+
ament_add_gtest(test_usb_cam_lib
91+
test/test_usb_cam_lib.cpp)
92+
target_link_libraries(test_usb_cam_lib
12093
${PROJECT_NAME})
121-
# TODO(flynneva): rewrite this test in another PR
122-
# Integration tests
123-
# ament_add_gtest(test_usb_cam_lib
124-
# test/test_usb_cam_lib.cpp)
125-
# target_link_libraries(test_usb_cam_lib
126-
# ${PROJECT_NAME})
12794
endif()
12895
endif()
12996

97+
install(
98+
PROGRAMS scripts/show_image.py
99+
DESTINATION lib/${PROJECT_NAME})
130100

131-
if($ENV{ROS_VERSION} EQUAL 1)
132-
install(TARGETS ${PROJECT_NAME}_node ${PROJECT_NAME}
133-
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
134-
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
135-
)
136-
137-
## Copy launch files
138-
install(DIRECTORY launch/
139-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
140-
FILES_MATCHING PATTERN "*.launch"
141-
)
142-
143-
install(DIRECTORY include/${PROJECT_NAME}/
144-
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
145-
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
146-
)
147-
else()
148-
install(
149-
PROGRAMS scripts/show_image.py
150-
DESTINATION lib/${PROJECT_NAME})
151-
152-
install(TARGETS
153-
${PROJECT_NAME}
154-
${PROJECT_NAME}_node
155-
ARCHIVE DESTINATION lib
156-
LIBRARY DESTINATION lib
157-
RUNTIME DESTINATION lib
158-
)
159-
160-
ament_auto_package(
161-
INSTALL_TO_SHARE
162-
launch
163-
config
164-
)
165-
endif()
101+
install(TARGETS
102+
${PROJECT_NAME}
103+
${PROJECT_NAME}_node
104+
ARCHIVE DESTINATION lib
105+
LIBRARY DESTINATION lib
106+
RUNTIME DESTINATION lib
107+
)
108+
109+
ament_auto_package(
110+
INSTALL_TO_SHARE
111+
launch
112+
config
113+
)

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,25 @@ Unfortunately `rviz2` and `show_image.py` do not support visualizing the compres
154154
ros2 run image_transport republish compressed raw --ros-args --remap in/compressed:=image_raw/compressed --remap out:=image_raw/uncompressed
155155
```
156156

157-
## Address and leak sanitizing
157+
## Testing
158+
159+
To run the basic unit tests for this repository:
160+
161+
```shell
162+
colcon build --packages-select usb_cam
163+
colcon test --pacakges-select usb_cam
164+
```
165+
166+
### Integration tests
167+
168+
To run integration tests for this repository:
169+
170+
```shell
171+
colcon build --packages-select usb_cam --cmake-args -DINTEGRATION_TESTS=1
172+
colcon test --pacakges-select usb_cam
173+
```
174+
175+
### Address and leak sanitizing
158176

159177
Incorporated into the `CMakelists.txt` file to assist with memory leak and address sanitizing
160178
is a flag to add these compile commands to the targets.

include/usb_cam/usb_cam.hpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,27 @@ typedef struct
104104

105105
typedef struct
106106
{
107-
std::string camera_name; // can be anything
108-
std::string device_name; // usually /dev/video0 or something similiar
109-
std::string frame_id;
110-
std::string io_method_name;
111-
std::string camera_info_url;
112-
// these parameters all have to be a combination supported by the device
113-
// Use
114-
// v4l2-ctl --device=0 --list-formats-ext
115-
// to discover them,
116-
// or guvcview
117-
std::string pixel_format_name;
118-
std::string av_device_format;
119-
int image_width;
120-
int image_height;
121-
int framerate;
122-
int brightness;
123-
int contrast;
124-
int saturation;
125-
int sharpness;
126-
int gain;
127-
int white_balance;
128-
int exposure;
129-
int focus;
130-
bool auto_white_balance;
131-
bool autoexposure;
132-
bool autofocus;
107+
std::string camera_name = "usb_cam"; // can be anything
108+
std::string device_name = "/dev/video0"; // usually /dev/video0 or something similiar
109+
std::string frame_id = "camera";
110+
std::string io_method_name = "mmap";
111+
std::string camera_info_url = "package://usb_cam/config/camera_info.yaml";
112+
std::string pixel_format_name = "yuyv2rgb";
113+
std::string av_device_format = "YUV422P";
114+
int image_width = 600;
115+
int image_height = 400;
116+
int framerate = 30.0;
117+
int brightness = -1;
118+
int contrast = -1;
119+
int saturation = -1;
120+
int sharpness = -1;
121+
int gain = -1;
122+
int white_balance = -1;
123+
int exposure = -1;
124+
int focus = -1;
125+
bool auto_white_balance = true;
126+
bool autoexposure = true;
127+
bool autofocus = false;
133128
} parameters_t;
134129

135130
typedef struct

0 commit comments

Comments
 (0)