Skip to content

Commit

Permalink
add CI and Test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBearing committed Sep 27, 2024
1 parent d267988 commit 8eca2c7
Show file tree
Hide file tree
Showing 17 changed files with 699 additions and 1 deletion.
115 changes: 115 additions & 0 deletions .github/workflows/humble_docker_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Humble_test_with_docker_NativeROS_string

on:
push:
branches:
- "main"
pull_request:
types: [opened, synchronize, labeled]
jobs:
ci:
runs-on: ${{ matrix.os }}
if: |
((github.event.action == 'labeled') && (github.event.label.name == 'TESTING') && (github.base_ref == 'main' )) ||
((github.event.action == 'synchronize') && (github.base_ref == 'main') && contains(github.event.pull_request.labels.*.name, 'TESTING')) ||
(github.ref_name == 'main')
container:
image: osrf/ros:${{ matrix.ros_distribution }}-desktop
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
ros_distribution: [humble]
steps:
- name: Checkout code
uses: actions/checkout@v3
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
# docker-compose.yml を使ってコンテナを起動
- name: Build and run containers
run: docker-compose up -d
- name: Wait for containers to start
run: sleep 20 # コンテナが確実に起動するのを待つ時間を長くする
- name: List running containers
run: docker ps -a # 全コンテナが起動しているか確認
- 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: |
# app2でポート8080をリスン
docker exec -d app2 bash -c "nc -l -p 8080"
# app1からapp2へのTCP接続を確認
docker exec app1 bash -c "echo 'Test' | nc -w 3 172.19.0.3 8080"
# app1: ビルドの準備 (chmod +x update_ip.sh と ./update_ip.sh の実行)
- name: Prepare build in mros
run: |
docker cp $GITHUB_WORKSPACE app1:/root/ws_mros # ソースコードをapp1コンテナにコピー
docker exec app1 bash -c "
cd /root/ws_mros &&
chmod +x update_ip.sh && # 権限変更
./update_ip.sh" # IPアドレス更新スクリプトの実行
# app1: クリーンビルド
- 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_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 : |
# テスト対象をバックグラウンドで実行
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=$! # テストプログラムのプロセスIDを取得
docker ps
# mROSが終了するまで待つ
wait $mros_pid
mros_status=$?
# 結果に基づいてCIの成否を判断
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
118 changes: 118 additions & 0 deletions .github/workflows/humble_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: ci_humble

on:
push:
branches:
- "main"
- "feat/add_ci_config"
pull_request:
types: [opened, synchronize, labeled]
jobs:
ci:
runs-on: ${{ matrix.os }}
if: |
((github.event.action == 'labeled') && (github.event.label.name == 'TESTING') && (github.base_ref == 'main' )) ||
((github.event.action == 'synchronize') && (github.base_ref == 'main') && contains(github.event.pull_request.labels.*.name, 'TESTING')) ||
(github.ref_name == 'main')
container:
image: osrf/ros:${{ matrix.ros_distribution }}-desktop
timeout-minutes: 3
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
ros_distribution: [humble]
comm-target: [native , mros]
comm-data-type: [string, twist]
steps:
- uses: actions/checkout@v3
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@v3
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_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_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=$! # mROSのプロセスIDを取得
# Native ROSをバックグラウンドで実行
cd ws_host/
source /opt/ros/humble/setup.bash
source install/setup.bash
ros2 run mros2_echoreply_${{ matrix.comm-data-type }} echoreply_node &
# mROSが終了するまで待つ
wait $mros_pid
mros_status=$?
# 結果に基づいてCIの成否を判断
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=$! # テストプログラムのプロセスIDを取得
# テスト対象をバックグラウンドで実行
./cmake_build/mros2-posix &
# mROSが終了するまで待つ
wait $mros_pid
mros_status=$?
# 結果に基づいてCIの成否を判断
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
2 changes: 1 addition & 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 jinja2
```

Please check the IP address and netmask of the execution environment.
Expand Down
38 changes: 38 additions & 0 deletions 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
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

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

# ネットマスクを取得(IPアドレスに対応するネットマスクを抽出)
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

# 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"

# IPアドレスをドットで分割
IFS='.' read -r -a IP_PARTS <<< "$IP_ADDRESS"

# ネットマスクをドットで分割
IFS='.' read -r -a NETMASK_PARTS <<< "$NETMASK"
echo "Netmask parts: ${NETMASK_PARTS[0]}, ${NETMASK_PARTS[1]}, ${NETMASK_PARTS[2]}, ${NETMASK_PARTS[3]}"

# include/rtps/config.h のIPアドレス置換

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


# include/netif.h のIPアドレスとネットマスク置換
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



# 結果を表示して確認
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
3 changes: 3 additions & 0 deletions workspace/test_echoback_string/Filelists.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(apl_SRCS
${PROJECT_SOURCE_DIR}/workspace/${MROS2_APPNAME}/app.cpp
)
Loading

0 comments on commit 8eca2c7

Please sign in to comment.