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

add ci config #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
113 changes: 113 additions & 0 deletions .github/workflows/humble_docker_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Humble_buid_and_test_with_docker_NativeROS_string

on:
push:
branches:
- "main"
pull_request:
types: [opened, synchronize]
jobs:
ci:
runs-on: ubuntu-latest
container:
image: osrf/ros:humble-desktop
timeout-minutes: 5
strategy:
fail-fast: false
# matrix:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Install Docker Compose
run: sudo apt-get update && sudo apt-get install -y docker-compose
# runs containers using docker-compose.yml
- name: Build and run containers
run: |
cd workspace/test/mros2
docker-compose up -d
cd -
- name: Wait for containers to start
run: sleep 20 # wait time for container startup.
- name: List running containers
run: docker ps -a # Check if all containers are running.
- name: Show container logs
run: |
docker logs app1
docker logs app2
- name: Show IP addresses
run: |
docker exec app1 ip addr show eth0
docker exec app2 ip addr show eth0
- name: Test communication between containers (ping)
run: |
docker exec app1 ping -c 4 172.19.0.3 # app1 から app2 へのPing
docker exec app2 ping -c 4 172.19.0.2 # app2 から app1 へのPing
- name: Test TCP connection between containers (netcat)
run: |
# Listen port 8080 on app2
docker exec -d app2 bash -c "nc -l -p 8080"
# Check connection to app2 from app1
docker exec app1 bash -c "echo 'Test' | nc -w 3 172.19.0.3 8080"
# app1: prepare build (run chmod +x update_ip.sh and ./update_ip.sh)
- name: Prepare build in mros
run: |
docker cp $GITHUB_WORKSPACE app1:/root/ws_mros # Copy source code to app1
docker exec app1 bash -c "
cd /root/ws_mros &&
chmod +x update_ip.sh && # Change grant
./update_ip.sh" # Run script to overwrite IP address.
# app1: clean and build
- name: Clean and build in mros
run: |
docker exec app1 bash -c "
cd /root/ws_mros &&
pwd &&
ls -la &&
bash build.bash clean &&
bash build.bash all test/mros2/test_echoback_string"
# app2:
- name: Clone Native test stub source code to app2 and build and run
run: |
docker exec app2 bash -c "
source /opt/ros/humble/setup.bash &&
cd &&
pwd &&
ls -la &&
git clone https://github.com/mROS-base/mros2-host-examples &&
cd mros2-host-examples &&
colcon build --packages-select mros2_echoreply_string &&
ls -la &&
source install/setup.bash"
- name: Run mROS and Native ROS
shell: bash
run : |
# Run native ROS respondeer in background
docker exec app2 bash -c "source /opt/ros/humble/setup.bash &&
cd mros2-host-examples &&
source install/setup.bash &&
ros2 run mros2_echoreply_string echoreply_node" &

docker exec app1 bash -c "cd /root/ws_mros && ./cmake_build/mros2-posix" &
mros_pid=$! # get mROS process id

docker ps

# Wait until mROS finishes
wait $mros_pid
mros_status=$?

# Judge CI success based on results
if [ $mros_status -eq 0 ] ;then
echo "Succeed pub/sub test process between mros2 and Native ROS"
exit 0
else
echo "Fail pub/sub test process between mros2 and Native ROS"
exit 1
fi
- name: Tear down containers
run: docker-compose down
111 changes: 111 additions & 0 deletions .github/workflows/humble_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Humble_build_and_test

on:
push:
branches:
- "main"
pull_request:
types: [opened, synchronize ]
jobs:
build_and_test:
runs-on: ubuntu-latest
container:
image: osrf/ros:humble-desktop
timeout-minutes: 3
strategy:
fail-fast: false
matrix:
comm-target: [native , mros]
comm-data-type: [string, twist]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: update
run: sudo apt-get update
- name: setup and install tools
run: >
sudo apt-get install -y iproute2 git wget build-essential gcc g++ libssl-dev libreadline-dev
zlib1g-dev make autoconf automake cmake pkg-config curl net-tools netcat python3-jinja2
- name: Clone Test Stub
uses: actions/checkout@v4
with:
repository: mROS-base/mros2-host-examples
path: ws_host/src/mros2-host-examples
- name: Update IP address
run: |
chmod +x update_ip.sh
./update_ip.sh
- name: Generate Twist Header files
if: matrix.comm-data-type == 'twist'
shell: bash
run: |
cd workspace
python3 ../mros2/mros2_header_generator/header_generator.py geometry_msgs/msg/Twist.msg
cd -
- name: Build mROS
shell: bash
run: |
bash build.bash clean
bash build.bash all test/mros2/test_echoback_${{ matrix.comm-data-type }}
mv cmake_build/ test_echoback_${{ matrix.comm-data-type }}/
- name: Build Native ROS responder
if: matrix.comm-target == 'native'
shell: bash
run: |
cd ws_host/
source /opt/ros/humble/setup.bash
colcon build --packages-select mros2_echoreply_${{ matrix.comm-data-type }}
- name: Build mROS responder
if: matrix.comm-target == 'mros'
shell: bash
run: |
bash build.bash clean
bash build.bash all test/mros2/test_echoback_${{ matrix.comm-data-type }}_responder
- name: Run Testing mROS and Native ROS
if: matrix.comm-target == 'native'
shell: bash
run : |
./test_echoback_${{ matrix.comm-data-type }}/mros2-posix &
mros_pid=$! # get mROS process id

# Run Native ROS in background
cd ws_host/
source /opt/ros/humble/setup.bash
source install/setup.bash
ros2 run mros2_echoreply_${{ matrix.comm-data-type }} echoreply_node &

# Wait until mROS finishes
wait $mros_pid
mros_status=$?

# Judge CI success based on results
if [ $mros_status -eq 0 ] ;then
echo "Succeed pub/sub test process between mros2 and Native ROS"
exit 0
else
echo "Fail pub/sub test process between mros2 and Native ROS"
exit 1
fi
- name: Run mROS and mROS
if: matrix.comm-target == 'mros'
shell: bash
run : |
./test_echoback_${{ matrix.comm-data-type }}/mros2-posix &
mros_pid=$! # get mROS process id

# Run mROS responder in background
./cmake_build/mros2-posix &

# Wait until mROS finishes
wait $mros_pid
mros_status=$?

# Judge CI success based on results
if [ $mros_status -eq 0 ] ;then
echo "Succeed pub/sub test process between mros2 and mros2"
exit 0
else
echo "Fail pub/sub test process between mros2 and mros2"
exit 1
fi
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sudo apt-get update && sudo apt-get install -y \
libssl-dev libreadline-dev zlib1g-dev \
make autoconf automake cmake \
pkg-config curl \
net-tools netcat
net-tools netcat python3-jinja2
```

Please check the IP address and netmask of the execution environment.
Expand All @@ -64,6 +64,22 @@ You need to edit the below files to set IP address and netmask.
* IP address and netmask to `include/netif.h`
* IP address to `include/rtps/config.h`

Alternatively, you can use the provided `update_ip.sh` script to automatically update these files according to your building environment.
The `update_ip.sh` script is designed to overwrite the IP address and netmask in `include/rtps/config.h` and `include/netif.h` files based on the current network configuration.

Below is an example of using this script.

```bash
bash update_ip.sh
```

This script retrieves the current IP address and netmask of the system's active network interface and updates the specified files accordingly.
Make sure to check the output to ensure the updates are correct before proceeding with the build.
If multiple network interfaces are available, ensure the correct one is being used.

For troubleshooting, verify that the script runs without errors.
If you encounter issues, check that the necessary network tools are installed and that your system has an active network connection.

## Getting Started

This section explains how to build and execute mros2-posix application as a Linux/POSIX process, using `echoback_string` as an example (please see workspace/README.md for another examples).
Expand Down
72 changes: 72 additions & 0 deletions update_ip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# Retrieve IP address
IP_ADDRESS=$(hostname -I | awk '{print $1}')
if [ -z "$IP_ADDRESS" ]; then
echo "Error: Failed to retrieve IP address."
exit 1
fi

# Retrieve netmask (extract the netmask corresponding to the IP address)
INTERFACE=$(ip -o addr show | grep "$IP_ADDRESS" | awk '{print $2}')
NETMASK=$(ip -o -f inet addr show $INTERFACE | awk '/inet/ {print $4}' | cut -d'/' -f2)
if [ -z "$NETMASK" ]; then
echo "Error: Failed to retrieve netmask."
exit 1
fi

# Calculate netmask from CIDR
function cidr_to_netmask() {
local cidr=$1
local mask=""
local octets=$(( cidr / 8 ))
local bits=$(( cidr % 8 ))

for (( i=0; i<4; i++ )); do
if [ $i -lt $octets ]; then
mask+="255"
elif [ $i -eq $octets ]; then
mask+=$(( 256 - 2**(8-bits) ))
else
mask+="0"
fi

if [ $i -lt 3 ]; then
mask+="."
fi
done
echo "$mask"
}

NETMASK=$(cidr_to_netmask $NETMASK)
echo "Retrieved Netmask for IP $IP_ADDRESS: $NETMASK"

# Split the IP address by dots
IFS='.' read -r -a IP_PARTS <<< "$IP_ADDRESS"

# Split the netmask by dots
IFS='.' read -r -a NETMASK_PARTS <<< "$NETMASK"
echo "Netmask parts: ${NETMASK_PARTS[0]}, ${NETMASK_PARTS[1]}, ${NETMASK_PARTS[2]}, ${NETMASK_PARTS[3]}"

# Replace the IP address in include/rtps/config.h

echo "Running sed on include/rtps/config.h"
sed -i "s/[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\}[[:space:]]*}; \
\/\/ Needs to be set in lwipcfg.h too./\
${IP_PARTS[0]}, ${IP_PARTS[1]}, ${IP_PARTS[2]}, ${IP_PARTS[3]}};\
\/\/ Needs to be set in lwipcfg.h too./" \
include/rtps/config.h


# Replace the IP address and netmask in include/netif.h
sed -i 's/#define NETIF_IPADDR ".*"/#define NETIF_IPADDR "'$IP_ADDRESS'"/' include/netif.h
sed -i 's/#define NETIF_NETMASK ".*"/#define NETIF_NETMASK "'$NETMASK'"/' include/netif.h



# Display the result for confirmation
echo "Updated IP Address: $IP_ADDRESS"
echo "Updated include/rtps/config.h:"
grep -E 'Needs to be set in lwipcfg.h too.' include/rtps/config.h
echo "Updated include/netif.h:"
grep -E 'NETIF_IPADDR' include/netif.h
20 changes: 20 additions & 0 deletions workspace/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,23 @@ We plan to maintain them in the near future, as they remain useful (see #1).
(embeddedRTPS and lwip-posix)
* embeddedRTPS layer: [fastdds-comp](https://github.com/mROS-base/mros2-posix/tree/main/workspace/test/fastdds-comp)



## mros2 Directory Overview

The `mros2` directory contains several test programs and configuration files, which are actively used in the CI testing process. Below is the structure and overview of the this directory:

```
mros2/
├── docker-compose.yml
├── test_echoback_string
├── test_echoback_string_responder
├── test_echoback_twist
└── test_echoback_twist_responder
```

- **docker-compose.yml**: This is an experimental file that was prepared for setting up the environment, but it is currently not used in the CI process. See `.github/workflows/humble_docker_test.yaml`
- **test_echoback_string**: A test program that sends a string message and expects an echo response, validating communication for string messages in a ROS 2 environment. It is designed to communicate with the `mros2-host-example`'s `mros2_echoreply_string` (a test for Native ROS) and `test_echoback_string_responder` (a test for mROS). The responder listens for incoming messages and sends back the received message.
- **test_echoback_string_responder**: This program subscribes to incoming string messages and echoes them back, facilitating the echo test for string messages.
- **test_echoback_twist**: A test program that sends a `geometry_msgs::msg::Twist` message and expects an echo response, validating communication for Twist messages in a ROS 2 environment. It communicates with the `mros2-host-example`'s `mros2_echoreply_twist` (a test for Native ROS) and `test_echoback_twist_responder` (a test for mROS).
- **test_echoback_twist_responder**: This program subscribes to incoming Twist messages and echoes them back, facilitating the echo test for Twist messages.
38 changes: 38 additions & 0 deletions workspace/test/mros2/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'
services:
app1:
container_name: app1
image: osrf/ros:humble-desktop # ROS Humble の Ubuntu ベースイメージを使用
command: >
bash -c "set -e &&
apt-get update &&
apt-get install -y iproute2 iputils-ping git wget build-essential gcc g++ libssl-dev libreadline-dev
zlib1g-dev make autoconf automake cmake pkg-config curl net-tools netcat python3-jinja2 &&
echo 'IP address:' &&
ip addr show eth0 &&
sleep 600"
networks:
test_net:
ipv4_address: 172.19.0.2

app2:
container_name: app2
image: osrf/ros:humble-desktop # ROS Humble の Ubuntu ベースイメージを使用
command: >
bash -c "set -e &&
apt-get update &&
apt-get install -y iproute2 iputils-ping git wget build-essential gcc g++ libssl-dev libreadline-dev
zlib1g-dev make autoconf automake cmake pkg-config curl net-tools netcat python3-jinja2 &&
echo 'IP address:' &&
ip addr show eth0 &&
sleep 600"
networks:
test_net:
ipv4_address: 172.19.0.3

networks:
test_net:
driver: bridge
ipam:
config:
- subnet: 172.19.0.0/16
Loading
Loading