2 * Copyright (C) 2021 Simon Marchi <simon.marchi@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 /* Utility to register some triggers, for test purposes. */
10 #include <common/filter/filter-ast.hpp>
11 #include <common/macros.hpp>
13 #include <lttng/lttng.h>
18 static void register_trigger(const char *trigger_name
,
19 struct lttng_condition
*condition
,
20 struct lttng_action
*action
)
22 struct lttng_trigger
*trigger
;
23 enum lttng_error_code ret
;
25 trigger
= lttng_trigger_create(condition
, action
);
26 ret
= lttng_register_trigger_with_name(trigger
, trigger_name
);
27 LTTNG_ASSERT(ret
== LTTNG_OK
);
28 lttng_trigger_destroy(trigger
);
29 lttng_condition_destroy(condition
);
30 lttng_action_destroy(action
);
34 * Register a trigger with the given condition and an action list containing a
35 * single notify action.
37 static void register_trigger_action_list_notify(const char *trigger_name
,
38 struct lttng_condition
*condition
)
40 struct lttng_action
*action_notify
;
41 struct lttng_action
*action_list
;
42 enum lttng_action_status action_status
;
44 action_list
= lttng_action_list_create();
45 action_notify
= lttng_action_notify_create();
46 action_status
= lttng_action_list_add_action(action_list
, action_notify
);
47 LTTNG_ASSERT(action_status
== LTTNG_ACTION_STATUS_OK
);
48 lttng_action_destroy(action_notify
);
50 register_trigger(trigger_name
, condition
, action_list
);
53 static struct lttng_condition
*create_session_consumed_size_condition(const char *session_name
,
56 struct lttng_condition
*condition
;
57 enum lttng_condition_status condition_status
;
59 condition
= lttng_condition_session_consumed_size_create();
61 lttng_condition_session_consumed_size_set_session_name(condition
, session_name
);
62 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
64 lttng_condition_session_consumed_size_set_threshold(condition
, threshold
);
65 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
70 static void test_session_consumed_size_condition()
72 register_trigger_action_list_notify(
73 "trigger-with-session-consumed-size-condition",
74 create_session_consumed_size_condition("the-session-name", 1234));
77 static void fill_buffer_usage_condition(struct lttng_condition
*condition
,
78 const char *session_name
,
79 const char *channel_name
,
80 enum lttng_domain_type domain_type
)
82 enum lttng_condition_status condition_status
;
84 condition_status
= lttng_condition_buffer_usage_set_session_name(condition
, session_name
);
85 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
86 condition_status
= lttng_condition_buffer_usage_set_channel_name(condition
, channel_name
);
87 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
88 condition_status
= lttng_condition_buffer_usage_set_domain_type(condition
, domain_type
);
89 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
92 static void fill_buffer_usage_bytes_condition(struct lttng_condition
*condition
,
93 const char *session_name
,
94 const char *channel_name
,
95 enum lttng_domain_type domain_type
,
98 enum lttng_condition_status condition_status
;
100 fill_buffer_usage_condition(condition
, session_name
, channel_name
, domain_type
);
101 condition_status
= lttng_condition_buffer_usage_set_threshold(condition
, threshold
);
102 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
105 static void fill_buffer_usage_ratio_condition(struct lttng_condition
*condition
,
106 const char *session_name
,
107 const char *channel_name
,
108 enum lttng_domain_type domain_type
,
111 enum lttng_condition_status condition_status
;
113 fill_buffer_usage_condition(condition
, session_name
, channel_name
, domain_type
);
114 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(condition
, ratio
);
115 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
118 static struct lttng_condition
*
119 create_buffer_usage_high_bytes_condition(const char *session_name
,
120 const char *channel_name
,
121 enum lttng_domain_type domain_type
,
124 struct lttng_condition
*condition
;
126 condition
= lttng_condition_buffer_usage_high_create();
127 fill_buffer_usage_bytes_condition(
128 condition
, session_name
, channel_name
, domain_type
, threshold
);
133 static struct lttng_condition
*
134 create_buffer_usage_low_bytes_condition(const char *session_name
,
135 const char *channel_name
,
136 enum lttng_domain_type domain_type
,
139 struct lttng_condition
*condition
;
141 condition
= lttng_condition_buffer_usage_low_create();
142 fill_buffer_usage_bytes_condition(
143 condition
, session_name
, channel_name
, domain_type
, threshold
);
148 static struct lttng_condition
*
149 create_buffer_usage_high_ratio_condition(const char *session_name
,
150 const char *channel_name
,
151 enum lttng_domain_type domain_type
,
154 struct lttng_condition
*condition
;
156 condition
= lttng_condition_buffer_usage_high_create();
157 fill_buffer_usage_ratio_condition(
158 condition
, session_name
, channel_name
, domain_type
, ratio
);
163 static struct lttng_condition
*
164 create_buffer_usage_low_ratio_condition(const char *session_name
,
165 const char *channel_name
,
166 enum lttng_domain_type domain_type
,
169 struct lttng_condition
*condition
;
171 condition
= lttng_condition_buffer_usage_low_create();
172 fill_buffer_usage_ratio_condition(
173 condition
, session_name
, channel_name
, domain_type
, ratio
);
178 static void test_buffer_usage_conditions()
180 register_trigger_action_list_notify(
181 "trigger-with-buffer-usage-high-bytes-condition",
182 create_buffer_usage_high_bytes_condition(
183 "the-session-name", "the-channel-name", LTTNG_DOMAIN_UST
, 1234));
185 register_trigger_action_list_notify(
186 "trigger-with-buffer-usage-low-bytes-condition",
187 create_buffer_usage_low_bytes_condition(
188 "the-session-name", "the-channel-name", LTTNG_DOMAIN_UST
, 2345));
190 register_trigger_action_list_notify(
191 "trigger-with-buffer-usage-high-ratio-condition",
192 create_buffer_usage_high_ratio_condition(
193 "the-session-name", "the-channel-name", LTTNG_DOMAIN_UST
, 0.25));
195 register_trigger_action_list_notify(
196 "trigger-with-buffer-usage-low-ratio-condition",
197 create_buffer_usage_low_ratio_condition(
198 "the-session-name", "the-channel-name", LTTNG_DOMAIN_UST
, 0.4));
201 static void fill_session_rotation_condition(struct lttng_condition
*condition
,
202 const char *session_name
)
204 enum lttng_condition_status condition_status
;
207 lttng_condition_session_rotation_set_session_name(condition
, session_name
);
208 LTTNG_ASSERT(condition_status
== LTTNG_CONDITION_STATUS_OK
);
211 static struct lttng_condition
*create_session_rotation_ongoing_condition(const char *session_name
)
213 struct lttng_condition
*condition
;
215 condition
= lttng_condition_session_rotation_ongoing_create();
217 fill_session_rotation_condition(condition
, session_name
);
222 static struct lttng_condition
*create_session_rotation_completed_condition(const char *session_name
)
224 struct lttng_condition
*condition
;
226 condition
= lttng_condition_session_rotation_completed_create();
228 fill_session_rotation_condition(condition
, session_name
);
233 static void test_session_rotation_conditions()
235 register_trigger_action_list_notify(
236 "trigger-with-session-rotation-ongoing-condition",
237 create_session_rotation_ongoing_condition("the-session-name"));
239 register_trigger_action_list_notify(
240 "trigger-with-session-rotation-completed-condition",
241 create_session_rotation_completed_condition("the-session-name"));
249 "test_session_consumed_size_condition",
250 test_session_consumed_size_condition
,
252 { "test_buffer_usage_conditions", test_buffer_usage_conditions
},
253 { "test_session_rotation_conditions", test_session_rotation_conditions
},
256 static void show_known_tests()
260 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
261 fprintf(stderr
, " - %s\n", tests
[i
].name
);
265 int main(int argc
, char **argv
)
272 fprintf(stderr
, "Usage: %s <test>\n", argv
[0]);
273 fprintf(stderr
, "\n");
274 fprintf(stderr
, "Test must be one of:\n");
281 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
282 if (strcmp(tests
[i
].name
, test
) == 0) {
287 if (i
== ARRAY_SIZE(tests
)) {
288 fprintf(stderr
, "Unrecognized test `%s`\n", test
);
289 fprintf(stderr
, "\n");
290 fprintf(stderr
, "Known tests:\n");