Add tracetools_test package with simple test
This commit is contained in:
parent
372f0296c0
commit
6caaa51764
5 changed files with 166 additions and 0 deletions
2
tracetools_test/.gitignore
vendored
Normal file
2
tracetools_test/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*~
|
||||||
|
*.pyc
|
49
tracetools_test/CMakeLists.txt
Normal file
49
tracetools_test/CMakeLists.txt
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
project(tracetools_test)
|
||||||
|
|
||||||
|
# Default to C++14
|
||||||
|
if(NOT CMAKE_CXX_STANDARD)
|
||||||
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
add_compile_options(-Wall -Wextra -Wpedantic -fPIC)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(ament_cmake REQUIRED)
|
||||||
|
find_package(rclcpp REQUIRED)
|
||||||
|
find_package(std_msgs REQUIRED)
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
add_executable(test_publisher
|
||||||
|
test/test_publisher.cpp
|
||||||
|
)
|
||||||
|
ament_target_dependencies(test_publisher
|
||||||
|
rclcpp
|
||||||
|
std_msgs
|
||||||
|
)
|
||||||
|
install(TARGETS
|
||||||
|
test_publisher
|
||||||
|
DESTINATION lib/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
find_package(ament_cmake_pytest REQUIRED)
|
||||||
|
|
||||||
|
# Run each test in its own pytest invocation
|
||||||
|
set(_tracetools_test_pytest_tests
|
||||||
|
test/test_publisher.py
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(_test_path ${_tracetools_test_pytest_tests})
|
||||||
|
get_filename_component(_test_name ${_test_path} NAME_WE)
|
||||||
|
ament_add_pytest_test(${_test_name} ${_test_path}
|
||||||
|
PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}"
|
||||||
|
APPEND_ENV AMENT_PREFIX_PATH=${ament_index_build_path}
|
||||||
|
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
TIMEOUT 60
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
ament_package()
|
28
tracetools_test/package.xml
Normal file
28
tracetools_test/package.xml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||||
|
<package format="2">
|
||||||
|
<name>tracetools_test</name>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<description>Separate test package for tracetools</description>
|
||||||
|
<author email="bedard.christophe@gmail.com">Christophe Bedard</author>
|
||||||
|
<maintainer email="bedard.christophe@gmail.com">Christophe Bedard</maintainer>
|
||||||
|
<license>APLv2</license>
|
||||||
|
|
||||||
|
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||||
|
<buildtool_depend>pkg-config</buildtool_depend>
|
||||||
|
|
||||||
|
<build_depend>rclcpp</build_depend>
|
||||||
|
<build_depend>std_msgs</build_depend>
|
||||||
|
|
||||||
|
<exec_depend>rclcpp</exec_depend>
|
||||||
|
<exec_depend>std_msgs</exec_depend>
|
||||||
|
|
||||||
|
<test_depend>ament_cmake_pytest</test_depend>
|
||||||
|
<test_depend>launch_ros</test_depend>
|
||||||
|
<test_depend>python3-pytest</test_depend>
|
||||||
|
<test_depend>tracetools_trace</test_depend>
|
||||||
|
|
||||||
|
<export>
|
||||||
|
<build_type>ament_cmake</build_type>
|
||||||
|
</export>
|
||||||
|
</package>
|
32
tracetools_test/test/test_publisher.cpp
Normal file
32
tracetools_test/test/test_publisher.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include "rclcpp/rclcpp.hpp"
|
||||||
|
#include "std_msgs/msg/string.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
class PubNode : public rclcpp::Node
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PubNode() : Node("pub_node")
|
||||||
|
{
|
||||||
|
pub_ = this->create_publisher<std_msgs::msg::String>(
|
||||||
|
"the_topic",
|
||||||
|
rclcpp::QoS(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
rclcpp::init(argc, argv);
|
||||||
|
|
||||||
|
rclcpp::executors::SingleThreadedExecutor exec;
|
||||||
|
auto pub_node = std::make_shared<PubNode>();
|
||||||
|
exec.add_node(pub_node);
|
||||||
|
|
||||||
|
printf("spinning once\n");
|
||||||
|
exec.spin_once();
|
||||||
|
|
||||||
|
rclcpp::shutdown();
|
||||||
|
return 0;
|
||||||
|
}
|
55
tracetools_test/test/test_publisher.py
Normal file
55
tracetools_test/test/test_publisher.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import time
|
||||||
|
import shutil
|
||||||
|
from launch import LaunchDescription
|
||||||
|
from launch import LaunchIntrospector
|
||||||
|
from launch import LaunchService
|
||||||
|
|
||||||
|
from launch_ros import get_default_launch_description
|
||||||
|
import launch_ros.actions
|
||||||
|
import unittest
|
||||||
|
from tracetools_analysis.test.utils import get_trace_event_names
|
||||||
|
from tracetools_trace.tools.lttng import (
|
||||||
|
lttng_setup,
|
||||||
|
lttng_start,
|
||||||
|
lttng_stop,
|
||||||
|
lttng_destroy,
|
||||||
|
)
|
||||||
|
|
||||||
|
PKG = 'tracetools_test'
|
||||||
|
|
||||||
|
publisher_creation_events = [
|
||||||
|
'ros2:rcl_publisher_init',
|
||||||
|
]
|
||||||
|
|
||||||
|
class TestPublisher(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_creation(self):
|
||||||
|
session_name = f'session-test-publisher-creation-{time.strftime("%Y%m%d%H%M%S")}'
|
||||||
|
path = '/tmp/' + session_name
|
||||||
|
print(f'trace directory: {path}')
|
||||||
|
|
||||||
|
lttng_setup(session_name, path, ros_events=publisher_creation_events, kernel_events=None)
|
||||||
|
lttng_start(session_name)
|
||||||
|
|
||||||
|
ld = LaunchDescription([
|
||||||
|
launch_ros.actions.Node(
|
||||||
|
package=PKG, node_executable='test_publisher', output='screen'),
|
||||||
|
])
|
||||||
|
ls = LaunchService()
|
||||||
|
ls.include_launch_description(get_default_launch_description())
|
||||||
|
ls.include_launch_description(ld)
|
||||||
|
|
||||||
|
exit_code = ls.run()
|
||||||
|
self.assertEqual(exit_code, 0)
|
||||||
|
|
||||||
|
lttng_stop(session_name)
|
||||||
|
lttng_destroy(session_name)
|
||||||
|
|
||||||
|
trace_events = get_trace_event_names(path)
|
||||||
|
print(f'trace_events: {trace_events}')
|
||||||
|
self.assertListEqual(publisher_creation_events, list(trace_events))
|
||||||
|
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue