ros2_tracing/tracetools_test/test/test_service_callback.py

71 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 13:05:05 +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 13:05:05 +02:00
2019-06-18 15:42:44 +02:00
class TestServiceCallback(TraceTestCase):
2019-06-24 14:22:59 +02:00
2019-06-18 15:42:44 +02:00
def __init__(self, *args) -> None:
super().__init__(
*args,
session_name_prefix='session-test-service-callback',
events_ros=[
'ros2:callback_start',
'ros2:callback_end',
],
2019-11-16 15:25:52 -08:00
nodes=['test_service_ping', 'test_service_pong'],
2019-06-18 15:42:44 +02:00
)
2019-06-03 13:05:05 +02:00
2019-06-19 15:26:46 +02:00
def test_all(self):
2019-11-14 16:15:55 -08:00
# Check events as set
self.assertEventsSet(self._events_ros)
2019-06-19 15:26:46 +02:00
# Check fields
start_events = self.get_events_with_name('ros2:callback_start')
2019-11-16 15:17:15 -08:00
end_events = self.get_events_with_name('ros2:callback_end')
2019-06-19 15:26:46 +02:00
for event in start_events:
self.assertValidHandle(event, 'callback')
# Should not be 1 for services (yet)
self.assertFieldEquals(
event,
'is_intra_process',
2019-06-19 15:26:46 +02:00
0,
2019-11-16 15:17:15 -08:00
'invalid value for is_intra_process',
)
2019-06-19 15:26:46 +02:00
for event in end_events:
self.assertValidHandle(event, 'callback')
2019-11-16 15:17:15 -08:00
# Check that there is at least 1 start/end pair for each node
2019-06-19 15:26:46 +02:00
for node in self._nodes:
test_start_events = self.get_events_with_procname(node, start_events)
test_end_events = self.get_events_with_procname(node, end_events)
2019-06-19 15:32:33 +02:00
self.assertGreater(
len(test_start_events),
0,
2019-11-16 15:17:15 -08:00
f'no start_callback events for node: {node}',
)
2019-06-19 15:32:33 +02:00
self.assertGreater(
len(test_end_events),
0,
2019-11-16 15:17:15 -08:00
f'no end_callback events for node: {node}',
)
2019-06-03 13:05:05 +02:00
if __name__ == '__main__':
unittest.main()