Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / tests / regression / tools / notification / base_client.c
index 21a8ac3fe7a2a33775919aa4fab808be7157e31e..b7e1a9f42f8eef81fa0be4ef55d924eec30c3034 100644 (file)
@@ -5,23 +5,8 @@
  *
  * Copyright 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * SPDX-License-Identifier: MIT
  *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
  */
 
 #include <stdio.h>
@@ -29,9 +14,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <inttypes.h>
-#include <assert.h>
 
 #include <lttng/action/action.h>
+#include <lttng/action/list.h>
 #include <lttng/action/notify.h>
 #include <lttng/condition/buffer-usage.h>
 #include <lttng/condition/condition.h>
@@ -41,6 +26,7 @@
 #include <lttng/notification/channel.h>
 #include <lttng/notification/notification.h>
 #include <lttng/trigger/trigger.h>
+#include <lttng/lttng-error.h>
 
 static unsigned int nr_notifications = 0;
 static unsigned int nr_expected_notifications = 0;
@@ -49,6 +35,7 @@ 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;
 
@@ -56,12 +43,16 @@ int handle_condition(
                const struct lttng_condition *condition,
                const struct lttng_evaluation *condition_evaluation);
 
-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];
@@ -70,6 +61,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 */
@@ -99,16 +91,39 @@ 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:
@@ -119,11 +134,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.
@@ -132,7 +149,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;
@@ -201,18 +218,48 @@ int main(int argc, char **argv)
                goto end;
        }
        condition_status = lttng_condition_buffer_usage_set_domain_type(
-                       condition, LTTNG_DOMAIN_UST);
+                       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);
@@ -222,14 +269,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;
        }
@@ -277,7 +324,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;
                }
@@ -297,7 +344,9 @@ end:
        if (trigger) {
                lttng_unregister_trigger(trigger);
        }
-       lttng_notification_channel_unsubscribe(notification_channel, condition);
+       if (lttng_notification_channel_unsubscribe(notification_channel, condition)) {
+               printf("error: channel unsubscribe error\n");
+       }
        lttng_trigger_destroy(trigger);
        lttng_condition_destroy(condition);
        lttng_action_destroy(action);
@@ -330,12 +379,27 @@ int handle_condition(
        }
 
        /* Fetch info to test */
-       lttng_condition_buffer_usage_get_session_name(condition,
+       ret = lttng_condition_buffer_usage_get_session_name(condition,
                        &condition_session_name);
-       lttng_condition_buffer_usage_get_channel_name(condition,
+       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);
-       lttng_condition_buffer_usage_get_domain_type(condition,
+       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);
+       if (ret) {
+               printf("error: domain type could not be fetched\n");
+               ret = 1;
+               goto end;
+       }
 
        if (strcmp(condition_session_name, session_name) != 0) {
                printf("error: session name differs\n");
This page took 0.027373 seconds and 4 git commands to generate.