Skip to content

Commit

Permalink
Ros2 unit test workflow (#471)
Browse files Browse the repository at this point in the history
* Added test workflow

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Added test workflow

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Added test workflow

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Update run-unit-tests-push.yaml

* Update run-unit-tests-push.yaml

* Update run-unit-tests-push.yaml

* Update simulation_deps.repos

* Update run-unit-tests-push.yaml

* Update run-unit-tests-push.yaml

* REmoved integration tests

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Trailing comma | typo

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* added buil type

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* added buil type

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* added buil type

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Moved tests to self-runner arg

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Updated readme

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Utest (#482)

* Test unit test

* Add debuging logs

* Change in test deconstructor

* test

* Test

* test

* Utest

* Add test namespace

* console_cohesion-

* test

* Test

* Update run-unit-tests-push.yaml

* Simplify

* Simplify NodeCreation test

* Move system_ros_interface to integration test

* Fix

* Remove redundant workflow

* Removed includes

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Add 2nd build and test

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* added id to first build and test

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

---------

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Co-authored-by: Rafal Gorecki <126687345+rafal-gorecki@users.noreply.github.com>
  • Loading branch information
delihus and rafal-gorecki authored Jan 28, 2025
1 parent e036b02 commit 6711cab
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 235 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/run-unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
name: Run unit tests

on:
push:
workflow_call:
workflow_dispatch:

jobs:
build-and-test:
name: Run unit tests ${{ matrix.build_type }} build type
runs-on: ubuntu-22.04
strategy:
matrix:
build_type: [simulation, hardware]

env:
HUSARION_ROS_BUILD_TYPE: ${{ matrix.build_type }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: ros-tooling/setup-ros@v0.7
with:
use-ros2-testing: true

- name: Build and test
uses: ros-tooling/action-ros-ci@v0.3
id: build_test_1
with:
vcs-repo-file-url: ${{ github.workspace }}/husarion_ugv/${{ env.HUSARION_ROS_BUILD_TYPE }}_deps.repos
target-ros2-distro: humble
colcon-defaults: |
{
"build": {
"packages-up-to": ["husarion_ugv"],
"cmake-args": ["-DCMAKE_BUILD_TYPE=Release"]
},
"test": {
"packages-up-to": ["husarion_ugv"]
}
}
continue-on-error: true

- name: Retry Build and test (if failed)
if: steps.build_test_1.outcome == 'failure'
uses: ros-tooling/action-ros-ci@v0.3
with:
vcs-repo-file-url: ${{ github.workspace }}/husarion_ugv/${{ env.HUSARION_ROS_BUILD_TYPE }}_deps.repos
target-ros2-distro: humble
colcon-defaults: |
{
"build": {
"packages-up-to": ["husarion_ugv"],
"cmake-args": ["-DCMAKE_BUILD_TYPE=Release"]
},
"test": {
"packages-up-to": ["husarion_ugv"]
}
}
80 changes: 0 additions & 80 deletions .github/workflows/unit-tests.yaml

This file was deleted.

11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Launch arguments are largely common to both simulation and physical robot. Howev
||| `wheel_config_path` | Path to wheel configuration file. <br/> ***string:*** [`{wheel_type}.yaml`](./husarion_ugv_description/config) |
||| `wheel_type` | Specify the wheel type. If the selected wheel type is not 'custom', the wheel_config_path and controller_config_path arguments will be automatically adjusted and can be omitted. <br/> ***string:*** `WH01` (for Panther), `WH05` (for Lynx) (choices: `WH01`, `WH02`, `WH04`, `WH05`, `custom`) |
||| `x` | Initial robot position in the global 'x' axis. <br/> ***float:*** `0.0` |
||| `y` | Initial robot position in the global 'y' axis. <br/> ***float:***` -2.0` |
||| `y` | Initial robot position in the global 'y' axis. <br/> ***float:*** `-2.0` |
||| `z` | Initial robot position in the global 'z' axis. <br/> ***float:*** `0.2` |
||| `roll` | Initial robot 'roll' orientation. <br/> ***float:*** `0.0` |
||| `pitch` | Initial robot 'pitch' orientation. <br/> ***float:*** `0.0` |
Expand All @@ -137,7 +137,16 @@ pre-commit install

### Unit testing

#### Running on laptop

```bash
colcon build --symlink-install --packages-up-to husarion_ugv --cmake-args -DCMAKE_BUILD_TYPE=Release -DTEST_INTEGRATION=OFF
colcon test --packages-up-to husarion_ugv
```

#### Running on the Built-In Computer

```bash
colcon build --symlink-install --packages-up-to husarion_ugv --cmake-args -DCMAKE_BUILD_TYPE=Release -DTEST_INTEGRATION=ON
colcon test --packages-up-to husarion_ugv
```
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class BatteryDriverNode : public rclcpp::Node
{
public:
BatteryDriverNode(
const std::string & node_name, const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
const std::string & node_name, const std::string & ns = "/",
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());

private:
void BatteryPubTimerCB();
Expand Down
5 changes: 3 additions & 2 deletions husarion_ugv_battery/src/battery_driver_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ namespace husarion_ugv_battery
{

BatteryDriverNode::BatteryDriverNode(
const std::string & node_name, const rclcpp::NodeOptions & options)
: Node(node_name, options), diagnostic_updater_(std::make_shared<diagnostic_updater::Updater>(this))
const std::string & node_name, const std::string & ns, const rclcpp::NodeOptions & options)
: Node(node_name, ns, options),
diagnostic_updater_(std::make_shared<diagnostic_updater::Updater>(this))
{
RCLCPP_INFO(this->get_logger(), "Constructing node.");

Expand Down
12 changes: 7 additions & 5 deletions husarion_ugv_battery/test/utils/test_battery_driver_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ TestBatteryNode::TestBatteryNode(const bool use_adc_battery, const bool dual_bat
options.parameter_overrides(params);

battery_driver_node_ = std::make_shared<husarion_ugv_battery::BatteryDriverNode>(
"battery_driver", options);
"battery_driver", "/test_battery", options);

battery_sub_ = battery_driver_node_->create_subscription<BatteryStateMsg>(
"battery/battery_status", 10,
Expand Down Expand Up @@ -136,12 +136,14 @@ template <typename T>
void TestBatteryNode::WriteNumberToFile(const T number, const std::string & file_path)
{
std::ofstream file(file_path);
if (file.is_open()) {
file << number;
file.close();
} else {
if (!file) {
throw std::runtime_error("Failed to create file: " + file_path);
}

file << number;
if (!file) {
throw std::runtime_error("Failed to write to file: " + file_path);
}
}

#endif // HUSARION_UGV_BATTERY_UTILS_TEST_BATTERY_DRIVER_NODE_HPP_
2 changes: 1 addition & 1 deletion husarion_ugv_diagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if(BUILD_TESTING)
${PACKAGE_DEPENDENCIES})

# Integration tests
option(TEST_INTEGRATION "Run integration tests" ON)
option(TEST_INTEGRATION "Run integration tests" OFF)
if(TEST_INTEGRATION)
add_ros_test(test/integration/system_monitor_node.test.py)
endif()
Expand Down
Loading

0 comments on commit 6711cab

Please sign in to comment.