Extract common test utils

This commit is contained in:
Christophe Bedard 2019-06-03 09:45:11 +02:00
parent cc8187e55b
commit 58625f27f6
4 changed files with 82 additions and 70 deletions

View file

@ -1,18 +1,8 @@
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,
from tracetools_test.utils import (
get_trace_event_names,
run_and_trace,
cleanup_trace,
)
PKG = 'tracetools_test'
@ -25,32 +15,18 @@ subscription_creation_events = [
class TestSubscription(unittest.TestCase):
def test_creation(self):
session_name = f'session-test-subscription-creation-{time.strftime("%Y%m%d%H%M%S")}'
path = '/tmp/' + session_name
print(f'trace directory: {path}')
session_name_prefix = 'session-test-subscription-creation'
base_path = '/tmp'
test_node = 'test_subscription'
lttng_setup(session_name, path, ros_events=subscription_creation_events, kernel_events=None)
lttng_start(session_name)
ld = LaunchDescription([
launch_ros.actions.Node(
package=PKG, node_executable='test_subscription', output='screen'),
])
ls = LaunchService()
ls.include_launch_description(get_default_launch_description())
ls.include_launch_description(ld)
exit_code = ls.run()
exit_code, full_path = run_and_trace(session_name_prefix, base_path, subscription_creation_events, None, PKG, test_node)
self.assertEqual(exit_code, 0)
lttng_stop(session_name)
lttng_destroy(session_name)
trace_events = get_trace_event_names(path)
trace_events = get_trace_event_names(full_path)
print(f'trace_events: {trace_events}')
self.assertListEqual(subscription_creation_events, list(trace_events))
self.assertSetEqual(set(subscription_creation_events), trace_events)
shutil.rmtree(path)
cleanup_trace(full_path)
if __name__ == '__main__':