3 # Copyright (C) 2023 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
10 from typing
import Any
, Callable
, Type
, Dict
, Iterator
13 from collections
.abc
import Mapping
16 Test the listing of recording rules associated to a channel.
19 # Import in-tree test utils
20 test_utils_import_path
= pathlib
.Path(__file__
).absolute().parents
[3] / "utils"
21 sys
.path
.append(str(test_utils_import_path
))
26 def test_identical_recording_rules_except_log_level_rule_type(tap
, test_env
):
27 # type: (lttngtest.TapGenerator, lttngtest._Environment) -> None
29 "Test adding and listing event rules that differ only by their log level rule type"
32 client
= lttngtest
.LTTngClient(test_env
, log
=tap
.diagnostic
)
34 session
= client
.create_session()
35 channel
= session
.add_channel(lttngtest
.TracingDomain
.User
)
38 app
= test_env
.launch_wait_trace_test_application(100)
40 llr_exactly
= lttngtest
.LogLevelRuleExactly(lttngtest
.UserLogLevel
.DEBUG_LINE
)
41 llr_as_severe_as
= lttngtest
.LogLevelRuleAsSevereAs(
42 lttngtest
.UserLogLevel
.DEBUG_LINE
45 recording_rule_log_at_level
= lttngtest
.UserTracepointEventRule(
46 "lttng*", None, llr_exactly
, None
48 recording_rule_log_at_least_level
= lttngtest
.UserTracepointEventRule(
49 "lttng*", None, llr_as_severe_as
, None
51 recording_rule_no_log_level
= lttngtest
.UserTracepointEventRule(
52 "lttng*", None, None, None
55 with tap
.case("Adding a recording rule with an `exact` log level rule"):
56 channel
.add_recording_rule(recording_rule_log_at_level
)
58 with tap
.case("Adding a recording rule with an `as severe as` log level rule"):
59 channel
.add_recording_rule(recording_rule_log_at_least_level
)
62 "Adding a recording rule without a log level rule (all log levels enabled)"
64 channel
.add_recording_rule(recording_rule_no_log_level
)
67 for rule
in channel
.recording_rules
:
69 rule
!= recording_rule_no_log_level
70 and rule
!= recording_rule_log_at_level
71 and rule
!= recording_rule_log_at_least_level
75 rule_match_count
= rule_match_count
+ 1
78 rule_match_count
== 3,
79 "Recording rules are added and listed",
83 tap
= lttngtest
.TapGenerator(4)
84 tap
.diagnostic("Test the addition and listing of event rules associated to a channel")
86 with lttngtest
.test_environment(with_sessiond
=True, log
=tap
.diagnostic
) as test_env
:
87 test_identical_recording_rules_except_log_level_rule_type(tap
, test_env
)
89 sys
.exit(0 if tap
.is_successful
else 1)