ros2_tracing/tracetools_test/test/test_node.py

64 lines
2.3 KiB
Python
Raw Normal View History

2019-06-18 09:10:05 +02:00
# Copyright 2019 Robert Bosch GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2019-06-03 10:07:43 +02:00
import unittest
2019-06-05 15:35:46 +02:00
2019-06-18 15:42:44 +02:00
from tracetools_test.case import TraceTestCase
2019-06-03 10:07:43 +02:00
VERSION_REGEX = r'^[0-9]\.[0-9]\.[0-9]$'
2019-06-18 15:42:44 +02:00
class TestNode(TraceTestCase):
2019-06-05 15:35:46 +02:00
2019-06-18 15:42:44 +02:00
def __init__(self, *args) -> None:
super().__init__(
*args,
session_name_prefix='session-test-node-creation',
events_ros=[
'ros2:rcl_init',
'ros2:rcl_node_init',
],
nodes=['test_publisher']
)
2019-06-03 10:07:43 +02:00
def test_all(self):
2019-06-19 15:26:46 +02:00
# Check events order as set (e.g. init before node_init)
self.assertEventsOrderSet(self._events_ros)
# Check fields
rcl_init_events = self.get_events_with_name('ros2:rcl_init')
for event in rcl_init_events:
self.assertValidHandle(event, 'context_handle')
# TODO actually compare to version fetched from the tracetools package?
version_field = self.get_field(event, 'version')
self.assertRegex(version_field, VERSION_REGEX, 'invalid version number')
rcl_node_init_events = self.get_events_with_name('ros2:rcl_node_init')
for event in rcl_node_init_events:
2019-06-19 15:26:46 +02:00
self.assertValidHandle(event, ['node_handle', 'rmw_handle'])
self.assertStringFieldNotEmpty(event, 'node_name')
self.assertStringFieldNotEmpty(event, 'namespace')
2019-06-19 15:32:33 +02:00
# Check that the launched nodes have a corresponding rcl_node_init event
node_name_fields = [self.get_field(e, 'node_name') for e in rcl_node_init_events]
for node_name in self._nodes:
self.assertTrue(
node_name in node_name_fields,
f'cannot find node_init event for node name: {node_name} ({node_name_fields})')
2019-06-03 10:07:43 +02:00
if __name__ == '__main__':
unittest.main()