Debian Codegraph @

tests/regression/tools/channel/test_cli_legacy_channel_buffering_policies.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 #
3 # SPDX-FileCopyrightText: 2025 Olivier Dion <[email protected]>
4 # SPDX-License-Identifier: GPL-2.0-only
5
6 import os
7 import pathlib
8 import shlex
9 import sys
10
11 import xml.etree.ElementTree as xml
12
13 # Import in-tree test utils
14 test_utils_import_path = pathlib.Path(__file__).absolute().parents[3] / "utils"
15 sys.path.append(str(test_utils_import_path))
16
17 import lttngtest
18
19 """
20 Ensure that legacy options, `--buffers-uid', `--buffers-pid' and
21 `--buffers-global' for the command `enable-channel' are working as before with
22 the introduction of the new `--buffer-ownership' option.
23 """
24
25
26 def do_test_cli_buffer_ownership(
27 client: lttngtest.LTTngClient,
28 session: lttngtest.Session,
29 legacy: str,
30 new: str,
31 expected_buffer_type: str,
32 userspace: bool = True,
33 ):
34
35 def make_channel(ownership):
36 name = lttngtest.lttngctl.Channel._generate_name()
37 args = [
38 "enable-channel",
39 "--userspace" if userspace else "--kernel",
40 "--session",
41 session.name,
42 ownership,
43 name,
44 ]
45 client._run_cmd(" ".join(shlex.quote(x) for x in args))
46 return name
47
48 channel_names = {make_channel(legacy), make_channel(new)}
49 session_xml = client.list_session_raw(session.name)
50
51 # Check that only a single domain is present and that both channels are in it.
52 domains = client._mi_get_in_element(session_xml, "domains")
53 domain = domains[0]
54
55 tap.test(
56 client._mi_get_in_element(domain, "buffer_type").text == expected_buffer_type,
57 "Domain has correct buffer type",
58 )
59
60 channels = client._mi_get_in_element(domain, "channels")
61
62 for channel in channels:
63 name = client._mi_get_in_element(channel, "name").text
64 channel_names.remove(name)
65
66 tap.test(
67 len(channel_names) == 0, "All created channels were part of the same domain"
68 )
69
70
71 def test_cli_buffer_ownership_userspace(
72 client: lttngtest.LTTngClient, tap: lttngtest.TapGenerator
73 ):
74 # Userspace domains
75 for legacy, new, buffer_type in [
76 ("--buffers-uid", "--buffer-ownership=user", "PER_UID"),
77 ("--buffers-pid", "--buffer-ownership=process", "PER_PID"),
78 ]:
79 tap.diagnostic("Testing buffer ownership: {} and {}".format(legacy, new))
80 session = client.create_session()
81 do_test_cli_buffer_ownership(client, session, legacy, new, buffer_type)
82 session.destroy()
83
84
85 def test_cli_buffer_ownership_kernel(
86 client: lttngtest.LTTngClient, tap: lttngtest.TapGenerator
87 ):
88 for legacy, new, buffer_type in [
89 (
90 "--buffers-global",
91 "--buffer-ownership=system",
92 "GLOBAL",
93 )
94 ]:
95 tap.diagnostic("Testing buffer ownership: {} and {}".format(legacy, new))
96 session = client.create_session()
97 do_test_cli_buffer_ownership(
98 client, session, legacy, new, buffer_type, userspace=False
99 )
100 session.destroy()
101
102
103 BUFFER_OWNERSHIP_COUNT = 3
104 TEST_PER_BUFFER_OWNERSHIP = 2
105
106 tap = lttngtest.TapGenerator(BUFFER_OWNERSHIP_COUNT * TEST_PER_BUFFER_OWNERSHIP)
107
108 with lttngtest.test_environment(
109 with_sessiond=True, log=tap.diagnostic, enable_kernel_domain=True
110 ) as test_env:
111 client = lttngtest.LTTngClient(test_env, log=tap.diagnostic)
112 test_cli_buffer_ownership_userspace(client, tap)
113
114 if test_env.run_kernel_tests():
115 test_cli_buffer_ownership_kernel(client, tap)
116 else:
117 tap.skip_all_remaining(
118 "Remaining tests require root to create kernel domain buffers"
119 )
120
121 sys.exit(0 if tap.is_successful else 1)