X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fnotification%2Fbase_client.c;h=1f7158aea34457782fb6a7e34005e88795f3b672;hb=HEAD;hp=70ad763abe51aa1645bfd9c6b2678a75dd6e8b51;hpb=53089c7cac36de845865cfb920f84725a1303c09;p=lttng-tools.git diff --git a/tests/regression/tools/notification/base_client.c b/tests/regression/tools/notification/base_client.c index 70ad763ab..1f7158aea 100644 --- a/tests/regression/tools/notification/base_client.c +++ b/tests/regression/tools/notification/base_client.c @@ -9,24 +9,24 @@ * */ -#include -#include -#include -#include -#include -#include - #include +#include #include #include #include #include #include #include +#include #include #include #include -#include + +#include +#include +#include +#include +#include static unsigned int nr_notifications = 0; static unsigned int nr_expected_notifications = 0; @@ -35,21 +35,22 @@ static const char *channel_name = NULL; static double threshold_ratio = 0.0; static uint64_t threshold_bytes = 0; static bool is_threshold_ratio = false; +static bool use_action_list = false; static enum lttng_condition_type buffer_usage_type = LTTNG_CONDITION_TYPE_UNKNOWN; static enum lttng_domain_type domain_type = LTTNG_DOMAIN_NONE; -int handle_condition( - const struct lttng_condition *condition, - const struct lttng_evaluation *condition_evaluation); +int handle_condition(const struct lttng_condition *condition, + const struct lttng_evaluation *condition_evaluation); -static -int parse_arguments(char **argv) +static int parse_arguments(char **argv) { + int sscanf_ret; const char *domain_type_string = NULL; const char *buffer_usage_type_string = NULL; const char *buffer_usage_threshold_type = NULL; const char *buffer_usage_threshold_value = NULL; const char *nr_expected_notifications_string = NULL; + const char *use_action_list_value = NULL; session_name = argv[1]; channel_name = argv[2]; @@ -58,6 +59,7 @@ int parse_arguments(char **argv) buffer_usage_threshold_type = argv[5]; buffer_usage_threshold_value = argv[6]; nr_expected_notifications_string = argv[7]; + use_action_list_value = argv[8]; /* Parse arguments */ /* Domain type */ @@ -87,16 +89,36 @@ int parse_arguments(char **argv) /* Ratio or bytes ? */ if (!strcasecmp("bytes", buffer_usage_threshold_type)) { is_threshold_ratio = false; - sscanf(buffer_usage_threshold_value, "%" SCNu64, &threshold_bytes); + sscanf_ret = sscanf(buffer_usage_threshold_value, "%" SCNu64, &threshold_bytes); + if (sscanf_ret != 1) { + printf("error: Invalid buffer usage threshold value bytes (integer), sscanf returned %d\n", + sscanf_ret); + goto error; + } } if (!strcasecmp("ratio", buffer_usage_threshold_type)) { is_threshold_ratio = true; - sscanf(buffer_usage_threshold_value, "%lf", &threshold_ratio); + sscanf_ret = sscanf(buffer_usage_threshold_value, "%lf", &threshold_ratio); + if (sscanf_ret != 1) { + printf("error: Invalid buffer usage threshold value ratio (float), sscanf returned %d\n", + sscanf_ret); + goto error; + } } /* Number of notification to expect */ - sscanf(nr_expected_notifications_string, "%d", &nr_expected_notifications); + sscanf_ret = sscanf(nr_expected_notifications_string, "%d", &nr_expected_notifications); + if (sscanf_ret != 1) { + printf("error: Invalid nr_expected_notifications, sscanf returned %d\n", + sscanf_ret); + goto error; + } + + /* Put notify action in a group. */ + if (!strcasecmp("1", use_action_list_value)) { + use_action_list = true; + } return 0; error: @@ -107,11 +129,13 @@ int main(int argc, char **argv) { int ret = 0; enum lttng_condition_status condition_status; + enum lttng_action_status action_status; enum lttng_notification_channel_status nc_status; struct lttng_notification_channel *notification_channel = NULL; struct lttng_condition *condition = NULL; struct lttng_action *action = NULL; struct lttng_trigger *trigger = NULL; + enum lttng_error_code ret_code; /* * Disable buffering on stdout. @@ -120,7 +144,7 @@ int main(int argc, char **argv) */ setbuf(stdout, NULL); - if (argc < 8) { + if (argc < 9) { printf("error: Missing arguments for tests\n"); ret = 1; goto end; @@ -133,8 +157,8 @@ int main(int argc, char **argv) } /* Setup */ - notification_channel = lttng_notification_channel_create( - lttng_session_daemon_notification_endpoint); + notification_channel = + lttng_notification_channel_create(lttng_session_daemon_notification_endpoint); if (!notification_channel) { printf("error: Could not create notification channel\n"); ret = 1; @@ -162,10 +186,10 @@ int main(int argc, char **argv) if (is_threshold_ratio) { condition_status = lttng_condition_buffer_usage_set_threshold_ratio( - condition, threshold_ratio); + condition, threshold_ratio); } else { - condition_status = lttng_condition_buffer_usage_set_threshold( - condition, threshold_bytes); + condition_status = + lttng_condition_buffer_usage_set_threshold(condition, threshold_bytes); } if (condition_status != LTTNG_CONDITION_STATUS_OK) { @@ -174,33 +198,60 @@ int main(int argc, char **argv) goto end; } - condition_status = lttng_condition_buffer_usage_set_session_name( - condition, session_name); + condition_status = lttng_condition_buffer_usage_set_session_name(condition, session_name); if (condition_status != LTTNG_CONDITION_STATUS_OK) { printf("error: Could not set session name\n"); ret = 1; goto end; } - condition_status = lttng_condition_buffer_usage_set_channel_name( - condition, channel_name); + condition_status = lttng_condition_buffer_usage_set_channel_name(condition, channel_name); if (condition_status != LTTNG_CONDITION_STATUS_OK) { printf("error: Could not set channel name\n"); ret = 1; goto end; } - condition_status = lttng_condition_buffer_usage_set_domain_type( - condition, domain_type); + condition_status = lttng_condition_buffer_usage_set_domain_type(condition, domain_type); if (condition_status != LTTNG_CONDITION_STATUS_OK) { printf("error: Could not set domain type\n"); ret = 1; goto end; } - action = lttng_action_notify_create(); - if (!action) { - printf("error: Could not create action notify\n"); - ret = 1; - goto end; + if (use_action_list) { + struct lttng_action *notify, *group; + + group = lttng_action_list_create(); + if (!group) { + printf("error: Could not create action list\n"); + ret = 1; + goto end; + } + + notify = lttng_action_notify_create(); + if (!notify) { + lttng_action_destroy(group); + printf("error: Could not create action notify\n"); + ret = 1; + goto end; + } + + action_status = lttng_action_list_add_action(group, notify); + if (action_status != LTTNG_ACTION_STATUS_OK) { + printf("error: Could not add action notify to action list\n"); + lttng_action_destroy(group); + lttng_action_destroy(notify); + ret = 1; + goto end; + } + + action = group; + } else { + action = lttng_action_notify_create(); + if (!action) { + printf("error: Could not create action notify\n"); + ret = 1; + goto end; + } } trigger = lttng_trigger_create(condition, action); @@ -210,14 +261,14 @@ int main(int argc, char **argv) goto end; } - ret = lttng_register_trigger(trigger); + ret_code = lttng_register_trigger_with_automatic_name(trigger); /* * An equivalent trigger might already be registered if an other app * registered an equivalent trigger. */ - if (ret < 0 && ret != -LTTNG_ERR_TRIGGER_EXISTS) { - printf("error: %s\n", lttng_strerror(ret)); + if (ret_code != LTTNG_OK && ret_code != LTTNG_ERR_TRIGGER_EXISTS) { + printf("error: %s\n", lttng_strerror(-ret_code)); ret = 1; goto end; } @@ -243,9 +294,8 @@ int main(int argc, char **argv) goto end; } /* Receive the next notification. */ - status = lttng_notification_channel_get_next_notification( - notification_channel, - ¬ification); + status = lttng_notification_channel_get_next_notification(notification_channel, + ¬ification); switch (status) { case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK: @@ -265,7 +315,7 @@ int main(int argc, char **argv) goto end; default: /* Unhandled conditions / errors. */ - printf("error: Unknown notification channel status\n"); + printf("error: Unknown notification channel status (%d) \n", status); ret = 1; goto end; } @@ -296,9 +346,8 @@ end: return ret; } -int handle_condition( - const struct lttng_condition *condition, - const struct lttng_evaluation *evaluation) +int handle_condition(const struct lttng_condition *condition, + const struct lttng_evaluation *evaluation) { int ret = 0; const char *string_low = "low"; @@ -320,22 +369,19 @@ int handle_condition( } /* Fetch info to test */ - ret = lttng_condition_buffer_usage_get_session_name(condition, - &condition_session_name); + ret = lttng_condition_buffer_usage_get_session_name(condition, &condition_session_name); if (ret) { printf("error: session name could not be fetched\n"); ret = 1; goto end; } - ret = lttng_condition_buffer_usage_get_channel_name(condition, - &condition_channel_name); + ret = lttng_condition_buffer_usage_get_channel_name(condition, &condition_channel_name); if (ret) { printf("error: channel name could not be fetched\n"); ret = 1; goto end; } - ret = lttng_condition_buffer_usage_get_domain_type(condition, - &condition_domain_type); + ret = lttng_condition_buffer_usage_get_domain_type(condition, &condition_domain_type); if (ret) { printf("error: domain type could not be fetched\n"); ret = 1; @@ -361,8 +407,7 @@ int handle_condition( } if (is_threshold_ratio) { - lttng_evaluation_buffer_usage_get_usage_ratio( - evaluation, &buffer_usage_ratio); + lttng_evaluation_buffer_usage_get_usage_ratio(evaluation, &buffer_usage_ratio); switch (condition_type) { case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: if (buffer_usage_ratio > threshold_ratio) { @@ -384,8 +429,7 @@ int handle_condition( goto end; } } else { - lttng_evaluation_buffer_usage_get_usage( - evaluation, &buffer_usage_bytes); + lttng_evaluation_buffer_usage_get_usage(evaluation, &buffer_usage_bytes); switch (condition_type) { case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: if (buffer_usage_bytes > threshold_bytes) {