From 5b876b066f8c4022939c7ba05c7b6e94a585653d Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 2 May 2017 14:27:24 -0400 Subject: [PATCH] Internalize trace listener API and bt_ctf_trace_get_metadata_string() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since the trace listener API is internal now, remove test_trace_listener.c because it cannot find the function symbols. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/babeltrace/ctf-ir/trace-internal.h | 16 +- include/babeltrace/ctf-ir/trace.h | 12 - tests/Makefile.am | 1 - tests/lib/Makefile.am | 5 +- tests/lib/test_trace_listener.c | 263 --------------------- 5 files changed, 16 insertions(+), 281 deletions(-) delete mode 100644 tests/lib/test_trace_listener.c diff --git a/include/babeltrace/ctf-ir/trace-internal.h b/include/babeltrace/ctf-ir/trace-internal.h index 619104d3..f49e85bc 100644 --- a/include/babeltrace/ctf-ir/trace-internal.h +++ b/include/babeltrace/ctf-ir/trace-internal.h @@ -119,7 +119,21 @@ is modified, \p listener is called with the new element and with @prenotnull{listener} @postrefcountsame{trace_class} */ -extern int bt_ctf_trace_add_listener(struct bt_ctf_trace *trace_class, +BT_HIDDEN +int bt_ctf_trace_add_listener(struct bt_ctf_trace *trace_class, bt_ctf_listener_cb listener, void *data); +/* + * bt_ctf_trace_get_metadata_string: get metadata string. + * + * Get the trace's TSDL metadata. The caller assumes the ownership of the + * returned string. + * + * @param trace Trace instance. + * + * Returns the metadata string on success, NULL on error. + */ +BT_HIDDEN +char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace); + #endif /* BABELTRACE_CTF_IR_TRACE_INTERNAL_H */ diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index feb5a6de..f3584225 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -870,18 +870,6 @@ extern int bt_ctf_trace_visit(struct bt_ctf_trace *trace_class, /** @} */ -/* - * bt_ctf_trace_get_metadata_string: get metadata string. - * - * Get the trace's TSDL metadata. The caller assumes the ownership of the - * returned string. - * - * @param trace Trace instance. - * - * Returns the metadata string on success, NULL on error. - */ -extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace); - #ifdef __cplusplus } #endif diff --git a/tests/Makefile.am b/tests/Makefile.am index 72a00dc4..0d0c2ebc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -17,7 +17,6 @@ TESTS = bin/test_trace_read \ lib/test_ctf_ir_ref \ lib/test_bt_ctf_field_type_validation \ lib/test_ir_visit \ - lib/test_trace_listener \ lib/test_bt_notification_heap \ lib/test_plugin_complete \ lib/test_graph_topo \ diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 39ab7d21..060ff29d 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -26,8 +26,6 @@ test_bt_ctf_field_type_validation_LDADD = $(COMMON_TEST_LDADD) test_ir_visit_LDADD = $(COMMON_TEST_LDADD) -test_trace_listener_LDADD = $(COMMON_TEST_LDADD) - test_bt_notification_heap_LDADD = $(COMMON_TEST_LDADD) test_plugin_LDADD = $(COMMON_TEST_LDADD) @@ -40,7 +38,7 @@ test_bt_notification_iterator_LDADD = $(COMMON_TEST_LDADD) noinst_PROGRAMS = test_bitfield test_ctf_writer test_bt_values \ test_ctf_ir_ref test_bt_ctf_field_type_validation test_ir_visit \ - test_trace_listener test_bt_notification_heap test_plugin test_graph_topo \ + test_bt_notification_heap test_plugin test_graph_topo \ test_cc_prio_map test_bt_notification_iterator test_bitfield_SOURCES = test_bitfield.c @@ -49,7 +47,6 @@ test_bt_values_SOURCES = test_bt_values.c test_ctf_ir_ref_SOURCES = test_ctf_ir_ref.c test_bt_ctf_field_type_validation_SOURCES = test_bt_ctf_field_type_validation.c test_ir_visit_SOURCES = test_ir_visit.c -test_trace_listener_SOURCES = test_trace_listener.c test_bt_notification_heap_SOURCES = test_bt_notification_heap.c test_plugin_SOURCES = test_plugin.c test_graph_topo_SOURCES = test_graph_topo.c diff --git a/tests/lib/test_trace_listener.c b/tests/lib/test_trace_listener.c deleted file mode 100644 index c472399c..00000000 --- a/tests/lib/test_trace_listener.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * test_trace_lister.c - * - * CTF IR trace listener interface test - * - * Copyright 2016 - Jérémie Galarneau - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "tap/tap.h" -#include -#include -#include -#include -#include -#include -#include - -#define NR_TESTS 21 - -struct visitor_state { - int i; -}; - -struct expected_result { - const char *object_name; - enum bt_ctf_object_type object_type; -}; - -struct expected_result expected_results[] = { - { NULL, BT_CTF_OBJECT_TYPE_TRACE }, - { "sc1", BT_CTF_OBJECT_TYPE_STREAM_CLASS }, - { "ec1", BT_CTF_OBJECT_TYPE_EVENT_CLASS }, - { "sc2", BT_CTF_OBJECT_TYPE_STREAM_CLASS }, - { "ec2", BT_CTF_OBJECT_TYPE_EVENT_CLASS }, - { "ec3", BT_CTF_OBJECT_TYPE_EVENT_CLASS }, - /* Elements added after the initial add_listener call. */ - { "sc3", BT_CTF_OBJECT_TYPE_STREAM_CLASS }, - { "ec4", BT_CTF_OBJECT_TYPE_EVENT_CLASS }, - { "ec5", BT_CTF_OBJECT_TYPE_EVENT_CLASS }, -}; - -const char *object_type_str(enum bt_ctf_object_type type) -{ - switch (type) { - case BT_CTF_OBJECT_TYPE_TRACE: - return "trace"; - case BT_CTF_OBJECT_TYPE_STREAM_CLASS: - return "stream class"; - case BT_CTF_OBJECT_TYPE_STREAM: - return "stream"; - case BT_CTF_OBJECT_TYPE_EVENT_CLASS: - return "event class"; - case BT_CTF_OBJECT_TYPE_EVENT: - return "event"; - default: - return "unknown"; - } -} - -struct bt_ctf_event_class *init_event_class(const char *name) -{ - int ret; - struct bt_ctf_event_class *ec = bt_ctf_event_class_create(name); - struct bt_ctf_field_type *int_field = - bt_ctf_field_type_integer_create(8); - - if (!ec || !int_field) { - goto error; - } - - ret = bt_ctf_event_class_add_field(ec, int_field, "an_int_field"); - if (ret) { - goto error; - } - - BT_PUT(int_field); - return ec; -error: - BT_PUT(ec); - BT_PUT(int_field); - return NULL; -} - -struct bt_ctf_trace *init_trace(void) -{ - int ret; - struct bt_ctf_trace *trace = bt_ctf_trace_create(); - struct bt_ctf_stream_class *sc1 = bt_ctf_stream_class_create("sc1"); - struct bt_ctf_stream_class *sc2 = bt_ctf_stream_class_create("sc2"); - struct bt_ctf_event_class *ec1 = init_event_class("ec1"); - struct bt_ctf_event_class *ec2 = init_event_class("ec2"); - struct bt_ctf_event_class *ec3 = init_event_class("ec3"); - - if (!trace || !sc1 || !sc2 || !ec1 || !ec2 || !ec3) { - goto end; - } - - ret = bt_ctf_trace_set_native_byte_order(trace, - BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); - if (ret) { - goto error; - } - - ret = bt_ctf_stream_class_add_event_class(sc1, ec1); - if (ret) { - goto error; - } - - ret = bt_ctf_stream_class_add_event_class(sc2, ec2); - if (ret) { - goto error; - } - - ret = bt_ctf_stream_class_add_event_class(sc2, ec3); - if (ret) { - goto error; - } - - ret = bt_ctf_trace_add_stream_class(trace, sc1); - if (ret) { - goto error; - } - - ret = bt_ctf_trace_add_stream_class(trace, sc2); - if (ret) { - goto error; - } -end: - BT_PUT(sc1); - BT_PUT(sc2); - BT_PUT(ec1); - BT_PUT(ec2); - BT_PUT(ec3); - return trace; -error: - BT_PUT(trace); - goto end; -} - -void visitor(struct bt_ctf_object *object, void *data) -{ - bool names_match; - const char *object_name; - struct visitor_state *state = data; - struct expected_result *expected = &expected_results[state->i++]; - - switch (bt_ctf_object_get_type(object)) { - case BT_CTF_OBJECT_TYPE_TRACE: - object_name = NULL; - names_match = expected->object_name == NULL; - break; - case BT_CTF_OBJECT_TYPE_STREAM_CLASS: - object_name = bt_ctf_stream_class_get_name( - bt_ctf_object_get_object(object)); - if (!object_name) { - return; - } - - names_match = !strcmp(object_name, expected->object_name); - break; - case BT_CTF_OBJECT_TYPE_EVENT_CLASS: - object_name = bt_ctf_event_class_get_name( - bt_ctf_object_get_object(object)); - if (!object_name) { - return; - } - - names_match = !strcmp(object_name, expected->object_name); - break; - default: - diag("Encountered an unexpected type while visiting trace"); - return; - } - - ok(expected->object_type == bt_ctf_object_get_type(object), - "Encoutered object type %s, expected %s", - object_type_str(expected->object_type), - object_type_str(bt_ctf_object_get_type(object))); - ok(names_match, "Element name is %s, expected %s", - object_name ? : "NULL", - expected->object_name ? : "NULL"); -} - -int main(int argc, char **argv) -{ - int ret, index; - struct bt_ctf_trace *trace; - struct visitor_state state = { 0 }; - struct bt_ctf_stream_class *sc3; - struct bt_ctf_event_class *ec4, *ec5; - - plan_tests(NR_TESTS); - - trace = init_trace(); - if (!trace) { - diag("Failed to initialize reference trace, aborting."); - exit(-1); - } - - ret = bt_ctf_trace_add_listener(trace, visitor, &state); - ok(!ret, "bt_ctf_trace_add_listener returned success"); - - /* - * Validate that listeners are notified when new objects are added to a - * trace. - */ - sc3 = bt_ctf_stream_class_create("sc3"); - if (!sc3) { - diag("Failed to create stream class, aborting."); - exit(-1); - } - - ec4 = init_event_class("ec4"); - ec5 = init_event_class("ec5"); - if (!ec4 || !ec5) { - diag("Failed to create event classes, aborting."); - exit(-1); - } - - ret = bt_ctf_stream_class_add_event_class(sc3, ec4); - if (ret) { - diag("Failed to add event class to stream class, aborting."); - } - - index = state.i; - ret = bt_ctf_trace_add_stream_class(trace, sc3); - if (ret) { - diag("Failed to add stream class sc3 to trace, aborting."); - exit(-1); - } - - /* Listener should have been invoked two times (sc3 + ec4). */ - ok(index + 2 == state.i, "trace modification listener has been invoked twice after addition of a stream class"); - - index = state.i; - ret = bt_ctf_stream_class_add_event_class(sc3, ec5); - if (ret) { - diag("Failed to add event class to stream class, aborting."); - exit(-1); - } - - ok(index + 1 == state.i, "trace modification has been invoked once after addition of an event class"); - - BT_PUT(sc3); - BT_PUT(ec5); - BT_PUT(ec4); - BT_PUT(trace); - return exit_status(); -} - -- 2.34.1