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.h>
11 #include <common/macros.h>
12 #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_trigger_status trigger_status
;
26 trigger
= lttng_trigger_create(condition
, action
);
27 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
28 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
29 ret
= lttng_register_trigger(trigger
);
34 * Register a trigger with the given condition and an action group containing a
35 * single notify action.
37 static void register_trigger_action_group_notify(
38 const char *trigger_name
, struct lttng_condition
*condition
)
40 struct lttng_action
*action_notify
;
41 struct lttng_action
*action_group
;
42 enum lttng_action_status action_status
;
44 action_group
= lttng_action_group_create();
45 action_notify
= lttng_action_notify_create();
46 action_status
= lttng_action_group_add_action(
47 action_group
, action_notify
);
48 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
50 register_trigger(trigger_name
, condition
, action_group
);
53 static struct lttng_condition
*create_session_consumed_size_condition(
54 const char *session_name
, uint64_t threshold
)
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(
62 condition
, session_name
);
63 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
64 condition_status
= lttng_condition_session_consumed_size_set_threshold(
65 condition
, threshold
);
66 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
71 static void test_session_consumed_size_condition(void)
73 register_trigger_action_group_notify(
74 "trigger-with-session-consumed-size-condition",
75 create_session_consumed_size_condition(
76 "the-session-name", 1234));
79 static void fill_buffer_usage_condition(struct lttng_condition
*condition
,
80 const char *session_name
,
81 const char *channel_name
,
82 enum lttng_domain_type domain_type
)
84 enum lttng_condition_status condition_status
;
86 condition_status
= lttng_condition_buffer_usage_set_session_name(
87 condition
, session_name
);
88 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
89 condition_status
= lttng_condition_buffer_usage_set_channel_name(
90 condition
, channel_name
);
91 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
92 condition_status
= lttng_condition_buffer_usage_set_domain_type(
93 condition
, domain_type
);
94 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
97 static void fill_buffer_usage_bytes_condition(struct lttng_condition
*condition
,
98 const char *session_name
,
99 const char *channel_name
,
100 enum lttng_domain_type domain_type
,
103 enum lttng_condition_status condition_status
;
105 fill_buffer_usage_condition(
106 condition
, session_name
, channel_name
, domain_type
);
107 condition_status
= lttng_condition_buffer_usage_set_threshold(
108 condition
, threshold
);
109 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
112 static void fill_buffer_usage_ratio_condition(struct lttng_condition
*condition
,
113 const char *session_name
,
114 const char *channel_name
,
115 enum lttng_domain_type domain_type
,
118 enum lttng_condition_status condition_status
;
120 fill_buffer_usage_condition(
121 condition
, session_name
, channel_name
, domain_type
);
122 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
124 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
127 static struct lttng_condition
*create_buffer_usage_high_bytes_condition(
128 const char *session_name
,
129 const char *channel_name
,
130 enum lttng_domain_type domain_type
,
133 struct lttng_condition
*condition
;
135 condition
= lttng_condition_buffer_usage_high_create();
136 fill_buffer_usage_bytes_condition(condition
, session_name
, channel_name
,
137 domain_type
, threshold
);
142 static struct lttng_condition
*create_buffer_usage_low_bytes_condition(
143 const char *session_name
,
144 const char *channel_name
,
145 enum lttng_domain_type domain_type
,
148 struct lttng_condition
*condition
;
150 condition
= lttng_condition_buffer_usage_low_create();
151 fill_buffer_usage_bytes_condition(condition
, session_name
, channel_name
,
152 domain_type
, threshold
);
157 static struct lttng_condition
*create_buffer_usage_high_ratio_condition(
158 const char *session_name
,
159 const char *channel_name
,
160 enum lttng_domain_type domain_type
,
163 struct lttng_condition
*condition
;
165 condition
= lttng_condition_buffer_usage_high_create();
166 fill_buffer_usage_ratio_condition(condition
, session_name
, channel_name
,
172 static struct lttng_condition
*create_buffer_usage_low_ratio_condition(
173 const char *session_name
,
174 const char *channel_name
,
175 enum lttng_domain_type domain_type
,
178 struct lttng_condition
*condition
;
180 condition
= lttng_condition_buffer_usage_low_create();
181 fill_buffer_usage_ratio_condition(condition
, session_name
, channel_name
,
187 static void test_buffer_usage_conditions(void)
189 register_trigger_action_group_notify(
190 "trigger-with-buffer-usage-high-bytes-condition",
191 create_buffer_usage_high_bytes_condition(
192 "the-session-name", "the-channel-name",
193 LTTNG_DOMAIN_UST
, 1234));
195 register_trigger_action_group_notify(
196 "trigger-with-buffer-usage-low-bytes-condition",
197 create_buffer_usage_low_bytes_condition(
198 "the-session-name", "the-channel-name",
199 LTTNG_DOMAIN_UST
, 2345));
201 register_trigger_action_group_notify(
202 "trigger-with-buffer-usage-high-ratio-condition",
203 create_buffer_usage_high_ratio_condition(
204 "the-session-name", "the-channel-name",
205 LTTNG_DOMAIN_UST
, 0.25));
207 register_trigger_action_group_notify(
208 "trigger-with-buffer-usage-low-ratio-condition",
209 create_buffer_usage_low_ratio_condition(
210 "the-session-name", "the-channel-name",
211 LTTNG_DOMAIN_UST
, 0.4));
214 static void fill_session_rotation_condition(
215 struct lttng_condition
*condition
, const char *session_name
)
217 enum lttng_condition_status condition_status
;
219 condition_status
= lttng_condition_session_rotation_set_session_name(
220 condition
, session_name
);
221 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
224 static struct lttng_condition
*create_session_rotation_ongoing_condition(
225 const char *session_name
)
227 struct lttng_condition
*condition
;
229 condition
= lttng_condition_session_rotation_ongoing_create();
231 fill_session_rotation_condition(condition
, session_name
);
236 static struct lttng_condition
*create_session_rotation_completed_condition(
237 const char *session_name
)
239 struct lttng_condition
*condition
;
241 condition
= lttng_condition_session_rotation_completed_create();
243 fill_session_rotation_condition(condition
, session_name
);
248 static void test_session_rotation_conditions(void)
250 register_trigger_action_group_notify(
251 "trigger-with-session-rotation-ongoing-condition",
252 create_session_rotation_ongoing_condition(
253 "the-session-name"));
255 register_trigger_action_group_notify(
256 "trigger-with-session-rotation-completed-condition",
257 create_session_rotation_completed_condition(
258 "the-session-name"));
263 void (*callback
)(void);
266 "test_session_consumed_size_condition",
267 test_session_consumed_size_condition
,
269 {"test_buffer_usage_conditions", test_buffer_usage_conditions
},
270 {"test_session_rotation_conditions",
271 test_session_rotation_conditions
},
274 static void show_known_tests(void)
278 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
279 fprintf(stderr
, " - %s\n", tests
[i
].name
);
283 int main(int argc
, char **argv
)
290 fprintf(stderr
, "Usage: %s <test>\n", argv
[0]);
291 fprintf(stderr
, "\n");
292 fprintf(stderr
, "Test must be one of:\n");
299 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
300 if (strcmp(tests
[i
].name
, test
) == 0) {
305 if (i
== ARRAY_SIZE(tests
)) {
306 fprintf(stderr
, "Unrecognized test `%s`\n", test
);
307 fprintf(stderr
, "\n");
308 fprintf(stderr
, "Known tests:\n");