Tests: Cleanup: add `register_buffer_usage_notify_trigger()` util function
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 7 Feb 2020 17:01:40 +0000 (12:01 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 4 Mar 2021 16:59:19 +0000 (11:59 -0500)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0ebfb41e3faf5ec468852f90fff51cbfb739fde3
Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479

tests/regression/tools/notification/notification.c

index e59f2428d579f7755a058b160279109aba88dabb..e995bb657b934ce0f1c2f44526b802b74b6fe9d7 100644 (file)
@@ -527,97 +527,124 @@ end:
        return;
 }
 
-static void test_notification_channel(const char *session_name,
+enum buffer_usage_type {
+       BUFFER_USAGE_TYPE_LOW,
+       BUFFER_USAGE_TYPE_HIGH,
+};
+
+static int register_buffer_usage_notify_trigger(const char *session_name,
                const char *channel_name,
                const enum lttng_domain_type domain_type,
-               const char **argv)
+               enum buffer_usage_type buffer_usage_type,
+               double ratio,
+               struct lttng_condition **condition,
+               struct lttng_action **action,
+               struct lttng_trigger **trigger)
 {
-       int ret = 0;
        enum lttng_condition_status condition_status;
-       enum lttng_notification_channel_status nc_status;
-
-       struct lttng_action *action = NULL;
-       struct lttng_notification *notification = NULL;
-       struct lttng_notification_channel *notification_channel = NULL;
-       struct lttng_trigger *trigger = NULL;
-
-       struct lttng_condition *low_condition = NULL;
-       struct lttng_condition *high_condition = NULL;
-
-       double low_ratio = 0.0;
-       double high_ratio = 0.90;
+       struct lttng_action *tmp_action = NULL;
+       struct lttng_condition *tmp_condition = NULL;
+       struct lttng_trigger *tmp_trigger = NULL;
+       int ret = 0;
 
        /* Set-up */
-       action = lttng_action_notify_create();
+       tmp_action = lttng_action_notify_create();
        if (!action) {
                fail("Setup error on action creation");
-               goto end;
-       }
-
-       /* Register a low condition with a ratio */
-       low_condition = lttng_condition_buffer_usage_low_create();
-       if (!low_condition) {
-               fail("Setup error on low_condition creation");
-               goto end;
-       }
-       condition_status = lttng_condition_buffer_usage_set_threshold_ratio(
-                       low_condition, low_ratio);
-       if (condition_status != LTTNG_CONDITION_STATUS_OK) {
-               fail("Setup error on low_condition creation");
-               goto end;
+               ret = -1;
+               goto error;
        }
 
-       ret = setup_buffer_usage_condition(low_condition, "low_condition",
-                       session_name, channel_name, domain_type);
-       if (ret) {
-               fail("Setup error on low condition creation");
-               goto end;
+       if (buffer_usage_type == BUFFER_USAGE_TYPE_LOW) {
+               tmp_condition = lttng_condition_buffer_usage_low_create();
+       } else {
+               tmp_condition = lttng_condition_buffer_usage_high_create();
        }
 
-       /* Register a high condition with a ratio */
-       high_condition = lttng_condition_buffer_usage_high_create();
-       if (!high_condition) {
-               fail("Setup error on high_condition creation");
-               goto end;
+       if (!tmp_condition) {
+               fail("Setup error on condition creation");
+               ret = -1;
+               goto error;
        }
 
+       /* Set the buffer usage threashold */
        condition_status = lttng_condition_buffer_usage_set_threshold_ratio(
-                       high_condition, high_ratio);
+                       tmp_condition, ratio);
        if (condition_status != LTTNG_CONDITION_STATUS_OK) {
-               fail("Setup error on high_condition creation");
-               goto end;
+               fail("Setup error on condition creation");
+               ret = -1;
+               goto error;
        }
 
-       ret = setup_buffer_usage_condition(high_condition, "high_condition",
+       ret = setup_buffer_usage_condition(tmp_condition, "condition_name",
                        session_name, channel_name, domain_type);
        if (ret) {
-               fail("Setup error on high condition creation");
-               goto end;
+               fail("Setup error on condition creation");
+               ret = -1;
+               goto error;
        }
 
-       /* Register the triggers for low and high condition */
-       trigger = lttng_trigger_create(low_condition, action);
-       if (!trigger) {
-               fail("Setup error on low trigger creation");
-               goto end;
+       /* Register the trigger for condition. */
+       tmp_trigger = lttng_trigger_create(tmp_condition, tmp_action);
+       if (!tmp_trigger) {
+               fail("Setup error on trigger creation");
+               ret = -1;
+               goto error;
        }
 
-       ret = lttng_register_trigger(trigger);
+       ret = lttng_register_trigger(tmp_trigger);
        if (ret) {
-               fail("Setup error on low trigger registration");
-               goto end;
+               fail("Setup error on trigger registration");
+               ret = -1;
+               goto error;
        }
 
-       lttng_trigger_destroy(trigger);
-       trigger = NULL;
+       *condition = tmp_condition;
+       *trigger = tmp_trigger;
+       *action = tmp_action;
+       goto end;
 
-       trigger = lttng_trigger_create(high_condition, action);
-       if (!trigger) {
-               fail("Setup error on high trigger creation");
+error:
+       lttng_action_destroy(tmp_action);
+       lttng_condition_destroy(tmp_condition);
+       lttng_trigger_destroy(tmp_trigger);
+
+end:
+       return ret;
+}
+
+static void test_notification_channel(const char *session_name,
+               const char *channel_name,
+               const enum lttng_domain_type domain_type,
+               const char **argv)
+{
+       int ret = 0;
+       enum lttng_notification_channel_status nc_status;
+
+       struct lttng_action *low_action = NULL;
+       struct lttng_action *high_action = NULL;
+       struct lttng_notification *notification = NULL;
+       struct lttng_notification_channel *notification_channel = NULL;
+       struct lttng_trigger *low_trigger = NULL;
+       struct lttng_trigger *high_trigger = NULL;
+
+       struct lttng_condition *low_condition = NULL;
+       struct lttng_condition *high_condition = NULL;
+
+       const double low_ratio = 0.0;
+       const double high_ratio = 0.90;
+
+       ret = register_buffer_usage_notify_trigger(session_name, channel_name,
+                       domain_type, BUFFER_USAGE_TYPE_LOW, low_ratio,
+                       &low_condition, &low_action, &low_trigger);
+       if (ret) {
+               fail("Setup error on low trigger registration");
                goto end;
        }
 
-       ret = lttng_register_trigger(trigger);
+       ret = register_buffer_usage_notify_trigger(session_name, channel_name,
+                       domain_type, BUFFER_USAGE_TYPE_HIGH, high_ratio,
+                       &high_condition, &high_action, &high_trigger);
        if (ret) {
                fail("Setup error on high trigger registration");
                goto end;
@@ -774,8 +801,10 @@ static void test_notification_channel(const char *session_name,
 
 end:
        lttng_notification_channel_destroy(notification_channel);
-       lttng_trigger_destroy(trigger);
-       lttng_action_destroy(action);
+       lttng_trigger_destroy(low_trigger);
+       lttng_trigger_destroy(high_trigger);
+       lttng_action_destroy(low_action);
+       lttng_action_destroy(high_action);
        lttng_condition_destroy(low_condition);
        lttng_condition_destroy(high_condition);
 }
This page took 0.028229 seconds and 4 git commands to generate.