Skip to content

Commit 9d21b95

Browse files
committed
add ci and test for native ros and mROS 2
1 parent d267988 commit 9d21b95

File tree

5 files changed

+209
-0
lines changed

5 files changed

+209
-0
lines changed

.github/workflows/ci_humble.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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: 5
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
os: [ubuntu-22.04]
24+
ros_distribution: [humble]
25+
steps:
26+
- uses: actions/checkout@v3
27+
with:
28+
submodules: recursive
29+
- name: update
30+
run: sudo apt-get update
31+
- name: setup and install tools
32+
run: >
33+
sudo apt-get install -y git wget build-essential gcc g++ libssl-dev libreadline-dev
34+
zlib1g-dev make autoconf automake cmake pkg-config curl net-tools netcat python3-jinja2
35+
- name: Clone Test Stub
36+
uses: actions/checkout@v3
37+
with:
38+
repository: mROS-base/mros2-host-examples
39+
path: ws_host/src/mros2-host-examples
40+
- name: Run IP update script
41+
run: |
42+
chmod +x update_ip.sh
43+
./update_ip.sh
44+
- name: Build
45+
run: |
46+
pwd
47+
ls -la
48+
bash build.bash clean
49+
bash build.bash all echoreply_string
50+
mv cmake_build cmake_build_echo_reply_strting
51+
- name: Build TestPrograms
52+
run: |
53+
pwd
54+
ls -la
55+
bash build.bash clean
56+
bash build.bash all test_echoreply_string
57+
- name: Buidl and Run test stub for Test with Comunicate Native ROS
58+
shell: bash
59+
run: |
60+
cd ws_host/
61+
source /opt/ros/humble/setup.bash
62+
colcon build --packages-select mros2_echoreply_string
63+
source install/setup.bash
64+
ls -la
65+
pwd
66+
ros2 run mros2_echoreply_string echoreply_node &
67+
- name: Run Test programs for Comunicate Native ROS
68+
run : |
69+
./cmake_build/mros2-posix
70+
# - name: Run Test for Comunicate mROS to mROS

update_ip.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# IPアドレスを取得
4+
IP_ADDRESS=$(hostname -I | awk '{print $1}')
5+
6+
# IPアドレスをドットで分割
7+
IFS='.' read -r -a IP_PARTS <<< "$IP_ADDRESS"
8+
9+
# include/rtps/config.h のIPアドレス置換
10+
11+
echo "Running sed on include/rtps/config.h"
12+
sed -i "s/[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\},[[:space:]]*[0-9]\{1,3\}[[:space:]]*}; \
13+
\/\/ Needs to be set in lwipcfg.h too./\
14+
${IP_PARTS[0]}, ${IP_PARTS[1]}, ${IP_PARTS[2]}, ${IP_PARTS[3]}};\
15+
\/\/ Needs to be set in lwipcfg.h too./" \
16+
include/rtps/config.h
17+
# 変更結果を確認
18+
19+
# include/netif.h のIPアドレス置換
20+
sed -i 's/#define NETIF_IPADDR ".*"/#define NETIF_IPADDR "'$IP_ADDRESS'"/' include/netif.h
21+
22+
# 結果を表示して確認
23+
echo "Updated IP Address: $IP_ADDRESS"
24+
echo "Updated include/rtps/config.h:"
25+
grep -E 'Needs to be set in lwipcfg.h too.' include/rtps/config.h
26+
echo "Updated include/netif.h:"
27+
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+
)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
/**
3+
* このプログラムとechoreply_stringを使う
4+
* 10回くらい送信して返ってくるかチェックする
5+
*/
6+
7+
#include "mros2.h"
8+
#include "std_msgs/msg/string.hpp"
9+
10+
#include "cmsis_os.h"
11+
#include "netif.h"
12+
#include "netif_posix_add.h"
13+
14+
#include <stdio.h>
15+
#include <string.h>
16+
#include <pthread.h>
17+
18+
bool result = true;
19+
auto TestMessagePreFix = "TestMessage";
20+
std::string expect = "";
21+
int sub_counter = 0;
22+
pthread_mutex_t mutex_expect_sting;
23+
24+
void userCallback(std_msgs::msg::String *msg)
25+
{
26+
pthread_mutex_lock(&mutex_expect_sting);
27+
sub_counter++;
28+
printf("*test count : %d\r\n", sub_counter);
29+
auto actual = msg->data;
30+
// FIXME 受信データに改行や不要な文字が含まれている模様
31+
actual.erase(std::remove(actual.begin(), actual.end(), '\n'), actual.end());
32+
actual.erase(std::remove(actual.begin(), actual.end(), '\r'), actual.end());
33+
34+
printf("expect : '%s',\r\nactural: '%s'\r\n", expect.c_str(), actual.c_str());
35+
printf("expect length: %lu, actual length: %lu\r\n", expect.size(), actual.size());
36+
if (strcmp(expect.c_str(), actual.c_str()) == 0)
37+
{
38+
printf("****SUCCEED****'\r\n");
39+
result = result & true;
40+
}
41+
else
42+
{
43+
printf("FAIL different data responsed.\r\n");
44+
result = result & false;
45+
}
46+
pthread_mutex_unlock(&mutex_expect_sting);
47+
printf("\r\n");
48+
49+
if (sub_counter > 10)
50+
{
51+
if (result)
52+
{
53+
printf("All tests succeed.\r\n");
54+
std::exit(0);
55+
}
56+
printf("Some tests faild.\r\n");
57+
std::exit(-1);
58+
}
59+
}
60+
61+
int main(int argc, char *argv[])
62+
{
63+
netif_posix_add(NETIF_IPADDR, NETIF_NETMASK);
64+
65+
osKernelStart();
66+
67+
printf("mros2-posix start!\r\n");
68+
printf("app name: echoback_string\r\n");
69+
mros2::init(0, NULL);
70+
MROS2_DEBUG("mROS 2 initialization is completed\r\n");
71+
72+
mros2::Node node = mros2::Node::create_node("mros2_test_node");
73+
mros2::Publisher pub = node.create_publisher<std_msgs::msg::String>("to_linux", 10);
74+
auto msg = std_msgs::msg::String();
75+
msg.data = "initial";
76+
pub.publish(msg);
77+
osDelay(1000);
78+
mros2::Subscriber sub = node.create_subscription<std_msgs::msg::String>("to_stm", 10, userCallback);
79+
80+
MROS2_INFO("ready to pub/sub message\r\n");
81+
auto count = 0;
82+
sub_counter = 0;
83+
while (true)
84+
{
85+
auto msg = std_msgs::msg::String();
86+
pthread_mutex_lock(&mutex_expect_sting);
87+
expect = TestMessagePreFix + std::to_string(count++);
88+
msg.data = expect;
89+
printf("publishing msg: '%s'\r\n", msg.data.c_str());
90+
pub.publish(msg);
91+
pthread_mutex_unlock(&mutex_expect_sting);
92+
93+
osDelay(1000);
94+
}
95+
96+
mros2::spin();
97+
return 0;
98+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
#include "std_msgs/msg/string.hpp"
3+
4+
5+
template mros2::Publisher mros2::Node::create_publisher<std_msgs::msg::String>(std::string topic_name, int qos);
6+
template void mros2::Publisher::publish(std_msgs::msg::String &msg);
7+
8+
9+
10+
template mros2::Subscriber mros2::Node::create_subscription(std::string topic_name, int qos, void (*fp)(std_msgs::msg::String*));
11+
template void mros2::Subscriber::callback_handler<std_msgs::msg::String>(void *callee, const rtps::ReaderCacheChange &cacheChange);

0 commit comments

Comments
 (0)