Skip to content

Commit 8eca2c7

Browse files
committed
add CI and Test
1 parent d267988 commit 8eca2c7

File tree

17 files changed

+699
-1
lines changed

17 files changed

+699
-1
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Humble_test_with_docker_NativeROS_string
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
types: [opened, synchronize, labeled]
9+
jobs:
10+
ci:
11+
runs-on: ${{ matrix.os }}
12+
if: |
13+
((github.event.action == 'labeled') && (github.event.label.name == 'TESTING') && (github.base_ref == 'main' )) ||
14+
((github.event.action == 'synchronize') && (github.base_ref == 'main') && contains(github.event.pull_request.labels.*.name, 'TESTING')) ||
15+
(github.ref_name == 'main')
16+
container:
17+
image: osrf/ros:${{ matrix.ros_distribution }}-desktop
18+
timeout-minutes: 5
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-22.04]
23+
ros_distribution: [humble]
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
with:
28+
submodules: recursive
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v1
31+
32+
- name: Install Docker Compose
33+
run: sudo apt-get update && sudo apt-get install -y docker-compose
34+
# docker-compose.yml を使ってコンテナを起動
35+
- name: Build and run containers
36+
run: docker-compose up -d
37+
- name: Wait for containers to start
38+
run: sleep 20 # コンテナが確実に起動するのを待つ時間を長くする
39+
- name: List running containers
40+
run: docker ps -a # 全コンテナが起動しているか確認
41+
- name: Show container logs # コンテナのログを確認する
42+
run: |
43+
docker logs app1
44+
docker logs app2
45+
- name: Show IP addresses
46+
run: |
47+
docker exec app1 ip addr show eth0
48+
docker exec app2 ip addr show eth0
49+
- name: Test communication between containers (ping)
50+
run: |
51+
docker exec app1 ping -c 4 172.19.0.3 # app1 から app2 へのPing
52+
docker exec app2 ping -c 4 172.19.0.2 # app2 から app1 へのPing
53+
- name: Test TCP connection between containers (netcat)
54+
run: |
55+
# app2でポート8080をリスン
56+
docker exec -d app2 bash -c "nc -l -p 8080"
57+
# app1からapp2へのTCP接続を確認
58+
docker exec app1 bash -c "echo 'Test' | nc -w 3 172.19.0.3 8080"
59+
# app1: ビルドの準備 (chmod +x update_ip.sh と ./update_ip.sh の実行)
60+
- name: Prepare build in mros
61+
run: |
62+
docker cp $GITHUB_WORKSPACE app1:/root/ws_mros # ソースコードをapp1コンテナにコピー
63+
docker exec app1 bash -c "
64+
cd /root/ws_mros &&
65+
chmod +x update_ip.sh && # 権限変更
66+
./update_ip.sh" # IPアドレス更新スクリプトの実行
67+
# app1: クリーンビルド
68+
- name: Clean and build in mros
69+
run: |
70+
docker exec app1 bash -c "
71+
cd /root/ws_mros &&
72+
pwd &&
73+
ls -la &&
74+
bash build.bash clean && # クリーンアップ
75+
bash build.bash all test_echoback_string"
76+
# app2: のコードをコンテナにコピーしてビルド
77+
- name: Clone Native test stub source code to app2 and build and run
78+
run: |
79+
docker exec app2 bash -c "
80+
source /opt/ros/humble/setup.bash &&
81+
cd &&
82+
pwd &&
83+
ls -la &&
84+
git clone https://github.com/mROS-base/mros2-host-examples &&
85+
cd mros2-host-examples &&
86+
colcon build --packages-select mros2_echoreply_string &&
87+
ls -la &&
88+
source install/setup.bash"
89+
- name: Run mROS and Native ROS
90+
shell: bash
91+
run : |
92+
# テスト対象をバックグラウンドで実行
93+
docker exec app2 bash -c "source /opt/ros/humble/setup.bash &&
94+
cd mros2-host-examples &&
95+
source install/setup.bash &&
96+
ros2 run mros2_echoreply_string echoreply_node" &
97+
98+
docker exec app1 bash -c "cd /root/ws_mros && ./cmake_build/mros2-posix" &
99+
mros_pid=$! # テストプログラムのプロセスIDを取得
100+
101+
docker ps
102+
103+
# mROSが終了するまで待つ
104+
wait $mros_pid
105+
mros_status=$?
106+
# 結果に基づいてCIの成否を判断
107+
if [ $mros_status -eq 0 ] ;then
108+
echo "Succeed pub/sub test process between mros2 and Native ROS"
109+
exit 0
110+
else
111+
echo "Fail pub/sub test process between mros2 and Native ROS"
112+
exit 1
113+
fi
114+
- name: Tear down containers
115+
run: docker-compose down

.github/workflows/humble_test.yaml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: ci_humble
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
- "feat/add_ci_config"
8+
pull_request:
9+
types: [opened, synchronize, labeled]
10+
jobs:
11+
ci:
12+
runs-on: ${{ matrix.os }}
13+
if: |
14+
((github.event.action == 'labeled') && (github.event.label.name == 'TESTING') && (github.base_ref == 'main' )) ||
15+
((github.event.action == 'synchronize') && (github.base_ref == 'main') && contains(github.event.pull_request.labels.*.name, 'TESTING')) ||
16+
(github.ref_name == 'main')
17+
container:
18+
image: osrf/ros:${{ matrix.ros_distribution }}-desktop
19+
timeout-minutes: 3
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
os: [ubuntu-22.04]
24+
ros_distribution: [humble]
25+
comm-target: [native , mros]
26+
comm-data-type: [string, twist]
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
submodules: recursive
31+
- name: update
32+
run: sudo apt-get update
33+
- name: setup and install tools
34+
run: >
35+
sudo apt-get install -y iproute2 git wget build-essential gcc g++ libssl-dev libreadline-dev
36+
zlib1g-dev make autoconf automake cmake pkg-config curl net-tools netcat python3-jinja2
37+
- name: Clone Test Stub
38+
uses: actions/checkout@v3
39+
with:
40+
repository: mROS-base/mros2-host-examples
41+
path: ws_host/src/mros2-host-examples
42+
- name: Update IP address
43+
run: |
44+
chmod +x update_ip.sh
45+
./update_ip.sh
46+
- name: Generate Twist Header files
47+
if: matrix.comm-data-type == 'twist'
48+
shell: bash
49+
run: |
50+
cd workspace
51+
python3 ../mros2/mros2_header_generator/header_generator.py geometry_msgs/msg/Twist.msg
52+
cd -
53+
- name: Build mROS
54+
shell: bash
55+
run: |
56+
bash build.bash clean
57+
bash build.bash all test_echoback_${{ matrix.comm-data-type }}
58+
mv cmake_build/ test_echoback_${{ matrix.comm-data-type }}/
59+
- name: Build Native ROS responder
60+
if: matrix.comm-target == 'native'
61+
shell: bash
62+
run: |
63+
cd ws_host/
64+
source /opt/ros/humble/setup.bash
65+
colcon build --packages-select mros2_echoreply_${{ matrix.comm-data-type }}
66+
- name: Build mROS responder
67+
if: matrix.comm-target == 'mros'
68+
shell: bash
69+
run: |
70+
bash build.bash clean
71+
bash build.bash all test_echoback_${{ matrix.comm-data-type }}_responder
72+
- name: Run Testing mROS and Native ROS
73+
if: matrix.comm-target == 'native'
74+
shell: bash
75+
run : |
76+
./test_echoback_${{ matrix.comm-data-type }}/mros2-posix &
77+
mros_pid=$! # mROSのプロセスIDを取得
78+
79+
# Native ROSをバックグラウンドで実行
80+
cd ws_host/
81+
source /opt/ros/humble/setup.bash
82+
source install/setup.bash
83+
ros2 run mros2_echoreply_${{ matrix.comm-data-type }} echoreply_node &
84+
85+
# mROSが終了するまで待つ
86+
wait $mros_pid
87+
mros_status=$?
88+
89+
# 結果に基づいてCIの成否を判断
90+
if [ $mros_status -eq 0 ] ;then
91+
echo "Succeed pub/sub test process between mros2 and Native ROS"
92+
exit 0
93+
else
94+
echo "Fail pub/sub test process between mros2 and Native ROS"
95+
exit 1
96+
fi
97+
- name: Run mROS and mROS
98+
if: matrix.comm-target == 'mros'
99+
shell: bash
100+
run : |
101+
./test_echoback_${{ matrix.comm-data-type }}/mros2-posix &
102+
mros_pid=$! # テストプログラムのプロセスIDを取得
103+
104+
# テスト対象をバックグラウンドで実行
105+
./cmake_build/mros2-posix &
106+
107+
# mROSが終了するまで待つ
108+
wait $mros_pid
109+
mros_status=$?
110+
111+
# 結果に基づいてCIの成否を判断
112+
if [ $mros_status -eq 0 ] ;then
113+
echo "Succeed pub/sub test process between mros2 and Native ROS"
114+
exit 0
115+
else
116+
echo "Fail pub/sub test process between mros2 and Native ROS"
117+
exit 1
118+
fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ sudo apt-get update && sudo apt-get install -y \
3737
libssl-dev libreadline-dev zlib1g-dev \
3838
make autoconf automake cmake \
3939
pkg-config curl \
40-
net-tools netcat
40+
net-tools netcat jinja2
4141
```
4242

4343
Please check the IP address and netmask of the execution environment.

docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: '3'
2+
services:
3+
app1:
4+
container_name: app1
5+
image: osrf/ros:humble-desktop # ROS Humble の Ubuntu ベースイメージを使用
6+
command: >
7+
bash -c "set -e &&
8+
apt-get update &&
9+
apt-get install -y iproute2 iputils-ping git wget build-essential gcc g++ libssl-dev libreadline-dev
10+
zlib1g-dev make autoconf automake cmake pkg-config curl net-tools netcat python3-jinja2 &&
11+
echo 'IP address:' &&
12+
ip addr show eth0 &&
13+
sleep 600"
14+
networks:
15+
test_net:
16+
ipv4_address: 172.19.0.2
17+
18+
app2:
19+
container_name: app2
20+
image: osrf/ros:humble-desktop # ROS Humble の Ubuntu ベースイメージを使用
21+
command: >
22+
bash -c "set -e &&
23+
apt-get update &&
24+
apt-get install -y iproute2 iputils-ping git wget build-essential gcc g++ libssl-dev libreadline-dev
25+
zlib1g-dev make autoconf automake cmake pkg-config curl net-tools netcat python3-jinja2 &&
26+
echo 'IP address:' &&
27+
ip addr show eth0 &&
28+
sleep 600"
29+
networks:
30+
test_net:
31+
ipv4_address: 172.19.0.3
32+
33+
networks:
34+
test_net:
35+
driver: bridge
36+
ipam:
37+
config:
38+
- subnet: 172.19.0.0/16

update_ip.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# IPアドレスを取得
4+
IP_ADDRESS=$(hostname -I | awk '{print $1}')
5+
if [ -z "$IP_ADDRESS" ]; then
6+
echo "Error: Failed to retrieve IP address."
7+
exit 1
8+
fi
9+
10+
# ネットマスクを取得(IPアドレスに対応するネットマスクを抽出)
11+
INTERFACE=$(ip -o addr show | grep "$IP_ADDRESS" | awk '{print $2}')
12+
NETMASK=$(ip -o -f inet addr show $INTERFACE | awk '/inet/ {print $4}' | cut -d'/' -f2)
13+
if [ -z "$NETMASK" ]; then
14+
echo "Error: Failed to retrieve netmask."
15+
exit 1
16+
fi
17+
18+
# CIDRからネットマスクを計算
19+
function cidr_to_netmask() {
20+
local cidr=$1
21+
local mask=""
22+
local octets=$(( cidr / 8 ))
23+
local bits=$(( cidr % 8 ))
24+
25+
for (( i=0; i<4; i++ )); do
26+
if [ $i -lt $octets ]; then
27+
mask+="255"
28+
elif [ $i -eq $octets ]; then
29+
mask+=$(( 256 - 2**(8-bits) ))
30+
else
31+
mask+="0"
32+
fi
33+
34+
if [ $i -lt 3 ]; then
35+
mask+="."
36+
fi
37+
done
38+
echo "$mask"
39+
}
40+
41+
NETMASK=$(cidr_to_netmask $NETMASK)
42+
echo "Retrieved Netmask for IP $IP_ADDRESS: $NETMASK"
43+
44+
# IPアドレスをドットで分割
45+
IFS='.' read -r -a IP_PARTS <<< "$IP_ADDRESS"
46+
47+
# ネットマスクをドットで分割
48+
IFS='.' read -r -a NETMASK_PARTS <<< "$NETMASK"
49+
echo "Netmask parts: ${NETMASK_PARTS[0]}, ${NETMASK_PARTS[1]}, ${NETMASK_PARTS[2]}, ${NETMASK_PARTS[3]}"
50+
51+
# include/rtps/config.h のIPアドレス置換
52+
53+
echo "Running sed on include/rtps/config.h"
54+
sed -i "s/[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\}[[:space:]]*}; \
55+
\/\/ Needs to be set in lwipcfg.h too./\
56+
${IP_PARTS[0]}, ${IP_PARTS[1]}, ${IP_PARTS[2]}, ${IP_PARTS[3]}};\
57+
\/\/ Needs to be set in lwipcfg.h too./" \
58+
include/rtps/config.h
59+
60+
61+
# include/netif.h のIPアドレスとネットマスク置換
62+
sed -i 's/#define NETIF_IPADDR ".*"/#define NETIF_IPADDR "'$IP_ADDRESS'"/' include/netif.h
63+
sed -i 's/#define NETIF_NETMASK ".*"/#define NETIF_NETMASK "'$NETMASK'"/' include/netif.h
64+
65+
66+
67+
# 結果を表示して確認
68+
echo "Updated IP Address: $IP_ADDRESS"
69+
echo "Updated include/rtps/config.h:"
70+
grep -E 'Needs to be set in lwipcfg.h too.' include/rtps/config.h
71+
echo "Updated include/netif.h:"
72+
grep -E 'NETIF_IPADDR' include/netif.h
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set(apl_SRCS
2+
${PROJECT_SOURCE_DIR}/workspace/${MROS2_APPNAME}/app.cpp
3+
)

0 commit comments

Comments
 (0)