From 1a6c16687ed25768d3cc13a87a8cab518983542b Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:28:25 +0200 Subject: [PATCH 01/27] Extract tracetools_trace from tracetools_analysis --- package.xml | 17 +++ setup.cfg | 4 + setup.py | 20 ++++ tracetools_trace/__init__.py | 0 tracetools_trace/tools/__init__.py | 0 tracetools_trace/tools/lttng.py | 183 +++++++++++++++++++++++++++++ tracetools_trace/tools/names.py | 64 ++++++++++ tracetools_trace/trace.py | 30 +++++ 8 files changed, 318 insertions(+) create mode 100644 package.xml create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 tracetools_trace/__init__.py create mode 100644 tracetools_trace/tools/__init__.py create mode 100644 tracetools_trace/tools/lttng.py create mode 100644 tracetools_trace/tools/names.py create mode 100644 tracetools_trace/trace.py diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..ab80157 --- /dev/null +++ b/package.xml @@ -0,0 +1,17 @@ + + + + tracetools_trace + 0.1.0 + Tools for setting up tracing sessions + + Christophe Bedard + Christophe Bedard + GPLv3 + + + + + ament_python + + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..6bbabc6 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script-dir=$base/lib/tracetools_trace +[install] +install-scripts=$base/lib/tracetools_trace diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fae47ef --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup + +package_name = 'tracetools_trace' + +setup( + name=package_name, + version='0.1.0', + packages=[package_name], + data_files=[ + ('share/' + package_name, ['package.xml']), + ], + install_requires=['setuptools'], + keywords=['ROS'], + description='Tools for setting up tracing sessions', + entry_points={ + 'console_scripts': [ + f'trace = {package_name}.trace:main', + ], + }, +) diff --git a/tracetools_trace/__init__.py b/tracetools_trace/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tracetools_trace/tools/__init__.py b/tracetools_trace/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tracetools_trace/tools/lttng.py b/tracetools_trace/tools/lttng.py new file mode 100644 index 0000000..b790d5b --- /dev/null +++ b/tracetools_trace/tools/lttng.py @@ -0,0 +1,183 @@ +# LTTng tracing interface + +# Temporary workaround +import sys +sys.path = ['/usr/local/lib/python3.6/site-packages'] + sys.path + +from lttng import * +from .names import DEFAULT_EVENTS_ROS, DEFAULT_EVENTS_KERNEL, DEFAULT_CONTEXT + +def lttng_setup(session_name, directory, ros_events=DEFAULT_EVENTS_ROS, kernel_events=DEFAULT_EVENTS_KERNEL, context_names=DEFAULT_CONTEXT): + """ + Setup LTTng session, with events and context + :param session_name (str): the name of the session + :param directory (str): the path of the main directory to write trace data to + :param ros_events (list(str)): list of ROS events to enable + :param kernel_events (list(str)): list of kernel events to enable + :param context_names (list(str)): list of context elements to enable + """ + ust_enabled = ros_events is not None and len(ros_events) > 0 + kernel_enabled = kernel_events is not None and len(kernel_events) > 0 + print(f'UST tracing {f"enabled ({len(ros_events)} events)" if ust_enabled else "disabled"}') + print(f'kernel tracing {f"enabled ({len(kernel_events)} events)" if kernel_enabled else "disabled"}') + + # Domains + if ust_enabled: + domain_ust = Domain() + domain_ust.type = DOMAIN_UST + domain_ust.buf_type = BUFFER_PER_UID + channel_ust = Channel() + channel_ust.name = 'ros2' + channel_ust.attr.overwrite = 0 + channel_ust.attr.subbuf_size = 2*4096 + channel_ust.attr.num_subbuf = 8 + channel_ust.attr.switch_timer_interval = 0 + channel_ust.attr.read_timer_interval = 200 + channel_ust.attr.output = EVENT_MMAP + events_list_ust = _create_events(ros_events) + if kernel_enabled: + domain_kernel = Domain() + domain_kernel.type = DOMAIN_KERNEL + domain_kernel.buf_type = BUFFER_GLOBAL + channel_kernel = Channel() + channel_kernel.name = 'kchan' + channel_kernel.attr.overwrite = 0 + channel_kernel.attr.subbuf_size = 8*4096 + channel_kernel.attr.num_subbuf = 8 + channel_kernel.attr.switch_timer_interval = 0 + channel_kernel.attr.read_timer_interval = 200 + channel_kernel.attr.output = EVENT_MMAP + events_list_kernel = _create_events(kernel_events) + + # Session + _create_session(session_name, directory) + + # Handles, channels, events + handle_ust = None + if ust_enabled: + handle_ust = _create_handle(session_name, domain_ust) + _enable_channel(handle_ust, channel_ust) + _enable_events(handle_ust, events_list_ust, channel_ust.name) + handle_kernel = None + if kernel_enabled: + handle_kernel = _create_handle(session_name, domain_kernel) + _enable_channel(handle_kernel, channel_kernel) + _enable_events(handle_kernel, events_list_kernel, channel_kernel.name) + + # Context + context_list = _create_context_list(context_names) + enabled_handles = [h for h in [handle_ust, handle_kernel] if h is not None] + _add_context(enabled_handles, context_list) + +def lttng_start(session_name): + """ + Start LTTng session, and check for errors + """ + result = start(session_name) + if result < 0: + raise RuntimeError(f'failed to start tracing: {strerror(result)}') + +def lttng_stop(session_name): + """ + Stop LTTng session, and check for errors + """ + result = stop(session_name) + if result < 0: + raise RuntimeError(f'failed to stop tracing: {strerror(result)}') + +def lttng_destroy(session_name): + """ + Destroy LTTng session, and check for errors + """ + result = destroy(session_name) + if result < 0: + raise RuntimeError(f'failed to destroy tracing session: {strerror(result)}') + +def _create_events(event_names_list): + """ + Create events list from names + """ + events_list = [] + for event_name in event_names_list: + e = Event() + e.name = event_name + e.type = EVENT_TRACEPOINT + e.loglevel_type = EVENT_LOGLEVEL_ALL + events_list.append(e) + return events_list + +def _create_session(session_name, directory): + """ + Create session from name and directory path, and check for errors + """ + result = create(session_name, directory) + LTTNG_ERR_EXIST_SESS = 28 + if result == -LTTNG_ERR_EXIST_SESS: + # Sessions seem to persist, so if it already exists, + # just destroy it and try again + lttng_destroy(session_name) + result = create(session_name, directory) + if result < 0: + raise RuntimeError(f'session creation failed: {strerror(result)}') + +def _create_handle(session_name, domain): + """ + Create a handle for a given session name and a domain, and check for errors + """ + handle = None + handle = Handle(session_name, domain) + if handle is None: + raise RuntimeError('handle creation failed') + return handle + +def _enable_channel(handle, channel): + """ + Enable channel for a handle, and check for errors + """ + result = enable_channel(handle, channel) + if result < 0: + raise RuntimeError(f'channel enabling failed: {strerror(result)}') + +def _enable_events(handle, events_list, channel_name): + """ + Enable events list for a given handle and channel name, and check for errors + """ + for event in events_list: + result = enable_event(handle, event, channel_name) + if result < 0: + raise RuntimeError(f'event enabling failed: {strerror(result)}') + +context_map = { + 'procname': EVENT_CONTEXT_PROCNAME, + 'pid': EVENT_CONTEXT_PID, + 'vpid': EVENT_CONTEXT_VPID, + 'vtid': EVENT_CONTEXT_VTID, +} +def _context_name_to_type(context_name): + """ + Convert from context name to LTTng enum/constant type + """ + return context_map.get(context_name) + +def _create_context_list(context_names_list): + """ + Create context list from names, and check for errors + """ + context_list = [] + for c in context_names_list: + ec = EventContext() + context_type = _context_name_to_type(c) + if context_type is not None: + ec.ctx = context_type + context_list.append(ec) + return context_list + +def _add_context(handles, context_list): + """ + Add context list to given handles, and check for errors + """ + for handle in handles: + for contex in context_list: + result = add_context(handle, contex, None, None) + if result < 0: + raise RuntimeError(f'failed to add context: {strerror(result)}') diff --git a/tracetools_trace/tools/names.py b/tracetools_trace/tools/names.py new file mode 100644 index 0000000..aec29f6 --- /dev/null +++ b/tracetools_trace/tools/names.py @@ -0,0 +1,64 @@ +# Lists of names (events, context) + +DEFAULT_EVENTS_KERNEL=[ + 'block_rq_complete', + 'block_rq_insert', + 'block_rq_issue', + 'block_bio_frontmerge', + 'irq_softirq_entry', + 'irq_softirq_raise' + 'irq_softirq_exit', + 'irq_handler_entry', + 'irq_handler_exit', + 'lttng_statedump_process_state', + 'lttng_statedump_start', + 'lttng_statedump_end', + 'lttng_statedump_network_interface', + 'lttng_statedump_block_device', + 'net_dev_queue', + 'netif_receive_skb', + 'net_if_receive_skb', + 'power_cpu_frequency', + 'sched_switch', + 'sched_waking', + 'sched_pi_setprio', + 'sched_process_fork', + 'sched_process_exit', + 'sched_process_free', + 'sched_wakeup', + 'sched_migrate', + 'sched_migrate_task', + 'timer_hrtimer_start', + 'timer_hrtimer_cancel', + 'timer_hrtimer_expire_entry', + 'timer_hrtimer_expire_exit', +] + +DEFAULT_EVENTS_ROS=[ + 'ros2:rcl_init', + 'ros2:rcl_node_init', + 'ros2:rcl_publisher_init', + 'ros2:rcl_subscription_init', + 'ros2:rclcpp_subscription_callback_added', + 'ros2:rclcpp_subscription_callback_start', + 'ros2:rclcpp_subscription_callback_end', + 'ros2:rcl_service_init', + 'ros2:rclcpp_service_callback_added', + 'ros2:rclcpp_service_callback_start', + 'ros2:rclcpp_service_callback_end', + 'ros2:rcl_client_init', + 'ros2:rcl_timer_init', + 'ros2:rclcpp_timer_callback_added', + 'ros2:rclcpp_timer_callback_start', + 'ros2:rclcpp_timer_callback_end', + 'ros2:rclcpp_callback_register', +] + +DEFAULT_CONTEXT=[ + 'procname', + 'perf:thread:instructions', + 'perf:thread:cycles', + 'perf:thread:cpu-cycles', + 'vpid', + 'vtid', +] diff --git a/tracetools_trace/trace.py b/tracetools_trace/trace.py new file mode 100644 index 0000000..3521823 --- /dev/null +++ b/tracetools_trace/trace.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# Entrypoint/script to setup and start an LTTng tracing session +# TODO + +import sys +import time +from tracetools_trace.tools.lttng import ( + lttng_setup, + lttng_start, + lttng_stop, + lttng_destroy, +) + +def main(argv=sys.argv): + if len(argv) != 3: + print("usage: session-name /path") + exit(1) + + session_name = argv[1] + path = argv[2] + '/' + session_name + lttng_setup(session_name, path) + lttng_start(session_name) + print(f'tracing session started: {path}') + + # TODO integrate this with launch + ROS shutdown + input('press enter to stop...') + + print('stopping & destroying tracing session') + lttng_stop(session_name) + lttng_destroy(session_name) From 63fd1de4ba4409cb812c0876392d4ad6ac71afff Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:29:08 +0200 Subject: [PATCH 02/27] Add gitignore for tracetools_trace --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eef29c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.pyc + From d55a7f4f3c240243ac9bebb727f3974364d0fd9e Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:29:23 +0200 Subject: [PATCH 03/27] Use proper arg parser --- tracetools_trace/trace.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tracetools_trace/trace.py b/tracetools_trace/trace.py index 3521823..794e8fe 100644 --- a/tracetools_trace/trace.py +++ b/tracetools_trace/trace.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 # Entrypoint/script to setup and start an LTTng tracing session -# TODO import sys import time +import argparse from tracetools_trace.tools.lttng import ( lttng_setup, lttng_start, @@ -11,13 +11,20 @@ from tracetools_trace.tools.lttng import ( lttng_destroy, ) -def main(argv=sys.argv): - if len(argv) != 3: - print("usage: session-name /path") - exit(1) +def main(): + parser = argparse.ArgumentParser(description='Setup and launch an LTTng tracing session.') + parser.add_argument('--session-name', '-s', dest='session_name', + default=f'session-{time.strftime("%Y%m%d%H%M%S")}', + help='the name of the tracing session (default: session-YYYYMMDDHHMMSS)') + parser.add_argument('--path', '-p', dest='path', + default='/tmp', + help='path of the base directory for trace data (default: %(default)s)') + args = parser.parse_args() + + session_name = args.session_name + base_path = args.path + path = base_path + '/' + session_name - session_name = argv[1] - path = argv[2] + '/' + session_name lttng_setup(session_name, path) lttng_start(session_name) print(f'tracing session started: {path}') From f45c3e543d0c2432f43bc6561ebb22674ef4c699 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:29:38 +0200 Subject: [PATCH 04/27] Add user input before lttng_start --- tracetools_trace/trace.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tracetools_trace/trace.py b/tracetools_trace/trace.py index 794e8fe..57f8204 100644 --- a/tracetools_trace/trace.py +++ b/tracetools_trace/trace.py @@ -26,8 +26,10 @@ def main(): path = base_path + '/' + session_name lttng_setup(session_name, path) + print(f'writting tracing session to: {path}') + + input('press enter to start...') lttng_start(session_name) - print(f'tracing session started: {path}') # TODO integrate this with launch + ROS shutdown input('press enter to stop...') From 77f63f8c95863ec8f0ca4ea18ce664ed547a5bba Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:30:04 +0200 Subject: [PATCH 05/27] Expose events through trace entrypoint --- tracetools_trace/trace.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tracetools_trace/trace.py b/tracetools_trace/trace.py index 57f8204..079a0b6 100644 --- a/tracetools_trace/trace.py +++ b/tracetools_trace/trace.py @@ -10,6 +10,10 @@ from tracetools_trace.tools.lttng import ( lttng_stop, lttng_destroy, ) +from tracetools_trace.tools.names import ( + DEFAULT_EVENTS_ROS, + DEFAULT_EVENTS_KERNEL, +) def main(): parser = argparse.ArgumentParser(description='Setup and launch an LTTng tracing session.') @@ -19,13 +23,19 @@ def main(): parser.add_argument('--path', '-p', dest='path', default='/tmp', help='path of the base directory for trace data (default: %(default)s)') + parser.add_argument('--ust', '-u', nargs='*', dest='events_ust', default=DEFAULT_EVENTS_ROS, + help='the ROS UST events to enable (default: all events) [to disable all UST events, provide this flag without any event name]') + parser.add_argument('--kernel', '-k', nargs='*', dest='events_kernel', default=DEFAULT_EVENTS_KERNEL, + help='the kernel events to enable (default: all events) [to disable all UST events, provide this flag without any event name]') args = parser.parse_args() session_name = args.session_name base_path = args.path path = base_path + '/' + session_name + ros_events = args.events_ust + kernel_events = args.events_kernel - lttng_setup(session_name, path) + lttng_setup(session_name, path, ros_events=ros_events, kernel_events=kernel_events) print(f'writting tracing session to: {path}') input('press enter to start...') From 65f50e3981a8d9af9af77043f244ebb8d680f76d Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:30:36 +0200 Subject: [PATCH 06/27] Remove TODO about integrating with launch --- tracetools_trace/trace.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tracetools_trace/trace.py b/tracetools_trace/trace.py index 079a0b6..7af99fc 100644 --- a/tracetools_trace/trace.py +++ b/tracetools_trace/trace.py @@ -40,8 +40,6 @@ def main(): input('press enter to start...') lttng_start(session_name) - - # TODO integrate this with launch + ROS shutdown input('press enter to stop...') print('stopping & destroying tracing session') From 99b6b0d5772fad05614e1fa1dd6b8859b65aa255 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:30:48 +0200 Subject: [PATCH 07/27] Move print statements to entrypoints and add events list display option --- tracetools_trace/tools/lttng.py | 2 -- tracetools_trace/trace.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tracetools_trace/tools/lttng.py b/tracetools_trace/tools/lttng.py index b790d5b..afac097 100644 --- a/tracetools_trace/tools/lttng.py +++ b/tracetools_trace/tools/lttng.py @@ -18,8 +18,6 @@ def lttng_setup(session_name, directory, ros_events=DEFAULT_EVENTS_ROS, kernel_e """ ust_enabled = ros_events is not None and len(ros_events) > 0 kernel_enabled = kernel_events is not None and len(kernel_events) > 0 - print(f'UST tracing {f"enabled ({len(ros_events)} events)" if ust_enabled else "disabled"}') - print(f'kernel tracing {f"enabled ({len(kernel_events)} events)" if kernel_enabled else "disabled"}') # Domains if ust_enabled: diff --git a/tracetools_trace/trace.py b/tracetools_trace/trace.py index 7af99fc..484b09c 100644 --- a/tracetools_trace/trace.py +++ b/tracetools_trace/trace.py @@ -27,6 +27,8 @@ def main(): help='the ROS UST events to enable (default: all events) [to disable all UST events, provide this flag without any event name]') parser.add_argument('--kernel', '-k', nargs='*', dest='events_kernel', default=DEFAULT_EVENTS_KERNEL, help='the kernel events to enable (default: all events) [to disable all UST events, provide this flag without any event name]') + parser.add_argument('--list', '-l', dest='list', action='store_true', + help='display lists of enabled events (default: %(default)s)') args = parser.parse_args() session_name = args.session_name @@ -35,6 +37,15 @@ def main(): ros_events = args.events_ust kernel_events = args.events_kernel + ust_enabled = len(ros_events) > 0 + kernel_enabled = len(kernel_events) > 0 + print(f'UST tracing {f"enabled ({len(ros_events)} events)" if ust_enabled else "disabled"}') + if args.list and ust_enabled: + print(f'\tevents: {ros_events}') + print(f'kernel tracing {f"enabled ({len(kernel_events)} events)" if kernel_enabled else "disabled"}') + if args.list and kernel_enabled: + print(f'\tevents: {kernel_events}') + lttng_setup(session_name, path, ros_events=ros_events, kernel_events=kernel_events) print(f'writting tracing session to: {path}') From d48ad1221441fcb239f536de7d4df4e33c631975 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:32:40 +0200 Subject: [PATCH 08/27] Add link to rosdep index --- package.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.xml b/package.xml index ab80157..3475a2f 100644 --- a/package.xml +++ b/package.xml @@ -9,7 +9,9 @@ Christophe Bedard GPLv3 - + ament_python From 0a76c66f9c06d891825ddf3ea4fab71ced9ab123 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:36:16 +0200 Subject: [PATCH 09/27] Rename params and variables --- tracetools_trace/tools/lttng.py | 14 +++++++------- tracetools_trace/trace.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tracetools_trace/tools/lttng.py b/tracetools_trace/tools/lttng.py index afac097..ae01cb8 100644 --- a/tracetools_trace/tools/lttng.py +++ b/tracetools_trace/tools/lttng.py @@ -7,11 +7,11 @@ sys.path = ['/usr/local/lib/python3.6/site-packages'] + sys.path from lttng import * from .names import DEFAULT_EVENTS_ROS, DEFAULT_EVENTS_KERNEL, DEFAULT_CONTEXT -def lttng_setup(session_name, directory, ros_events=DEFAULT_EVENTS_ROS, kernel_events=DEFAULT_EVENTS_KERNEL, context_names=DEFAULT_CONTEXT): +def lttng_setup(session_name, full_path, ros_events=DEFAULT_EVENTS_ROS, kernel_events=DEFAULT_EVENTS_KERNEL, context_names=DEFAULT_CONTEXT): """ Setup LTTng session, with events and context :param session_name (str): the name of the session - :param directory (str): the path of the main directory to write trace data to + :param full_path (str): the full path to the main directory to write trace data to :param ros_events (list(str)): list of ROS events to enable :param kernel_events (list(str)): list of kernel events to enable :param context_names (list(str)): list of context elements to enable @@ -48,7 +48,7 @@ def lttng_setup(session_name, directory, ros_events=DEFAULT_EVENTS_ROS, kernel_e events_list_kernel = _create_events(kernel_events) # Session - _create_session(session_name, directory) + _create_session(session_name, full_path) # Handles, channels, events handle_ust = None @@ -104,17 +104,17 @@ def _create_events(event_names_list): events_list.append(e) return events_list -def _create_session(session_name, directory): +def _create_session(session_name, full_path): """ - Create session from name and directory path, and check for errors + Create session from name and full directory path, and check for errors """ - result = create(session_name, directory) + result = create(session_name, full_path) LTTNG_ERR_EXIST_SESS = 28 if result == -LTTNG_ERR_EXIST_SESS: # Sessions seem to persist, so if it already exists, # just destroy it and try again lttng_destroy(session_name) - result = create(session_name, directory) + result = create(session_name, full_path) if result < 0: raise RuntimeError(f'session creation failed: {strerror(result)}') diff --git a/tracetools_trace/trace.py b/tracetools_trace/trace.py index 484b09c..967fb76 100644 --- a/tracetools_trace/trace.py +++ b/tracetools_trace/trace.py @@ -33,7 +33,7 @@ def main(): session_name = args.session_name base_path = args.path - path = base_path + '/' + session_name + full_path = base_path + '/' + session_name ros_events = args.events_ust kernel_events = args.events_kernel @@ -46,8 +46,8 @@ def main(): if args.list and kernel_enabled: print(f'\tevents: {kernel_events}') - lttng_setup(session_name, path, ros_events=ros_events, kernel_events=kernel_events) - print(f'writting tracing session to: {path}') + lttng_setup(session_name, full_path, ros_events=ros_events, kernel_events=kernel_events) + print(f'writting tracing session to: {full_path}') input('press enter to start...') lttng_start(session_name) From ed259dc312ba0c9e67082d7d650dfd7d471e0437 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:36:53 +0200 Subject: [PATCH 10/27] Setup tests for *analysis and *trace packages --- package.xml | 5 +++++ setup.py | 4 +++- test/test_copyright.py | 23 +++++++++++++++++++++++ test/test_flake8.py | 23 +++++++++++++++++++++++ test/test_pep257.py | 23 +++++++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/test_copyright.py create mode 100644 test/test_flake8.py create mode 100644 test/test_pep257.py diff --git a/package.xml b/package.xml index 3475a2f..301a46a 100644 --- a/package.xml +++ b/package.xml @@ -13,6 +13,11 @@ https://github.com/ros/rosdistro/blob/master/rosdep/python.yaml --> + ament_copyright + ament_flake8 + ament_pep257 + python3-pytest + ament_python diff --git a/setup.py b/setup.py index fae47ef..3e349ea 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +from setuptools import find_packages from setuptools import setup package_name = 'tracetools_trace' @@ -5,7 +6,7 @@ package_name = 'tracetools_trace' setup( name=package_name, version='0.1.0', - packages=[package_name], + packages=find_packages(exclude=['test']), data_files=[ ('share/' + package_name, ['package.xml']), ], @@ -17,4 +18,5 @@ setup( f'trace = {package_name}.trace:main', ], }, + tests_require=['pytest'], ) diff --git a/test/test_copyright.py b/test/test_copyright.py new file mode 100644 index 0000000..cf0fae3 --- /dev/null +++ b/test/test_copyright.py @@ -0,0 +1,23 @@ +# Copyright 2017 Open Source Robotics Foundation, Inc. +# +# 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. + +from ament_copyright.main import main +import pytest + + +@pytest.mark.copyright +@pytest.mark.linter +def test_copyright(): + rc = main(argv=['.', 'test']) + assert rc == 0, 'Found errors' diff --git a/test/test_flake8.py b/test/test_flake8.py new file mode 100644 index 0000000..eff8299 --- /dev/null +++ b/test/test_flake8.py @@ -0,0 +1,23 @@ +# Copyright 2017 Open Source Robotics Foundation, Inc. +# +# 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. + +from ament_flake8.main import main +import pytest + + +@pytest.mark.flake8 +@pytest.mark.linter +def test_flake8(): + rc = main(argv=[]) + assert rc == 0, 'Found errors' diff --git a/test/test_pep257.py b/test/test_pep257.py new file mode 100644 index 0000000..3aeb4d3 --- /dev/null +++ b/test/test_pep257.py @@ -0,0 +1,23 @@ +# Copyright 2015 Open Source Robotics Foundation, Inc. +# +# 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. + +from ament_pep257.main import main +import pytest + + +@pytest.mark.linter +@pytest.mark.pep257 +def test_pep257(): + rc = main(argv=[]) + assert rc == 0, 'Found code style errors / warnings' From 128d54586599e4f7106cc3710c4a42850d4aebb0 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 6 Jun 2019 09:37:20 +0200 Subject: [PATCH 11/27] Fix authors/maintainer --- package.xml | 5 ++--- setup.py | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.xml b/package.xml index 301a46a..40a655d 100644 --- a/package.xml +++ b/package.xml @@ -4,9 +4,8 @@ tracetools_trace 0.1.0 Tools for setting up tracing sessions - - Christophe Bedard - Christophe Bedard + Christophe Bedard + Christophe Bedard GPLv3