lib: add post condition assertions for current thread error after user functions
[babeltrace.git] / src / lib / graph / graph.c
index 44a5e1b4d657d98de328859f0df095734ea42e6b..0f30ec46a529a217c451810b13347492cfb560af 100644 (file)
@@ -40,6 +40,7 @@
 #include <babeltrace2/value-const.h>
 #include "lib/value.h"
 #include <unistd.h>
+#include <stdbool.h>
 #include <glib.h>
 
 #include "component-class-sink-simple.h"
@@ -587,6 +588,7 @@ int consume_graph_sink(struct bt_component_sink *comp)
                consume_status == BT_FUNC_STATUS_MEMORY_ERROR,
                "Invalid component status returned by consuming method: "
                "status=%s", bt_common_func_status_string(consume_status));
+       BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(consume_status);
        if (consume_status) {
                if (consume_status < 0) {
                        BT_LIB_LOGW_APPEND_CAUSE(
@@ -773,8 +775,15 @@ enum bt_graph_run_status bt_graph_run(struct bt_graph *graph)
                }
        } while (status == BT_FUNC_STATUS_OK);
 
-       if (g_queue_is_empty(graph->sinks_to_consume)) {
-               status = BT_FUNC_STATUS_END;
+       if (status == BT_FUNC_STATUS_END) {
+               /*
+                * The last call to consume_no_check() returned
+                * `BT_FUNC_STATUS_END`, but bt_graph_run() has no
+                * `BT_GRAPH_RUN_STATUS_END` status: replace with
+                * `BT_GRAPH_RUN_STATUS_OK` (success: graph ran
+                * completely).
+                */
+               status = BT_FUNC_STATUS_OK;
        }
 
 end:
@@ -1092,7 +1101,7 @@ enum bt_graph_listener_func_status bt_graph_notify_port_added(
                        listeners = graph->listeners.source_output_port_added;
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
 
                break;
@@ -1107,7 +1116,7 @@ enum bt_graph_listener_func_status bt_graph_notify_port_added(
                        listeners = graph->listeners.filter_output_port_added;
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
 
                break;
@@ -1119,13 +1128,13 @@ enum bt_graph_listener_func_status bt_graph_notify_port_added(
                        listeners = graph->listeners.sink_input_port_added;
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
 
                break;
        }
        default:
-               abort();
+               bt_common_abort();
        }
 
        for (i = 0; i < listeners->len; i++) {
@@ -1136,6 +1145,7 @@ enum bt_graph_listener_func_status bt_graph_notify_port_added(
 
                BT_ASSERT(listener->func);
                status = listener->func(comp, port, listener->base.data);
+               BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status);
                if (status != BT_FUNC_STATUS_OK) {
                        goto end;
                }
@@ -1180,7 +1190,7 @@ enum bt_graph_listener_func_status bt_graph_notify_ports_connected(
                                graph->listeners.source_sink_ports_connected;
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
 
                break;
@@ -1197,13 +1207,13 @@ enum bt_graph_listener_func_status bt_graph_notify_ports_connected(
                                graph->listeners.filter_sink_ports_connected;
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
 
                break;
        }
        default:
-               abort();
+               bt_common_abort();
        }
 
        for (i = 0; i < listeners->len; i++) {
@@ -1214,6 +1224,7 @@ enum bt_graph_listener_func_status bt_graph_notify_ports_connected(
                BT_ASSERT(listener->func);
                status = listener->func(upstream_comp, downstream_comp,
                        upstream_port, downstream_port, listener->base.data);
+               BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(status);
                if (status != BT_FUNC_STATUS_OK) {
                        goto end;
                }
@@ -1330,6 +1341,7 @@ int add_component_with_init_method_data(
                init_status = init_method(component, NULL, params, init_method_data);
                BT_LOGD("User method returned: status=%s",
                        bt_common_func_status_string(init_status));
+               BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(init_status);
                if (init_status != BT_FUNC_STATUS_OK) {
                        if (init_status < 0) {
                                BT_LIB_LOGW_APPEND_CAUSE(
This page took 0.025598 seconds and 4 git commands to generate.