forked from ros2/ros2_tracing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_node.py
66 lines (53 loc) · 2.34 KB
/
test_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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.
import unittest
from tracetools_test.case import TraceTestCase
from tracetools_trace.tools import tracepoints as tp
VERSION_REGEX = r'^[0-9]+\.[0-9]+\.[0-9]+$'
class TestNode(TraceTestCase):
def __init__(self, *args) -> None:
super().__init__(
*args,
session_name_prefix='session-test-node-creation',
events_ros=[
tp.rcl_init,
tp.rcl_node_init,
],
package='test_tracetools',
nodes=['test_publisher'],
)
def test_all(self):
# Check events as set
self.assertEventsSet(self._events_ros)
# Check fields
rcl_init_events = self.get_events_with_name(tp.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(tp.rcl_node_init)
for event in rcl_node_init_events:
self.assertValidHandle(event, ['node_handle', 'rmw_handle'])
self.assertStringFieldNotEmpty(event, 'node_name')
self.assertStringFieldNotEmpty(event, 'namespace')
# 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})',
)
if __name__ == '__main__':
unittest.main()