lib: assign a unique ID to each pre/postcond. and report it on failure
[babeltrace.git] / src / lib / graph / query-executor.c
index e922d3ea1bd3c52c5c38e4d9b31605e9f05d3c9f..e68d1e978470cb7c535546e8fe7549d373d91e4d 100644 (file)
@@ -1,23 +1,7 @@
 /*
- * Copyright 2017-2018 Philippe Proulx <pproulx@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.
+ * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  */
 
 #define BT_LOG_TAG "LIB/QUERY-EXECUTOR"
@@ -25,8 +9,7 @@
 
 #include "common/assert.h"
 #include "common/common.h"
-#include "lib/assert-pre.h"
-#include "lib/assert-post.h"
+#include "lib/assert-cond.h"
 #include <babeltrace2/graph/query-executor.h>
 #include <babeltrace2/graph/component-class.h>
 #include <babeltrace2/graph/query-executor.h>
@@ -74,8 +57,8 @@ struct bt_query_executor *bt_query_executor_create_with_method_data(
        struct bt_query_executor *query_exec;
 
        BT_ASSERT_PRE_NO_ERROR();
-       BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
-       BT_ASSERT_PRE_NON_NULL(object, "Object");
+       BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
+       BT_ASSERT_PRE_NON_NULL("object", object, "Object");
        BT_LIB_LOGD("Creating query executor: "
                "%![comp-cls-]+C, object=\"%s\", %![params-]+v",
                comp_cls, object, params);
@@ -157,10 +140,11 @@ enum bt_query_executor_query_status bt_query_executor_query(
        enum bt_query_executor_query_status status;
        enum bt_component_class_query_method_status query_status;
        method_t method = NULL;
+       const char *method_name = NULL;
 
        BT_ASSERT_PRE_NO_ERROR();
-       BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor");
-       BT_ASSERT_PRE_NON_NULL(user_result, "Result (output)");
+       BT_ASSERT_PRE_QUERY_EXEC_NON_NULL(query_exec);
+       BT_ASSERT_PRE_RES_OUT_NON_NULL(user_result);
 
        /*
         * Initial check: is the query executor already interrupted? If
@@ -192,6 +176,7 @@ enum bt_query_executor_query_status bt_query_executor_query(
                        query_exec->comp_cls;
 
                method = (method_t) src_cc->methods.query;
+               method_name = "bt_component_class_source_query_method";
                break;
        }
        case BT_COMPONENT_CLASS_TYPE_FILTER:
@@ -200,6 +185,7 @@ enum bt_query_executor_query_status bt_query_executor_query(
                        query_exec->comp_cls;
 
                method = (method_t) flt_cc->methods.query;
+               method_name = "bt_component_class_filter_query_method";
                break;
        }
        case BT_COMPONENT_CLASS_TYPE_SINK:
@@ -208,6 +194,7 @@ enum bt_query_executor_query_status bt_query_executor_query(
                        query_exec->comp_cls;
 
                method = (method_t) sink_cc->methods.query;
+               method_name = "bt_component_class_sink_query_method";
                break;
        }
        default:
@@ -234,9 +221,10 @@ enum bt_query_executor_query_status bt_query_executor_query(
                query_exec->params, query_exec->method_data, user_result);
        BT_LIB_LOGD("User method returned: status=%s, %![res-]+v",
                bt_common_func_status_string(query_status), *user_result);
-       BT_ASSERT_POST(query_status != BT_FUNC_STATUS_OK || *user_result,
+       BT_ASSERT_POST(method_name, "status-ok-with-result",
+               query_status != BT_FUNC_STATUS_OK || *user_result,
                "User method returned `BT_FUNC_STATUS_OK` without a result.");
-       BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(query_status);
+       BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(method_name, query_status);
        status = (int) query_status;
 
        if (status < 0) {
@@ -259,8 +247,8 @@ enum bt_query_executor_add_interrupter_status bt_query_executor_add_interrupter(
                const struct bt_interrupter *intr)
 {
        BT_ASSERT_PRE_NO_ERROR();
-       BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor");
-       BT_ASSERT_PRE_NON_NULL(intr, "Interrupter");
+       BT_ASSERT_PRE_QUERY_EXEC_NON_NULL(query_exec);
+       BT_ASSERT_PRE_INTR_NON_NULL(intr);
        g_ptr_array_add(query_exec->interrupters, (void *) intr);
        bt_object_get_ref_no_null_check(intr);
        BT_LIB_LOGD("Added interrupter to query executor: "
@@ -271,7 +259,7 @@ enum bt_query_executor_add_interrupter_status bt_query_executor_add_interrupter(
 
 bt_bool bt_query_executor_is_interrupted(const struct bt_query_executor *query_exec)
 {
-       BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor");
+       BT_ASSERT_PRE_QUERY_EXEC_NON_NULL(query_exec);
        return (bt_bool) bt_interrupter_array_any_is_set(
                query_exec->interrupters);
 }
@@ -279,7 +267,7 @@ bt_bool bt_query_executor_is_interrupted(const struct bt_query_executor *query_e
 struct bt_interrupter *bt_query_executor_borrow_default_interrupter(
                struct bt_query_executor *query_exec)
 {
-       BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor");
+       BT_ASSERT_PRE_QUERY_EXEC_NON_NULL(query_exec);
        return query_exec->default_interrupter;
 }
 
@@ -287,7 +275,7 @@ enum bt_query_executor_set_logging_level_status
 bt_query_executor_set_logging_level(struct bt_query_executor *query_exec,
                enum bt_logging_level log_level)
 {
-       BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor");
+       BT_ASSERT_PRE_QUERY_EXEC_NON_NULL(query_exec);
        query_exec->log_level = log_level;
        return BT_FUNC_STATUS_OK;
 }
@@ -295,7 +283,7 @@ bt_query_executor_set_logging_level(struct bt_query_executor *query_exec,
 enum bt_logging_level bt_query_executor_get_logging_level(
                const struct bt_query_executor *query_exec)
 {
-       BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor");
+       BT_ASSERT_PRE_QUERY_EXEC_NON_NULL(query_exec);
        return query_exec->log_level;
 }
 
This page took 0.028659 seconds and 4 git commands to generate.