File: test_trace_format_kernel.py

package info (click to toggle)
ltt-control 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,860 kB
  • sloc: cpp: 192,012; sh: 28,777; ansic: 10,960; python: 7,108; makefile: 3,520; java: 109; xml: 46
file content (89 lines) | stat: -rwxr-xr-x 2,673 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
#
# SPDX-FileCopyrightText: 2025 Jérémie Galarneau <jeremie.galarneau@efficios.com>
#
# SPDX-License-Identifier: GPL-2.0-only

import pathlib
import sys
import os
import contextlib
import subprocess

# Import in-tree test utils
test_utils_import_path = pathlib.Path(__file__).absolute().parents[3] / "utils"
sys.path.append(str(test_utils_import_path))

import lttngtest
import bt2

from trace_format_helpers import (
    test_local_trace_all_formats,
)


def capture_local_kernel_trace(environment):
    # type: (lttngtest._Environment) -> pathlib.Path
    session_output_location = lttngtest.LocalSessionOutputLocation(
        environment.create_temporary_directory("trace")
    )

    client = lttngtest.LTTngClient(environment, log=tap.diagnostic)

    session = client.create_session(output=session_output_location)
    tap.diagnostic("Created session `{session_name}`".format(session_name=session.name))

    channel = session.add_channel(lttngtest.TracingDomain.User)
    tap.diagnostic("Created channel `{channel_name}`".format(channel_name=channel.name))

    # Only track the events emitted by this process
    session.kernel_vpid_process_attribute_tracker.track(os.getpid())

    channel.add_recording_rule(
        lttngtest.KernelTracepointEventRule("lttng_test_filter_event")
    )

    session.start()

    with lttngtest.kernel_module("lttng-test"):
        tap.diagnostic("Loaded kernel module `lttng-test`")
        tap.diagnostic("Writing to /proc/lttng-test-filter-event")
        with open("/proc/lttng-test-filter-event", "w") as f:
            f.write("10")

        session.stop()
        session.destroy()

    return session_output_location.path


tap = lttngtest.TapGenerator(10)
tap.diagnostic("Test trace format generation (kernel)")

version_parts = tuple(map(int, bt2.__version__.split(".")[:2]))
if version_parts < (2, 1):
    tap.skip_all_remaining(
        "Skipping test: Babeltrace 2.1.0 or later is required to run the trace format test"
    )
    sys.exit(0)

if not lttngtest._Environment.run_kernel_tests():
    tap.skip_all_remaining(
        "Skipping test: Kernel tests are not enabled, skipping trace format test"
    )
    sys.exit(0)

pretty_expect_path = pretty_expect_path = pathlib.Path(__file__).absolute().parents[
    0
] / "kernel-local-trace-pretty.expect{}".format(
    ".32" if lttngtest.getconf("LONG_BIT") == "32" else ""
)
test_local_trace_all_formats(
    tap=tap,
    capture_local_trace=capture_local_kernel_trace,
    pretty_expect_path=pretty_expect_path,
    enable_kernel_domain=True,
    expected_events={"lttng_test_filter_event": 10},
)

sys.exit(0 if tap.is_successful else 1)