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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
/*
* SPDX-FileCopyrightText: 2021 Simon Marchi <simon.marchi@efficios.com>
*
* SPDX-License-Identifier: GPL-2.0-only
*
*/
/* Utility to register some triggers, for test purposes. */
#include <common/filter/filter-ast.hpp>
#include <common/macros.hpp>
#include <lttng/lttng.h>
#include <stdlib.h>
#include <string.h>
static void register_trigger(const char *trigger_name,
struct lttng_condition *condition,
struct lttng_action *action)
{
struct lttng_trigger *trigger;
enum lttng_error_code ret;
trigger = lttng_trigger_create(condition, action);
ret = lttng_register_trigger_with_name(trigger, trigger_name);
LTTNG_ASSERT(ret == LTTNG_OK);
lttng_trigger_destroy(trigger);
lttng_condition_destroy(condition);
lttng_action_destroy(action);
}
/*
* Register a trigger with the given condition and an action list containing a
* single notify action.
*/
static void register_trigger_action_list_notify(const char *trigger_name,
struct lttng_condition *condition)
{
struct lttng_action *action_notify;
struct lttng_action *action_list;
enum lttng_action_status action_status;
action_list = lttng_action_list_create();
action_notify = lttng_action_notify_create();
action_status = lttng_action_list_add_action(action_list, action_notify);
LTTNG_ASSERT(action_status == LTTNG_ACTION_STATUS_OK);
lttng_action_destroy(action_notify);
register_trigger(trigger_name, condition, action_list);
}
static struct lttng_condition *create_session_consumed_size_condition(const char *session_name,
uint64_t threshold)
{
struct lttng_condition *condition;
enum lttng_condition_status condition_status;
condition = lttng_condition_session_consumed_size_create();
condition_status =
lttng_condition_session_consumed_size_set_session_name(condition, session_name);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
condition_status =
lttng_condition_session_consumed_size_set_threshold(condition, threshold);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
return condition;
}
static void test_session_consumed_size_condition()
{
register_trigger_action_list_notify(
"trigger-with-session-consumed-size-condition",
create_session_consumed_size_condition("the-session-name", 1234));
}
static void fill_buffer_usage_condition(struct lttng_condition *condition,
const char *session_name,
const char *channel_name,
enum lttng_domain_type domain_type)
{
enum lttng_condition_status condition_status;
condition_status = lttng_condition_buffer_usage_set_session_name(condition, session_name);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
condition_status = lttng_condition_buffer_usage_set_channel_name(condition, channel_name);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
condition_status = lttng_condition_buffer_usage_set_domain_type(condition, domain_type);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
}
static void fill_buffer_usage_bytes_condition(struct lttng_condition *condition,
const char *session_name,
const char *channel_name,
enum lttng_domain_type domain_type,
uint64_t threshold)
{
enum lttng_condition_status condition_status;
fill_buffer_usage_condition(condition, session_name, channel_name, domain_type);
condition_status = lttng_condition_buffer_usage_set_threshold(condition, threshold);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
}
static void fill_buffer_usage_ratio_condition(struct lttng_condition *condition,
const char *session_name,
const char *channel_name,
enum lttng_domain_type domain_type,
double ratio)
{
enum lttng_condition_status condition_status;
fill_buffer_usage_condition(condition, session_name, channel_name, domain_type);
condition_status = lttng_condition_buffer_usage_set_threshold_ratio(condition, ratio);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
}
static struct lttng_condition *
create_buffer_usage_high_bytes_condition(const char *session_name,
const char *channel_name,
enum lttng_domain_type domain_type,
uint64_t threshold)
{
struct lttng_condition *condition;
condition = lttng_condition_buffer_usage_high_create();
fill_buffer_usage_bytes_condition(
condition, session_name, channel_name, domain_type, threshold);
return condition;
}
static struct lttng_condition *
create_buffer_usage_low_bytes_condition(const char *session_name,
const char *channel_name,
enum lttng_domain_type domain_type,
uint64_t threshold)
{
struct lttng_condition *condition;
condition = lttng_condition_buffer_usage_low_create();
fill_buffer_usage_bytes_condition(
condition, session_name, channel_name, domain_type, threshold);
return condition;
}
static struct lttng_condition *
create_buffer_usage_high_ratio_condition(const char *session_name,
const char *channel_name,
enum lttng_domain_type domain_type,
double ratio)
{
struct lttng_condition *condition;
condition = lttng_condition_buffer_usage_high_create();
fill_buffer_usage_ratio_condition(
condition, session_name, channel_name, domain_type, ratio);
return condition;
}
static struct lttng_condition *
create_buffer_usage_low_ratio_condition(const char *session_name,
const char *channel_name,
enum lttng_domain_type domain_type,
double ratio)
{
struct lttng_condition *condition;
condition = lttng_condition_buffer_usage_low_create();
fill_buffer_usage_ratio_condition(
condition, session_name, channel_name, domain_type, ratio);
return condition;
}
static void test_buffer_usage_conditions()
{
register_trigger_action_list_notify(
"trigger-with-buffer-usage-high-bytes-condition",
create_buffer_usage_high_bytes_condition(
"the-session-name", "the-channel-name", LTTNG_DOMAIN_UST, 1234));
register_trigger_action_list_notify(
"trigger-with-buffer-usage-low-bytes-condition",
create_buffer_usage_low_bytes_condition(
"the-session-name", "the-channel-name", LTTNG_DOMAIN_UST, 2345));
register_trigger_action_list_notify(
"trigger-with-buffer-usage-high-ratio-condition",
create_buffer_usage_high_ratio_condition(
"the-session-name", "the-channel-name", LTTNG_DOMAIN_UST, 0.25));
register_trigger_action_list_notify(
"trigger-with-buffer-usage-low-ratio-condition",
create_buffer_usage_low_ratio_condition(
"the-session-name", "the-channel-name", LTTNG_DOMAIN_UST, 0.4));
}
static void fill_session_rotation_condition(struct lttng_condition *condition,
const char *session_name)
{
enum lttng_condition_status condition_status;
condition_status =
lttng_condition_session_rotation_set_session_name(condition, session_name);
LTTNG_ASSERT(condition_status == LTTNG_CONDITION_STATUS_OK);
}
static struct lttng_condition *create_session_rotation_ongoing_condition(const char *session_name)
{
struct lttng_condition *condition;
condition = lttng_condition_session_rotation_ongoing_create();
fill_session_rotation_condition(condition, session_name);
return condition;
}
static struct lttng_condition *create_session_rotation_completed_condition(const char *session_name)
{
struct lttng_condition *condition;
condition = lttng_condition_session_rotation_completed_create();
fill_session_rotation_condition(condition, session_name);
return condition;
}
static void test_session_rotation_conditions()
{
register_trigger_action_list_notify(
"trigger-with-session-rotation-ongoing-condition",
create_session_rotation_ongoing_condition("the-session-name"));
register_trigger_action_list_notify(
"trigger-with-session-rotation-completed-condition",
create_session_rotation_completed_condition("the-session-name"));
}
static struct {
const char *name;
void (*callback)();
} tests[] = {
{
"test_session_consumed_size_condition",
test_session_consumed_size_condition,
},
{ "test_buffer_usage_conditions", test_buffer_usage_conditions },
{ "test_session_rotation_conditions", test_session_rotation_conditions },
};
static void show_known_tests()
{
size_t i;
for (i = 0; i < ARRAY_SIZE(tests); i++) {
fprintf(stderr, " - %s\n", tests[i].name);
}
}
int main(int argc, char **argv)
{
const char *test;
size_t i;
int ret;
if (argc != 2) {
fprintf(stderr, "Usage: %s <test>\n", argv[0]);
fprintf(stderr, "\n");
fprintf(stderr, "Test must be one of:\n");
show_known_tests();
goto error;
}
test = argv[1];
for (i = 0; i < ARRAY_SIZE(tests); i++) {
if (strcmp(tests[i].name, test) == 0) {
break;
}
}
if (i == ARRAY_SIZE(tests)) {
fprintf(stderr, "Unrecognized test `%s`\n", test);
fprintf(stderr, "\n");
fprintf(stderr, "Known tests:\n");
show_known_tests();
goto error;
}
tests[i].callback();
ret = 0;
goto end;
error:
ret = 1;
end:
return ret;
}
|