Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ros2 unit test workflow #471

Merged
merged 26 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bf09553
Added test workflow
delihus Nov 12, 2024
5c2c325
Added test workflow
delihus Nov 12, 2024
ca1b2b3
Added test workflow
delihus Nov 12, 2024
ee565fa
Update run-unit-tests-push.yaml
delihus Nov 12, 2024
670ad21
Update run-unit-tests-push.yaml
delihus Nov 12, 2024
a6300af
Update run-unit-tests-push.yaml
delihus Nov 12, 2024
064c730
Update simulation_deps.repos
delihus Nov 12, 2024
42b6bfc
Update run-unit-tests-push.yaml
delihus Dec 11, 2024
fe4e650
Update run-unit-tests-push.yaml
delihus Dec 11, 2024
7d43459
Merge remote-tracking branch 'origin/ros2-devel' into ros2-unit-test-…
delihus Dec 12, 2024
450925d
REmoved integration tests
delihus Dec 12, 2024
efbf7be
Trailing comma | typo
delihus Dec 12, 2024
acb8ddd
added buil type
delihus Dec 12, 2024
5741f32
added buil type
delihus Dec 12, 2024
435cda8
added buil type
delihus Dec 12, 2024
fbe010a
Merge remote-tracking branch 'origin/ros2-devel' into ros2-unit-test-…
delihus Dec 17, 2024
c247ca1
Moved tests to self-runner arg
delihus Dec 17, 2024
134b1b2
Updated readme
delihus Dec 17, 2024
089b5de
Merge remote-tracking branch 'origin/ros2-devel' into ros2-unit-test-…
delihus Dec 20, 2024
c8373a0
Merge remote-tracking branch 'origin/ros2-devel' into ros2-unit-test-…
delihus Jan 7, 2025
112a313
Merge remote-tracking branch 'origin/ros2-devel' into ros2-unit-test-…
delihus Jan 17, 2025
c1acb77
Utest (#482)
rafal-gorecki Jan 23, 2025
87aeb23
Removed includes
delihus Jan 24, 2025
bc7950b
Merge remote-tracking branch 'origin/ros2-devel' into ros2-unit-test-…
delihus Jan 24, 2025
1fdc675
Add 2nd build and test
delihus Jan 27, 2025
bcf68eb
added id to first build and test
delihus Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/run-unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reconsider using continue-on-error: true.

Using continue-on-error: true might hide build or test failures. Consider removing it since you already have a retry mechanism in place.

-        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"]
}
}
Comment on lines +47 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the retry condition step ID reference.

The condition references an undefined step ID build_test_1. The previous step needs an ID to be referenced in the retry condition.

Apply this diff to fix the step ID reference:

      - name: Build and test
+       id: build_test_1
        uses: ros-tooling/action-ros-ci@v0.3

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 actionlint (1.7.4)

47-47: property "build_test_1" is not defined in object type {}

(expression)

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
Loading