Skip to content

Commit

Permalink
Add automated testing (via catkin_virtualenv) (ros-drivers#136)
Browse files Browse the repository at this point in the history
Automatically test the code on every push or PR by playing back data to the driver and test whether the expected amount of messages is outputted by the driver and the messages contain the expected data.

The tester can cover more functionality that the current version of the nmea_navsat_driver supports, for these features new PRs will be created. The full usage can be observed in the boschresearch fork.

Signed-off-by: Gabriel Gaessler <[email protected]>
  • Loading branch information
ggaessler authored Jan 2, 2022
1 parent f60d849 commit 9413fe0
Show file tree
Hide file tree
Showing 10 changed files with 631 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on: [push, pull_request]

jobs:
test:
runs-on: [ubuntu-latest]
timeout-minutes: 10
strategy:
matrix:
ros_distro: [noetic]
ubuntu_distro: [focal]
arch: [amd64]
steps:
- uses: ros-tooling/[email protected]
with:
required-ros-distributions: ${{ matrix.ros_distro }}
- name: build and test
uses: ros-tooling/[email protected]
with:
package-name: nmea_navsat_driver
target-ros1-distro: ${{ matrix.ros_distro }}
30 changes: 27 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
cmake_minimum_required(VERSION 3.0.2)
project(nmea_navsat_driver)

find_package(catkin REQUIRED)
if (NOT CATKIN_ENABLE_TESTING)
find_package(catkin REQUIRED COMPONENTS
)
endif()
if (CATKIN_ENABLE_TESTING)
find_package(catkin REQUIRED COMPONENTS
catkin_virtualenv
)
endif()

catkin_python_setup()
catkin_package()
Expand All @@ -19,12 +27,28 @@ install(DIRECTORY launch/
FILES_MATCHING PATTERN "*.launch"
)

install(FILES LICENSE.txt
install(FILES
LICENSE.txt
test/requirements.txt
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

if (CATKIN_ENABLE_TESTING)
find_package(roslint)
catkin_generate_virtualenv(
PYTHON_INTERPRETER python3
)

catkin_add_nosetests(
test/test_driver.py
DEPENDENCIES ${${PROJECT_NAME}_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_virtualenv
)

catkin_install_python(
PROGRAMS
test/test_driver.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

find_package(roslint REQUIRED)
roslint_python()
roslint_add_test()
endif()
8 changes: 8 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@
<exec_depend>rospy</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-serial</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-serial</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-rospkg</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-rospkg</exec_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>nmea_msgs</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>tf</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-yaml</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-yaml</exec_depend>

<test_depend condition="$ROS_PYTHON_VERSION == 3">catkin_virtualenv</test_depend>

<test_depend>roslint</test_depend>
<test_depend>rostest</test_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- This is a pure Python package, so mark it architecture independent -->
<architecture_independent/>
<pip_requirements>test/requirements.txt</pip_requirements>
</export>
</package>
16 changes: 16 additions & 0 deletions test/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
nmea_navsat_driver testing
==========================

This folder contains a tester for the nmea_navsat_driver_package as well as configurations and GNSS device logs for playback.

Configurations
--------------

* `config_launch.yaml` defines with launch files should be called, which interface they refer to and which messages are in scope. For `serial` a virtual serial port is created and for `tcp` a TCP-server is created.
* `config_logs.yaml` defines which pre-recorded logs shall be tested in which mode at which speed. And even more important which messages are to be expected from the driver in which quantity and which fields have to stay in which boundaries. These settings determine whether the test will result in pass or fail. Also defines which parameters shall be passed to the launch files.
* `config_tester.yaml` general settings of the tester.

Running the test
----------------

The tester can be automatically executed via Github Actions, running the nosetests defined in the CMakeLists.txt eventually calling the rostest. The workflow configuration is therefore located at `.github/workflows/ci.yaml`.
7 changes: 7 additions & 0 deletions test/configs/config_launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# list of all launch files to be tested
nmea_serial_driver.launch:
# interface, serial or TCP
interface: serial
# messages that are supported by this driver configuration
messages:
- NavSatFix
15 changes: 15 additions & 0 deletions test/configs/config_log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# list of all raw data logs that shall be tested
nmea.log:
# mode, nmea or binary (u-blox)
mode: nmea
# rate for nmea mode in lines per second
rate: 4
# additional parameters to pass to the launch file
parameters: []
topics:
fix:
_message_count: 120
_type: NavSatFix
latitude:
max: 48.7734
min: 48.7733
8 changes: 8 additions & 0 deletions test/configs/config_tester.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# speedup in comparison to real time playback
speedup_rate: 20
# chunksize in bytes to read at once for binary data
binary_read_len: 10
# tcp host
tcp_host: 127.0.0.1
# tcp port to start with, will increment from here
tcp_port: 4242
Loading

0 comments on commit 9413fe0

Please sign in to comment.