From 2f0c39abc7f5b5aa05036bb01e76bd6a06485c15 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Mon, 7 Oct 2024 14:20:09 -0700 Subject: [PATCH] Provide error strings if kernel tracing test skipped Signed-off-by: Christophe Bedard --- .../test/test_ros2trace/test_trace.py | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/test_ros2trace/test/test_ros2trace/test_trace.py b/test_ros2trace/test/test_ros2trace/test_trace.py index eaf31d1..bf48b68 100644 --- a/test_ros2trace/test/test_ros2trace/test_trace.py +++ b/test_ros2trace/test/test_ros2trace/test_trace.py @@ -52,6 +52,24 @@ def are_tracepoints_included() -> bool: return 0 == process.returncode +def skip_if_no_kernel_tracing(func): + """Skip test if kernel tracing for kernel tracepoints or syscalls is not available.""" + def wrapper(*args, **kwargs): + kernel_tracepoints = lttngpy.get_tracepoints(domain_type=lttngpy.LTTNG_DOMAIN_KERNEL) + syscalls = lttngpy.get_syscalls() + error = ', '.join( + f'{name}: {lttngpy.lttng_strerror(error_code)}' for name, error_code in ( + ('kernel tracepoints', kernel_tracepoints), + ('syscalls', syscalls), + ) + if isinstance(error_code, int) + ) + if error: + raise unittest.SkipTest(f'kernel tracer is required: {error}') + return func(*args, **kwargs) + return wrapper + + @unittest.skipIf(not is_lttng_installed(minimum_version='2.9.0'), 'LTTng is required') class TestROS2TraceCLI(unittest.TestCase): @@ -316,13 +334,7 @@ def test_default_tracing(self) -> None: shutil.rmtree(tmpdir) - @unittest.skipIf( - ( - isinstance(lttngpy.get_tracepoints(domain_type=lttngpy.LTTNG_DOMAIN_KERNEL), int) or - isinstance(lttngpy.get_syscalls(), int) - ), - 'kernel tracer is required', - ) + @skip_if_no_kernel_tracing def test_kernel_tracing(self) -> None: tmpdir = self.create_test_tmpdir('test_kernel_tracing') session_name = 'test_kernel_tracing'