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 system test to github workflow for all distributions. #32

Merged
merged 2 commits into from
Dec 22, 2024
Merged
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ to install local colcon workspace,
# cd <colcon_workspace>/src
# git clone https://github.com/fujitatomoya/ros2_persist_parameter_server
# cd <colcon_workspace>
# colcon build --symlink-install
# colcon build --symlink-install --packages-select parameter_server ros2_persistent_parameter_server_test
# source install/local_setup.bash
```

Expand Down Expand Up @@ -237,8 +237,7 @@ make sure to add the path of `launch` package to the PATH environment.
```bash
# mkdir -p /tmp/test
# cp <colcon_workspace>/src/ros2_persist_parameter/server/param/parameter_server.yaml /tmp/test
# cd <colcon_workspace>/src/ros2_persist_parameter/test
# ./test.py
# ./<colcon_workspace>/src/ros2_persist_parameter/test/test.py
```

All of the test is listed with result as following
Expand Down
18 changes: 17 additions & 1 deletion scripts/build-verification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,25 @@ function build_parameter_server () {
echo "[${FUNCNAME[0]}]: build ROS 2 parameter server."
source /opt/ros/${ROS_DISTRO}/setup.bash
cd ${COLCON_WORKSPACE}
# TODO: test project should be integrated with `colcon test`.
colcon build --symlink-install --packages-select parameter_server ros2_persistent_parameter_server_test
}

function test_parameter_server () {
trap exit_trap ERR
echo "[${FUNCNAME[0]}]: test ROS 2 parameter server."
source /opt/ros/${ROS_DISTRO}/setup.bash
cd ${COLCON_WORKSPACE}

# TODO(@fujitatomoya): currently unit tests are missing for parameter server with `colcon test`.
Copy link
Owner Author

Choose a reason for hiding this comment

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

this is unit tests for parameter server interfaces and APIs, handled with #18


# source the parameter server local packages
source ./install/local_setup.bash
# setup and execute the system test
mkdir /tmp/test
cp ./src/ros2_persist_parameter_server/server/param/parameter_server.yaml /tmp/test
./src/ros2_persist_parameter_server/test/test.py
}

########
# Main #
########
Expand All @@ -70,5 +85,6 @@ trap exit_trap ERR
install_prerequisites
setup_build_colcon_env
build_parameter_server
test_parameter_server

exit 0
7 changes: 0 additions & 7 deletions test/launch/test.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@

from launch import LaunchDescription
from launch.substitutions import EnvironmentVariable
import launch_ros.actions
import launch
import os
import sys
import pathlib

def generate_launch_description():
return LaunchDescription([
launch.actions.ExecuteProcess(
cmd = ['ros2', 'run', 'parameter_server', 'server', '--file-path', '/tmp/test/parameter_server.yaml'],
respawn=True
),
launch.actions.ExecuteProcess(
cmd = ['ros2', 'run', 'ros2_persistent_parameter_server_test', 'client']
Comment on lines -31 to -32
Copy link
Owner Author

Choose a reason for hiding this comment

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

since i am not sure how to get the return code from this specific command via launch action, remove this test command from here. instead, having it in the python script to call the command via subprocess to check the return code to tell the test is failed or not to github workflow.

)
])
13 changes: 10 additions & 3 deletions test/src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,23 @@ class TestPersistParameter
}

// Get all test results.
inline void print_result() const
inline int print_result() const
{
int ret = EXIT_SUCCESS;
RCLCPP_INFO(this->get_logger(), "****************************************************"
"***********************");
RCLCPP_INFO(this->get_logger(), "*********************************Test Result*********"
"**********************");
for(const auto & res : result_map_) {
RCLCPP_INFO(this->get_logger(), "%-60s : %16s", res.first.c_str(), res.second?"PASS":"NOT PASS");

// if any tests are not passed, return EXIT_FAILURE.
if (res.second == false) {
ret = EXIT_FAILURE;
}
}

return;
return ret;
}

static inline rclcpp::Logger get_logger()
Expand Down Expand Up @@ -223,7 +229,8 @@ int main(int argc, char ** argv)
RCLCPP_ERROR(test_client->get_logger(), "unexpectedly failed: %s", e.what());
}

test_client->print_result();
// if any tests are not passed, return EXIT_FAILURE.
ret_code = test_client->print_result();
rclcpp::shutdown();

return ret_code;
Expand Down
47 changes: 38 additions & 9 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/usr/bin/python3

"""A script to start `Server && Client` throught launch file and responsible for killing the Server"""
"""A script to start `Server && Client` through launch file and responsible for killing the Server"""
from threading import Thread
import time
import os
import sys
import signal
import shutil

import os
import psutil
import shutil
import signal
import subprocess
import sys
import time

signal.signal(signal.SIGINT, signal.SIG_DFL)
sleep_time = 3
launchCmd = 'ros2 launch ros2_persistent_parameter_server_test test.launch.py'
launchServerCmd = ['ros2', 'launch', 'ros2_persistent_parameter_server_test', 'test.launch.py']
launchClientCmd = ['ros2', 'run', 'ros2_persistent_parameter_server_test', 'client']

if shutil.which('ros2') is None:
print("source <colcon_ws>/install/setup.bash...then retry.")
Expand All @@ -33,8 +36,34 @@ def kill_server():
print("parameter server cannot be killed")
return
time.sleep(5)
print("Press CTRL-C to shutdown...")
#print("Press CTRL-C to shutdown...")

# Start Server process with respawn enabled, this process stays running
server_process = subprocess.Popen(launchServerCmd, preexec_fn=os.setsid)
print(f"Parameter Server Process started with PID: {server_process.pid}")

# Start test client process
client_process = subprocess.Popen(launchClientCmd)
print(f"Parameter Client Process started with PID: {client_process.pid}")

# Start killer thread to respawn the parameter server
t = Thread(target = kill_server, args = ())
t.start()
os.system(launchCmd)

# Wait until the client process finishes
return_code = client_process.wait()

# Cleanup the process and thread
t.join()
os.killpg(os.getpgid(server_process.pid), signal.SIGTERM)

print("\nTest process finished.")
print(f"Return Code: {return_code}")

# Check if the client process completed successfully
if return_code == 0:
print("The process completed successfully.")
sys.exit(0)
else:
print("The process failed.")
sys.exit(1)
Loading