X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Ftrigger%2Futils%2Fnotification-client.c;h=7803fd51dac96eca02d4b05a9f56bc3c6f152ae0;hp=aecc478bd3fcc63e02ac79eb9e28c46978c458a7;hb=7d59def241ece2d8d1c77ecce46431019b51a494;hpb=6ba3189157b61924ae7fe08ff32fb02e81f56f24 diff --git a/tests/regression/tools/trigger/utils/notification-client.c b/tests/regression/tools/trigger/utils/notification-client.c index aecc478bd..7803fd51d 100644 --- a/tests/regression/tools/trigger/utils/notification-client.c +++ b/tests/regression/tools/trigger/utils/notification-client.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include "utils.h" @@ -22,7 +22,7 @@ static struct option long_options[] = { /* These options set a flag. */ - {"trigger", required_argument, 0, 'i'}, + {"trigger", required_argument, 0, 't'}, {"sync-after-notif-register", required_argument, 0, 'a'}, {0, 0, 0, 0} }; @@ -53,44 +53,35 @@ static bool action_group_contains_notify( return false; } -static bool is_expected_trigger_name(const char *expected_trigger_name, +static bool is_trigger_name(const char *expected_trigger_name, struct lttng_notification *notification) { - int ret = false; - const struct lttng_evaluation *evaluation = - lttng_notification_get_evaluation(notification); - const enum lttng_condition_type type = - lttng_evaluation_get_type(evaluation); - - switch (type) { - case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE: - case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: - case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: - case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING: - case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED: - break; - case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT: - { - const char *trigger_name; - enum lttng_evaluation_status evaluation_status; - - evaluation_status = - lttng_evaluation_event_rule_get_trigger_name( - evaluation, &trigger_name); - if (evaluation_status != LTTNG_EVALUATION_STATUS_OK) { - fprintf(stderr, "Failed to get trigger name of event rule notification\n"); - ret = -1; - break; - } + const char *trigger_name = NULL; + enum lttng_trigger_status trigger_status; + const struct lttng_trigger *trigger; + bool names_match; - ret = true; - break; + trigger = lttng_notification_get_trigger(notification); + if (!trigger) { + fprintf(stderr, "Failed to get trigger from notification\n"); + names_match = false; + goto end; } - default: - fprintf(stderr, "Unknown notification type (%d)\n", type); + + trigger_status = lttng_trigger_get_name(trigger, &trigger_name); + if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { + fprintf(stderr, "Failed to get name from notification's trigger\n"); + names_match = false; + goto end; } - return ret; + names_match = strcmp(expected_trigger_name, trigger_name) == 0; + if (!names_match) { + fprintf(stderr, "Got an unexpected trigger name: name = '%s', expected name = '%s'\n", + trigger_name, expected_trigger_name); + } +end: + return names_match; } int main(int argc, char **argv) @@ -139,6 +130,7 @@ int main(int argc, char **argv) ret = lttng_list_triggers(&triggers); if (ret != LTTNG_OK) { fprintf(stderr, "Failed to list triggers\n"); + ret = -1; goto end; } @@ -149,6 +141,7 @@ int main(int argc, char **argv) goto end; } + /* Look for the trigger we want to subscribe to. */ for (i = 0; i < count; i++) { const struct lttng_trigger *trigger = lttng_triggers_get_at_index(triggers, i); @@ -212,14 +205,16 @@ int main(int argc, char **argv) switch (channel_status) { case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED: printf("Dropped notification\n"); - break; + ret = -1; + goto end; case LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED: - ret = 0; + ret = -1; goto end; case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK: break; case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED: printf("Notification channel was closed by peer.\n"); + ret = -1; break; default: fprintf(stderr, "A communication error occurred on the notification channel.\n"); @@ -227,10 +222,12 @@ int main(int argc, char **argv) goto end; } - ret = is_expected_trigger_name(expected_trigger_name, - notification); + ret = is_trigger_name(expected_trigger_name, notification); lttng_notification_destroy(notification); - if (ret) { + if (!ret) { + ret = -1; + goto end; + } else { ret = 0; goto end; }