Skip to content

Commit

Permalink
Provide error strings if kernel tracing test skipped
Browse files Browse the repository at this point in the history
Signed-off-by: Christophe Bedard <[email protected]>
  • Loading branch information
christophebedard committed Oct 8, 2024
1 parent c105689 commit 2f0c39a
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions test_ros2trace/test/test_ros2trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 2f0c39a

Please sign in to comment.